8e8b6ad3eaa05be09a86aeb6c20b38efef831e29
[ccsdk/cds.git] /
1 import {Component, OnInit} from '@angular/core';
2 import {InputActionAttribute, OutputActionAttribute} from './models/InputActionAttribute';
3
4 @Component({
5     selector: 'app-action-attributes',
6     templateUrl: './action-attributes.component.html',
7     styleUrls: ['./action-attributes.component.css']
8 })
9 export class ActionAttributesComponent implements OnInit {
10
11     inputs = [];
12     outputs = [];
13     actionAttributesSideBar: boolean;
14     inputActionAttribute = new InputActionAttribute();
15     outputActionAttribute = new OutputActionAttribute();
16     isInputOtherType: boolean;
17     isOutputOtherType: boolean;
18     outputOtherType = '';
19     inputOtherType = '';
20
21     constructor() {
22
23     }
24
25     ngOnInit() {
26     }
27
28     addInput(input: InputActionAttribute) {
29         if (input && input.type && input.name) {
30             const insertedInputActionAttribute = Object.assign({}, input);
31             this.inputs.push(insertedInputActionAttribute);
32         }
33     }
34
35     addOutput(output: OutputActionAttribute) {
36         if (output && output.type && output.name) {
37             const insertedOutputActionAttribute = Object.assign({}, output);
38             this.outputs.push(insertedOutputActionAttribute);
39         }
40     }
41
42     setInputType(type: string) {
43         this.inputActionAttribute.type = type;
44         this.isInputOtherType = this.checkIfTypeIsOther(type);
45     }
46
47     setInputRequired(isRequired) {
48         this.inputActionAttribute.required = isRequired;
49     }
50
51     setOutputRequired(isRequired) {
52         this.outputActionAttribute.required = isRequired;
53     }
54
55     setOutputType(type: string) {
56         this.outputActionAttribute.type = type;
57         this.isOutputOtherType = this.checkIfTypeIsOther(type);
58     }
59
60     checkIfTypeIsOther(type) {
61         return type.includes('Other');
62     }
63
64     submitAttributes() {
65         console.log(this.inputActionAttribute);
66         console.log(this.outputActionAttribute);
67         this.addInput(this.inputActionAttribute);
68         this.addOutput(this.outputActionAttribute);
69         this.clearFormInputs();
70     }
71
72     private clearFormInputs() {
73         this.inputActionAttribute = new InputActionAttribute();
74         this.outputActionAttribute = new OutputActionAttribute();
75         this.outputOtherType = '';
76         this.inputOtherType = '';
77     }
78 }