summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts
blob: cc7b5feaf31353564aec9b41019dab70535d089c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as _ from "lodash";
import {Component} from '@angular/core';
import {DropdownValue} from "app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component";
import {InputModel, OperationModel, OperationParam} from 'app/models';

@Component({
    selector: 'operation-creator',
    templateUrl: './operation-creator.component.html',
    styleUrls:['./operation-creator.component.less'],
})

export class OperationCreatorComponent {

    inputProperties: Array<DropdownValue>;
    input: any;
    inputParams: Array<OperationParam> = [];
    operation: OperationModel;
    isEditMode: boolean = false;

    ngOnInit() {
        this.operation = new OperationModel(this.input.operation || {});

        if (this.input.operation) {
            let {inputParams} = this.input.operation;

            if (inputParams) {
                _.forEach(inputParams.listToscaDataDefinition, (input: OperationParam) => {
                    this.addParam(input);
                });
            }

            if (this.input.operation.uniqueId) {
                this.isEditMode = true;
            }
        }

        this.inputProperties = _.map(this.input.inputProperties,
            (input: InputModel) => new DropdownValue(input.uniqueId, input.name)
        );
    }

    addParam(param?: OperationParam): void {
        this.inputParams.push(new OperationParam(param));
    }

    isAddAllowed(): boolean {
        if (this.inputParams.length === 0) {
            return true;
        }

        const {paramId, paramName} = _.last(this.inputParams);
        return paramId && paramName.length > 0;
    }

    onRemoveParam = (param: OperationParam): void  => {
        let index = _.indexOf(this.inputParams, param);
        this.inputParams.splice(index, 1);
    }

    createInputParamList(): void {
        this.operation.createInputParamsList(this.inputParams);
    }

    checkFormValidForSubmit(): boolean {
        return this.operation.operationType && this.operation.operationType.length > 0 && this.isAddAllowed();
    }

}