X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-ui%2Fsrc%2Fapp%2Fview-models%2Fworkspace%2Ftabs%2Fgeneral%2Fgeneral-view-model.ts;h=96ce7d5fb4cc437f769f9a7db1fcf46404b405ad;hb=a762f63e5dc464dd160808615fce1cfa6c922c90;hp=5065023cb42a70c2cfb00d0a789ed7c33eb61f23;hpb=458bf21d934e356c20b69a1c7b0aae79197e1023;p=sdc.git 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 5065023cb4..96ce7d5fb4 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 @@ -85,6 +85,10 @@ export interface IGeneralScope extends IWorkspaceViewModelScope { instantiationTypes:Array; isHiddenCategorySelected: boolean; isModelRequired: boolean; + othersFlag: boolean; + functionOption: string; + othersRoleFlag: boolean; + roleOption: string; save():Promise; revert():void; @@ -108,6 +112,8 @@ export interface IGeneralScope extends IWorkspaceViewModelScope { possibleToUpdateIcon():boolean; initModel():void; isVspImport(): boolean; + setServiceFunction(option:string):void; + setServiceRole(option:string):void; } // tslint:disable-next-line:max-classes-per-file @@ -253,6 +259,8 @@ export class GeneralViewModel { this.$scope.progressService = this.progressService; this.$scope.componentCategories = new componentCategories(); this.$scope.componentCategories.selectedCategory = this.$scope.component.selectedCategory; + this.$scope.othersFlag = false; + this.$scope.othersRoleFlag = false; // Init UIModel this.$scope.component.tags = _.without(this.$scope.component.tags, this.$scope.component.name); @@ -299,6 +307,7 @@ export class GeneralViewModel { }); (this.$scope.component).derivedFromGenericType = serviceCsar.substitutionNodeType; this.$scope.onBaseTypeChange(); + this.setFunctionRole(service); }, (error) => { const errorMsg = this.$filter('translate')('IMPORT_FAILURE_MESSAGE_TEXT'); @@ -312,6 +321,9 @@ export class GeneralViewModel { this.$state.go('dashboard'); }); } + + this.setFunctionRole(service); + if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) { this.$scope.isShowFileBrowse = true; } @@ -383,6 +395,28 @@ export class GeneralViewModel { return s && s[0].toUpperCase() + s.slice(1); } + private setFunctionRole = (service : Service) : void => { + if (service.serviceFunction) { + const functionList : string[] = this.$scope.getMetadataKeyValidValues('Service Function'); + if (functionList.find(value => value == service.serviceFunction) != undefined) { + this.$scope.functionOption = service.serviceFunction; + } else { + this.$scope.functionOption = 'Others'; + this.$scope.othersFlag = true; + } + } + + if (service.serviceRole) { + const roleList : string[] = this.$scope.getMetadataKeyValidValues('Service Role'); + if (roleList.find(value => value == service.serviceRole) != undefined) { + this.$scope.roleOption = service.serviceRole; + } else { + this.$scope.roleOption = 'Others'; + this.$scope.othersRoleFlag = true; + } + } + } + // Convert category string MainCategory_#_SubCategory to Array with one item (like the server except) private convertCategoryStringToOneArray = ():IMainCategory[] => { let tmp = this.$scope.component.selectedCategory.split("_#_"); @@ -768,6 +802,13 @@ export class GeneralViewModel { } this.$scope.component.selectedCategory = this.$scope.componentCategories.selectedCategory; if (this.$scope.component.selectedCategory) { + this.$scope.roleOption = null; + (this.$scope.component).serviceRole = null; + this.$scope.othersFlag = false; + this.$scope.functionOption = null; + (this.$scope.component).serviceFunction = null; + this.$scope.othersRoleFlag = false; + this.$scope.component.categories = this.convertCategoryStringToOneArray(); this.$scope.component.icon = DEFAULT_ICON; if (this.$scope.component.categories[0].metadataKeys) { @@ -775,6 +816,13 @@ export class GeneralViewModel { if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) { this.$scope.component.categorySpecificMetadata[metadataKey.name] = metadataKey.defaultValue ? metadataKey.defaultValue : ""; } + if (metadataKey.name === 'Service Role') { + this.$scope.roleOption = this.$scope.component.categorySpecificMetadata[metadataKey.name]; + (this.$scope.component).serviceRole = this.$scope.roleOption; + } + if (metadataKey.name === 'Service Function') { + this.$scope.functionOption = this.$scope.component.categorySpecificMetadata[metadataKey.name]; + } } } if (this.$scope.component.categories[0].subcategories && this.$scope.component.categories[0].subcategories[0].metadataKeys) { @@ -852,6 +900,28 @@ export class GeneralViewModel { } }; + this.$scope.setServiceFunction = (option:string): void => { + if (option === 'Others') { + this.$scope.othersFlag = true; + (this.$scope.component).serviceFunction = ''; + } else { + this.$scope.othersFlag = false; + (this.$scope.component).serviceFunction = option; + } + + } + + this.$scope.setServiceRole = (option:string): void => { + if (option === 'Others') { + this.$scope.othersRoleFlag = true; + (this.$scope.component).serviceRole = ''; + } else { + this.$scope.othersRoleFlag = false; + (this.$scope.component).serviceRole = option; + } + + } + this.EventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.$scope.reload); this.$scope.isMetadataKeyMandatory = (key: string): boolean => { @@ -862,7 +932,11 @@ export class GeneralViewModel { this.$scope.getMetadataKeyValidValues = (key: string): string[] => { let metadataKey = this.getMetadataKey(key); if (metadataKey) { - return metadataKey.validValues; + if (key == 'Service Function' || key == 'Service Role') { + return metadataKey.validValues.concat("Others"); + } else { + return metadataKey.validValues; + } } return []; } @@ -885,8 +959,10 @@ export class GeneralViewModel { this.$scope.isMetadataKeyForComponentCategoryService = (key: string, attribute: string): boolean => { let metadatakey = this.getMetadataKey(key); - if (metadatakey && (!this.$scope.component[attribute] || !metadatakey.validValues.find(v => v === this.$scope.component[attribute]))) { - this.$scope.component[attribute] = metadatakey.defaultValue; + if (attribute != 'serviceFunction' && attribute != 'serviceRole') { + if (metadatakey && (!this.$scope.component[attribute] || !metadatakey.validValues.find(v => v === this.$scope.component[attribute]))) { + this.$scope.component[attribute] = metadatakey.defaultValue; + } } return metadatakey != null; }