diff options
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts')
-rw-r--r-- | catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts | 132 |
1 files changed, 115 insertions, 17 deletions
diff --git a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts index d2bad5f02d..42f95d577c 100644 --- a/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts +++ b/catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts @@ -1,12 +1,13 @@ import * as _ from "lodash"; -import {Component} from '@angular/core'; +import {Component, ViewChild} from '@angular/core'; import {Subscription} from "rxjs/Subscription"; import {TranslateService} from "app/ng2/shared/translator/translate.service"; import {WorkflowServiceNg2} from 'app/ng2/services/workflow.service'; -import {OperationModel, OperationParameter, InputBEModel} from 'app/models'; +import {OperationModel, OperationParameter, InputBEModel, RadioButtonModel} from 'app/models'; +import {Tabs, Tab} from "app/ng2/components/ui/tabs/tabs.component"; import {DropdownValue} from "app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component"; export interface OperationCreatorInput { @@ -17,6 +18,7 @@ export interface OperationCreatorInput { isService: boolean } + @Component({ selector: 'operation-creator', templateUrl: './operation-creator.component.html', @@ -38,8 +40,16 @@ export class OperationCreatorComponent { noAssignInputParameters: Array<OperationParameter> = []; assignInputParameters: { [key: string]: { [key: string]: Array<OperationParameter>; }; } = {}; + outputParameters: Array<OperationParameter> = []; + noAssignOutputParameters: Array<OperationParameter> = []; + assignOutputParameters: { [key: string]: { [key: string]: Array<OperationParameter>; }; } = {}; + + tableParameters: Array<OperationParameter> = []; + + associationOptions: Array<DropdownValue>; + workflowAssociationType: String; + enableWorkflowAssociation: boolean; - isAssociateWorkflow: boolean; isEditMode: boolean = false; isLoading: boolean = false; readonly: boolean; @@ -47,10 +57,30 @@ export class OperationCreatorComponent { propertyTooltipText: String; + WORKFLOW_ASSOCIATION_OPTIONS = { + NONE: 'No Workflow', + NEW: 'New Workflow', + EXISTING: 'Existing Workflow' + } + + TYPE_INPUT = 'Inputs'; + TYPE_OUTPUT = 'Outputs'; + + @ViewChild('propertyInputTabs') propertyInputTabs: Tabs; + currentTab: String; + constructor(private workflowServiceNg2: WorkflowServiceNg2, private translateService: TranslateService) { this.translateService.languageChangedObservable.subscribe(lang => { this.propertyTooltipText = this.translateService.translate("OPERATION_PROPERTY_TOOLTIP_TEXT"); }); + this.currentTab = this.TYPE_INPUT; + + this.associationOptions = [ + new DropdownValue(this.WORKFLOW_ASSOCIATION_OPTIONS.NONE, this.WORKFLOW_ASSOCIATION_OPTIONS.NONE), + new DropdownValue(this.WORKFLOW_ASSOCIATION_OPTIONS.NEW, this.WORKFLOW_ASSOCIATION_OPTIONS.NEW), + new DropdownValue(this.WORKFLOW_ASSOCIATION_OPTIONS.EXISTING, this.WORKFLOW_ASSOCIATION_OPTIONS.EXISTING) + ]; + this.workflowAssociationType = this.WORKFLOW_ASSOCIATION_OPTIONS.NONE; } ngOnInit() { @@ -91,20 +121,37 @@ export class OperationCreatorComponent { if (inputOperation) { if (!this.enableWorkflowAssociation || !inputOperation.workflowVersionId || this.isService) { this.inputParameters = this.noAssignInputParameters; - this.isAssociateWorkflow = false; - this.buildInputParams(); + this.outputParameters = this.noAssignOutputParameters; + this.buildParams(); + this.updateTable(); } else { - this.isAssociateWorkflow = true; - this.onSelectWorkflow(inputOperation.workflowVersionId).add(this.buildInputParams); + this.workflowAssociationType = this.WORKFLOW_ASSOCIATION_OPTIONS.EXISTING; + this.onSelectWorkflow(inputOperation.workflowVersionId).add(() => { + this.buildParams(); + this.updateTable(); + }); } if (inputOperation.uniqueId) { this.isEditMode = true; } } + this.updateTable(); } - buildInputParams = () => { + buildParams = () => { + if (this.input.operation.outputParams) { + this.currentTab = this.TYPE_OUTPUT; + this.updateTable(); + _.forEach( + [...this.input.operation.outputParams.listToscaDataDefinition].sort((a, b) => a.name.localeCompare(b.name)), + (output: OperationParameter) => { + this.addParam(output); + } + ); + } + this.currentTab = this.TYPE_INPUT; + this.updateTable(); if (this.input.operation.inputParams) { _.forEach( [...this.input.operation.inputParams.listToscaDataDefinition].sort((a, b) => a.name.localeCompare(b.name)), @@ -120,6 +167,7 @@ export class OperationCreatorComponent { this.operation.workflowVersionId = selectedVersionId || null; if (!this.assignInputParameters[this.operation.workflowId]) { this.assignInputParameters[this.operation.workflowId] = {}; + this.assignOutputParameters[this.operation.workflowId] = {}; } this.isLoading = true; @@ -141,6 +189,16 @@ export class OperationCreatorComponent { }); }) .sort((a, b) => a.name.localeCompare(b.name)); + + this.assignOutputParameters[this.operation.workflowId][version.id] = _.map(version.outputs, (output: any) => { + return new OperationParameter({ + name: output.name, + type: output.type && output.type.toLowerCase(), + property: null, + mandatory: output.mandatory, + }); + }) + .sort((a, b) => a.name.localeCompare(b.name)); } return new DropdownValue(version.id, `V ${version.name}`); } @@ -156,30 +214,55 @@ export class OperationCreatorComponent { changeWorkflowVersion() { this.inputParameters = this.assignInputParameters[this.operation.workflowId][this.operation.workflowVersionId]; + this.outputParameters = this.assignOutputParameters[this.operation.workflowId][this.operation.workflowVersionId]; + this.updateTable(); } toggleAssociateWorkflow() { - if (!this.isAssociateWorkflow) { + if (this.workflowAssociationType !== this.WORKFLOW_ASSOCIATION_OPTIONS.EXISTING) { this.inputParameters = this.noAssignInputParameters; + this.outputParameters = this.noAssignOutputParameters; } else { if (!this.operation.workflowId || !this.operation.workflowVersionId) { this.inputParameters = []; + this.outputParameters = []; } else { this.inputParameters = this.assignInputParameters[this.operation.workflowId][this.operation.workflowVersionId]; + this.outputParameters = this.assignOutputParameters[this.operation.workflowId][this.operation.workflowVersionId]; } } + this.updateTable(); + + } + + tabChanged = (event) => { + this.currentTab = event.title; + this.updateTable(); + } + + updateTable() { + switch (this.currentTab) { + case this.TYPE_INPUT: + this.tableParameters = this.inputParameters; + break; + case this.TYPE_OUTPUT: + this.tableParameters = this.outputParameters; + break; + } } addParam(param?: OperationParameter): void { - this.inputParameters.push(new OperationParameter(param)); + this.tableParameters.push(new OperationParameter(param)); } isParamsValid(): boolean { - for (let ctr=0; ctr<this.inputParameters.length; ctr++) { - if (!this.inputParameters[ctr].name || !this.inputParameters[ctr].property) { + for (let ctr=0; ctr<this.tableParameters.length; ctr++) { + if (!this.tableParameters[ctr].name || + (this.currentTab == this.TYPE_INPUT && !this.tableParameters[ctr].property) + ) { return false; } } @@ -188,17 +271,32 @@ export class OperationCreatorComponent { } onRemoveParam = (param: OperationParameter): void => { - let index = _.indexOf(this.inputParameters, param); - this.inputParameters.splice(index, 1); + let index = _.indexOf(this.tableParameters, param); + this.tableParameters.splice(index, 1); } - createInputParamList(): void { - this.operation.createInputParamsList(this.inputParameters); + createParamLists(): void { + this.operation.createInputParamsList(_.map(this.inputParameters, input => { + return { + name: input.name, + type: input.type, + property: input.property, + mandatory: Boolean(input.mandatory) + } + })); + this.operation.createOutputParamsList(_.map(this.outputParameters, output => { + return { + name: output.name, + type: output.type, + property: output.property, + mandatory: Boolean(output.mandatory) + } + })); } checkFormValidForSubmit(): boolean { return this.operation.operationType && - (!this.isAssociateWorkflow || this.operation.workflowVersionId) && + (this.workflowAssociationType !== this.WORKFLOW_ASSOCIATION_OPTIONS.EXISTING || this.operation.workflowVersionId) && this.isParamsValid(); } |