55d051f2017574fdd32e31c8e06ae56c6f1ce683
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12
13 import { AfterViewInit, Component } from '@angular/core';
14 import { TreeNode } from 'primeng/primeng';
15
16 import { SequenceFlow } from '../../model/workflow/sequence-flow';
17 import { BroadcastService } from '../../services/broadcast.service';
18 import { JsPlumbService } from '../../services/jsplumb.service';
19 import { ModelService } from '../../services/model.service';
20 import { NodeType } from '../../model/workflow/node-type.enum';
21
22 /**
23  * property component presents information of a workflow node.
24  * the presented information can be edit in this component.
25  * it may load information dynamically. the content may be different for different node type.
26  */
27 @Component({
28     selector: 'wfm-sequence-flow',
29     styleUrls: ['./sequence-flow.component.css'],
30     templateUrl: 'sequence-flow.component.html',
31 })
32 export class SequenceFlowComponent implements AfterViewInit {
33     public sequenceFlow: SequenceFlow;
34     public show = false;
35
36     constructor(private broadcastService: BroadcastService,
37         private modelService: ModelService,
38         private jsPlumbService: JsPlumbService) {
39
40     }
41
42     public ngAfterViewInit() {
43         this.broadcastService.showProperty$.subscribe(element => {
44             if (element && !this.modelService.isNode(element)) {
45                 this.sequenceFlow = element as SequenceFlow;
46                 this.show = true;
47             } else {
48                 this.show = false;
49             }
50         });
51     }
52
53     public showCondition(sourceRef: string): boolean {
54         if (sourceRef) {
55             let node = this.modelService.getNodeMap().get(sourceRef);
56             if (node && (NodeType[NodeType.parallelGateway] === node.type || NodeType[NodeType.exclusiveGateway] === node.type)) {
57                 return true;
58             } else {
59                 return false;
60             }
61         } else {
62             return false;
63         }
64     }
65
66     public nameChanged(name: string) {
67         this.sequenceFlow.name = name;
68         this.jsPlumbService.setLabel(this.sequenceFlow.sourceRef, this.sequenceFlow.targetRef, name);
69     }
70
71     public delete() {
72         this.show = false;
73         this.modelService.deleteConnection(this.sequenceFlow.sourceRef, this.sequenceFlow.targetRef);
74         this.jsPlumbService.deleteConnect(this.sequenceFlow.sourceRef, this.sequenceFlow.targetRef);
75     }
76 }