Repository navigation
Expand file tree
/
Copy pathgraph.js
More file actions
132 lines (115 loc) · 3.32 KB
/
Copy pathgraph.js
File metadata and controls
132 lines (115 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import Diagram from 'diagram-js';
@Component({
selector: 'app-workflow-viewer',
templateUrl: './workflow-viewer.component.html',
styleUrls: ['./workflow-viewer.component.scss'],
})
export class WorkflowViewerComponent implements AfterViewInit {
@ViewChild('diagramContainer') diagramContainer!: ElementRef;
private diagram: any;
private selectedTask: any = null;
taskDetails: string | null = null;
constructor() {}
ngAfterViewInit() {
// Initialize diagram-js
this.diagram = new Diagram({
container: this.diagramContainer.nativeElement,
});
// Create the workflow sequence
this.createWorkflow();
}
createWorkflow() {
const canvas = this.diagram.get('canvas');
const elementFactory = this.diagram.get('elementFactory');
const modeling = this.diagram.get('modeling');
// Define workflow elements
const startEvent = elementFactory.createShape({
type: 'bpmn:StartEvent',
x: 100,
y: 200,
width: 40,
height: 40,
});
const validatePayloadTask = elementFactory.createShape({
type: 'bpmn:Task',
x: 200,
y: 180,
width: 100,
height: 80,
businessObject: { name: 'Validate Payload' },
});
const awaitingApprovalTask = elementFactory.createShape({
type: 'bpmn:Task',
x: 350,
y: 180,
width: 100,
height: 80,
businessObject: { name: 'Awaiting Approval' },
});
const userTask = elementFactory.createShape({
type: 'bpmn:Task',
x: 500,
y: 180,
width: 100,
height: 80,
businessObject: { name: 'User Task', id: 'userTask1' },
});
const endEvent = elementFactory.createShape({
type: 'bpmn:EndEvent',
x: 650,
y: 200,
width: 40,
height: 40,
});
// Add elements to canvas
canvas.addShape(startEvent);
canvas.addShape(validatePayloadTask);
canvas.addShape(awaitingApprovalTask);
canvas.addShape(userTask);
canvas.addShape(endEvent);
// Connect the elements
modeling.createConnection(
startEvent,
validatePayloadTask,
{ type: 'bpmn:SequenceFlow' },
canvas
);
modeling.createConnection(
validatePayloadTask,
awaitingApprovalTask,
{ type: 'bpmn:SequenceFlow' },
canvas
);
modeling.createConnection(
awaitingApprovalTask,
userTask,
{ type: 'bpmn:SequenceFlow' },
canvas
);
modeling.createConnection(
userTask,
endEvent,
{ type: 'bpmn:SequenceFlow' },
canvas
);
// Add labels
modeling.updateLabel(validatePayloadTask, 'Validate Payload');
modeling.updateLabel(awaitingApprovalTask, 'Awaiting Approval');
modeling.updateLabel(userTask, 'User Task');
// Add click event listener for User Task
const eventBus = this.diagram.get('eventBus');
eventBus.on('element.click', (e: any) => {
if (e.element.businessObject && e.element.businessObject.id === 'userTask1') {
this.showTaskDetails(e.element);
}
});
}
showTaskDetails(element: any) {
this.selectedTask = element;
this.taskDetails = `Task: ${element.businessObject.name}\nDetails: Perform the assigned user task.\nStatus: Pending`;
}
clearDetails() {
this.taskDetails = null;
}
}