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 = [];
80 const namesOfInput = Object.keys(action.inputs);
81 this.inputs = this.extractFields(namesOfInput, action.inputs);
85 const namesOfOutput = Object.keys(action.outputs);
86 this.outputs = this.extractFields(namesOfOutput, action.outputs);
91 this.functionsStore.state$.subscribe(functions => {
92 this.functions = functions;
95 this.packageCreationStore.state$
96 .subscribe(cbaPackage => {
97 this.cbaPackage = cbaPackage;
103 private extractFields(namesOfOutput: string[], container: {}) {
105 for (const nameOutput of namesOfOutput) {
106 const fieldAttribute = new OutputActionAttribute();
107 fieldAttribute.name = nameOutput;
108 fieldAttribute.description = container[nameOutput].description;
109 fieldAttribute.required = container[nameOutput].required;
110 fieldAttribute.type = container[nameOutput].type;
111 fieldAttribute.value = container[nameOutput].value;
112 console.log(fieldAttribute.value);
113 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
114 fields.push(insertedOutputActionAttribute);
119 addInput(input: InputActionAttribute) {
121 if (input && input.type && input.name) {
122 const insertedInputActionAttribute = Object.assign({}, input);
123 if (!this.newInputs.some(obj => obj.name === input.name)) {
124 this.newInputs.push(insertedInputActionAttribute);
129 addOutput(output: OutputActionAttribute) {
131 if (output && output.type && output.name) {
132 const insertedOutputActionAttribute = Object.assign({}, output);
133 this.newOutputs.push(insertedOutputActionAttribute);
137 setInputType(type: string) {
138 this.inputActionAttribute.type = type;
139 this.isInputOtherType = this.checkIfTypeIsOther(type);
142 setInputRequired(isRequired) {
143 this.inputActionAttribute.required = isRequired;
146 setOutputRequired(isRequired) {
147 this.outputActionAttribute.required = isRequired;
150 setOutputType(type: string) {
151 this.outputActionAttribute.type = type;
152 this.isOutputOtherType = this.checkIfTypeIsOther(type);
153 console.log(this.outputActionAttribute.type , this.isOutputOtherType , this.outputOtherType);
156 checkIfTypeIsOther(type) {
157 return type.includes('Other');
161 console.log(this.getValue());
162 this.addInput(this.inputActionAttribute);
163 if (this.selectedFunctionName && this.selectedAttributeName) {
164 console.log(this.getValue());
165 this.outputActionAttribute.value =
168 if (this.isOutputOtherType) {
169 this.outputActionAttribute.type = this.outputOtherType;
171 this.addOutput(this.outputActionAttribute);
172 this.clearFormInputs();
173 this.storeOutputs(this.newOutputs);
174 this.storeInputs((this.newInputs));
175 this.newInputs.forEach(input => {
176 if (!this.inputs.includes(input.name)) {
177 this.inputs.push(input);
181 this.newOutputs.forEach(output => {
182 if (!this.outputs.includes(output)) {
183 this.outputs.push(output);
187 this.newOutputs = [];
191 let value = '["' + this.selectedFunctionName + '", "' + '","' + this.selectedAttributeName;
193 if (!this.isParametersHidden) {
194 let currentSelected = '';
195 for (const selectedParameter of this.selectedParameterList) {
196 currentSelected += '"' + selectedParameter + '",';
198 value += '","' + this.currentSuggestedArtifact + '",'
199 + currentSelected.substr(0, currentSelected.length - 2) + '';
200 } else if (!this.isNotComponentResourceResolution && this.currentSuggestedArtifact) {
201 value += '","' + this.currentSuggestedArtifact + '';
205 return value += '"]';
208 public clearFormInputs() {
209 console.log('trying to clear ');
210 this.inputActionAttribute = new InputActionAttribute();
211 this.outputActionAttribute = new OutputActionAttribute();
212 this.outputOtherType = '';
213 this.inputOtherType = '';
216 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
219 InputActionAttributes.forEach(input => {
220 inputs += this.appendAttributes(input);
223 if (inputs.length > 0) {
224 this.writeAttribute(inputs, 'inputs');
228 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
230 OutputActionAttributes.forEach(output => {
231 outputs += this.appendOutputAttributes(output);
233 if (outputs.length > 0) {
234 this.writeAttribute(outputs, 'outputs');
239 private appendAttributes(inputActionAttribute: InputActionAttribute) {
240 const entrySchema: string = this.getEntrySchema(inputActionAttribute);
241 const input = '"' + inputActionAttribute.name + '" : {\n' +
242 ' "required" : ' + inputActionAttribute.required + ',\n' +
243 ' "type" : "' + inputActionAttribute.type + '",\n' +
244 ' "description" : "' + inputActionAttribute.description + '"';
245 return input + entrySchema;
248 private getEntrySchema(inputActionAttribute: InputActionAttribute) {
249 return inputActionAttribute.type.includes('list') ?
250 ',\n\t' + '"entry_schema" : {\n' +
251 ' "type" : "string"\n' +
257 setInputAndOutputs(targetName) {
258 console.log(targetName);
259 const nodeTemplate = this.designerState.template.node_templates[targetName];
260 console.log(this.designerState.template.node_templates);
261 console.log(nodeTemplate);
262 /* tslint:disable:no-string-literal */
263 console.log(nodeTemplate['type']);
264 this.functions.serverFunctions
265 /* tslint:disable:no-string-literal */
266 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
267 .forEach(currentFunction => {
268 console.log(currentFunction);
269 /* tslint:disable:no-string-literal */
270 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
271 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
272 if (interfaces && interfaces.length > 0) {
273 const interfaceName = interfaces[0];
274 console.log(interfaceName);
275 this.currentInterfaceName = interfaceName;
277 if (!this.functionAndAttributesInput.has(targetName)) {
278 this.currentTargetFunctionName = targetName;
279 this.functionAndAttributesInput.set(targetName, []);
282 if (!this.functionAndAttributesOutput.has(targetName)) {
283 this.currentTargetFunctionName = targetName;
284 this.functionAndAttributesOutput.set(targetName, []);
287 if (nodeTemplate['interfaces'] &&
288 nodeTemplate['interfaces'][interfaceName]['operations'] &&
289 nodeTemplate['interfaces'][interfaceName]['operations']['process']
292 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
293 /* tslint:disable:no-string-literal */
294 this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
295 [interfaceName]['operations']['process']['inputs']);
296 this.filterTwoCollections(this.suggestedInputs, this.inputs);
299 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
300 /* tslint:disable:no-string-literal */
301 this.suggestedOutputs = Object.keys(nodeTemplate['interfaces']
302 [interfaceName]['operations']['process']['outputs']);
303 this.filterTwoCollections(this.suggestedOutputs, this.outputs);
310 console.log(nodeTemplate);
313 private filterTwoCollections(suggestedInputs: string[], inputs: any[]) {
314 inputs.forEach(input => {
315 if (suggestedInputs.includes(input.name)) {
316 this.deleteAttribute(suggestedInputs, input.name);
322 this.setInputAndOutputs(
323 this.designerState.template.workflows[this.actionName]['steps'][this.steps[0]]['target']
327 addTempInput(suggestedInput: string) {
328 this.addAttribute(this.tempInputs, suggestedInput);
329 this.deleteAttribute(this.suggestedInputs, suggestedInput);
330 this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
333 addTempOutput(suggestedOutput: string) {
334 this.addAttribute(this.tempOutputs, suggestedOutput);
335 this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
336 this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
339 deleteAttribute(container: string[], suggestedAttribute: string) {
340 if (container && suggestedAttribute && container.includes(suggestedAttribute)) {
341 const index: number = container.indexOf(suggestedAttribute);
344 container.splice(index, 1);
349 addAttribute(container: string[], suggestedAttribute: string) {
350 if (container && suggestedAttribute && !container.includes(suggestedAttribute)) {
351 container.push(suggestedAttribute);
356 submitTempAttributes() {
357 this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs');
358 this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs');
361 private writeSelectedAttribute(map: Map<string, string[]>, attributeType: string) {
362 map.forEach((value, key) => {
363 const nodeTemplate = this.getNodeTemplate(key);
364 this.functions.serverFunctions
365 /* tslint:disable:no-string-literal */
366 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
367 .forEach(currentFunction => {
369 if (currentFunction['definition'] && currentFunction['definition']['interfaces']
370 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
371 ['operations']['process'][attributeType]) {
372 let newAttributes = '';
373 const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces']
374 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
375 ['operations']['process'][attributeType];
376 value.forEach(attribute => {
377 newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ',';
379 if (value.length > 0) {
380 this.writeAttribute(newAttributes, attributeType);
387 private writeAttribute(newAttributes: string, attributeType: string) {
388 newAttributes = this.removeTheLastComma(newAttributes);
389 console.log(newAttributes);
390 let originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
392 this.createAttributeTypeIfNotExisted(originalAttributes, attributeType);
393 originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
395 if (originalAttributes.length > 2) {
396 this.designerState.template.workflows[this.actionName][attributeType] =
397 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
398 + ',' + newAttributes + '}');
400 this.designerState.template.workflows[this.actionName][attributeType] =
401 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
402 + newAttributes + '}');
407 private removeTheLastComma(newInputs: string): string {
408 if (newInputs.endsWith(',')) {
409 newInputs = newInputs.substr(0, newInputs.length - 1);
414 private convertToString = object => JSON.stringify(object);
416 private convertToObject = stringValue => JSON.parse(stringValue);
418 private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
421 getAttributesAndOutputs(functionName: string) {
422 this.suggestedAttributes = [];
423 console.log(functionName);
425 const nodeTemplate = this.designerState.template.node_templates[functionName];
426 if (nodeTemplate['type'].includes('component-resource-resolution')) {
427 this.isNotComponentResourceResolution = false;
428 this.isParametersHidden = true;
430 this.isNotComponentResourceResolution = true;
431 this.isParametersHidden = true;
433 /* tslint:disable:no-string-literal */
434 console.log(nodeTemplate['type']);
435 this.functions.serverFunctions
436 /* tslint:disable:no-string-literal */
437 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
438 .forEach(currentFunction => {
439 if (currentFunction.definition['attributes']) {
440 Object.keys(currentFunction.definition['attributes']).forEach(attribute => {
441 this.suggestedAttributes.push(attribute);
444 console.log(this.suggestedAttributes);
446 this.selectedFunctionName = functionName;
452 addTempOutputAttr(suggestedOutputAndAttribute: string) {
454 this.selectedAttributeName = suggestedOutputAndAttribute;
455 this.currentArtifacts = [];
456 const nodeTemplate = this.designerState.template.node_templates[this.selectedFunctionName];
457 if (nodeTemplate['artifacts']
459 Object.keys(nodeTemplate['artifacts']).forEach(key => {
460 const mappingName = key.split('-')[0];
461 if (!this.currentArtifacts.includes(mappingName)) {
462 this.currentArtifacts.push(mappingName);
466 console.log('happend');
471 private appendOutputAttributes(outputActionAttribute: OutputActionAttribute) {
472 const entrySchema: string = this.getEntrySchema(outputActionAttribute);
473 const output = '"' + outputActionAttribute.name + '" : {\n' +
474 ' "required" : ' + outputActionAttribute.required + ',\n' +
475 ' "type" : "' + outputActionAttribute.type + '",\n' +
476 ' "description" : "' + outputActionAttribute.description + '",\n' +
477 ' "value\" :' + '{\n' +
478 ' "get_attribute" : ' + outputActionAttribute.value + '\n' +
481 return output + entrySchema;
485 addArtifactFile(suggestedArtifact: string) {
486 this.currentSuggestedArtifact = suggestedArtifact;
487 this.isParametersHidden = !this.selectedAttributeName.includes('assignment-map');
488 if (!this.isParametersHidden) {
489 this.suggestedMappingParameters = this.getSuggestedMappingParameters(suggestedArtifact);
493 private getSuggestedMappingParameters(suggestedArtifact: string) {
494 const suggestedMappingParameters = [];
496 this.cbaPackage.mapping.files.forEach(((value, key) => {
497 if (key.includes(suggestedArtifact)) {
499 JSON.parse(value).forEach(value2 => {
500 suggestedMappingParameters.push(value2['name']);
504 return suggestedMappingParameters;
507 addSuggestedMappingParameter(suggestedMappingParameter: string) {
508 this.addAttribute(this.selectedParameterList, suggestedMappingParameter);
509 this.deleteAttribute(this.suggestedMappingParameters, suggestedMappingParameter);
513 editAttribute(input: any) {
514 this.suggestedEditedAttribute = input;
517 private createAttributeTypeIfNotExisted(originalAttributes: string, attributeType: string) {
518 if (!originalAttributes) {
519 this.designerState.template.workflows[this.actionName][attributeType] = {};
523 private checkIfTypeIsList(type: string) {
524 return type.includes('list');
527 markDeletedInput(input: any) {
528 this.suggestedDeletedInput = input;
531 deleteActionAttribute() {
532 delete this.designerState.template.workflows[this.actionName]
533 ['inputs'][this.suggestedDeletedInput.name];
534 this.deleteAttribute(this.inputs, this.suggestedDeletedInput);
536 delete this.designerState.template.workflows[this.actionName]
537 ['outputs'][this.suggestedDeletedInput.name];
538 this.deleteAttribute(this.outputs, this.suggestedDeletedInput);