diff options
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 | 205 |
1 files changed, 188 insertions, 17 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 ee4b19930..11429ead6 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 @@ -1,6 +1,10 @@ import {Component, OnInit} from '@angular/core'; import {InputActionAttribute, OutputActionAttribute} from './models/InputActionAttribute'; import {DesignerStore} from '../designer.store'; +import {DesignerDashboardState} from '../model/designer.dashboard.state'; +import {Action} from './models/Action'; +import {FunctionsStore} from '../functions.store'; +import {FunctionsState} from '../model/functions.state'; @Component({ selector: 'app-action-attributes', @@ -18,12 +22,76 @@ export class ActionAttributesComponent implements OnInit { isOutputOtherType: boolean; outputOtherType = ''; inputOtherType = ''; + actionName = ''; + designerState: DesignerDashboardState; + isFunctionAttributeActive = false; + functions: FunctionsState; + steps: string[]; + suggestedInputs: string[] = []; + suggestedOutputs: string[] = []; - constructor(private designerStore: DesignerStore) { + tempInputs: string[] = []; + tempOutputs: string[] = []; + currentInterfaceName: string; + + constructor(private designerStore: DesignerStore, private functionsStore: FunctionsStore) { } ngOnInit() { + this.designerStore.state$.subscribe(designerState => { + this.designerState = designerState; + if (this.designerState && this.designerState.actionName) { + this.actionName = this.designerState.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.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); + this.inputs = this.extractFields(namesOfInput, action.inputs); + } + this.outputs = []; + if (action.outputs) { + const namesOfOutput = Object.keys(action.outputs); + this.outputs = this.extractFields(namesOfOutput, action.outputs); + } + } + }); + + this.functionsStore.state$.subscribe(functions => { + this.functions = functions; + }); + } + + + private extractFields(namesOfOutput: string[], container: {}) { + const fields = []; + for (const nameOutput of namesOfOutput) { + const fieldAttribute = new OutputActionAttribute(); + fieldAttribute.name = nameOutput; + fieldAttribute.description = container[nameOutput].description; + fieldAttribute.required = container[nameOutput].required; + fieldAttribute.type = container[nameOutput].type; + const insertedOutputActionAttribute = Object.assign({}, fieldAttribute); + fields.push(insertedOutputActionAttribute); + } + return fields; } addInput(input: InputActionAttribute) { @@ -34,6 +102,7 @@ export class ActionAttributesComponent implements OnInit { } addOutput(output: OutputActionAttribute) { + console.log(output); if (output && output.type && output.name) { const insertedOutputActionAttribute = Object.assign({}, output); this.outputs.push(insertedOutputActionAttribute); @@ -63,14 +132,11 @@ export class ActionAttributesComponent implements OnInit { } submitAttributes() { - console.log(this.inputActionAttribute); - console.log(this.outputActionAttribute); this.addInput(this.inputActionAttribute); this.addOutput(this.outputActionAttribute); this.clearFormInputs(); - console.log(this.storeInputs(this.inputs)); - this.designerStore.setInputsToSpecificWorkflow(this.storeInputs(this.inputs)); - console.log(this.storeOutputs(this.outputs)); + this.designerStore.setInputsAndOutputsToSpecificWorkflow(this.storeInputs(this.inputs) + , this.storeOutputs(this.outputs), this.actionName); } private clearFormInputs() { @@ -87,9 +153,10 @@ export class ActionAttributesComponent implements OnInit { inputs += this.appendAttributes(input); }); - const returnedInputMap = new Map<string, string>(); - returnedInputMap.set('inputs', inputs); - return returnedInputMap; + if (inputs.endsWith(',')) { + inputs = inputs.substr(0, inputs.length - 1); + } + return JSON.parse('{' + inputs + '}'); } private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) { @@ -97,16 +164,120 @@ export class ActionAttributesComponent implements OnInit { OutputActionAttributes.forEach(output => { outputs += this.appendAttributes(output); }); - const returnedOutputMap = new Map<string, string>(); - returnedOutputMap.set('outputs', outputs); - return returnedOutputMap; + if (outputs.endsWith(',')) { + outputs = outputs.substr(0, outputs.length - 1); + } + return JSON.parse('{' + outputs + '}'); } private appendAttributes(output: OutputActionAttribute) { - return '"' + output.name + '":{\n' + - ' \'required\': ' + output.required + ',\n' + - ' \'type\': "' + output.type + '",\n' + - ' \'description\': "' + output.description + '"\n' + - ' }' + '\n'; + return '"' + output.name + '" : {\n' + + ' "required" : ' + output.required + ',\n' + + ' "type" : "' + output.type + '",\n' + + ' "description" : "' + output.description + '"\n' + + ' },'; + } + + setInputAndOutputs(targetName) { + console.log(targetName); + const nodeTemplate = this.designerState.template.node_templates[targetName]; + 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 => { + console.log(currentFunction); + /* tslint:disable:no-string-literal */ + if (currentFunction['definition'] && currentFunction['definition']['interfaces']) { + const interfaces = Object.keys(currentFunction['definition']['interfaces']); + if (interfaces && interfaces.length > 0) { + const interfaceName = interfaces[0]; + console.log(interfaceName); + this.currentInterfaceName = interfaceName; + + if (nodeTemplate['interfaces'] && + nodeTemplate['interfaces'][interfaceName]['operations'] && + nodeTemplate['interfaces'][interfaceName]['operations']['process'] + ) { + console.log('here'); + if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) { + /* 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 */ + this.suggestedOutputs = Object.keys(nodeTemplate['interfaces'] + [interfaceName]['operations']['process']['outputs']); + console.log(this.suggestedInputs); + } + + } + } + } + }); + console.log(nodeTemplate); + } + + printSomethings() { + console.log('something'); + } + + addTempInput(suggestedInput: string) { + this.addAttribute(this.tempInputs, suggestedInput); + this.deleteAttribute(this.suggestedInputs, suggestedInput); + } + + addTempOutput(suggestedOutput: string) { + this.addAttribute(this.tempOutputs, suggestedOutput); + this.deleteAttribute(this.suggestedOutputs, suggestedOutput); + } + + deleteAttribute(container: string[], suggestedAttribute: string) { + if (container && suggestedAttribute && container.includes(suggestedAttribute)) { + const index: number = container.indexOf(suggestedAttribute); + if (index !== -1) { + container.splice(index, 1); + } + } + } + + addAttribute(container: string[], suggestedAttribute: string) { + if (container && suggestedAttribute && !container.includes(suggestedAttribute)) { + container.push(suggestedAttribute); + } + } + + + 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 + ','; + + }); + 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 + '}'); + } + + 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); + }); + } } } |