-
Notifications
You must be signed in to change notification settings - Fork 4
[NAE-1684] Frontend component for data field caseRef #112
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
Open
Kovy95
wants to merge
13
commits into
release/6.4.0
Choose a base branch
from
NAE-1684
base: release/6.4.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fb106b5
[NAE-1684] Frontend component for data field caseRef
Kovy95 3492f30
[NAE-1684] Frontend component for data field caseRef
Kovy95 4be5f89
[NAE-1684] Frontend component for data field caseRef
Kovy95 f29e020
[NAE-1684] Frontend component for data field caseRef
Kovy95 4341b11
[NAE-1684] Frontend component for data field caseRef
Kovy95 532b3db
[NAE-1684] Frontend component for data field caseRef
Kovy95 6661bf4
Merge remote-tracking branch 'origin/release/6.3.0' into NAE-1684
Kovy95 133c7b6
[NAE-1684] Frontend component for data field caseRef
Kovy95 c5e74cd
[NAE-1684] Frontend component for data field caseRef
Kovy95 b4d227f
[NAE-1684] Frontend component for data field caseRef
Kovy95 4a494a6
Merge remote-tracking branch 'origin/release/6.4.0' into NAE-1684
machacjozef 1b2cc3b
Merge branch 'release/6.4.0' into NAE-1684
machacjozef 52be36d
Merge branch 'release/6.4.0' into NAE-1684
machacjozef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
261 changes: 261 additions & 0 deletions
261
...f-components-core/src/lib/data-fields/case-ref-field/abstract-case-ref-field.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
import {AfterViewInit, Component, Inject, Input, OnDestroy, Optional} from '@angular/core'; | ||
import { | ||
PetriflowArc, | ||
PetriflowCanvasConfigurationService, | ||
PetriflowCanvasFactoryService, | ||
PetriflowCanvasService, | ||
PetriflowInhibitorArc, | ||
PetriflowPlace, | ||
PetriflowPlaceTransitionArc, PetriflowReadArc, | ||
PetriflowResetArc, | ||
PetriflowTransition, PetriflowTransitionPlaceArc | ||
} from '@netgrif/petriflow.svg'; | ||
import { | ||
Arc, | ||
InhibitorArc, Place, | ||
ReadArc, | ||
RegularPlaceTransitionArc, | ||
RegularTransitionPlaceArc, | ||
ResetArc | ||
} from '@netgrif/petri.svg'; | ||
import {CaseRefField} from './models/case-ref-field'; | ||
import {PetriNetResourceService} from '../../resources/engine-endpoint/petri-net-resource.service'; | ||
import {CaseResourceService} from '../../resources/engine-endpoint/case-resource.service'; | ||
import {TransitionImport} from '../../resources/interface/transition-import'; | ||
import {PlaceImport} from '../../resources/interface/place-import'; | ||
import {ArcImport} from '../../resources/interface/arc-import'; | ||
import {ArcType} from '../../resources/interface/arc-type'; | ||
import {PetriNetImport} from '../../resources/interface/petri-net-import'; | ||
import {LoggerService} from '../../logger/services/logger.service'; | ||
import {SnackBarService} from '../../snack-bar/services/snack-bar.service'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {AbstractDataFieldComponent} from '../models/abstract-data-field-component'; | ||
import {NAE_INFORM_ABOUT_INVALID_DATA} from '../models/invalid-data-policy-token'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-case-ref-field', | ||
template: '' | ||
}) | ||
export abstract class AbstractCaseRefFieldComponent extends AbstractDataFieldComponent implements AfterViewInit, OnDestroy { | ||
|
||
@Input() public dataField: CaseRefField; | ||
protected sub: Subscription; | ||
|
||
constructor(protected _petriflowCanvasService: PetriflowCanvasService, protected _petriflowFactoryService: PetriflowCanvasFactoryService, | ||
protected _petriflowConfigService: PetriflowCanvasConfigurationService, protected _caseResourceService: CaseResourceService, | ||
protected _petriNetResourceService: PetriNetResourceService, protected _log: LoggerService, protected _snackBar: SnackBarService, | ||
protected _translate: TranslateService, @Optional() @Inject(NAE_INFORM_ABOUT_INVALID_DATA) informAboutInvalidData: boolean | null) { | ||
super(informAboutInvalidData); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.sub = this.formControl.valueChanges.subscribe(value => { | ||
if (value?.length > 0) { | ||
this._petriNetResourceService.getNetByCaseId(value[0]).subscribe(net => { | ||
this.createNet(net); | ||
}, error => { | ||
this._log.error('Getting net by Case ID failed in field ['+ this.dataField.stringId + ']', error); | ||
this._snackBar.openErrorSnackBar(this._translate.instant('dataField.snackBar.caseNetGetFailed')); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
protected createNet(net: PetriNetImport) { | ||
const trans: Array<PetriflowTransition> = []; | ||
const places: Array<PetriflowPlace> = []; | ||
const arcs: Array<PetriflowArc<any>> = []; | ||
let minX: number = Number.MAX_SAFE_INTEGER; | ||
let minY: number = Number.MAX_SAFE_INTEGER; | ||
net.transitions.forEach((value) => { | ||
const t = this.createTransitions(value) | ||
trans.push(t); | ||
minX = Math.min(minX, value.position.x); | ||
minY = Math.min(minY, value.position.y); | ||
this.setEmptyEvents(t.canvasElement.element); | ||
}) | ||
net.places.forEach((value) => { | ||
const p = this.createPlace(value) | ||
places.push(p); | ||
minX = Math.min(minX, value.position.x); | ||
minY = Math.min(minY, value.position.y); | ||
this.setEmptyEvents(p.canvasElement.element); | ||
p.canvasElement.markingTokens.forEach(markingToken => { | ||
this.setEmptyEvents(markingToken); | ||
}); | ||
}) | ||
net.arcs.forEach((arc) => { | ||
const a = this.createArcs(trans, places, arc, net) | ||
arcs.push(a); | ||
arc.breakpoints?.forEach(value => { | ||
minX = Math.min(minX, value.x); | ||
minY = Math.min(minY, value.y); | ||
}); | ||
this.setEmptyEvents(a.element.arcLine); | ||
}); | ||
trans.forEach(value => { | ||
if (net.assignedTasks.includes(value.canvasElement.label.textContent)) { | ||
value.select(); | ||
} | ||
if (this.isEnabled(value, places, arcs)) { | ||
value.canvasElement.element.classList.add('svg-transition-enabled'); | ||
value.canvasElement.element.setAttributeNS(null, 'fill', 'yellowgreen'); | ||
value.canvasElement.element.setAttributeNS(null, 'stroke', 'green'); | ||
minop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
this._petriflowCanvasService.panzoom?.moveTo(-minX + 20, -minY + 20); | ||
if (this.dataField.component?.properties?.lock === 'true') { | ||
setTimeout(() => { | ||
this._petriflowCanvasService.panzoom?.pause(); | ||
}) | ||
} | ||
} | ||
|
||
protected createTransitions(value: TransitionImport): PetriflowTransition { | ||
const transition = this._petriflowFactoryService.createTransition(new DOMPoint(value.position.x, value.position.y)); | ||
transition.changeId(value.stringId); | ||
this._petriflowConfigService.addTransitionEvents(transition); | ||
return transition; | ||
} | ||
|
||
protected createPlace(value: PlaceImport): PetriflowPlace { | ||
const place = this._petriflowFactoryService.createPlace(value.tokens, new DOMPoint(value.position.x, value.position.y)); | ||
place.changeId(value.stringId); | ||
this._petriflowConfigService.addPlaceEvents(place); | ||
return place; | ||
} | ||
|
||
protected createArcs(trans: Array<PetriflowTransition>, places: Array<PetriflowPlace>, arc: ArcImport, net: PetriNetImport) { | ||
let source: PetriflowPlace | PetriflowTransition = trans.find(value => value.canvasElement.label.textContent === arc.sourceId); | ||
let destination: PetriflowPlace | PetriflowTransition; | ||
let activable: boolean = false; | ||
if (source === undefined) { | ||
source = places.find(value => value.canvasElement.label.textContent === arc.sourceId); | ||
destination = trans.find(value => value.canvasElement.label.textContent === arc.destinationId); | ||
if (net.assignedTasks.includes(destination.canvasElement.label.textContent)) { | ||
source.select(); | ||
destination.select(); | ||
activable = true; | ||
} | ||
} else { | ||
destination = places.find(value => value.canvasElement.label.textContent === arc.destinationId); | ||
if (net.finishedTasks.includes(source.canvasElement.label.textContent)) { | ||
source.select(); | ||
destination.select(); | ||
activable = true; | ||
} | ||
} | ||
if (source === undefined || destination === undefined) { | ||
this._log.error("Can't find source or destination for arc [" + arc.importId + "]"); | ||
} else { | ||
const newArc: Arc = this.createArc(arc, source, destination); | ||
const petriflowArc: PetriflowArc<Arc> = this.createPetriflowArc(arc, newArc, source); | ||
if (activable) { | ||
petriflowArc.select(); | ||
} | ||
this._petriflowCanvasService.canvas.container.appendChild(newArc.container); | ||
this._petriflowCanvasService.petriflowElementsCollection.arcs.push(petriflowArc); | ||
return petriflowArc; | ||
} | ||
return undefined | ||
} | ||
|
||
protected createArc(arc: ArcImport, source: PetriflowTransition | PetriflowPlace, destination: PetriflowPlace | PetriflowTransition) { | ||
if (source instanceof PetriflowPlace) { | ||
switch (arc.type) { | ||
case ArcType.ARC: { | ||
return this._petriflowFactoryService.createArc(RegularPlaceTransitionArc, source.canvasElement, destination.canvasElement, arc.breakpoints, arc.multiplicity); | ||
} | ||
case ArcType.RESET: { | ||
return this._petriflowFactoryService.createArc(ResetArc, source.canvasElement, destination.canvasElement, arc.breakpoints, arc.multiplicity); | ||
} | ||
case ArcType.INHIBITOR: { | ||
return this._petriflowFactoryService.createArc(InhibitorArc, source.canvasElement, destination.canvasElement, arc.breakpoints, arc.multiplicity); | ||
} | ||
case ArcType.READ: { | ||
return this._petriflowFactoryService.createArc(ReadArc, source.canvasElement, destination.canvasElement, arc.breakpoints, arc.multiplicity); | ||
} | ||
default: { | ||
return undefined; | ||
} | ||
} | ||
} else if (arc.type === ArcType.ARC) { | ||
return this._petriflowFactoryService.createArc(RegularTransitionPlaceArc, source.canvasElement, destination.canvasElement, arc.breakpoints, arc.multiplicity); | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
|
||
protected createPetriflowArc(arc: ArcImport, newArc: Arc, source: PetriflowTransition | PetriflowPlace) { | ||
if (source instanceof PetriflowPlace) { | ||
switch (arc.type) { | ||
case ArcType.ARC: { | ||
return this._petriflowFactoryService.createArc(PetriflowPlaceTransitionArc, newArc); | ||
} | ||
case ArcType.RESET: { | ||
return this._petriflowFactoryService.createArc(PetriflowResetArc, newArc); | ||
} | ||
case ArcType.INHIBITOR: { | ||
return this._petriflowFactoryService.createArc(PetriflowInhibitorArc, newArc); | ||
} | ||
case ArcType.READ: { | ||
return this._petriflowFactoryService.createArc(PetriflowReadArc, newArc); | ||
} | ||
default: { | ||
return undefined; | ||
} | ||
} | ||
} else if (arc.type === ArcType.ARC) { | ||
return this._petriflowFactoryService.createArc(PetriflowTransitionPlaceArc, newArc); | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
|
||
protected isEnabled(t: PetriflowTransition, places: Array<PetriflowPlace>, arcs: Array<PetriflowArc<any>>): boolean { | ||
const testMarking: Map<string, number> = new Map(); | ||
|
||
for (const place of places) { | ||
testMarking.set(place.canvasElement.id, place.canvasElement.tokensCount); | ||
} | ||
for (const arc of arcs) { | ||
if (arc.element.end.id === t.canvasElement.id && (arc instanceof PetriflowInhibitorArc) && testMarking.get((arc.element.start as Place).id) >= parseInt(arc.element.multiplicity.data, 10)) { | ||
return false; | ||
} | ||
} | ||
for (const arc of arcs) { | ||
if (arc.element.end.id === t.canvasElement.id && (arc instanceof PetriflowReadArc) && testMarking.get((arc.element.start as Place).id) < parseInt(arc.element.multiplicity.data, 10)) { | ||
return false; | ||
} | ||
} | ||
for (const arc of arcs) { | ||
if (arc.element.end.id === t.canvasElement.id && arc instanceof PetriflowPlaceTransitionArc) { | ||
const place = testMarking.get((arc.element.start as Place).id) | ||
testMarking.set((arc.element.start as Place).id, place - parseInt(arc.element.multiplicity.data, 10)); | ||
} | ||
} | ||
for (const place of testMarking.values()) { | ||
if (place < 0) { | ||
minop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public getHeight() { | ||
return (this.dataField.layout && this.dataField.layout.rows && this.dataField.layout.rows) > 1 ? | ||
this.dataField.layout.rows * CaseRefField.FIELD_HEIGHT : CaseRefField.FIELD_HEIGHT; | ||
} | ||
|
||
protected setEmptyEvents(svgElement: SVGElement) { | ||
svgElement.onmouseenter = () => {}; | ||
svgElement.onmouseleave = () => {}; | ||
} | ||
|
||
ngOnDestroy() { | ||
super.ngOnDestroy(); | ||
this.sub.unsubscribe(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
projects/netgrif-components-core/src/lib/data-fields/case-ref-field/models/case-ref-field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Behavior} from '../../models/behavior'; | ||
import {Layout} from '../../models/layout'; | ||
import {Validation} from '../../models/validation'; | ||
import {Component} from '../../models/component'; | ||
import {DataField} from '../../models/abstract-data-field'; | ||
|
||
export class CaseRefField extends DataField<Array<string>> { | ||
|
||
public static FIELD_HEIGHT: number = 75; | ||
|
||
constructor(stringId: string, title: string, value: Array<string>, behavior: Behavior, placeholder?: string, | ||
description?: string, layout?: Layout, validations?: Array<Validation>, _component?: Component, parentTaskId?: string) { | ||
super(stringId, title, value, behavior, placeholder, description, layout, validations, _component, parentTaskId); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
projects/netgrif-components-core/src/lib/resources/interface/arc-import.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Position} from './position'; | ||
import {ArcType} from './arc-type'; | ||
|
||
export interface ArcImport { | ||
destinationId: string; | ||
sourceId: string; | ||
importId: string; | ||
multiplicity: number; | ||
stringId: string; | ||
breakpoints: Array<Position>; | ||
type: ArcType; | ||
} |
6 changes: 6 additions & 0 deletions
6
projects/netgrif-components-core/src/lib/resources/interface/arc-type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum ArcType { | ||
ARC = 'arc', | ||
RESET = 'reset', | ||
INHIBITOR = 'inhibitor', | ||
READ = 'read' | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.