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
10 * ZTE - initial API and implementation and/or initial documentation
13 import {Component, EventEmitter, Input, Output, ViewChild} from "@angular/core";
14 import {TranslateService} from "@ngx-translate/core";
15 import {isArray, isObject} from "util";
16 import {ModelService} from "../../services/model.service";
17 import {NoticeService} from "../../services/notice.service";
18 import {NodeType} from "../../model/workflow/node-type.enum";
19 import {ValueSource} from "../../model/value-source.enum";
20 import {JsPlumbService} from "../../services/jsplumb.service";
21 import {WorkflowNode} from "../../model/workflow/workflow-node";
24 * node or workflow-line name
27 selector: 'wfm-editable-property',
28 templateUrl: 'editable-property.component.html',
29 styleUrls: ['./editable-property.component.css']
31 export class EditablePropertyComponent {
32 @Input() public value: string;
33 @Output() public valueChange = new EventEmitter<string>();
34 @ViewChild('editInput') private editInput: any;
36 public editValue = '';
37 public editable = false;
39 public preEdit(): void {
42 this.editValue = this.value;
46 public afterEdit(): void {
48 this.editable = false;
49 if (this.value === this.editValue) {
53 if (this.editInput.wfInput.valid) {
54 this.value = this.editValue;
55 this.valueChange.emit(this.value);
57 this.editValue = this.value;
62 /*private validate(): boolean {
63 const nodes = this.modelService.getNodes();
64 const existNode = nodes.find(node => node.id === this.editValue);
66 this.translate.get('WORKFLOW.MSG.NODE_ID_SAME', {value: existNode.id}).subscribe((res: string) => {
67 this.notice.error(res, 10000);
74 private changeReferencedValue(): void {
75 const newNodeConnections = [];
76 const nodes = this.modelService.getNodes();
77 nodes.forEach((node: any) => {
78 this.changeConnectionReferencedValue(node, this.value, this.editValue);
80 if (node.type === NodeType[NodeType.restTask]) {
81 const parameters = node.parameters || [];
82 parameters.forEach(param => {
83 this.changeRestTaskReferencedValue(param, this.value, this.editValue);
89 private changeConnectionReferencedValue(node: WorkflowNode, oldValue: string, newValue: string): void {
90 node.connection.forEach(connection => {
91 if (connection.sourceRef === oldValue) {
92 connection.sourceRef = newValue;
93 } else if (connection.targetRef === oldValue) {
94 connection.targetRef = newValue;
99 // 当restTask类型的节点的属性中valueSource是Plan时,value的值为引用其他节点id
100 // value格式为[restTask_2].[responseBody].[name],可能有更多层,当时第一个[]里面的值为被引用节点的id
101 private changeRestTaskReferencedValue(param: any, oldValue: string, newValue: string): void {
102 if (param.valueSource === ValueSource[ValueSource.Plan]) {
103 const value = param.value || '';
104 const index = value.indexOf('].[');
106 const nodeId = value.substring(1, index);
107 if (nodeId === oldValue) {
108 param.value = '[' + newValue + value.substring(index);
111 } else if (param.valueSource === ValueSource[ValueSource.Definition]) {
112 const value = param.value;
113 if (isArray(value)) {
114 value.forEach(subValue => {
115 this.changeRestTaskReferencedValue(subValue, oldValue, newValue);
117 } else if (isObject(value)) {
118 this.changeRestTaskReferencedValue(value, oldValue, newValue);