Skip to content

Commit fc78a5a

Browse files
committed
[NAB-358] Release 2.1.0
- fix duplicate action id bug
1 parent cf2a8b5 commit fc78a5a

File tree

3 files changed

+51
-48
lines changed

3 files changed

+51
-48
lines changed

src/app/modeler/actions-mode/action-editor/action-editor.service.ts

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
} from '@netgrif/petriflow';
2424
import {MasterItem} from './classes/master-item';
2525
import {EventType} from './event-type';
26+
import {SequenceGenerator} from '../../services/model/sequence-generator';
27+
import {ModelService} from '../../services/model/model.service';
2628

2729
@Injectable({
2830
providedIn: 'root'
@@ -32,18 +34,17 @@ export class ActionEditorService {
3234
public editedActions: Array<ActionGroup>;
3335
public historySave: boolean;
3436
private _datarefMap: Map<string, DataRef>;
35-
private _lastUsedId: number;
3637
private _currentlyEdited: Transition | DataVariable | PetriNet | Role;
3738

38-
constructor() {
39+
constructor(
40+
private _modelService: ModelService,
41+
) {
3942
this.editedActions = [];
40-
this._lastUsedId = 0;
4143
this._datarefMap = new Map<string, DataRef>();
4244
}
4345

4446
public nextId(): string {
45-
this._lastUsedId++;
46-
return String(this._lastUsedId);
47+
return this._modelService.nextActionId();
4748
}
4849

4950
public populateEditedActionsFromTransition(transition: Transition): void {
@@ -116,50 +117,10 @@ export class ActionEditorService {
116117
private loadAction(action: Action, actionType: ActionType, eventType: EventType, phase: EventPhase, parentDataRefId?: string): EditableAction {
117118
if (action.id === undefined || action.id === null) {
118119
action.id = this.nextId();
119-
} else {
120-
this.updateLastId(action.id);
121120
}
122121
return new EditableAction(action.id, actionType, false, action.definition, eventType, phase, parentDataRefId);
123122
}
124123

125-
private updateLastId(id: string): void {
126-
const parsedId = parseInt(id, 10);
127-
this._lastUsedId = Math.max(this._lastUsedId, isNaN(parsedId) ? 0 : parsedId);
128-
}
129-
130-
public updateIds(model: PetriNet): void {
131-
model.getProcessEvents().forEach(e => {
132-
e.preActions.forEach(a => this.updateLastId(a.id));
133-
e.postActions.forEach(a => this.updateLastId(a.id));
134-
});
135-
model.getCaseEvents().forEach(e => {
136-
e.preActions.forEach(a => this.updateLastId(a.id));
137-
e.postActions.forEach(a => this.updateLastId(a.id));
138-
});
139-
model.getRoles().forEach(r => {
140-
r.getEvents().forEach(e => {
141-
e.preActions.forEach(a => this.updateLastId(a.id));
142-
e.postActions.forEach(a => this.updateLastId(a.id));
143-
});
144-
});
145-
model.getTransitions().forEach(t => {
146-
t.eventSource.getEvents().forEach(e => {
147-
e.preActions.forEach(a => this.updateLastId(a.id));
148-
e.postActions.forEach(a => this.updateLastId(a.id));
149-
});
150-
t.dataGroups.forEach(g => g.getDataRefs().forEach(d => d.getEvents().forEach(e => {
151-
e.preActions.forEach(a => this.updateLastId(a.id));
152-
e.postActions.forEach(a => this.updateLastId(a.id));
153-
})));
154-
});
155-
model.getDataSet().forEach(d => {
156-
d.getEvents().forEach(e => {
157-
e.preActions.forEach(a => this.updateLastId(a.id));
158-
e.postActions.forEach(a => this.updateLastId(a.id));
159-
});
160-
});
161-
}
162-
163124
public saveActionChange(changedAction: EditableAction) {
164125
this.saveAction(changedAction);
165126
changedAction.commitChanges();

src/app/modeler/services/model/model.service.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Injectable} from '@angular/core';
22
import {
3+
Action,
34
Arc,
45
ArcType,
56
Breakpoint,
@@ -44,6 +45,7 @@ export class ModelService {
4445
private _arcIdSequence = new SequenceGenerator('a');
4546
private _dataIdSequence = new SequenceGenerator('data');
4647
private _roleIdSequence = new SequenceGenerator('role');
48+
private _actionIdSequence = new SequenceGenerator('action');
4749

4850
private xmlArcTypeMapping: Map<XmlArcType, ArcType> = new Map([
4951
[XmlArcType.REGULAR, ArcType.REGULAR_PT],
@@ -76,6 +78,7 @@ export class ModelService {
7678
this._arcIdSequence.reset(newModel.getArcs());
7779
this._dataIdSequence.reset(newModel.getDataSet());
7880
this._roleIdSequence.reset(newModel.getRoles());
81+
this._actionIdSequence.reset(this.collectActions(newModel));
7982
}
8083

8184
get model(): PetriNet {
@@ -441,6 +444,45 @@ export class ModelService {
441444
return id;
442445
}
443446

447+
public nextActionId(): string {
448+
return this._actionIdSequence.next();
449+
}
450+
451+
private collectActions(newModel: PetriNet): Action[] {
452+
const actions = new Array<Action>();
453+
newModel.getCaseEvents().forEach(e => {
454+
actions.push(...e.preActions);
455+
actions.push(...e.postActions);
456+
});
457+
newModel.getProcessEvents().forEach(e => {
458+
actions.push(...e.preActions);
459+
actions.push(...e.postActions);
460+
});
461+
newModel.getRoles().forEach(r => {
462+
r.getEvents().forEach(e => {
463+
actions.push(...e.preActions);
464+
actions.push(...e.postActions);
465+
});
466+
});
467+
newModel.getTransitions().forEach(t => {
468+
t.eventSource.getEvents().forEach(e => {
469+
actions.push(...e.preActions);
470+
actions.push(...e.postActions);
471+
});
472+
t.dataGroups.forEach(g => g.getDataRefs().forEach(d => d.getEvents().forEach(e => {
473+
actions.push(...e.preActions);
474+
actions.push(...e.postActions);
475+
})));
476+
});
477+
newModel.getDataSet().forEach(d => {
478+
d.getEvents().forEach(e => {
479+
actions.push(...e.preActions);
480+
actions.push(...e.postActions);
481+
});
482+
});
483+
return actions;
484+
}
485+
444486
public alignModel(model = this.model): void {
445487
[...model.getPlaces(), ...model.getTransitions()].forEach(node => {
446488
node.x = this.alignPositionX(node.x);

src/app/modeler/services/model/sequence-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {DataVariable, Element, Role} from '@netgrif/petriflow';
1+
import {Action, DataVariable, Element, Role} from '@netgrif/petriflow';
22

33
export class SequenceGenerator {
44
private _id = 0;
@@ -13,9 +13,9 @@ export class SequenceGenerator {
1313
return `${this._prefix}${this._id}`;
1414
}
1515

16-
public reset(collection: Array<Element | DataVariable | Role>): void {
16+
public reset(collection: Array<Element | DataVariable | Role | Action>): void {
1717
this._id = collection.filter(e => e.id.startsWith(this._prefix))
18-
.map(e => Number.parseInt(e.id.substring(1), 10))
18+
.map(e => Number.parseInt(e.id.substring(this._prefix.length), 10))
1919
.filter(elementId => !isNaN(elementId))
2020
.reduce((a, b) => Math.max(a, b), 0);
2121
}

0 commit comments

Comments
 (0)