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 {
20 actionAttributesSideBar: boolean;
21 inputActionAttribute = new InputActionAttribute();
22 outputActionAttribute = new OutputActionAttribute();
23 isInputOtherType: boolean;
24 isOutputOtherType: boolean;
28 designerState: DesignerDashboardState;
29 isFunctionAttributeActive = false;
30 functions: FunctionsState;
32 suggestedInputs: string[] = [];
33 suggestedOutputs: string[] = [];
35 tempInputs: string[] = [];
36 tempOutputs: string[] = [];
37 currentInterfaceName: string;
38 functionAndAttributesInput: Map<string, string[]> = new Map<string, string[]>();
39 private currentTargetFunctionName: any;
40 private functionAndAttributesOutput: Map<string, string[]> = new Map<string, string[]>();
41 suggestedAttributes: string[] = [];
42 selectedFunctionName = '';
43 selectedAttributeName = '';
44 isNotComponentResourceResolution = true;
45 currentArtifacts: string[] = [];
46 isParametersHidden = true;
48 constructor(private designerStore: DesignerStore, private functionsStore: FunctionsStore) {
53 console.log('is paramters hidden' + this.isParametersHidden);
54 console.log('is artifacts hidden' + this.isNotComponentResourceResolution);
55 this.designerStore.state$.subscribe(designerState => {
56 this.designerState = designerState;
57 if (this.designerState && this.designerState.actionName) {
58 this.actionName = this.designerState.actionName;
59 console.log(this.actionName);
60 const action = this.designerState.template.workflows[this.actionName] as Action;
62 const steps = Object.keys(action.steps);
63 this.isFunctionAttributeActive = steps && steps.length > 0;
65 this.suggestedOutputs = [];
66 this.suggestedInputs = [];
71 const namesOfInput = Object.keys(action.inputs);
72 this.inputs = this.extractFields(namesOfInput, action.inputs);
76 const namesOfOutput = Object.keys(action.outputs);
77 this.outputs = this.extractFields(namesOfOutput, action.outputs);
82 this.functionsStore.state$.subscribe(functions => {
83 this.functions = functions;
88 private extractFields(namesOfOutput: string[], container: {}) {
90 for (const nameOutput of namesOfOutput) {
91 const fieldAttribute = new OutputActionAttribute();
92 fieldAttribute.name = nameOutput;
93 fieldAttribute.description = container[nameOutput].description;
94 fieldAttribute.required = container[nameOutput].required;
95 fieldAttribute.type = container[nameOutput].type;
96 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
97 fields.push(insertedOutputActionAttribute);
102 addInput(input: InputActionAttribute) {
103 if (input && input.type && input.name) {
104 const insertedInputActionAttribute = Object.assign({}, input);
105 this.newInputs.push(insertedInputActionAttribute);
109 addOutput(output: OutputActionAttribute) {
111 if (output && output.type && output.name) {
112 const insertedOutputActionAttribute = Object.assign({}, output);
113 this.newOutputs.push(insertedOutputActionAttribute);
117 setInputType(type: string) {
118 this.inputActionAttribute.type = type;
119 this.isInputOtherType = this.checkIfTypeIsOther(type);
122 setInputRequired(isRequired) {
123 this.inputActionAttribute.required = isRequired;
126 setOutputRequired(isRequired) {
127 this.outputActionAttribute.required = isRequired;
130 setOutputType(type: string) {
131 this.outputActionAttribute.type = type;
132 this.isOutputOtherType = this.checkIfTypeIsOther(type);
135 checkIfTypeIsOther(type) {
136 return type.includes('Other');
140 this.addInput(this.inputActionAttribute);
141 if (this.selectedFunctionName && this.selectedAttributeName) {
142 this.outputActionAttribute.value =
143 '["' + this.selectedFunctionName + '","' + this.selectedAttributeName + '"]';
145 this.addOutput(this.outputActionAttribute);
146 this.clearFormInputs();
147 this.storeOutputs(this.newOutputs);
148 this.storeInputs((this.newInputs));
149 this.newInputs.forEach(input => {
150 this.inputs.push(input);
153 this.newOutputs.forEach(output => {
154 this.outputs.push(output);
158 private clearFormInputs() {
159 this.inputActionAttribute = new InputActionAttribute();
160 this.outputActionAttribute = new OutputActionAttribute();
161 this.outputOtherType = '';
162 this.inputOtherType = '';
165 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
168 InputActionAttributes.forEach(input => {
169 inputs += this.appendAttributes(input);
172 this.writeAttribute(inputs, 'inputs');
175 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
177 OutputActionAttributes.forEach(output => {
178 outputs += this.appendOutputAttributes(output);
180 this.writeAttribute(outputs, 'outputs');
183 private appendAttributes(inputActionAttribute: InputActionAttribute) {
184 return '"' + inputActionAttribute.name + '" : {\n' +
185 ' "required" : ' + inputActionAttribute.required + ',\n' +
186 ' "type" : "' + inputActionAttribute.type + '",\n' +
187 ' "description" : "' + inputActionAttribute.description + '"\n' +
191 setInputAndOutputs(targetName) {
192 console.log(targetName);
193 const nodeTemplate = this.designerState.template.node_templates[targetName];
194 console.log(this.designerState.template.node_templates);
195 console.log(nodeTemplate);
196 /* tslint:disable:no-string-literal */
197 console.log(nodeTemplate['type']);
198 this.functions.serverFunctions
199 /* tslint:disable:no-string-literal */
200 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
201 .forEach(currentFunction => {
202 console.log(currentFunction);
203 /* tslint:disable:no-string-literal */
204 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
205 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
206 if (interfaces && interfaces.length > 0) {
207 const interfaceName = interfaces[0];
208 console.log(interfaceName);
209 this.currentInterfaceName = interfaceName;
211 if (!this.functionAndAttributesInput.has(targetName)) {
212 this.currentTargetFunctionName = targetName;
213 this.functionAndAttributesInput.set(targetName, []);
216 if (!this.functionAndAttributesOutput.has(targetName)) {
217 this.currentTargetFunctionName = targetName;
218 this.functionAndAttributesOutput.set(targetName, []);
221 if (nodeTemplate['interfaces'] &&
222 nodeTemplate['interfaces'][interfaceName]['operations'] &&
223 nodeTemplate['interfaces'][interfaceName]['operations']['process']
226 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
227 /* tslint:disable:no-string-literal */
228 this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
229 [interfaceName]['operations']['process']['inputs']);
231 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
232 /* tslint:disable:no-string-literal */
233 this.suggestedOutputs = Object.keys(nodeTemplate['interfaces']
234 [interfaceName]['operations']['process']['outputs']);
235 console.log(this.suggestedInputs);
242 console.log(nodeTemplate);
246 console.log('something');
249 addTempInput(suggestedInput: string) {
250 this.addAttribute(this.tempInputs, suggestedInput);
251 this.deleteAttribute(this.suggestedInputs, suggestedInput);
252 this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
255 addTempOutput(suggestedOutput: string) {
256 this.addAttribute(this.tempOutputs, suggestedOutput);
257 this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
258 this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
261 deleteAttribute(container: string[], suggestedAttribute: string) {
262 if (container && suggestedAttribute && container.includes(suggestedAttribute)) {
263 const index: number = container.indexOf(suggestedAttribute);
265 container.splice(index, 1);
270 addAttribute(container: string[], suggestedAttribute: string) {
271 if (container && suggestedAttribute && !container.includes(suggestedAttribute)) {
272 container.push(suggestedAttribute);
277 submitTempAttributes() {
278 this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs');
279 this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs');
282 private writeSelectedAttribute(map: Map<string, string[]>, attributeType: string) {
283 map.forEach((value, key) => {
284 const nodeTemplate = this.getNodeTemplate(key);
285 this.functions.serverFunctions
286 /* tslint:disable:no-string-literal */
287 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
288 .forEach(currentFunction => {
290 if (currentFunction['definition'] && currentFunction['definition']['interfaces']
291 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
292 ['operations']['process'][attributeType]) {
293 let newAttributes = '';
294 const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces']
295 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
296 ['operations']['process'][attributeType];
297 value.forEach(attribute => {
298 newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ',';
300 if (value.length > 0) {
301 this.writeAttribute(newAttributes, attributeType);
308 private writeAttribute(newAttributes: string, attributeType: string) {
309 newAttributes = this.removeTheLastComma(newAttributes);
310 const originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
312 console.log(originalAttributes.substr(0, originalAttributes.length - 1) + ',' + newAttributes + '}');
313 this.designerState.template.workflows[this.actionName][attributeType] =
314 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
315 + ',' + newAttributes + '}');
318 private removeTheLastComma = (newInputs: string) => {
319 if (newInputs.endsWith(',')) {
320 newInputs = newInputs.substr(0, newInputs.length - 1);
325 private convertToString = object => JSON.stringify(object);
327 private convertToObject = stringValue => JSON.parse(stringValue);
329 private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
332 getAttributesAndOutputs(functionName: string) {
333 this.suggestedAttributes = [];
334 console.log(functionName);
335 if (functionName.includes('component-resource-resolution')) {
336 this.isNotComponentResourceResolution = false;
337 this.isParametersHidden = true;
339 this.isNotComponentResourceResolution = true;
340 this.isParametersHidden = true;
342 const nodeTemplate = this.designerState.template.node_templates[functionName];
343 console.log(this.designerState.template.node_templates);
344 console.log(nodeTemplate);
345 /* tslint:disable:no-string-literal */
346 console.log(nodeTemplate['type']);
347 this.functions.serverFunctions
348 /* tslint:disable:no-string-literal */
349 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
350 .forEach(currentFunction => {
351 if (currentFunction.definition['attributes']) {
352 Object.keys(currentFunction.definition['attributes']).forEach(attribute => {
353 this.suggestedAttributes.push(attribute);
354 this.suggestedAttributes.push('assignment-map');
357 console.log(this.suggestedAttributes);
359 this.selectedFunctionName = functionName;
365 addTempOutputAttr(suggestedOutputAndAttribute: string) {
367 this.selectedAttributeName = suggestedOutputAndAttribute;
368 this.currentArtifacts = [];
369 const nodeTemplate = this.designerState.template.node_templates[this.selectedFunctionName];
370 if (nodeTemplate['artifacts']
372 Object.keys(nodeTemplate['artifacts']).forEach(key => {
373 const mappingName = key.split('-')[0];
374 if (!this.currentArtifacts.includes(mappingName)) {
375 this.currentArtifacts.push(mappingName);
379 console.log('happend');
384 private appendOutputAttributes(output: OutputActionAttribute) {
385 return '"' + output.name + '" : {\n' +
386 ' "required" : ' + output.required + ',\n' +
387 ' "type" : "' + output.type + '",\n' +
388 ' "description" : "' + output.description + '",\n' +
389 ' "value\" :' + '{\n' +
390 ' "get_attribute" : ' + output.value + '\n' +
396 addArtifactFile(suggestedArtifact: string) {
397 console.log(suggestedArtifact);
398 this.isParametersHidden = !this.selectedAttributeName.includes('assignment-map');
399 console.log('assignement map ' + this.isParametersHidden);