a0f5fd93247ca46cd2113680028304bff1114e98
[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
14 import { ScriptTask } from "../../../model/workflow/script-task";
15 import { NodeTypeService } from '../../../services/node-type.service';
16
17 @Component({
18     selector: 'wfm-script-task',
19     templateUrl: 'script-task.component.html',
20 })
21 export class ScriptTaskComponent implements OnInit {
22     @Input() public node: ScriptTask;
23
24     public canChangeFormat = true;
25     public scriptOperations = ['JavaScript', 'Groovy'];
26
27     constructor(private nodeTypeService: NodeTypeService) { }
28
29     public ngOnInit() {
30         const nodeDataType = this.nodeTypeService.getNodeDataTypeById(this.node.typeId);
31         let scriptFormat = nodeDataType.content.scriptFormat;
32         // scriptFormat is not support, reset it as null;
33         if (undefined === this.scriptOperations.find(format => format == scriptFormat)) {
34             scriptFormat = null;
35         }
36         // Defined scriptFormat value, use it as default and can not change.
37         if (scriptFormat && '' != scriptFormat) {
38             this.canChangeFormat = false;
39             if (!this.node.scriptFormat || '' == this.node.scriptFormat) {
40                 this.node.scriptFormat = scriptFormat;
41                 this.node.script = nodeDataType.content.script;
42             }
43         } else {
44             // Default scriptFormat value should be 'JavaScript'
45             if (!this.node.scriptFormat || '' == this.node.scriptFormat) {
46                 this.node.scriptFormat = 'JavaScript';
47                 this.node.script = '';
48             }
49         }
50     }
51 }