From 4f7d5991694ecd8533877f90c16aeeecd7b5acd9 Mon Sep 17 00:00:00 2001 From: ShaabanEltanany Date: Sun, 8 Nov 2020 10:26:08 +0200 Subject: adding import inputs and outputs from functions into actions Refactor. Issue-ID: CCSDK-2779 Signed-off-by: ShaabanEltanany Change-Id: Iced334d788728da817c19f0b208c8fb2d821f889 --- .../action-attributes.component.ts | 79 ++++++---------------- 1 file changed, 21 insertions(+), 58 deletions(-) (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts') diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts index 56c1d0e64..b0b6ae56d 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts @@ -46,24 +46,16 @@ export class ActionAttributesComponent implements OnInit { this.designerState = designerState; if (this.designerState && this.designerState.actionName) { this.actionName = this.designerState.actionName; + console.log(this.actionName); const action = this.designerState.template.workflows[this.actionName] as Action; if (action.steps) { const steps = Object.keys(action.steps); - if (steps && steps.length > 0) { - this.isFunctionAttributeActive = true; - } else { - this.isFunctionAttributeActive = false; - } + this.isFunctionAttributeActive = steps && steps.length > 0; this.steps = steps; this.suggestedOutputs = []; this.suggestedInputs = []; - /*steps.forEach(step => { - const target = action.steps[step].target; - this.getInputs(target); - });*/ } - this.inputs = []; if (action.inputs) { const namesOfInput = Object.keys(action.inputs); @@ -268,67 +260,38 @@ export class ActionAttributesComponent implements OnInit { submitTempAttributes() { - this.writeSelectedAttributeInputs(); - this.writeSelectedAttributeOutputs(); + this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs'); + this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs'); } - private writeSelectedAttributeOutputs() { - this.functionAndAttributesOutput.forEach((key, value) => { - const nodeTemplate = this.getNodeTemplate(value); + private writeSelectedAttribute(map: Map, attributeType: string) { + map.forEach((value, key) => { + const nodeTemplate = this.getNodeTemplate(key); this.functions.serverFunctions /* tslint:disable:no-string-literal */ .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type'])) .forEach(currentFunction => { - if (currentFunction['definition'] && currentFunction['definition']['interfaces'] - [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])] - ['operations']['process']['outputs']) { - let newOutputs = ''; - const outputs = currentFunction['definition'] && currentFunction['definition']['interfaces'] - [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])] - ['operations']['process']['outputs']; - key.forEach(attribute => { - newOutputs += '"' + attribute + '": ' + this.convertToString(outputs[attribute]) + ','; - }); - if (key.length > 0) { - newOutputs = this.removeTheLastComma(newOutputs); - const originalOutputs = this.convertToString(this.designerState.template.workflows[this.actionName]['outputs']); - console.log(originalOutputs.substr(0, originalOutputs.length - 1) + ',' + newOutputs + '}'); - this.designerState.template.workflows[this.actionName]['outputs'] = - this.convertToObject(originalOutputs.substr(0, originalOutputs.length - 1) + ',' + newOutputs + '}'); - } - } - }); - }); - } - - private writeSelectedAttributeInputs() { - this.functionAndAttributesInput.forEach((key, value) => { - const nodeTemplate = this.getNodeTemplate(value); - this.functions.serverFunctions - /* tslint:disable:no-string-literal */ - .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type'])) - .forEach(currentFunction => { if (currentFunction['definition'] && currentFunction['definition']['interfaces'] [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])] - ['operations']['process']['inputs']) { - let newInputs = ''; - const inputs = currentFunction['definition'] && currentFunction['definition']['interfaces'] + ['operations']['process'][attributeType]) { + let newAttributes = ''; + const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces'] [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])] - ['operations']['process']['inputs']; - key.forEach(attribute => { - newInputs += '"' + attribute + '": ' + this.convertToString(inputs[attribute]) + ','; + ['operations']['process'][attributeType]; + value.forEach(attribute => { + newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ','; }); - if (key.length > 0) { - newInputs = this.removeTheLastComma(newInputs); - const originalInputs = this.convertToString(this.designerState.template.workflows[this.actionName]['inputs']); - console.log(originalInputs.substr(0, originalInputs.length - 1) + ',' + newInputs + '}'); - this.designerState.template.workflows[this.actionName]['inputs'] = - this.convertToObject(originalInputs.substr(0, originalInputs.length - 1) + ',' + newInputs + '}'); + if (value.length > 0) { + newAttributes = this.removeTheLastComma(newAttributes); + const originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName] + [attributeType]); + console.log(originalAttributes.substr(0, originalAttributes.length - 1) + ',' + newAttributes + '}'); + this.designerState.template.workflows[this.actionName][attributeType] = + this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1) + + ',' + newAttributes + '}'); } } - - }); }); } -- cgit 1.2.3-korg