import {CacheService, ElementService, ModelService, ImportVSPService, OnboardingService} from "app/services-ng2";
import {Component, IAppConfigurtaion, ICsarComponent, IMainCategory, IMetadataKey, ISubCategory, IValidate, Resource, Service} from "app/models";
import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
-import {CATEGORY_SERVICE_METADATA_KEYS, PREVIOUS_CSAR_COMPONENT} from "../../../../utils/constants";
+import {CATEGORY_SERVICE_METADATA_KEYS, PREVIOUS_CSAR_COMPONENT, DEFAULT_MODEL_NAME} from "../../../../utils/constants";
import {Observable} from "rxjs";
import {Model} from "../../../../models/model";
convertCategoryStringToOneArray(category:string, subcategory:string):Array<IMainCategory>;
onCategoryChange():void;
onEcompGeneratedNamingChange():void;
+ onModelChange():void;
onBaseTypeChange():void;
openOnBoardingModal():void;
- initCategoreis():void;
+ initCategories():void;
initEnvironmentContext():void;
initInstantiationTypes():void;
initBaseTypes():void;
this.$scope.componentCategories = new componentCategories();
this.$scope.componentCategories.selectedCategory = this.$scope.component.selectedCategory;
-
// Init UIModel
this.$scope.component.tags = _.without(this.$scope.component.tags, this.$scope.component.name);
// Init categories
- this.$scope.initCategoreis();
+ this.$scope.initCategories();
// Init Environment Context
this.$scope.initEnvironmentContext();
if (this.$scope.component.isResource() &&
(this.$scope.component as Resource).resourceType === ResourceType.VF ||
- (this.$scope.component as Resource).resourceType === ResourceType.PNF && (this.$scope.component as Resource).csarUUID) {
+ (this.$scope.component as Resource).resourceType === ResourceType.PNF && (this.$scope.component as Resource).csarUUID) {
this.$scope.isShowOnboardingSelectionBrowse = true;
this.setImportedFileText();
} else {
});
return tempCategories;
- };
-
+ };
+
private initScopeMethods = ():void => {
- this.$scope.initCategoreis = ():void => {
+ this.$scope.initCategories = ():void => {
if (this.$scope.componentType === ComponentType.RESOURCE) {
this.$scope.categories = this.cacheService.get('resourceCategories');
//Flag to disbale category if service is created through External API
this.$scope.isHiddenCategorySelected = this.isHiddenCategory(this.$scope.component.selectedCategory);
}
-
+
}
};
this.$scope.initBaseTypes = ():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)
- if (baseType.toscaResourceName === this.$scope.component.derivedFromGenericType){
- baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
- }});
- })
+ if (!this.$scope.component.derivedFromGenericType) {
+ this.$scope.component.derivedFromGenericVersion = undefined;
+ this.$scope.showBaseTypeVersions = false;
+ return;
+ }
+ let modelName = this.$scope.component.model ? this.$scope.component.model : null;
+ const categoryName = this.$scope.component.categories[0].name;
+ this.elementService.getCategoryBaseTypes(categoryName, modelName).subscribe((data: ListBaseTypesResponse) => {
+ this.$scope.baseTypes = []
+ this.$scope.baseTypeVersions = []
+ this.$scope.isBaseTypeRequired = data.required;
+ data.baseTypes.forEach(baseType => {
+ this.$scope.baseTypes.push(baseType.toscaResourceName);
+ if (baseType.toscaResourceName === this.$scope.component.derivedFromGenericType) {
+ baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
+ }
+ });
+ this.$scope.showBaseTypeVersions = true;
+ })
}
};
this.$scope.initModel = ():void => {
this.$scope.isModelRequired = false;
this.$scope.models = [];
- this.$scope.defaultModelOption = 'SDC AID';
+ this.$scope.defaultModelOption = DEFAULT_MODEL_NAME;
this.$scope.showDefaultModelOption = true;
+ if (this.$scope.componentType === ComponentType.SERVICE) {
+ this.filterCategoriesByModel(this.$scope.component.model);
+ }
if (this.$scope.isCreateMode() && this.$scope.isVspImport()) {
if (this.$scope.component.componentMetadata.models) {
this.$scope.isModelRequired = true;
if (!this.$scope.isCreateMode() && this.$scope.isVspImport()){
this.modelService.getModels().subscribe((modelsFound: Model[]) => {
- modelsFound.sort().forEach(model => {this.$scope.models.push(model.name)});
+ modelsFound.sort().forEach(model => {
+ if (this.$scope.component.model != undefined) {
+ if (model.modelType == "NORMATIVE_EXTENSION") {
+ this.$scope.component.model = model.derivedFrom;
+ this.$scope.models.push(model.derivedFrom)
+ } else {
+ this.$scope.component.model = model.name;
+ this.$scope.models.push(model.name)
+ }
+ }
+ });
});
} else {
this.modelService.getModelsOfType("normative").subscribe((modelsFound: Model[]) => {
this.importVSPService.openOnboardingModal(csarUUID, csarVersion).subscribe((result) => {
this.ComponentFactory.getComponentWithMetadataFromServer(result.type.toUpperCase(), result.previousComponent.uniqueId).then(
(component:Component)=> {
- if (result.componentCsar && component.isResource()){
- this.cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
- component = this.ComponentFactory.updateComponentFromCsar(result.componentCsar, <Resource>component);
- }
- this.$scope.setComponent(component);
- this.$scope.save();
- this.setImportedFileText();
- }, ()=> {
- // ERROR
- });
+ if (result.componentCsar && component.isResource()){
+ this.cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
+ component = this.ComponentFactory.updateComponentFromCsar(result.componentCsar, <Resource>component);
+ }
+ this.$scope.setComponent(component);
+ this.$scope.save();
+ this.setImportedFileText();
+ }, ()=> {
+ // ERROR
+ });
})
};
return;
}
-
+
let subtype:string = ComponentType.RESOURCE == this.$scope.componentType ? this.$scope.component.getComponentSubType() : undefined;
if (subtype == "SRVC") {
subtype = "VF"
this.$scope.onCategoryChange = (): void => {
this.$scope.component.selectedCategory = this.$scope.componentCategories.selectedCategory;
- this.$scope.component.categories = this.convertCategoryStringToOneArray();
- this.$scope.component.icon = DEFAULT_ICON;
- if (this.$scope.component.categories[0].metadataKeys) {
- for (let metadataKey of this.$scope.component.categories[0].metadataKeys) {
- if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
- this.$scope.component.categorySpecificMetadata[metadataKey.name] = metadataKey.defaultValue ? metadataKey.defaultValue : "";
- }
+ if (this.$scope.component.selectedCategory) {
+ this.$scope.component.categories = this.convertCategoryStringToOneArray();
+ this.$scope.component.icon = DEFAULT_ICON;
+ if (this.$scope.component.categories[0].metadataKeys) {
+ for (let metadataKey of this.$scope.component.categories[0].metadataKeys) {
+ if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
+ this.$scope.component.categorySpecificMetadata[metadataKey.name] = metadataKey.defaultValue ? metadataKey.defaultValue : "";
+ }
+ }
}
- }
- if (this.$scope.component.categories[0].subcategories && this.$scope.component.categories[0].subcategories[0].metadataKeys) {
- for (let metadataKey of this.$scope.component.categories[0].subcategories[0].metadataKeys) {
- if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
- this.$scope.component.categorySpecificMetadata[metadataKey.name] = metadataKey.defaultValue ? metadataKey.defaultValue : "";
- }
+ if (this.$scope.component.categories[0].subcategories && this.$scope.component.categories[0].subcategories[0].metadataKeys) {
+ for (let metadataKey of this.$scope.component.categories[0].subcategories[0].metadataKeys) {
+ if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
+ this.$scope.component.categorySpecificMetadata[metadataKey.name] = metadataKey.defaultValue ? metadataKey.defaultValue : "";
+ }
+ }
+ }
+ if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component.categories[0]) {
+ const modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
+ this.elementService.getCategoryBaseTypes(this.$scope.component.categories[0].name, modelName)
+ .subscribe((data: ListBaseTypesResponse) => {
+ if (this.$scope.isCreateMode()) {
+ this.loadBaseTypes(data);
+ } else {
+ let isValidForBaseType:boolean = data.baseTypes.some(baseType => {
+ return !this.$scope.component.derivedFromGenericType ||
+ baseType.toscaResourceName === this.$scope.component.derivedFromGenericType;
+ });
+ this.$scope.editForm['category'].$setValidity('validForBaseType', isValidForBaseType);
+ }
+ });
}
+ } else {
+ this.clearBaseTypes();
}
- if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component.categories[0]) {
- let modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
- this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
-
- if(this.$scope.isCreateMode()){
- 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];
- } else {
- var isValidForBaseType:boolean = false;
- data.forEach(baseType => {if (!this.$scope.component.derivedFromGenericType || baseType.toscaResourceName === this.$scope.component.derivedFromGenericType){
- isValidForBaseType = true;
- };});
- this.$scope.editForm['category'].$setValidity('validForBaseType', isValidForBaseType);
- }
- });
- }
};
this.$scope.onEcompGeneratedNamingChange = (): void => {
}
};
+ this.$scope.getCategoryDisplayNameOrName = (mainCategory: any): string => {
+ return mainCategory.displayName ? mainCategory.displayName : mainCategory.name ;
+ }
+
this.$scope.onBaseTypeChange = (): void => {
- let modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
- this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
- this.$scope.baseTypeVersions = []
- data.forEach(baseType => {
- if(baseType.toscaResourceName === this.$scope.component.derivedFromGenericType) {
- baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
- this.$scope.component.derivedFromGenericVersion = baseType.versions[0];
- };
- });
- })
+ if (!this.$scope.component.derivedFromGenericType) {
+ this.$scope.component.derivedFromGenericVersion = undefined;
+ this.$scope.showBaseTypeVersions = false;
+ return;
+ }
+
+ const modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
+ const categoryName = this.$scope.component.categories[0].name;
+ this.elementService.getCategoryBaseTypes(categoryName, modelName).subscribe((baseTypeResponseList: ListBaseTypesResponse) => {
+ this.$scope.baseTypeVersions = []
+ baseTypeResponseList.baseTypes.forEach(baseType => {
+ if (baseType.toscaResourceName === this.$scope.component.derivedFromGenericType) {
+ baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
+ this.$scope.component.derivedFromGenericVersion = baseType.versions[0];
+ }
+ });
+ this.$scope.showBaseTypeVersions = true;
+ });
};
this.$scope.onModelChange = (): void => {
- if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) {
+ if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.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];
- });
+ this.$scope.component.categories = undefined;
+ this.$scope.component.selectedCategory = undefined;
+ this.$scope.componentCategories.selectedCategory = undefined;
+ this.filterCategoriesByModel(modelName);
+ this.filterBaseTypesByModelAndCategory(modelName)
}
};
this.$scope.component.icon = DEFAULT_ICON;
}
};
- this.EventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.$scope.reload);
+ this.EventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.$scope.reload);
this.$scope.isMetadataKeyMandatory = (key: string): boolean => {
- let metadataKey = this.getMetadataKey(this.$scope.component.categories, key);
+ let metadataKey = this.getMetadataKey(key);
return metadataKey && metadataKey.mandatory;
}
this.$scope.getMetadataKeyValidValues = (key: string): string[] => {
- let metadataKey = this.getMetadataKey(this.$scope.component.categories, key);
+ let metadataKey = this.getMetadataKey(key);
if (metadataKey) {
return metadataKey.validValues;
}
- return [];
+ return [];
+ }
+
+ this.$scope.getMetadataDisplayName = (key: string): string => {
+ let metadataKey = this.getMetadataKey(key);
+ if (metadataKey) {
+ return metadataKey.displayName ? metadataKey.displayName : metadataKey.name;
+ }
+ return "";
}
this.$scope.isMetadataKeyForComponentCategory = (key: string): boolean => {
- return this.getMetadataKey(this.$scope.component.categories, key) != null;
+ return this.getMetadataKey(key) != null;
}
this.$scope.isCategoryServiceMetadataKey = (key: string): boolean => {
}
this.$scope.isMetadataKeyForComponentCategoryService = (key: string, attribute: string): boolean => {
- let metadatakey = this.getMetadataKey(this.$scope.component.categories, key);
+ 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;
}
return metadatakey != null;
- }
+ }
+ }
+
+ private filterCategoriesByModel(modelName:string) {
+ // reload categories
+ this.$scope.initCategories();
+ this.$scope.categories = this.$scope.categories.filter(category =>
+ !modelName ? category.models.indexOf(DEFAULT_MODEL_NAME) !== -1 : category.models !== null && category.models.indexOf(modelName) !== -1);
+ }
+
+
+ private filterBaseTypesByModelAndCategory(modelName:string) {
+ let categories = this.$scope.component.categories;
+ if (categories) {
+ this.elementService.getCategoryBaseTypes(categories[0].name, modelName).subscribe((data: ListBaseTypesResponse) => {
+ this.loadBaseTypes(data);
+ });
+ return;
+ }
+ this.clearBaseTypes();
+ }
+
+ private loadBaseTypes(baseTypeResponseList: ListBaseTypesResponse) {
+ this.$scope.isBaseTypeRequired = baseTypeResponseList.required;
+ this.$scope.baseTypes = [];
+ this.$scope.baseTypeVersions = [];
+ baseTypeResponseList.baseTypes.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName));
+ if (this.$scope.isBaseTypeRequired) {
+ const baseType = baseTypeResponseList.baseTypes[0];
+ baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
+ this.$scope.component.derivedFromGenericType = baseType.toscaResourceName;
+ this.$scope.component.derivedFromGenericVersion = this.$scope.baseTypeVersions[0];
+ this.$scope.showBaseTypeVersions = true;
+ return
+ }
+ this.$scope.component.derivedFromGenericType = undefined;
+ this.$scope.component.derivedFromGenericVersion = undefined;
+ this.$scope.showBaseTypeVersions = false;
+ }
+
+ private clearBaseTypes() {
+ this.$scope.isBaseTypeRequired = false;
+ this.$scope.baseTypes = [];
+ this.$scope.baseTypeVersions = [];
+ this.$scope.component.derivedFromGenericType = undefined;
+ this.$scope.component.derivedFromGenericVersion = undefined;
+ this.$scope.showBaseTypeVersions = false;
}
private setUnsavedChanges = (hasChanges: boolean): void => {
this.$state.current.data.unsavedChanges = hasChanges;
}
- private getMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
- let metadataKey = this.getSubcategoryMetadataKey(this.$scope.component.categories, key);
- if (!metadataKey){
- return this.getCategoryMetadataKey(this.$scope.component.categories, key);
+ private getMetadataKey(key: string) : IMetadataKey {
+ if (this.$scope.component.categories) {
+ let metadataKey = this.getSubcategoryMetadataKey(this.$scope.component.categories, key);
+ if (!metadataKey){
+ return this.getCategoryMetadataKey(this.$scope.component.categories, key);
+ }
+ return metadataKey;
}
- return metadataKey;
+ return null;
}
private getSubcategoryMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
- if (categories[0].subcategories && categories[0].subcategories[0].metadataKeys && categories[0].subcategories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+ if (categories[0].subcategories && categories[0].subcategories[0].metadataKeys && categories[0].subcategories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
return categories[0].subcategories[0].metadataKeys.find(metadataKey => metadataKey.name == key);
}
return null;
}
private getCategoryMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
- if (categories[0].metadataKeys && categories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+ if (categories[0].metadataKeys && categories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
return categories[0].metadataKeys.find(metadataKey => metadataKey.name == key);
}
return null;
}
}
-