Skip to content

Commit 532b3db

Browse files
committed
[NAE-1684] Frontend component for data field caseRef
- little refactor - fix the problem with highlighting
1 parent 4341b11 commit 532b3db

File tree

1 file changed

+64
-42
lines changed

1 file changed

+64
-42
lines changed

projects/netgrif-components-core/src/lib/data-fields/case-ref-field/abstract-case-ref-field.component.ts

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,49 +47,64 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
4747
ngAfterViewInit(): void {
4848
this._petriNetResourceService.getNetByCaseId(this.dataField.value).subscribe(net => {
4949
if (net) {
50-
const trans: Array<PetriflowTransition> = [];
51-
const places: Array<PetriflowPlace> = [];
52-
const arcs: Array<PetriflowArc<any>> = [];
53-
let minX: number = Number.MAX_SAFE_INTEGER;
54-
let minY: number = Number.MAX_SAFE_INTEGER;
55-
net.transitions.forEach((value) => {
56-
trans.push(this.createTransitions(value));
57-
minX = Math.min(minX, value.position.x);
58-
minY = Math.min(minY, value.position.y);
59-
})
60-
net.places.forEach((value) => {
61-
places.push(this.createPlace(value));
62-
minX = Math.min(minX, value.position.x);
63-
minY = Math.min(minY, value.position.y);
64-
})
65-
net.arcs.forEach((arc) => {
66-
arcs.push(this.createArcs(trans, places, arc, net));
67-
arc.breakpoints?.forEach(value => {
68-
minX = Math.min(minX, value.x);
69-
minY = Math.min(minY, value.y);
70-
});
71-
});
72-
trans.forEach(value => {
73-
if (net.assignedTasks.includes(value.canvasElement.label.textContent)) {
74-
value.activate();
75-
}
76-
if (this.isEnabled(value, places, arcs)) {
77-
value.canvasElement.element.classList.add('svg-transition-enabled');
78-
}
79-
});
80-
this._petriflowCanvasService.panzoom?.moveTo(-minX + 20, -minY + 20);
81-
if (this.dataField.component?.properties?.lock === 'true') {
82-
setTimeout(() => {
83-
this._petriflowCanvasService.panzoom?.pause();
84-
})
85-
}
50+
this.createNet(net);
8651
}
8752
}, error => {
88-
this._log.error('Getting net by Case ID failed', error);
53+
this._log.error('Getting net by Case ID failed in field ['+ this.dataField.stringId + ']', error);
8954
this._snackBar.openErrorSnackBar(this._translate.instant('dataField.snackBar.caseNetGetFailed'));
9055
});
9156
}
9257

58+
protected createNet(net: PetriNetImport) {
59+
const trans: Array<PetriflowTransition> = [];
60+
const places: Array<PetriflowPlace> = [];
61+
const arcs: Array<PetriflowArc<any>> = [];
62+
let minX: number = Number.MAX_SAFE_INTEGER;
63+
let minY: number = Number.MAX_SAFE_INTEGER;
64+
net.transitions.forEach((value) => {
65+
const t = this.createTransitions(value)
66+
trans.push(t);
67+
minX = Math.min(minX, value.position.x);
68+
minY = Math.min(minY, value.position.y);
69+
this.setPlaceActions(t.canvasElement.element);
70+
})
71+
net.places.forEach((value) => {
72+
const p = this.createPlace(value)
73+
places.push(p);
74+
minX = Math.min(minX, value.position.x);
75+
minY = Math.min(minY, value.position.y);
76+
this.setPlaceActions(p.canvasElement.element);
77+
p.canvasElement.markingTokens.forEach(markingToken => {
78+
this.setPlaceActions(markingToken);
79+
});
80+
})
81+
net.arcs.forEach((arc) => {
82+
const a = this.createArcs(trans, places, arc, net)
83+
arcs.push(a);
84+
arc.breakpoints?.forEach(value => {
85+
minX = Math.min(minX, value.x);
86+
minY = Math.min(minY, value.y);
87+
});
88+
this.setPlaceActions(a.element.arcLine);
89+
});
90+
trans.forEach(value => {
91+
if (net.assignedTasks.includes(value.canvasElement.label.textContent)) {
92+
value.select();
93+
}
94+
if (this.isEnabled(value, places, arcs)) {
95+
value.canvasElement.element.classList.add('svg-transition-enabled');
96+
value.canvasElement.element.setAttributeNS(null, 'fill', 'yellowgreen');
97+
value.canvasElement.element.setAttributeNS(null, 'stroke', 'green');
98+
}
99+
});
100+
this._petriflowCanvasService.panzoom?.moveTo(-minX + 20, -minY + 20);
101+
if (this.dataField.component?.properties?.lock === 'true') {
102+
setTimeout(() => {
103+
this._petriflowCanvasService.panzoom?.pause();
104+
})
105+
}
106+
}
107+
93108
protected createTransitions(value: TransitionImport): PetriflowTransition {
94109
const transition = this._petriflowFactoryService.createTransition(new DOMPoint(value.position.x, value.position.y));
95110
transition.changeId(value.stringId);
@@ -112,25 +127,26 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
112127
source = places.find(value => value.canvasElement.label.textContent === arc.sourceId);
113128
destination = trans.find(value => value.canvasElement.label.textContent === arc.destinationId);
114129
if (net.assignedTasks.includes(destination.canvasElement.label.textContent)) {
115-
source.activate();
116-
destination.activate();
130+
source.select();
131+
destination.select();
117132
activable = true;
118133
}
119134
} else {
120135
destination = places.find(value => value.canvasElement.label.textContent === arc.destinationId);
121136
if (net.finishedTasks.includes(source.canvasElement.label.textContent)) {
122-
source.activate();
137+
source.select();
138+
destination.select();
123139
activable = true;
124140
}
125141
}
126142
if (source === undefined || destination === undefined) {
127143
this._log.error("Can't find source or destination for arc [" + arc.importId + "]");
128144
} else {
129145
const newArc: Arc = this.createArc(arc, source, destination);
146+
const petriflowArc: PetriflowArc<Arc> = this.createPetriflowArc(arc, newArc, source);
130147
if (activable) {
131-
newArc.activate();
148+
petriflowArc.select();
132149
}
133-
const petriflowArc: PetriflowArc<Arc> = this.createPetriflowArc(arc, newArc, source);
134150
this._petriflowCanvasService.canvas.container.appendChild(newArc.container);
135151
this._petriflowCanvasService.petriflowElementsCollection.arcs.push(petriflowArc);
136152
return petriflowArc;
@@ -225,4 +241,10 @@ export abstract class AbstractCaseRefFieldComponent implements AfterViewInit {
225241
return (this.dataField.layout && this.dataField.layout.rows && this.dataField.layout.rows) > 1 ?
226242
this.dataField.layout.rows * CaseRefField.FIELD_HEIGHT : CaseRefField.FIELD_HEIGHT;
227243
}
244+
245+
protected setPlaceActions(svgElement: SVGElement) {
246+
svgElement.onmouseenter = () => {};
247+
svgElement.onmouseleave = () => {};
248+
}
249+
228250
}

0 commit comments

Comments
 (0)