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;
54 constructor(private designerStore: DesignerStore,
55 private functionsStore: FunctionsStore,
56 private packageCreationStore: PackageCreationStore) {
61 console.log('is paramters hidden' + this.isParametersHidden);
62 console.log('is artifacts hidden' + this.isNotComponentResourceResolution);
63 this.designerStore.state$.subscribe(designerState => {
64 this.designerState = designerState;
65 if (this.designerState && this.designerState.actionName) {
66 this.actionName = this.designerState.actionName;
67 console.log(this.actionName);
68 const action = this.designerState.template.workflows[this.actionName] as Action;
70 const steps = Object.keys(action.steps);
71 this.isFunctionAttributeActive = steps && steps.length > 0;
73 this.suggestedOutputs = [];
74 this.suggestedInputs = [];
79 const namesOfInput = Object.keys(action.inputs);
80 this.inputs = this.extractFields(namesOfInput, action.inputs);
84 const namesOfOutput = Object.keys(action.outputs);
85 this.outputs = this.extractFields(namesOfOutput, action.outputs);
90 this.functionsStore.state$.subscribe(functions => {
91 this.functions = functions;
94 this.packageCreationStore.state$
95 .subscribe(cbaPackage => {
96 this.cbaPackage = cbaPackage;
102 private extractFields(namesOfOutput: string[], container: {}) {
104 for (const nameOutput of namesOfOutput) {
105 const fieldAttribute = new OutputActionAttribute();
106 fieldAttribute.name = nameOutput;
107 fieldAttribute.description = container[nameOutput].description;
108 fieldAttribute.required = container[nameOutput].required;
109 fieldAttribute.type = container[nameOutput].type;
110 const insertedOutputActionAttribute = Object.assign({}, fieldAttribute);
111 fields.push(insertedOutputActionAttribute);
116 addInput(input: InputActionAttribute) {
118 if (input && input.type && input.name) {
119 const insertedInputActionAttribute = Object.assign({}, input);
120 this.newInputs.push(insertedInputActionAttribute);
124 addOutput(output: OutputActionAttribute) {
126 if (output && output.type && output.name) {
127 const insertedOutputActionAttribute = Object.assign({}, output);
128 this.newOutputs.push(insertedOutputActionAttribute);
132 setInputType(type: string) {
133 this.inputActionAttribute.type = type;
134 this.isInputOtherType = this.checkIfTypeIsOther(type);
137 setInputRequired(isRequired) {
138 this.inputActionAttribute.required = isRequired;
141 setOutputRequired(isRequired) {
142 this.outputActionAttribute.required = isRequired;
145 setOutputType(type: string) {
146 this.outputActionAttribute.type = type;
147 this.isOutputOtherType = this.checkIfTypeIsOther(type);
150 checkIfTypeIsOther(type) {
151 return type.includes('Other');
155 this.addInput(this.inputActionAttribute);
156 if (this.selectedFunctionName && this.selectedAttributeName) {
157 console.log(this.getValue());
158 this.outputActionAttribute.value =
161 this.addOutput(this.outputActionAttribute);
162 this.clearFormInputs();
163 this.storeOutputs(this.newOutputs);
164 this.storeInputs((this.newInputs));
165 this.newInputs.forEach(input => {
166 if (!this.inputs.includes(input)) {
167 this.inputs.push(input);
171 this.newOutputs.forEach(output => {
172 if (!this.outputs.includes(output)) {
173 this.outputs.push(output);
179 let value = '["' + this.selectedFunctionName + '", "' + '","' + this.selectedAttributeName;
181 if (!this.isParametersHidden) {
182 let currentSelected = '';
183 for (const selectedParameter of this.selectedParameterList) {
184 currentSelected += '"' + selectedParameter + '",';
186 value += '","' + this.currentSuggestedArtifact + '",'
187 + currentSelected.substr(0, currentSelected.length - 2) + '';
188 } else if (!this.isNotComponentResourceResolution && this.currentSuggestedArtifact) {
189 value += '","' + this.currentSuggestedArtifact + '';
193 return value += '"]';
196 public clearFormInputs() {
197 console.log('trying to clear ');
198 this.inputActionAttribute = new InputActionAttribute();
199 this.outputActionAttribute = new OutputActionAttribute();
200 this.outputOtherType = '';
201 this.inputOtherType = '';
204 private storeInputs(InputActionAttributes: InputActionAttribute[]) {
207 InputActionAttributes.forEach(input => {
208 inputs += this.appendAttributes(input);
211 if (inputs.length > 0) {
212 this.writeAttribute(inputs, 'inputs');
216 private storeOutputs(OutputActionAttributes: OutputActionAttribute[]) {
218 OutputActionAttributes.forEach(output => {
219 outputs += this.appendOutputAttributes(output);
221 if (outputs.length > 0) {
222 this.writeAttribute(outputs, 'outputs');
227 private appendAttributes(inputActionAttribute: InputActionAttribute) {
228 const entrySchema: string = this.getEntrySchema(inputActionAttribute);
229 const input = '"' + inputActionAttribute.name + '" : {\n' +
230 ' "required" : ' + inputActionAttribute.required + ',\n' +
231 ' "type" : "' + inputActionAttribute.type + '",\n' +
232 ' "description" : "' + inputActionAttribute.description + '"';
233 return input + entrySchema;
236 private getEntrySchema(inputActionAttribute: InputActionAttribute) {
237 return inputActionAttribute.type.includes('list') ?
238 ',\n\t' + '"entry_schema" : {\n' +
239 ' "type" : "string"\n' +
245 setInputAndOutputs(targetName) {
246 console.log(targetName);
247 const nodeTemplate = this.designerState.template.node_templates[targetName];
248 console.log(this.designerState.template.node_templates);
249 console.log(nodeTemplate);
250 /* tslint:disable:no-string-literal */
251 console.log(nodeTemplate['type']);
252 this.functions.serverFunctions
253 /* tslint:disable:no-string-literal */
254 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
255 .forEach(currentFunction => {
256 console.log(currentFunction);
257 /* tslint:disable:no-string-literal */
258 if (currentFunction['definition'] && currentFunction['definition']['interfaces']) {
259 const interfaces = Object.keys(currentFunction['definition']['interfaces']);
260 if (interfaces && interfaces.length > 0) {
261 const interfaceName = interfaces[0];
262 console.log(interfaceName);
263 this.currentInterfaceName = interfaceName;
265 if (!this.functionAndAttributesInput.has(targetName)) {
266 this.currentTargetFunctionName = targetName;
267 this.functionAndAttributesInput.set(targetName, []);
270 if (!this.functionAndAttributesOutput.has(targetName)) {
271 this.currentTargetFunctionName = targetName;
272 this.functionAndAttributesOutput.set(targetName, []);
275 if (nodeTemplate['interfaces'] &&
276 nodeTemplate['interfaces'][interfaceName]['operations'] &&
277 nodeTemplate['interfaces'][interfaceName]['operations']['process']
280 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['inputs']) {
281 /* tslint:disable:no-string-literal */
282 this.suggestedInputs = Object.keys(nodeTemplate['interfaces']
283 [interfaceName]['operations']['process']['inputs']);
285 if (nodeTemplate['interfaces'][interfaceName]['operations']['process']['outputs']) {
286 /* tslint:disable:no-string-literal */
287 this.suggestedOutputs = Object.keys(nodeTemplate['interfaces']
288 [interfaceName]['operations']['process']['outputs']);
289 console.log(this.suggestedInputs);
296 console.log(nodeTemplate);
300 console.log('something');
303 addTempInput(suggestedInput: string) {
304 this.addAttribute(this.tempInputs, suggestedInput);
305 this.deleteAttribute(this.suggestedInputs, suggestedInput);
306 this.addAttribute(this.functionAndAttributesInput.get(this.currentTargetFunctionName), suggestedInput);
309 addTempOutput(suggestedOutput: string) {
310 this.addAttribute(this.tempOutputs, suggestedOutput);
311 this.deleteAttribute(this.suggestedOutputs, suggestedOutput);
312 this.addAttribute(this.functionAndAttributesOutput.get(this.currentTargetFunctionName), suggestedOutput);
315 deleteAttribute(container: string[], suggestedAttribute: string) {
316 if (container && suggestedAttribute && container.includes(suggestedAttribute)) {
317 const index: number = container.indexOf(suggestedAttribute);
319 container.splice(index, 1);
324 addAttribute(container: string[], suggestedAttribute: string) {
325 if (container && suggestedAttribute && !container.includes(suggestedAttribute)) {
326 container.push(suggestedAttribute);
331 submitTempAttributes() {
332 this.writeSelectedAttribute(this.functionAndAttributesInput, 'inputs');
333 this.writeSelectedAttribute(this.functionAndAttributesOutput, 'outputs');
336 private writeSelectedAttribute(map: Map<string, string[]>, attributeType: string) {
337 map.forEach((value, key) => {
338 const nodeTemplate = this.getNodeTemplate(key);
339 this.functions.serverFunctions
340 /* tslint:disable:no-string-literal */
341 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
342 .forEach(currentFunction => {
344 if (currentFunction['definition'] && currentFunction['definition']['interfaces']
345 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
346 ['operations']['process'][attributeType]) {
347 let newAttributes = '';
348 const attributes = currentFunction['definition'] && currentFunction['definition']['interfaces']
349 [Object.keys(currentFunction['definition'] && currentFunction['definition']['interfaces'])]
350 ['operations']['process'][attributeType];
351 value.forEach(attribute => {
352 newAttributes += '"' + attribute + '": ' + this.convertToString(attributes[attribute]) + ',';
354 if (value.length > 0) {
355 this.writeAttribute(newAttributes, attributeType);
362 private writeAttribute(newAttributes: string, attributeType: string) {
363 newAttributes = this.removeTheLastComma(newAttributes);
364 console.log(newAttributes);
365 let originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
367 this.createAttributeTypeIfNotExisted(originalAttributes, attributeType);
368 originalAttributes = this.convertToString(this.designerState.template.workflows[this.actionName]
370 if (originalAttributes.length > 2) {
371 this.designerState.template.workflows[this.actionName][attributeType] =
372 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
373 + ',' + newAttributes + '}');
375 this.designerState.template.workflows[this.actionName][attributeType] =
376 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
377 + newAttributes + '}');
379 /* console.log(originalAttributes.substr(0, originalAttributes.length - 1) + ',' + newAttributes + '}');
380 this.designerState.template.workflows[this.actionName][attributeType] =
381 this.convertToObject(originalAttributes.substr(0, originalAttributes.length - 1)
382 + ',' + newAttributes + '}');*/
385 private removeTheLastComma(newInputs: string): string {
386 if (newInputs.endsWith(',')) {
387 newInputs = newInputs.substr(0, newInputs.length - 1);
392 private convertToString = object => JSON.stringify(object);
394 private convertToObject = stringValue => JSON.parse(stringValue);
396 private getNodeTemplate = (value: string) => this.designerState.template.node_templates[value];
399 getAttributesAndOutputs(functionName: string) {
400 this.suggestedAttributes = [];
401 console.log(functionName);
403 const nodeTemplate = this.designerState.template.node_templates[functionName];
404 if (nodeTemplate['type'].includes('component-resource-resolution')) {
405 this.isNotComponentResourceResolution = false;
406 this.isParametersHidden = true;
408 this.isNotComponentResourceResolution = true;
409 this.isParametersHidden = true;
411 /* tslint:disable:no-string-literal */
412 console.log(nodeTemplate['type']);
413 this.functions.serverFunctions
414 /* tslint:disable:no-string-literal */
415 .filter(currentFunction => currentFunction.modelName.includes(nodeTemplate['type']))
416 .forEach(currentFunction => {
417 if (currentFunction.definition['attributes']) {
418 Object.keys(currentFunction.definition['attributes']).forEach(attribute => {
419 this.suggestedAttributes.push(attribute);
420 this.suggestedAttributes.push('assignment-map');
423 console.log(this.suggestedAttributes);
425 this.selectedFunctionName = functionName;
431 addTempOutputAttr(suggestedOutputAndAttribute: string) {
433 this.selectedAttributeName = suggestedOutputAndAttribute;
434 this.currentArtifacts = [];
435 const nodeTemplate = this.designerState.template.node_templates[this.selectedFunctionName];
436 if (nodeTemplate['artifacts']
438 Object.keys(nodeTemplate['artifacts']).forEach(key => {
439 const mappingName = key.split('-')[0];
440 if (!this.currentArtifacts.includes(mappingName)) {
441 this.currentArtifacts.push(mappingName);
445 console.log('happend');
450 private appendOutputAttributes(outputActionAttribute: OutputActionAttribute) {
451 const entrySchema: string = this.getEntrySchema(outputActionAttribute);
452 const output = '"' + outputActionAttribute.name + '" : {\n' +
453 ' "required" : ' + outputActionAttribute.required + ',\n' +
454 ' "type" : "' + outputActionAttribute.type + '",\n' +
455 ' "description" : "' + outputActionAttribute.description + '",\n' +
456 ' "value\" :' + '{\n' +
457 ' "get_attribute" : ' + outputActionAttribute.value + '\n' +
460 return output + entrySchema;
464 addArtifactFile(suggestedArtifact: string) {
465 this.currentSuggestedArtifact = suggestedArtifact;
466 this.isParametersHidden = !this.selectedAttributeName.includes('assignment-map');
467 if (!this.isParametersHidden) {
468 this.suggestedMappingParameters = this.getSuggestedMappingParameters(suggestedArtifact);
472 private getSuggestedMappingParameters(suggestedArtifact: string) {
473 const suggestedMappingParameters = [];
475 this.cbaPackage.mapping.files.forEach(((value, key) => {
476 if (key.includes(suggestedArtifact)) {
478 JSON.parse(value).forEach(value2 => {
479 suggestedMappingParameters.push(value2['name']);
483 return suggestedMappingParameters;
486 addSuggestedMappingParameter(suggestedMappingParameter: string) {
487 this.addAttribute(this.selectedParameterList, suggestedMappingParameter);
488 this.deleteAttribute(this.suggestedMappingParameters, suggestedMappingParameter);
492 editAttribute(input: any) {
496 private createAttributeTypeIfNotExisted(originalAttributes: string, attributeType: string) {
497 if (!originalAttributes) {
498 this.designerState.template.workflows[this.actionName][attributeType] = {};
502 private checkIfTypeIsList(type: string) {
503 return type.includes('list');