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';
8 import {PackageCreationStore} from '../../package-creation/package-creation.store';
9 import {CBAPackage} from '../../package-creation/mapping-models/CBAPacakge.model';
12 selector: 'app-action-attributes',
13 templateUrl: './action-attributes.component.html',
14 styleUrls: ['./action-attributes.component.css']
16 export class ActionAttributesComponent implements OnInit {
22 actionAttributesSideBar: boolean;
23 inputActionAttribute = new InputActionAttribute();
24 outputActionAttribute = new OutputActionAttribute();
25 isInputOtherType: boolean;
26 isOutputOtherType: boolean;
30 designerState: DesignerDashboardState;
31 isFunctionAttributeActive = false;
32 functions: FunctionsState;
34 suggestedInputs: string[] = [];
35 suggestedOutputs: string[] = [];
37 tempInputs: string[] = [];
38 tempOutputs: string[] = [];
39 currentInterfaceName: string;
40 functionAndAttributesInput: Map<string, string[]> = new Map<string, string[]>();
41 private currentTargetFunctionName: any;
42 private functionAndAttributesOutput: Map<string, string[]> = new Map<string, string[]>();
43 suggestedAttributes: string[] = [];
44 selectedFunctionName = '';
45 selectedAttributeName = '';
46 isNotComponentResourceResolution = true;
47 currentArtifacts: string[] = [];
48 isParametersHidden = true;
49 cbaPackage: CBAPackage;
50 suggestedMappingParameters: string[] = [];
51 selectedParameterList: string[] = [];
52 currentSuggestedArtifact: string;
54 constructor(private designerStore: DesignerStore,
55 private functionsStore: FunctionsStore,
56 private packageCreationStore: PackageCreationStore) {
61 console.log('is paramters hidden' + this.isParametersHidden);
62 console.log('is artifacts hidden' + this.isNotComponentResourceResolution);
63 this.designerStore.state$.subscribe(designerState => {
64 this.designerState = designerState;
65 if (this.designerState && this.designerState.actionName) {
66 this.actionName = this.designerState.actionName;
67 console.log(this.actionName);
68 const action = this.designerState.template.workflows[this.actionName] as Action;
70 const steps = Object.keys(action.steps);
71 this.isFunctionAttributeActive = steps && steps.length > 0;
73 this.suggestedOutputs = [];
74 this.suggestedInputs = [];
79 const namesOfInput = Object.keys(action.inputs);
80 this.inputs = this.extractFields(namesOfInput, action.inputs);
84 const namesOfOutput = Object.keys(action.outputs);
85 this.outputs = this.extractFields(namesOfOutput, action.outputs);
90 this.functionsStore.state$.subscribe(functions => {
91 this.functions = functions;
94 this.packageCreationStore.state$
95 .subscribe(cbaPackage => {
96 this.cbaPackage = cbaPackage;
102 private extractFields(namesOfOutput: string[], container: {}) {
104 for (const nameOutput of namesOfOutput) {
105 const fieldAttribute = new OutputActionAttribute();
106 fieldAttribute.name = nameOutput;
107 fieldAttribute.description = container[nameOutput].description;
108 fieldAttribute.required = container[nameOutput].required;
109 fieldAttribute.type = container[nameOutput].type;
110 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
111 fields.push(insertedOutputActionAttribute);
116 addInput(input: InputActionAttribute) {
117 if (input && input.type && input.name) {
118 const insertedInputActionAttribute = Object.assign({}, input);
119 this.newInputs.push(insertedInputActionAttribute);
123 addOutput(output: OutputActionAttribute) {
125 if (output && output.type && output.name) {
126 const insertedOutputActionAttribute = Object.assign({}, output);
127 this.newOutputs.push(insertedOutputActionAttribute);
131 setInputType(type: string) {
132 this.inputActionAttribute.type = type;
133 this.isInputOtherType = this.checkIfTypeIsOther(type);
136 setInputRequired(isRequired) {
137 this.inputActionAttribute.required = isRequired;
140 setOutputRequired(isRequired) {
141 this.outputActionAttribute.required = isRequired;
144 setOutputType(type: string) {
145 this.outputActionAttribute.type = type;
146 this.isOutputOtherType = this.checkIfTypeIsOther(type);
149 checkIfTypeIsOther(type) {
150 return type.includes('Other');
154 this.addInput(this.inputActionAttribute);
155 if (this.selectedFunctionName && this.selectedAttributeName) {
156 console.log(this.getValue());
157 this.outputActionAttribute.value =
160 this.addOutput(this.outputActionAttribute);
161 this.clearFormInputs();
162 this.storeOutputs(this.newOutputs);
163 this.storeInputs((this.newInputs));
164 this.newInputs.forEach(input => {
165 if (!this.inputs.includes(input)) {
166 this.inputs.push(input);
170 this.newOutputs.forEach(output => {
171 if (!this.outputs.includes(output)) {
172 this.outputs.push(output);
178 let value = '["' + this.selectedFunctionName + '", "' + '","' + this.selectedAttributeName;
180 if (!this.isParametersHidden) {
181 let currentSelected = '';
182 for (const selectedParameter of this.selectedParameterList) {
183 currentSelected += '"' + selectedParameter + '",';
185 value += '","' + this.currentSuggestedArtifact + '",'
186 + currentSelected.substr(0, currentSelected.length - 2) + '';
187 } else if (!this.isNotComponentResourceResolution && this.currentSuggestedArtifact) {
188 value += '","' + this.currentSuggestedArtifact + '';
192 return value += '"]';
195 public clearFormInputs() {
196 console.log('trying to clear ');
197 this.inputActionAttribute = new InputActionAttribute();
198 this.outputActionAttribute = new OutputActionAttribute();
199 this.outputOtherType = '';
200 this.inputOtherType = '';
203 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
206 InputActionAttributes.forEach(input => {
207 inputs += this.appendAttributes(input);
210 if (inputs.length > 0) {
211 this.writeAttribute(inputs, 'inputs');
215 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
217 OutputActionAttributes.forEach(output => {
218 outputs += this.appendOutputAttributes(output);
220 if (outputs.length > 0) {
221 this.writeAttribute(outputs, 'outputs');
226 private appendAttributes(inputActionAttribute: InputActionAttribute) {
227 return '"' + inputActionAttribute.name + '" : {\n' +
228 ' "required" : ' + inputActionAttribute.required + ',\n' +
229 ' "type" : "' + inputActionAttribute.type + '",\n' +
230 ' "description" : "' + inputActionAttribute.description + '"\n' +
234 setInputAndOutputs(targetName) {
235 console.log(targetName);
236 const nodeTemplate = this.designerState.template.node_templates[targetName];
237 console.log(this.designerState.template.node_templates);
238 console.log(nodeTemplate);
239 /* tslint:disable:no-string-literal */
240 console.log(nodeTemplate['type']);
241 this.functions.serverFunctions
242 /* tslint:disable:no-string-literal */
243 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
244 .forEach(currentFunction => {
245 console.log(currentFunction);
246 /* tslint:disable:no-string-literal */
247 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
248 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
249 if (interfaces && interfaces.length > 0) {
250 const interfaceName = interfaces[0];
251 console.log(interfaceName);
252 this.currentInterfaceName = interfaceName;
254 if (!this.functionAndAttributesInput.has(targetName)) {
255 this.currentTargetFunctionName = targetName;
256 this.functionAndAttributesInput.set(targetName, []);
259 if (!this.functionAndAttributesOutput.has(targetName)) {
260 this.currentTargetFunctionName = targetName;
261 this.functionAndAttributesOutput.set(targetName, []);
264 if (nodeTemplate['interfaces'] &&
265 nodeTemplate['interfaces'][interfaceName]['operations'] &&
266 nodeTemplate['interfaces'][interfaceName]['operations']['process']
269 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
270 /* tslint:disable:no-string-literal */
271 this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
272 [interfaceName]['operations']['process']['inputs']);
274 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
275 /* tslint:disable:no-string-literal */
276 this.suggestedOutputs = Object.keys(nodeTemplate['interfaces']
277 [interfaceName]['operations']['process']['outputs']);
278 console.log(this.suggestedInputs);
285 console.log(nodeTemplate);
289 console.log('something');
292 addTempInput(suggestedInput: string) {
293 this.addAttribute(this.tempInputs, suggestedInput);
294 this.deleteAttribute(this.suggestedInputs, suggestedInput);
295 this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
298 addTempOutput(suggestedOutput: string) {
299 this.addAttribute(this.tempOutputs, suggestedOutput);
300 this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
301 this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
304 deleteAttribute(container: string[], suggestedAttribute: string) {
305 if (container && suggestedAttribute && container.includes(suggestedAttribute)) {
306 const index: number = container.indexOf(suggestedAttribute);
308 container.splice(index, 1);
313 addAttribute(container: string[], suggestedAttribute: string) {
314 if (container && suggestedAttribute && !container.includes(suggestedAttribute)) {
315 container.push(suggestedAttribute);
320 submitTempAttributes() {
321 this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs');
322 this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs');
325 private writeSelectedAttribute(map: Map<string, string[]>, attributeType: string) {
326 map.forEach((value, key) => {
327 const nodeTemplate = this.getNodeTemplate(key);
328 this.functions.serverFunctions
329 /* tslint:disable:no-string-literal */
330 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
331 .forEach(currentFunction => {
333 if (currentFunction['definition'] && currentFunction['definition']['interfaces']
334 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
335 ['operations']['process'][attributeType]) {
336 let newAttributes = '';
337 const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces']
338 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
339 ['operations']['process'][attributeType];
340 value.forEach(attribute => {
341 newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ',';
343 if (value.length > 0) {
344 this.writeAttribute(newAttributes, attributeType);
351 private writeAttribute(newAttributes: string, attributeType: string) {
352 newAttributes = this.removeTheLastComma(newAttributes);
353 console.log(newAttributes);
354 let originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
356 this.createAttributeTypeIfNotExisted(originalAttributes, attributeType);
357 originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
359 if (originalAttributes.length > 2) {
360 this.designerState.template.workflows[this.actionName][attributeType] =
361 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
362 + ',' + newAttributes + '}');
364 this.designerState.template.workflows[this.actionName][attributeType] =
365 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
366 + newAttributes + '}');
368 /* console.log(originalAttributes.substr(0, originalAttributes.length - 1) + ',' + newAttributes + '}');
369 this.designerState.template.workflows[this.actionName][attributeType] =
370 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
371 + ',' + newAttributes + '}');*/
374 private removeTheLastComma(newInputs: string): string {
375 if (newInputs.endsWith(',')) {
376 newInputs = newInputs.substr(0, newInputs.length - 1);
381 private convertToString = object => JSON.stringify(object);
383 private convertToObject = stringValue => JSON.parse(stringValue);
385 private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
388 getAttributesAndOutputs(functionName: string) {
389 this.suggestedAttributes = [];
390 console.log(functionName);
392 const nodeTemplate = this.designerState.template.node_templates[functionName];
393 if (nodeTemplate['type'].includes('component-resource-resolution')) {
394 this.isNotComponentResourceResolution = false;
395 this.isParametersHidden = true;
397 this.isNotComponentResourceResolution = true;
398 this.isParametersHidden = true;
400 /* tslint:disable:no-string-literal */
401 console.log(nodeTemplate['type']);
402 this.functions.serverFunctions
403 /* tslint:disable:no-string-literal */
404 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
405 .forEach(currentFunction => {
406 if (currentFunction.definition['attributes']) {
407 Object.keys(currentFunction.definition['attributes']).forEach(attribute => {
408 this.suggestedAttributes.push(attribute);
409 this.suggestedAttributes.push('assignment-map');
412 console.log(this.suggestedAttributes);
414 this.selectedFunctionName = functionName;
420 addTempOutputAttr(suggestedOutputAndAttribute: string) {
422 this.selectedAttributeName = suggestedOutputAndAttribute;
423 this.currentArtifacts = [];
424 const nodeTemplate = this.designerState.template.node_templates[this.selectedFunctionName];
425 if (nodeTemplate['artifacts']
427 Object.keys(nodeTemplate['artifacts']).forEach(key => {
428 const mappingName = key.split('-')[0];
429 if (!this.currentArtifacts.includes(mappingName)) {
430 this.currentArtifacts.push(mappingName);
434 console.log('happend');
439 private appendOutputAttributes(output: OutputActionAttribute) {
440 return '"' + output.name + '" : {\n' +
441 ' "required" : ' + output.required + ',\n' +
442 ' "type" : "' + output.type + '",\n' +
443 ' "description" : "' + output.description + '",\n' +
444 ' "value\" :' + '{\n' +
445 ' "get_attribute" : ' + output.value + '\n' +
451 addArtifactFile(suggestedArtifact: string) {
452 this.currentSuggestedArtifact = suggestedArtifact;
453 this.isParametersHidden = !this.selectedAttributeName.includes('assignment-map');
454 if (!this.isParametersHidden) {
455 this.suggestedMappingParameters = this.getSuggestedMappingParameters(suggestedArtifact);
459 private getSuggestedMappingParameters(suggestedArtifact: string) {
460 const suggestedMappingParameters = [];
462 this.cbaPackage.mapping.files.forEach(((value, key) => {
463 if (key.includes(suggestedArtifact)) {
465 JSON.parse(value).forEach(value2 => {
466 suggestedMappingParameters.push(value2['name']);
470 return suggestedMappingParameters;
473 addSuggestedMappingParameter(suggestedMappingParameter: string) {
474 this.addAttribute(this.selectedParameterList, suggestedMappingParameter);
475 this.deleteAttribute(this.suggestedMappingParameters, suggestedMappingParameter);
479 editAttribute(input: any) {
483 private createAttributeTypeIfNotExisted(originalAttributes: string, attributeType: string) {
484 if (!originalAttributes) {
485 this.designerState.template.workflows[this.actionName][attributeType] = {};