0f721242d72b4fd14110d9d3aceb6cad67ed39be
[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 import { Component, Input, OnInit } from '@angular/core';
13 import { Subscription } from 'rxjs/Subscription';
14
15 import { ValueSource } from '../../../model/value-source.enum';
16 import { Parameter } from '../../../model/workflow/parameter';
17 import { StartEvent } from '../../../model/workflow/start-event';
18 import { BroadcastService } from '../../../services/broadcast.service';
19 import { WorkflowUtil } from '../../../util/workflow-util';
20 import { TranslateService } from '@ngx-translate/core';
21
22 @Component({
23     selector: 'wfm-start-event',
24     styleUrls: ['./start-event.component.css'],
25     templateUrl: 'start-event.component.html',
26 })
27 export class StartEventComponent implements OnInit {
28     @Input() public node: StartEvent;
29     public sources: ValueSource[] = [ValueSource.string];
30
31     constructor(private translate: TranslateService) { }
32
33     ngOnInit() { }
34
35     public create(): void {
36         let parameter = new Parameter('', '', ValueSource[ValueSource.string]);
37         this.node.parameters.push(parameter);
38     }
39
40     public delete(index: number): void {
41         this.node.parameters.splice(index, 1);
42     }
43
44     public checkKey(newName: string, index: number): void {
45         this.node.parameters[index].name = newName;
46         this.node.parameters.forEach(parameter => {
47             parameter.errorMsg = '';
48         });
49         if (!newName) {
50             this.translate.get('WORKFLOW.MSG.VARIABLE_EMPTY').subscribe((res: string) => {
51                 this.node.parameters[index].errorMsg = res;
52             });
53         }
54         this.node.parameters.forEach((parameter, i) => {
55             if (i + 1 < this.node.parameters.length) {
56                 for (let j = i + 1; j < this.node.parameters.length; j++) {
57                     let element = this.node.parameters[j];
58                     if (element.name && parameter.name === element.name) {
59                         this.translate.get('WORKFLOW.MSG.VARIABLE_SAME').subscribe((res: string) => {
60                             parameter.errorMsg = res;
61                             element.errorMsg = res;
62                         });
63                     }
64                 }
65             }
66         });
67     }
68 }