aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client
diff options
context:
space:
mode:
authorShaabanEltanany <shaaban.eltanany.ext@orange.com>2020-11-05 15:11:37 +0200
committerShaabanEltanany <shaaban.eltanany.ext@orange.com>2020-11-05 15:11:37 +0200
commitaeb93fa27fe2d7d64954edf774526e0c7db88881 (patch)
tree279099af7729df46405d02c862eebdfb998a70dd /cds-ui/designer-client
parente41115226cbc6384a73a66b6bc6f6cedbc91dff3 (diff)
adding import inputs and outputs from functions into actions phase3.
Issue-ID: CCSDK-2779 Signed-off-by: ShaabanEltanany <shaaban.eltanany.ext@orange.com> Change-Id: I036a945eab1ecd0e1b1d5aadf01cdb1c1841d9e9
Diffstat (limited to 'cds-ui/designer-client')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/action-attributes/action-attributes.component.ts116
1 files changed, 91 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 11429ead6..56c1d0e64 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
@@ -33,6 +33,9 @@ export class ActionAttributesComponent implements OnInit {
tempInputs: string[] = [];
tempOutputs: string[] = [];
currentInterfaceName: string;
+ functionAndAttributesInput: Map<string, string[]> = new Map<string, string[]>();
+ private currentTargetFunctionName: any;
+ private functionAndAttributesOutput: Map<string, string[]> = new Map<string, string[]>();
constructor(private designerStore: DesignerStore, private functionsStore: FunctionsStore) {
@@ -156,7 +159,7 @@ export class ActionAttributesComponent implements OnInit {
if (inputs.endsWith(',')) {
inputs = inputs.substr(0, inputs.length - 1);
}
- return JSON.parse('{' + inputs + '}');
+ return this.convertToObject('{' + inputs + '}');
}
private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
@@ -167,7 +170,7 @@ export class ActionAttributesComponent implements OnInit {
if (outputs.endsWith(',')) {
outputs = outputs.substr(0, outputs.length - 1);
}
- return JSON.parse('{' + outputs + '}');
+ return this.convertToObject('{' + outputs + '}');
}
private appendAttributes(output: OutputActionAttribute) {
@@ -198,6 +201,16 @@ export class ActionAttributesComponent implements OnInit {
console.log(interfaceName);
this.currentInterfaceName = interfaceName;
+ if (!this.functionAndAttributesInput.has(targetName)) {
+ this.currentTargetFunctionName = targetName;
+ this.functionAndAttributesInput.set(targetName, []);
+ }
+
+ if (!this.functionAndAttributesOutput.has(targetName)) {
+ this.currentTargetFunctionName = targetName;
+ this.functionAndAttributesOutput.set(targetName, []);
+ }
+
if (nodeTemplate['interfaces'] &&
nodeTemplate['interfaces'][interfaceName]['operations'] &&
nodeTemplate['interfaces'][interfaceName]['operations']['process']
@@ -207,7 +220,6 @@ export class ActionAttributesComponent implements OnInit {
/* tslint:disable:no-string-literal */
this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
[interfaceName]['operations']['process']['inputs']);
- console.log(this.suggestedInputs);
}
if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
/* tslint:disable:no-string-literal */
@@ -230,11 +242,13 @@ export class ActionAttributesComponent implements OnInit {
addTempInput(suggestedInput: string) {
this.addAttribute(this.tempInputs, suggestedInput);
this.deleteAttribute(this.suggestedInputs, suggestedInput);
+ this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
}
addTempOutput(suggestedOutput: string) {
this.addAttribute(this.tempOutputs, suggestedOutput);
this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
+ this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
}
deleteAttribute(container: string[], suggestedAttribute: string) {
@@ -254,30 +268,82 @@ export class ActionAttributesComponent implements OnInit {
submitTempAttributes() {
- if (this.tempInputs && this.tempInputs.length > 0) {
- let newInputs = '';
- this.tempInputs.forEach(tempAttribute => {
- const currentInputNode: string = this.designerState.template.node_templates[this.actionName]['interfaces']
- [this.currentInterfaceName]['operations']['process']['inputs'][tempAttribute];
- const currentInputNodeAsString = JSON.stringify(currentInputNode);
- newInputs += '"' + tempAttribute + '": ' + currentInputNodeAsString + ',';
+ this.writeSelectedAttributeInputs();
+ this.writeSelectedAttributeOutputs();
+ }
- });
- if (newInputs.endsWith(',')) {
- newInputs = newInputs.substr(0, newInputs.length - 1);
- }
- const originalInputs = JSON.stringify(this.designerState.template.workflows[this.actionName]['inputs']);
- console.log(originalInputs.substr(0, originalInputs.length - 1) + ',' + newInputs + '}');
- this.designerState.template.workflows[this.actionName]['inputs'] =
- JSON.parse(originalInputs.substr(0, originalInputs.length - 1) + ',' + newInputs + '}');
- }
+ private writeSelectedAttributeOutputs() {
+ this.functionAndAttributesOutput.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']['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 + '}');
+ }
+ }
+ });
+ });
+ }
- if (this.tempOutputs && this.tempOutputs.length > 0) {
- this.tempOutputs.forEach(tempAttribute => {
- const currentOutputNode = this.designerState.template.node_templates[this.actionName]['interfaces']
- [this.currentInterfaceName]['operations']['process']['outputs'][tempAttribute];
- console.log(currentOutputNode);
- });
+
+ 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']
+ [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
+ ['operations']['process']['inputs'];
+ key.forEach(attribute => {
+ newInputs += '"' + attribute + '": ' + this.convertToString(inputs[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 + '}');
+ }
+ }
+
+
+ });
+ });
+ }
+
+ private removeTheLastComma = (newInputs: string) => {
+ if (newInputs.endsWith(',')) {
+ newInputs = newInputs.substr(0, newInputs.length - 1);
}
+ return newInputs;
}
+
+ private convertToString = object => JSON.stringify(object);
+
+ private convertToObject = stringValue => JSON.parse(stringValue);
+
+ private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
+
}