From 502c354da7b9f649d3b9e6a00c159a2ad53e7b1f Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Mon, 16 Aug 2021 17:08:17 +0100 Subject: Select a Model when Importing a VSP Change-Id: I7537af4c7279636de7e450ec398210ace376eade Issue-ID: SDC-3670 Signed-off-by: andre.schmid --- catalog-ui/src/app/models/component-metadata.ts | 2 + catalog-ui/src/app/models/components/resource.ts | 3 ++ catalog-ui/src/app/models/csar-component.ts | 2 + .../src/app/ng2/services/onboarding.service.ts | 2 + .../workspace/tabs/general/general-view-model.ts | 62 +++++++++++++++++----- .../workspace/tabs/general/general-view.html | 22 ++++---- .../view-models/workspace/workspace-view-model.ts | 5 ++ 7 files changed, 75 insertions(+), 23 deletions(-) (limited to 'catalog-ui/src/app') diff --git a/catalog-ui/src/app/models/component-metadata.ts b/catalog-ui/src/app/models/component-metadata.ts index 1cbecda2b3..351ae4a79b 100644 --- a/catalog-ui/src/app/models/component-metadata.ts +++ b/catalog-ui/src/app/models/component-metadata.ts @@ -126,6 +126,7 @@ export class ComponentMetadata implements IComponentMetadata { public resourceType: string; public csarUUID: string; public csarVersion: string; + public csarVersionId: string; public derivedList: string[]; public vendorName: string; public vendorRelease: string; @@ -134,6 +135,7 @@ export class ComponentMetadata implements IComponentMetadata { public csarPackageType: string; public packageId: string; public iconSprite: string; + public models: string[]; // Service only public serviceFunction: string; diff --git a/catalog-ui/src/app/models/components/resource.ts b/catalog-ui/src/app/models/components/resource.ts index 733f2ff9d1..267a8b4bd6 100644 --- a/catalog-ui/src/app/models/components/resource.ts +++ b/catalog-ui/src/app/models/components/resource.ts @@ -47,6 +47,7 @@ export class Resource extends Component { // Onboarding parameters public csarUUID:string; public csarVersion:string; + public csarVersionId: string; public csarPackageType:string; public packageId:string; @@ -61,6 +62,7 @@ export class Resource extends Component { this.resourceType = component.resourceType; this.csarUUID = component.csarUUID; this.csarVersion = component.csarVersion; + this.csarVersionId = component.csarVersionId; this.resourceVendorModelNumber = component.resourceVendorModelNumber; this.filterTerm = this.name + ' ' + this.description + ' ' + (this.tags ? this.tags.toString() : '') + ' ' + this.version + ' ' + this.resourceType; if (component.categories && component.categories[0] && component.categories[0].subcategories && component.categories[0].subcategories[0]) { @@ -82,6 +84,7 @@ export class Resource extends Component { this.resourceType = componentMetadata.resourceType; this.csarUUID = componentMetadata.csarUUID; this.csarVersion = componentMetadata.csarVersion; + this.csarVersionId = componentMetadata.csarVersionId; this.derivedFrom = componentMetadata.derivedFrom; this.resourceVendorModelNumber = componentMetadata.resourceVendorModelNumber; this.setComponentDisplayData(); diff --git a/catalog-ui/src/app/models/csar-component.ts b/catalog-ui/src/app/models/csar-component.ts index cb89f0ba5e..e388550ccb 100644 --- a/catalog-ui/src/app/models/csar-component.ts +++ b/catalog-ui/src/app/models/csar-component.ts @@ -25,6 +25,7 @@ export interface ICsarComponent { description:string; vspName:string; version:string; + versionId:string; packageId:string; category:string; subCategory:string @@ -32,5 +33,6 @@ export interface ICsarComponent { packageType:string; resourceType:string; vendorRelease:string; + models: Array; } diff --git a/catalog-ui/src/app/ng2/services/onboarding.service.ts b/catalog-ui/src/app/ng2/services/onboarding.service.ts index 51a7fc4c7f..638603f94a 100644 --- a/catalog-ui/src/app/ng2/services/onboarding.service.ts +++ b/catalog-ui/src/app/ng2/services/onboarding.service.ts @@ -112,6 +112,7 @@ export class OnboardingService { newMetadata.csarUUID = csar.packageId; newMetadata.csarPackageType = csar.packageType; newMetadata.csarVersion = csar.version; + newMetadata.csarVersionId = csar.versionId; newMetadata.packageId = csar.packageId; newMetadata.description = csar.description; newMetadata.selectedCategory = selectedCategory && selectedSubCategory ? selectedCategory.name + "_#_" + selectedSubCategory.name : ''; @@ -121,6 +122,7 @@ export class OnboardingService { newMetadata.tags = []; newMetadata.icon = DEFAULT_ICON; newMetadata.iconSprite = "sprite-resource-icons"; + newMetadata.models = csar.models; return newMetadata; }; diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index c78852de4c..c319b806c0 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -81,6 +81,7 @@ export interface IGeneralScope extends IWorkspaceViewModelScope { componentModel:componentModel; instantiationTypes:Array; isHiddenCategorySelected: boolean; + isModelRequired: boolean; save():Promise; revert():void; @@ -102,6 +103,7 @@ export interface IGeneralScope extends IWorkspaceViewModelScope { updateIcon():void; possibleToUpdateIcon():boolean; initModel():void; + isVspImport(): boolean; } // tslint:disable-next-line:max-classes-per-file @@ -465,12 +467,48 @@ export class GeneralViewModel { }; this.$scope.initModel = ():void => { - this.$scope.models = new Array(); + this.$scope.isModelRequired = false; + this.$scope.models = [{id: '', name: 'SDC AID'}]; + if (this.$scope.isCreateMode() && this.$scope.isVspImport()) { + if (this.$scope.component.componentMetadata.models) { + this.$scope.isModelRequired = true; + const modelOptions = this.$scope.component.componentMetadata.models.map(value => { + return {id: value, name: value}; + }); + if (modelOptions.length == 1) { + this.$scope.models = modelOptions; + this.$scope.component.model = modelOptions[0].id; + } else { + this.$scope.models = [{id: '', name: 'Select'}, ...modelOptions]; + } + } + return; + } + this.modelService.getModels().subscribe((modelsFound: Model[]) => { - modelsFound.forEach(model => {this.$scope.models.push(model.name)});}) - this.$scope.models.filter(model => model.name === this.$scope.component).model; + modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})}); + }); + + this.$scope.models.sort(function (model1, model2) { + if (model1.id > model2.id) { + return 1; + } + if (model1.id < model2.id) { + return -1; + } + return 0; + }); }; + this.$scope.isVspImport = (): boolean => { + if (!this.$scope.component || !this.$scope.component.isResource()) { + return false; + } + + const resource = this.$scope.component; + return resource.isCsarComponent(); + } + this.$scope.initEnvironmentContext = ():void => { if (this.$scope.componentType === ComponentType.SERVICE) { this.$scope.environmentContextObj = this.cacheService.get('UIConfiguration').environmentContext; @@ -725,15 +763,15 @@ export class GeneralViewModel { this.$scope.onModelChange = (): void => { if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) { - let modelName = this.$scope.component.model ? this.$scope.component.model : null; - this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { - this.$scope.baseTypes = [] - this.$scope.baseTypeVersions = [] - data.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName)); - data[0].versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); - this.$scope.component.derivedFromGenericType = data[0].toscaResourceName; - this.$scope.component.derivedFromGenericVersion = data[0].versions[0]; - }) + let modelName = this.$scope.component.model ? this.$scope.component.model : null; + this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => { + this.$scope.baseTypes = [] + this.$scope.baseTypeVersions = [] + data.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName)); + data[0].versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); + this.$scope.component.derivedFromGenericType = data[0].toscaResourceName; + this.$scope.component.derivedFromGenericVersion = data[0].versions[0]; + }); } }; diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html index fa4af6d6f5..f9854e2256 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html @@ -611,17 +611,17 @@
- - + +
diff --git a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts index e132d53eaf..411ef10639 100644 --- a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts @@ -55,6 +55,10 @@ import { IDependenciesServerResponse } from '../../ng2/services/responses/depend import { WorkspaceNg1BridgeService } from '../../ng2/pages/workspace/workspace-ng1-bridge-service'; import { WorkspaceService } from '../../ng2/pages/workspace/workspace.service'; +interface ModelSelectOption { + id: string; + name: string; +} export interface IWorkspaceViewModelScope extends ng.IScope { @@ -92,6 +96,7 @@ export interface IWorkspaceViewModelScope extends ng.IScope { unsavedChangesCallback: Function; unsavedFile: boolean; hasNoDependencies: boolean; + models: Array; startProgress(message: string): void; -- cgit 1.2.3-korg