diff options
author | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-11-09 13:04:44 +0200 |
---|---|---|
committer | ShaabanEltanany <shaaban.eltanany.ext@orange.com> | 2020-11-09 15:36:00 +0200 |
commit | b4932b02edc5d6bef5cec16d88f35dda392e3f91 (patch) | |
tree | 7f422d2fc4a8d4897a24b055ef8bc976239afb83 /cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts | |
parent | 3b653f855c95d9ebfb88e537f0f2fcc5c96ac164 (diff) |
adding value attribute for customized output for action
Issue-ID: CCSDK-2975
Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com>
Change-Id: I9a7d15943d9b3c59f0444d4b98597f6af57e3044
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts')
-rw-r--r-- | cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts | 102 |
1 files changed, 77 insertions, 25 deletions
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 b0b6ae56d..9f96e2ccf 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 @@ -15,6 +15,8 @@ export class ActionAttributesComponent implements OnInit { inputs = []; outputs = []; + newInputs = []; + newOutputs = []; actionAttributesSideBar: boolean; inputActionAttribute = new InputActionAttribute(); outputActionAttribute = new OutputActionAttribute(); @@ -36,6 +38,9 @@ export class ActionAttributesComponent implements OnInit { functionAndAttributesInput: Map<string, string[]> = new Map<string, string[]>(); private currentTargetFunctionName: any; private functionAndAttributesOutput: Map<string, string[]> = new Map<string, string[]>(); + suggestedAttributes: string[] = []; + selectedFunctionName = ''; + selectedAttributeName = ''; constructor(private designerStore: DesignerStore, private functionsStore: FunctionsStore) { @@ -92,7 +97,7 @@ export class ActionAttributesComponent implements OnInit { addInput(input: InputActionAttribute) { if (input && input.type && input.name) { const insertedInputActionAttribute = Object.assign({}, input); - this.inputs.push(insertedInputActionAttribute); + this.newInputs.push(insertedInputActionAttribute); } } @@ -100,7 +105,7 @@ export class ActionAttributesComponent implements OnInit { console.log(output); if (output && output.type && output.name) { const insertedOutputActionAttribute = Object.assign({}, output); - this.outputs.push(insertedOutputActionAttribute); + this.newOutputs.push(insertedOutputActionAttribute); } } @@ -128,10 +133,21 @@ export class ActionAttributesComponent implements OnInit { submitAttributes() { this.addInput(this.inputActionAttribute); + if (this.selectedFunctionName && this.selectedAttributeName) { + this.outputActionAttribute.value = + '["' + this.selectedFunctionName + '","' + this.selectedAttributeName + '"]'; + } this.addOutput(this.outputActionAttribute); this.clearFormInputs(); - this.designerStore.setInputsAndOutputsToSpecificWorkflow(this.storeInputs(this.inputs) - , this.storeOutputs(this.outputs), this.actionName); + this.storeOutputs(this.newOutputs); + this.storeInputs((this.newInputs)); + this.newInputs.forEach(input => { + this.inputs.push(input); + }); + + this.newOutputs.forEach(output => { + this.outputs.push(output); + }); } private clearFormInputs() { @@ -148,28 +164,22 @@ export class ActionAttributesComponent implements OnInit { inputs += this.appendAttributes(input); }); - if (inputs.endsWith(',')) { - inputs = inputs.substr(0, inputs.length - 1); - } - return this.convertToObject('{' + inputs + '}'); + this.writeAttribute(inputs, 'inputs'); } private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) { let outputs = ''; OutputActionAttributes.forEach(output => { - outputs += this.appendAttributes(output); + outputs += this.appendOutputAttributes(output); }); - if (outputs.endsWith(',')) { - outputs = outputs.substr(0, outputs.length - 1); - } - return this.convertToObject('{' + outputs + '}'); + this.writeAttribute(outputs, 'outputs'); } - private appendAttributes(output: OutputActionAttribute) { - return '"' + output.name + '" : {\n' + - ' "required" : ' + output.required + ',\n' + - ' "type" : "' + output.type + '",\n' + - ' "description" : "' + output.description + '"\n' + + private appendAttributes(inputActionAttribute: InputActionAttribute) { + return '"' + inputActionAttribute.name + '" : {\n' + + ' "required" : ' + inputActionAttribute.required + ',\n' + + ' "type" : "' + inputActionAttribute.type + '",\n' + + ' "description" : "' + inputActionAttribute.description + '"\n' + ' },'; } @@ -283,19 +293,23 @@ export class ActionAttributesComponent implements OnInit { newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ','; }); 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 + '}'); + this.writeAttribute(newAttributes, attributeType); } } }); }); } + private writeAttribute(newAttributes: string, attributeType: string) { + 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 + '}'); + } + private removeTheLastComma = (newInputs: string) => { if (newInputs.endsWith(',')) { newInputs = newInputs.substr(0, newInputs.length - 1); @@ -309,4 +323,42 @@ export class ActionAttributesComponent implements OnInit { private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value]; + getAttributesAndOutputs(functionName: string) { + this.suggestedAttributes = []; + console.log(functionName); + const nodeTemplate = this.designerState.template.node_templates[functionName]; + console.log(this.designerState.template.node_templates); + console.log(nodeTemplate); + /* tslint:disable:no-string-literal */ + console.log(nodeTemplate['type']); + this.functions.serverFunctions + /* tslint:disable:no-string-literal */ + .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type'])) + .forEach(currentFunction => { + if (currentFunction.definition['attributes']) { + Object.keys(currentFunction.definition['attributes']).forEach(attribute => { + this.suggestedAttributes.push(attribute); + }); + } + console.log(this.suggestedAttributes); + this.selectedFunctionName = functionName; + }); + } + + addTempOutputAttr(suggestedOutputAndAttribute: string) { + this.selectedAttributeName = suggestedOutputAndAttribute; + } + + + private appendOutputAttributes(output: OutputActionAttribute) { + return '"' + output.name + '" : {\n' + + ' "required" : ' + output.required + ',\n' + + ' "type" : "' + output.type + '",\n' + + ' "description" : "' + output.description + '",\n' + + ' "value\" :' + '{\n' + + ' "get_attribute" : ' + output.value + '\n' + + ' }\n' + + ' },'; + + } } |