+ this.$scope.getMetadataKeyValidValues = (key: string): string[] => {
+ let metadataKey = this.getMetadataKey(key);
+ if (metadataKey) {
+ if (key == 'Service Function' || key == 'Service Role') {
+ return metadataKey.validValues.concat("Others");
+ } else {
+ return metadataKey.validValues;
+ }
+ }
+ 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(key) != null;
+ }
+
+ this.$scope.isCategoryServiceMetadataKey = (key: string): boolean => {
+ return this.isServiceMetadataKey(key);
+ }
+
+ 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;
+ }
+ return metadatakey != null;
+ }
+
+ this.$scope.isNotApplicableMetadataKeys = (key: string): boolean => {
+ return this.$scope.component.categories && this.$scope.component.categories[0].notApplicableMetadataKeys && this.$scope.component.categories[0].notApplicableMetadataKeys.some(item => item === key);
+ }
+ }
+
+ private filterCategoriesByModel(modelName:string) {
+ // reload categories
+ this.$scope.initCategories();
+ this.$scope.categories = this.$scope.categories.filter(category =>
+ !modelName ? !category.models || 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 = [];
+ let defaultBaseType = baseTypeResponseList.defaultBaseType;
+ baseTypeResponseList.baseTypes.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName));
+ if (this.$scope.isBaseTypeRequired || defaultBaseType != null) {
+ let baseType = baseTypeResponseList.baseTypes[0];
+ if(defaultBaseType != null){
+ baseTypeResponseList.baseTypes.forEach(baseTypeObj => {
+ if(baseTypeObj.toscaResourceName == defaultBaseType) {
+ baseType = baseTypeObj;
+ }
+ });
+ }
+ if((<Service>this.$scope.component).derivedFromGenericType) {
+ baseTypeResponseList.baseTypes.forEach(baseTypeObj => {
+ if(baseTypeObj.toscaResourceName == (<Service>this.$scope.component).derivedFromGenericType) {
+ baseType = baseTypeObj;
+ }
+ });
+ }
+ 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 => {