1 import {Component, OnInit} from '@angular/core';
2 import {InputActionAttribute, OutputActionAttribute} from './models/InputActionAttribute';
3 import {DesignerStore} from '../designer.store';
4 import {DesignerDashboardState} from '../model/designer.dashboard.state';
5 import {Action} from './models/Action';
6 import {FunctionsStore} from '../functions.store';
7 import {FunctionsState} from '../model/functions.state';
10 selector: 'app-action-attributes',
11 templateUrl: './action-attributes.component.html',
12 styleUrls: ['./action-attributes.component.css']
14 export class ActionAttributesComponent implements OnInit {
18 actionAttributesSideBar: boolean;
19 inputActionAttribute = new InputActionAttribute();
20 outputActionAttribute = new OutputActionAttribute();
21 isInputOtherType: boolean;
22 isOutputOtherType: boolean;
26 designerState: DesignerDashboardState;
27 isFunctionAttributeActive = false;
28 functions: FunctionsState;
30 constructor(private designerStore: DesignerStore, private functionsStore: FunctionsStore) {
35 this.designerStore.state$.subscribe(designerState => {
36 this.designerState = designerState;
37 if (this.designerState && this.designerState.actionName) {
38 this.actionName = this.designerState.actionName;
39 const action = this.designerState.template.workflows[this.actionName] as Action;
41 const steps = Object.keys(action.steps);
42 if (steps && steps.length > 0) {
43 this.isFunctionAttributeActive = true;
45 this.isFunctionAttributeActive = false;
47 steps.forEach(step => {
48 const target = action.steps[step].target;
49 this.getInputs(target);
56 const namesOfInput = Object.keys(action.inputs);
57 this.inputs = this.extractFields(namesOfInput, action.inputs);
61 const namesOfOutput = Object.keys(action.outputs);
62 this.outputs = this.extractFields(namesOfOutput, action.outputs);
67 this.functionsStore.state$.subscribe(functions => {
68 this.functions = functions;
73 private extractFields(namesOfOutput: string[], container: {}) {
75 for (const nameOutput of namesOfOutput) {
76 const fieldAttribute = new OutputActionAttribute();
77 fieldAttribute.name = nameOutput;
78 fieldAttribute.description = container[nameOutput].description;
79 fieldAttribute.required = container[nameOutput].required;
80 fieldAttribute.type = container[nameOutput].type;
81 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
82 fields.push(insertedOutputActionAttribute);
87 addInput(input: InputActionAttribute) {
88 if (input && input.type && input.name) {
89 const insertedInputActionAttribute = Object.assign({}, input);
90 this.inputs.push(insertedInputActionAttribute);
94 addOutput(output: OutputActionAttribute) {
95 if (output && output.type && output.name) {
96 const insertedOutputActionAttribute = Object.assign({}, output);
97 this.outputs.push(insertedOutputActionAttribute);
101 setInputType(type: string) {
102 this.inputActionAttribute.type = type;
103 this.isInputOtherType = this.checkIfTypeIsOther(type);
106 setInputRequired(isRequired) {
107 this.inputActionAttribute.required = isRequired;
110 setOutputRequired(isRequired) {
111 this.outputActionAttribute.required = isRequired;
114 setOutputType(type: string) {
115 this.outputActionAttribute.type = type;
116 this.isOutputOtherType = this.checkIfTypeIsOther(type);
119 checkIfTypeIsOther(type) {
120 return type.includes('Other');
124 this.addInput(this.inputActionAttribute);
125 this.addOutput(this.outputActionAttribute);
126 this.clearFormInputs();
127 this.designerStore.setInputsAndOutputsToSpecificWorkflow(this.storeInputs(this.inputs)
128 , this.storeOutputs(this.outputs), this.actionName);
131 private clearFormInputs() {
132 this.inputActionAttribute = new InputActionAttribute();
133 this.outputActionAttribute = new OutputActionAttribute();
134 this.outputOtherType = '';
135 this.inputOtherType = '';
138 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
141 InputActionAttributes.forEach(input => {
142 inputs += this.appendAttributes(input);
145 if (inputs.endsWith(',')) {
146 inputs = inputs.substr(0, inputs.length - 1);
148 return JSON.parse('{' + inputs + '}');
151 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
153 OutputActionAttributes.forEach(output => {
154 outputs += this.appendAttributes(output);
156 if (outputs.endsWith(',')) {
157 outputs = outputs.substr(0, outputs.length - 1);
159 return JSON.parse('{' + outputs + '}');
162 private appendAttributes(output: OutputActionAttribute) {
163 return '"' + output.name + '" : {\n' +
164 ' "required" : ' + output.required + ',\n' +
165 ' "type" : "' + output.type + '",\n' +
166 ' "description" : "' + output.description + '"\n' +
170 getInputs(targetName) {
171 const nodeTemplate = this.designerState.template.node_templates[targetName];
172 /* tslint:disable:no-string-literal */
173 console.log(nodeTemplate['type']);
174 this.functions.serverFunctions
175 /* tslint:disable:no-string-literal */
176 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
177 .forEach(currentFunction => {
178 console.log(currentFunction);
179 /* tslint:disable:no-string-literal */
180 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
181 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
182 if (interfaces && interfaces.length > 0) {
183 const interfaceName = interfaces[0];
184 if (nodeTemplate['interfaces'][interfaceName]['operations'] &&
185 nodeTemplate['interfaces'][interfaceName]['operations']['process']
187 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
188 /* tslint:disable:no-string-literal */
189 console.log(Object.keys(nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']));
191 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
192 /* tslint:disable:no-string-literal */
193 console.log(Object.keys(nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']));
200 console.log(nodeTemplate);
204 console.log('something');