diff options
author | aribeiro <anderson.ribeiro@est.tech> | 2021-07-15 09:18:37 +0100 |
---|---|---|
committer | aribeiro <anderson.ribeiro@est.tech> | 2021-08-06 17:22:20 +0100 |
commit | 47bcc63a9daff1f310125fed006f27c93656fa83 (patch) | |
tree | 3c61670b039c0e63d14880f909e6047d54776492 /catalog-ui/src/app/ng2/pages/properties-assignment | |
parent | 0ed125f98ae8ea9e80c855a640c328654660d081 (diff) |
Retrieve data types based on component model
Issue-ID: SDC-3660
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: I09c533eb39277532b29e581e4dd57e9df952e8e6
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment')
5 files changed, 48 insertions, 34 deletions
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/declare-list/declare-list.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/declare-list/declare-list.component.ts index 8ca4f44116..cb90b8b83e 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/declare-list/declare-list.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/declare-list/declare-list.component.ts @@ -29,6 +29,7 @@ import { ModalService } from 'app/ng2/services/modal.service'; import { PROPERTY_DATA } from 'app/utils'; import * as _ from 'lodash'; import { PROPERTY_TYPES } from '../../../../utils'; +import {WorkspaceService} from "../../workspace/workspace.service"; @Component({ selector: 'declare-list', @@ -50,7 +51,7 @@ export class DeclareListComponent { propertiesListString: string; privateDataType: DataTypeModel; - constructor(protected dataTypeService: DataTypeService, private modalService: ModalService) {} + constructor(protected dataTypeService: DataTypeService, private modalService: ModalService, private workspaceService: WorkspaceService) {} ngOnInit() { console.log('DeclareListComponent.ngOnInit() - enter'); @@ -59,7 +60,7 @@ export class DeclareListComponent { this.propertyModel.schema.property.type = ''; this.propertyModel.required = false; const types: string[] = PROPERTY_DATA.TYPES; // All types - simple type + map + list - this.dataTypes = this.dataTypeService.getAllDataTypes(); // Get all data types in service + this.dataTypes = this.dataTypeService.getDataTypeByModel(this.workspaceService.metadata.model); // Get all data types in service const nonPrimitiveTypes: string[] = _.filter(Object.keys(this.dataTypes), (type: string) => { return types.indexOf(type) === -1; }); diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts index ae4aa57572..10273e2636 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts @@ -36,12 +36,13 @@ import {ComponentModeService} from "../../services/component-services/component- import {SdcUiComponentsModule} from "onap-ui-angular"; import {ModalFormsModule} from "app/ng2/components/ui/forms/modal-forms.module"; import {HierarchyNavigationModule} from "../../components/logic/hierarchy-navigtion/hierarchy-navigation.module"; +import {PropertyCreatorComponent} from "./property-creator/property-creator.component"; @NgModule({ declarations: [ PropertiesAssignmentComponent, InputsTableComponent, - FilterPropertiesAssignmentComponent + FilterPropertiesAssignmentComponent, ], imports: [ BrowserModule, @@ -59,7 +60,7 @@ import {HierarchyNavigationModule} from "../../components/logic/hierarchy-navigt exports: [ PropertiesAssignmentComponent ], - providers: [PropertiesService, HierarchyNavService, PropertiesUtils, InputsUtils, DataTypeService, ComponentModeService] + providers: [PropertiesService, HierarchyNavService, PropertiesUtils, InputsUtils, DataTypeService, ComponentModeService, PropertyCreatorComponent] }) export class PropertiesAssignmentModule { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html index 8847e96d18..b54cbc97c2 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html @@ -87,7 +87,7 @@ </div> <div class="right-column"> <div *ngIf="!isReadonly && !isInputsTabSelected" class="add-btn" - (click)="addProperty()" data-tests-id="properties-add-button" [ngClass]="{'disabled': !isSelf()}">Add Property</div> + (click)="addProperty(component.model)" data-tests-id="properties-add-button" [ngClass]="{'disabled': !isSelf()}">Add Property</div> <div *ngIf="!isReadonly && isInputsTabSelected" class="add-btn" (click)="addInput()" [ngClass]="{'disabled': !isSelf()}">Add Input</div> <tabs #hierarchyNavTabs tabStyle="simple-tabs" class="gray-border"> diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index 6d009a8039..fbbc4d8b0e 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -67,6 +67,7 @@ import {ToscaPresentationData} from "../../../models/tosca-presentation"; import {Observable} from "rxjs"; import {ToscaGetFunctionType} from "../../../models/tosca-get-function-type.enum"; import {TranslateService} from "../../shared/translator/translate.service"; +import {Model} from '../../../models/model'; const SERVICE_SELF_TITLE = "SELF"; @Component({ @@ -130,6 +131,7 @@ export class PropertiesAssignmentComponent { private inputsUtils: InputsUtils, private componentServiceNg2: ComponentServiceNg2, private componentInstanceServiceNg2: ComponentInstanceServiceNg2, + private propertyCreatorComponent: PropertyCreatorComponent, @Inject("$stateParams") _stateParams, @Inject("$scope") private $scope: ng.IScope, @Inject("$state") private $state: ng.ui.IStateService, @@ -220,6 +222,8 @@ export class PropertiesAssignmentComponent { }); } }); + + this.loadDataTypesByComponentModel(this.component.model); }; ngOnDestroy() { @@ -1142,7 +1146,8 @@ export class PropertiesAssignmentComponent { } /*** addProperty ***/ - addProperty = () => { + addProperty = (model: Model) => { + this.loadDataTypesByComponentModel(model) let modalTitle = 'Add Property'; let modal = this.ModalService.createCustomModal(new ModalModel( 'sm', @@ -1172,8 +1177,8 @@ export class PropertiesAssignmentComponent { ], null )); - this.ModalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {}); modal.instance.open(); + this.ModalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {}); } /*** addInput ***/ @@ -1245,6 +1250,10 @@ export class PropertiesAssignmentComponent { private isInput = (instanceType:string):boolean =>{ return instanceType === ResourceType.VF || instanceType === ResourceType.PNF || instanceType === ResourceType.CVFC || instanceType === ResourceType.CR; } - + + loadDataTypesByComponentModel(model:Model) { + let modelName = new Model(model).name; + this.propertyCreatorComponent.filterDataTypesByModel(modelName); + } } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/property-creator/property-creator.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/property-creator/property-creator.component.ts index 8167caa959..57c9f97387 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/property-creator/property-creator.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/property-creator/property-creator.component.ts @@ -7,6 +7,7 @@ import { PROPERTY_DATA } from 'app/utils'; import * as _ from 'lodash'; import { PROPERTY_TYPES } from '../../../../utils'; import {Validation} from "../../../../view-models/workspace/tabs/general/general-view-model"; +import {WorkspaceService} from "../../workspace/workspace.service"; @Component({ selector: 'property-creator', @@ -23,14 +24,38 @@ export class PropertyCreatorComponent { dataTypes: DataTypesMap; isLoading: boolean; - constructor(protected dataTypeService: DataTypeService) {} + constructor(protected dataTypeService: DataTypeService, private workspaceService: WorkspaceService) { + this.filterDataTypesByModel(this.workspaceService.metadata.model); + } + + checkFormValidForSubmit() { + const showSchema: boolean = this.showSchema(); + const isSchemaValid: boolean = (showSchema && !this.propertyModel.schema.property.type) ? false : true; + if (!showSchema) { + this.propertyModel.schema.property.type = ''; + } + return this.propertyModel.name && this.propertyModel.type && isSchemaValid; + } + + showSchema(): boolean { + return [PROPERTY_TYPES.LIST, PROPERTY_TYPES.MAP].indexOf(this.propertyModel.type) > -1; + } + + onSchemaTypeChange(): void { + if (this.propertyModel.type === PROPERTY_TYPES.MAP) { + this.propertyModel.value = JSON.stringify({'': null}); + } else if (this.propertyModel.type === PROPERTY_TYPES.LIST) { + this.propertyModel.value = JSON.stringify([]); + } + } - ngOnInit() { + public filterDataTypesByModel = (modelName: string) => { + this.dataTypes = new DataTypesMap(null); + this.dataTypes = this.dataTypeService.getDataTypeByModel(modelName); this.propertyModel = new PropertyBEModel(); this.propertyModel.type = ''; this.propertyModel.schema.property.type = ''; const types: string[] = PROPERTY_DATA.TYPES; // All types - simple type + map + list - this.dataTypes = this.dataTypeService.getAllDataTypes(); // Get all data types in service const nonPrimitiveTypes: string[] = _.filter(Object.keys(this.dataTypes), (type: string) => { return types.indexOf(type) === -1; }); @@ -43,35 +68,13 @@ export class PropertyCreatorComponent { ); const nonPrimitiveTypesValues = _.map(nonPrimitiveTypes, (type: string) => new DropdownValue(type, - type.replace('org.openecomp.datatypes.heat.', '')) + type.replace('org.openecomp.datatypes.heat.', '')) ) .sort((a, b) => a.label.localeCompare(b.label)); this.typesProperties = _.concat(this.typesProperties, nonPrimitiveTypesValues); this.typesSchemaProperties = _.concat(typesSimpleProperties, nonPrimitiveTypesValues); this.typesProperties.unshift(new DropdownValue('', 'Select Type...')); this.typesSchemaProperties.unshift(new DropdownValue('', 'Select Schema Type...')); - - } - - checkFormValidForSubmit() { - const showSchema: boolean = this.showSchema(); - const isSchemaValid: boolean = (showSchema && !this.propertyModel.schema.property.type) ? false : true; - if (!showSchema) { - this.propertyModel.schema.property.type = ''; - } - return this.propertyModel.name && this.propertyModel.type && isSchemaValid; - } - - showSchema(): boolean { - return [PROPERTY_TYPES.LIST, PROPERTY_TYPES.MAP].indexOf(this.propertyModel.type) > -1; - } - - onSchemaTypeChange(): void { - if (this.propertyModel.type === PROPERTY_TYPES.MAP) { - this.propertyModel.value = JSON.stringify({'': null}); - } else if (this.propertyModel.type === PROPERTY_TYPES.LIST) { - this.propertyModel.value = JSON.stringify([]); - } } } |