Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(demo): simplify the UseCase classes and how to set theme #564

Merged
merged 8 commits into from
Oct 12, 2023
Next Next commit
remove the type of a use case
  • Loading branch information
csouchet committed Oct 11, 2023
commit 0347afdb27cab98091ba2a93d145a66a78d7718c
4 changes: 2 additions & 2 deletions demo/hacktoberfest-custom-themes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ <h5>Theme Year</h5>
</div>
<div id="use-case-panel" class="column bg-gray">
<div class="column col-12 text-center">
<h4 id="hacktoberfest-title" class="title"></h4>
<h4 id="title" class="title"></h4>
</div>
<div class="column col-12">
<div id="hacktoberfest-bpmn-container" class="column col-12 bpmn-container"></div>
<div id="bpmn-container" class="column col-12 bpmn-container"></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class HacktoberfestUseCase extends UseCase {

constructor(inputProjectName, title) {
document.querySelector(`[id*="hacktoberfest-title"]`).textContent = title;
document.querySelector(`[id*="hacktoberfest-bpmn-container"]`).textContent = undefined;
super('hacktoberfest', () => getHacktoberfestBpmnDiagram(inputProjectName), false);
super({
getDiagram: () => getHacktoberfestBpmnDiagram(inputProjectName),
navigationEnabled: false,
title
});
}

updateCellsLabel(projectName) {
Expand Down
4 changes: 2 additions & 2 deletions demo/monitoring-all-process-instances/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h5>Displayed information</h5>
</div>
<div id="use-case-panel" class="bg-gray">
<div class="text-center">
<h4 id="monitoring-title"></h4>
<h4 id="title"></h4>
</div>
<div class="columns">
<div id="legend" class="column col-auto col-mx-auto">
Expand Down Expand Up @@ -145,7 +145,7 @@ <h4 id="monitoring-title"></h4>
</div>
</div>
<div class="column col-10 col-mx-auto">
<div id="monitoring-bpmn-container" class="col-12 bpmn-container"></div>
<div id="bpmn-container" class="col-12 bpmn-container"></div>
</div>
</div>
</div>
Expand Down
11 changes: 2 additions & 9 deletions demo/monitoring-all-process-instances/js/monitoring-use-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ class MonitoringUseCase extends UseCase {
#executionData;

constructor(getDiagram, executionData, title) {
document.querySelector(`[id*="monitoring-title"]`).textContent = title;
document.querySelector(`[id*="monitoring-bpmn-container"]`).textContent = undefined;
super('monitoring', getDiagram, true);
super({ getDiagram, navigationEnabled: true, title });
this.#executionData = executionData;
}

display(dataType) {
this.#executionData.updateLegends();
super.display(dataType);
this.displayData(dataType);
}
Expand Down Expand Up @@ -55,10 +54,4 @@ class MonitoringUseCase extends UseCase {
}
console.info('%s data set', dataType);
}


_displayPanel() {
super._displayPanel();
this.#executionData.updateLegends();
}
}
4 changes: 2 additions & 2 deletions demo/prediction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h5>Use case</h5>
</div>
<div id="use-case-panel" class="bg-gray">
<div class="text-center">
<h4 id="prediction-title"></h4>
<h4 id="title"></h4>
</div>
<div class="columns" style="padding: 0 1rem">
<div id="legend" class="column col-2 col-mx-auto state-predicted-late" style="margin: auto; padding-right: 0.7rem">
Expand All @@ -108,7 +108,7 @@ <h4 id="prediction-title"></h4>
</fieldset>
</div>
<div class="column col-10 col-mx-auto">
<div id="prediction-bpmn-container" class="col-12 bpmn-container"></div>
<div id="bpmn-container" class="col-12 bpmn-container"></div>
</div>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions demo/prediction/js/prediction-use-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ class PredicatedLateUseCase extends UseCase {
_executionData;

constructor(title) {
document.querySelector(`[id*="prediction-title"]`).textContent = title;
document.querySelector(`[id*="prediction-bpmn-container"]`).textContent = undefined;
super('prediction', () => pizzaDiagram(), false, {fit: {type: 'Center', margin: 20}});
super({
getDiagram:() => pizzaDiagram(),
navigationEnabled: false,
loadOptions: {fit: {type: 'Center', margin: 20}},
title
});
}

display(dataType) {
Expand Down
53 changes: 8 additions & 45 deletions demo/static/js/use-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const defaultLoadOptions = {
}

class UseCase {
#type;
#getDiagram;
#navigationEnabled;
#loadOptions;
Expand All @@ -13,17 +12,13 @@ class UseCase {
*/
_bpmnVisualization;

#alreadyLoad = false;

constructor(type, getDiagram, navigationEnabled, loadOptions) {
this.#type = type;
constructor({ getDiagram, navigationEnabled, loadOptions, title }) {
this.#getDiagram = getDiagram;
this.#navigationEnabled = navigationEnabled;
this.#loadOptions = {...defaultLoadOptions, ...loadOptions};
}

get type() {
return this.#type;
document.querySelector(`[id*="title"]`).textContent = title;
document.querySelector(`[id*="bpmn-container"]`).textContent = undefined;
}

/**
Expand All @@ -32,16 +27,11 @@ class UseCase {
* @param {string} dataType
*/
display(dataType) {
this._displayPanel();

if (!this.#alreadyLoad) {
this._bpmnVisualization = this._initBpmnVisualization({container: `${this.#type}-bpmn-container`, navigation: {enabled: this.#navigationEnabled}});
this._displayVersionInfoInFooter(); // This is called by each use case available in the page, but this is not an issue. All use the same bpmn-visualization version
this._preLoadDiagram();
this._bpmnVisualization.load(this.#getDiagram(), this.#loadOptions);
this._postLoadDiagram();
this.#alreadyLoad = true;
}
this._bpmnVisualization = this._initBpmnVisualization({container: 'bpmn-container', navigation: {enabled: this.#navigationEnabled}});
this._displayVersionInfoInFooter(); // This is called by each use case available in the page, but this is not an issue. All use the same bpmn-visualization version
this._preLoadDiagram();
this._bpmnVisualization.load(this.#getDiagram(), this.#loadOptions);
this._postLoadDiagram();
}

_displayVersionInfoInFooter() {
Expand Down Expand Up @@ -70,31 +60,4 @@ class UseCase {
*/
_postLoadDiagram() {
}

/**
* Generic implementation
*/
_displayPanel() {
this._displayElementAndHideOthers("bpmn-container");
this._displayElementAndHideOthers("title");
}

/**
* Generic implementation
*/
_displayElementAndHideOthers(subId) {
// Hide all corresponding HTML elements
const bpmnContainers = document.querySelectorAll(`[id*="${subId}"]`);
for (let i = 0; i < bpmnContainers.length; i++) {
bpmnContainers.item(i).classList.add('d-hide');
}

// Display corresponding HTML element
const element = document.getElementById(`${this.#type}-${subId}`);
if(element) {
element.classList.remove('d-hide');
console.info('%s displayed', `${this.#type}-${subId}`);
}
}

}