1b381c5d8133face0955b7a013f4f2b8d0ac5664
[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 {Component, OnInit} from "@angular/core";
14 import {TranslateService} from "@ngx-translate/core";
15 import {PlanTreeviewItem} from "../../model/plan-treeview-item";
16 import {ValueSource} from "../../model/value-source.enum";
17 import {NodeType} from "../../model/workflow/node-type.enum";
18 import {WorkflowNode} from "../../model/workflow/workflow-node";
19 import {BroadcastService} from "../../services/broadcast.service";
20 import {JsPlumbService} from "../../services/jsplumb.service";
21 import {ModelService} from "../../services/model.service";
22 import {NoticeService} from "../../services/notice.service";
23
24 /**
25  * property component presents information of a workflow node.
26  * the presented information can be edit in this component.
27  * it may load information dynamically. the content may be different for different node type.
28  */
29 @Component({
30     selector: 'wfm-properties',
31     styleUrls: ['./properties.component.css'],
32     templateUrl: 'properties.component.html',
33 })
34 export class PropertiesComponent implements OnInit {
35     public node: WorkflowNode;
36     public planTreeviewItems: PlanTreeviewItem[];
37     public nodeType = NodeType;
38     // public nodeTypes: string[] = WorkflowNodeType;
39     public show = false;
40     public titleEditing = false;
41     public valueSource = [ValueSource.string];
42
43     constructor(private broadcastService: BroadcastService,
44                 private modelService: ModelService,
45                 private translate: TranslateService,
46                 private noticeService: NoticeService,
47                 private jsPlumbService: JsPlumbService) {
48
49     }
50
51     public ngOnInit() {
52         this.broadcastService.showProperty$.subscribe(element => {
53             if (element && this.modelService.isNode(element)) {
54                 this.node = element as WorkflowNode;
55                 // temporarily, if config info not exists then close the property panel
56                 // TODOS: 1) save config info in case config info no exists on a different environment.
57                 //        2) display property panel even if config info not exists for it may be adjust.
58                 try {
59                     this.planTreeviewItems = this.modelService.getPlanParameters(this.node.id);
60                     this.show = true;
61                 } catch (error) {
62                     this.show = false;
63                     this.translate.get('WORKFLOW.MSG.SWAGGER_NOT_EXISTS').subscribe((res: string) => {
64                         this.noticeService.error(res);
65                     });
66                 }
67             } else {
68                 this.show = false;
69             }
70         });
71     }
72
73     public deleteNode() {
74         this.show = false;
75         const parentId = this.jsPlumbService.getParentNodeId(this.node.id);
76         this.jsPlumbService.remove(this.node);
77         this.modelService.deleteNode(parentId, this.node.id);
78     }
79 }