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;
53 suggestedDeletedInput: any = {};
54 suggestedEditedAttribute: any = {};
56 constructor(private designerStore: DesignerStore,
57 private functionsStore: FunctionsStore,
58 private packageCreationStore: PackageCreationStore) {
63 console.log('is paramters hidden' + this.isParametersHidden);
64 console.log('is artifacts hidden' + this.isNotComponentResourceResolution);
65 this.designerStore.state$.subscribe(designerState => {
66 this.designerState = designerState;
67 if (this.designerState && this.designerState.actionName) {
68 this.actionName = this.designerState.actionName;
69 console.log(this.actionName);
70 const action = this.designerState.template.workflows[this.actionName] as Action;
72 const steps = Object.keys(action.steps);
73 this.isFunctionAttributeActive = steps && steps.length > 0;
75 this.suggestedOutputs = [];
76 this.suggestedInputs = [];
81 const namesOfInput = Object.keys(action.inputs);
82 this.inputs = this.extractFields(namesOfInput, action.inputs);
86 const namesOfOutput = Object.keys(action.outputs);
87 this.outputs = this.extractFields(namesOfOutput, action.outputs);
92 this.functionsStore.state$.subscribe(functions => {
93 this.functions = functions;
96 this.packageCreationStore.state$
97 .subscribe(cbaPackage => {
98 this.cbaPackage = cbaPackage;
104 private extractFields(namesOfOutput: string[], container: {}) {
106 for (const nameOutput of namesOfOutput) {
107 const fieldAttribute = new OutputActionAttribute();
108 fieldAttribute.name = nameOutput;
109 fieldAttribute.description = container[nameOutput].description;
110 fieldAttribute.required = container[nameOutput].required;
111 fieldAttribute.type = container[nameOutput].type;
112 fieldAttribute.value = container[nameOutput].value;
113 console.log(fieldAttribute.value);
114 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
115 fields.push(insertedOutputActionAttribute);
120 addInput(input: InputActionAttribute) {
122 if (input && input.type && input.name) {
123 const insertedInputActionAttribute = Object.assign({}, input);
124 this.newInputs.push(insertedInputActionAttribute);
128 addOutput(output: OutputActionAttribute) {
130 if (output && output.type && output.name) {
131 const insertedOutputActionAttribute = Object.assign({}, output);
132 this.newOutputs.push(insertedOutputActionAttribute);
136 setInputType(type: string) {
137 this.inputActionAttribute.type = type;
138 this.isInputOtherType = this.checkIfTypeIsOther(type);
141 setInputRequired(isRequired) {
142 this.inputActionAttribute.required = isRequired;
145 setOutputRequired(isRequired) {
146 this.outputActionAttribute.required = isRequired;
149 setOutputType(type: string) {
150 this.outputActionAttribute.type = type;
151 this.isOutputOtherType = this.checkIfTypeIsOther(type);
154 checkIfTypeIsOther(type) {
155 return type.includes('Other');
159 this.addInput(this.inputActionAttribute);
160 if (this.selectedFunctionName && this.selectedAttributeName) {
161 console.log(this.getValue());
162 this.outputActionAttribute.value =
165 this.addOutput(this.outputActionAttribute);
166 this.clearFormInputs();
167 this.storeOutputs(this.newOutputs);
168 this.storeInputs((this.newInputs));
169 this.newInputs.forEach(input => {
170 if (!this.inputs.includes(input)) {
171 this.inputs.push(input);
175 this.newOutputs.forEach(output => {
176 if (!this.outputs.includes(output)) {
177 this.outputs.push(output);
183 let value = '["' + this.selectedFunctionName + '", "' + '","' + this.selectedAttributeName;
185 if (!this.isParametersHidden) {
186 let currentSelected = '';
187 for (const selectedParameter of this.selectedParameterList) {
188 currentSelected += '"' + selectedParameter + '",';
190 value += '","' + this.currentSuggestedArtifact + '",'
191 + currentSelected.substr(0, currentSelected.length - 2) + '';
192 } else if (!this.isNotComponentResourceResolution && this.currentSuggestedArtifact) {
193 value += '","' + this.currentSuggestedArtifact + '';
197 return value += '"]';
200 public clearFormInputs() {
201 console.log('trying to clear ');
202 this.inputActionAttribute = new InputActionAttribute();
203 this.outputActionAttribute = new OutputActionAttribute();
204 this.outputOtherType = '';
205 this.inputOtherType = '';
208 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
211 InputActionAttributes.forEach(input => {
212 inputs += this.appendAttributes(input);
215 if (inputs.length > 0) {
216 this.writeAttribute(inputs, 'inputs');
220 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
222 OutputActionAttributes.forEach(output => {
223 outputs += this.appendOutputAttributes(output);
225 if (outputs.length > 0) {
226 this.writeAttribute(outputs, 'outputs');
231 private appendAttributes(inputActionAttribute: InputActionAttribute) {
232 const entrySchema: string = this.getEntrySchema(inputActionAttribute);
233 const input = '"' + inputActionAttribute.name + '" : {\n' +
234 ' "required" : ' + inputActionAttribute.required + ',\n' +
235 ' "type" : "' + inputActionAttribute.type + '",\n' +
236 ' "description" : "' + inputActionAttribute.description + '"';
237 return input + entrySchema;
240 private getEntrySchema(inputActionAttribute: InputActionAttribute) {
241 return inputActionAttribute.type.includes('list') ?
242 ',\n\t' + '"entry_schema" : {\n' +
243 ' "type" : "string"\n' +
249 setInputAndOutputs(targetName) {
250 console.log(targetName);
251 const nodeTemplate = this.designerState.template.node_templates[targetName];
252 console.log(this.designerState.template.node_templates);
253 console.log(nodeTemplate);
254 /* tslint:disable:no-string-literal */
255 console.log(nodeTemplate['type']);
256 this.functions.serverFunctions
257 /* tslint:disable:no-string-literal */
258 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
259 .forEach(currentFunction => {
260 console.log(currentFunction);
261 /* tslint:disable:no-string-literal */
262 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
263 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
264 if (interfaces && interfaces.length > 0) {
265 const interfaceName = interfaces[0];
266 console.log(interfaceName);
267 this.currentInterfaceName = interfaceName;
269 if (!this.functionAndAttributesInput.has(targetName)) {
270 this.currentTargetFunctionName = targetName;
271 this.functionAndAttributesInput.set(targetName, []);
274 if (!this.functionAndAttributesOutput.has(targetName)) {
275 this.currentTargetFunctionName = targetName;
276 this.functionAndAttributesOutput.set(targetName, []);
279 if (nodeTemplate['interfaces'] &&
280 nodeTemplate['interfaces'][interfaceName]['operations'] &&
281 nodeTemplate['interfaces'][interfaceName]['operations']['process']
284 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
285 /* tslint:disable:no-string-literal */
286 this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
287 [interfaceName]['operations']['process']['inputs']);
288 this.filterTwoCollections(this.suggestedInputs, this.inputs);
291 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
292 /* tslint:disable:no-string-literal */
293 this.suggestedOutputs = Object.keys(nodeTemplate['interfaces']
294 [interfaceName]['operations']['process']['outputs']);
295 this.filterTwoCollections(this.suggestedOutputs, this.outputs);
302 console.log(nodeTemplate);
305 private filterTwoCollections(suggestedInputs: string[], inputs: any[]) {
306 inputs.forEach(input => {
307 if (suggestedInputs.includes(input.name)) {
308 this.deleteAttribute(suggestedInputs, input.name);
314 this.setInputAndOutputs(
315 this.designerState.template.workflows[this.actionName]['steps'][this.steps[0]]['target']
319 addTempInput(suggestedInput: string) {
320 this.addAttribute(this.tempInputs, suggestedInput);
321 this.deleteAttribute(this.suggestedInputs, suggestedInput);
322 this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
325 addTempOutput(suggestedOutput: string) {
326 this.addAttribute(this.tempOutputs, suggestedOutput);
327 this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
328 this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
331 deleteAttribute(container: string[], suggestedAttribute: string) {
332 if (container && suggestedAttribute && container.includes(suggestedAttribute)) {
333 const index: number = container.indexOf(suggestedAttribute);
336 container.splice(index, 1);
341 addAttribute(container: string[], suggestedAttribute: string) {
342 if (container && suggestedAttribute && !container.includes(suggestedAttribute)) {
343 container.push(suggestedAttribute);
348 submitTempAttributes() {
349 this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs');
350 this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs');
353 private writeSelectedAttribute(map: Map<string, string[]>, attributeType: string) {
354 map.forEach((value, key) => {
355 const nodeTemplate = this.getNodeTemplate(key);
356 this.functions.serverFunctions
357 /* tslint:disable:no-string-literal */
358 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
359 .forEach(currentFunction => {
361 if (currentFunction['definition'] && currentFunction['definition']['interfaces']
362 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
363 ['operations']['process'][attributeType]) {
364 let newAttributes = '';
365 const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces']
366 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
367 ['operations']['process'][attributeType];
368 value.forEach(attribute => {
369 newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ',';
371 if (value.length > 0) {
372 this.writeAttribute(newAttributes, attributeType);
379 private writeAttribute(newAttributes: string, attributeType: string) {
380 newAttributes = this.removeTheLastComma(newAttributes);
381 console.log(newAttributes);
382 let originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
384 this.createAttributeTypeIfNotExisted(originalAttributes, attributeType);
385 originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
387 if (originalAttributes.length > 2) {
388 this.designerState.template.workflows[this.actionName][attributeType] =
389 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
390 + ',' + newAttributes + '}');
392 this.designerState.template.workflows[this.actionName][attributeType] =
393 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
394 + newAttributes + '}');
396 /* console.log(originalAttributes.substr(0, originalAttributes.length - 1) + ',' + newAttributes + '}');
397 this.designerState.template.workflows[this.actionName][attributeType] =
398 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
399 + ',' + newAttributes + '}');*/
402 private removeTheLastComma(newInputs: string): string {
403 if (newInputs.endsWith(',')) {
404 newInputs = newInputs.substr(0, newInputs.length - 1);
409 private convertToString = object => JSON.stringify(object);
411 private convertToObject = stringValue => JSON.parse(stringValue);
413 private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
416 getAttributesAndOutputs(functionName: string) {
417 this.suggestedAttributes = [];
418 console.log(functionName);
420 const nodeTemplate = this.designerState.template.node_templates[functionName];
421 if (nodeTemplate['type'].includes('component-resource-resolution')) {
422 this.isNotComponentResourceResolution = false;
423 this.isParametersHidden = true;
425 this.isNotComponentResourceResolution = true;
426 this.isParametersHidden = true;
428 /* tslint:disable:no-string-literal */
429 console.log(nodeTemplate['type']);
430 this.functions.serverFunctions
431 /* tslint:disable:no-string-literal */
432 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
433 .forEach(currentFunction => {
434 if (currentFunction.definition['attributes']) {
435 Object.keys(currentFunction.definition['attributes']).forEach(attribute => {
436 this.suggestedAttributes.push(attribute);
437 this.suggestedAttributes.push('assignment-map');
440 console.log(this.suggestedAttributes);
442 this.selectedFunctionName = functionName;
448 addTempOutputAttr(suggestedOutputAndAttribute: string) {
450 this.selectedAttributeName = suggestedOutputAndAttribute;
451 this.currentArtifacts = [];
452 const nodeTemplate = this.designerState.template.node_templates[this.selectedFunctionName];
453 if (nodeTemplate['artifacts']
455 Object.keys(nodeTemplate['artifacts']).forEach(key => {
456 const mappingName = key.split('-')[0];
457 if (!this.currentArtifacts.includes(mappingName)) {
458 this.currentArtifacts.push(mappingName);
462 console.log('happend');
467 private appendOutputAttributes(outputActionAttribute: OutputActionAttribute) {
468 const entrySchema: string = this.getEntrySchema(outputActionAttribute);
469 const output = '"' + outputActionAttribute.name + '" : {\n' +
470 ' "required" : ' + outputActionAttribute.required + ',\n' +
471 ' "type" : "' + outputActionAttribute.type + '",\n' +
472 ' "description" : "' + outputActionAttribute.description + '",\n' +
473 ' "value\" :' + '{\n' +
474 ' "get_attribute" : ' + outputActionAttribute.value + '\n' +
477 return output + entrySchema;
481 addArtifactFile(suggestedArtifact: string) {
482 this.currentSuggestedArtifact = suggestedArtifact;
483 this.isParametersHidden = !this.selectedAttributeName.includes('assignment-map');
484 if (!this.isParametersHidden) {
485 this.suggestedMappingParameters = this.getSuggestedMappingParameters(suggestedArtifact);
489 private getSuggestedMappingParameters(suggestedArtifact: string) {
490 const suggestedMappingParameters = [];
492 this.cbaPackage.mapping.files.forEach(((value, key) => {
493 if (key.includes(suggestedArtifact)) {
495 JSON.parse(value).forEach(value2 => {
496 suggestedMappingParameters.push(value2['name']);
500 return suggestedMappingParameters;
503 addSuggestedMappingParameter(suggestedMappingParameter: string) {
504 this.addAttribute(this.selectedParameterList, suggestedMappingParameter);
505 this.deleteAttribute(this.suggestedMappingParameters, suggestedMappingParameter);
509 editAttribute(input: any) {
510 this.suggestedEditedAttribute = input;
513 private createAttributeTypeIfNotExisted(originalAttributes: string, attributeType: string) {
514 if (!originalAttributes) {
515 this.designerState.template.workflows[this.actionName][attributeType] = {};
519 private checkIfTypeIsList(type: string) {
520 return type.includes('list');
523 markDeletedInput(input: any) {
524 this.suggestedDeletedInput = input;
527 deleteActionAttribute() {
528 delete this.designerState.template.workflows[this.actionName]
529 ['inputs'][this.suggestedDeletedInput.name];
530 this.deleteAttribute(this.inputs, this.suggestedDeletedInput);
532 delete this.designerState.template.workflows[this.actionName]
533 ['outputs'][this.suggestedDeletedInput.name];
534 this.deleteAttribute(this.outputs, this.suggestedDeletedInput);