Fix create a service with SDC AID model 07/124007/2
authorandre.schmid <andre.schmid@est.tech>
Thu, 9 Sep 2021 15:45:25 +0000 (16:45 +0100)
committerMichael Morris <michael.morris@est.tech>
Fri, 10 Sep 2021 09:21:40 +0000 (09:21 +0000)
Change-Id: Ia5f0fa1304f6eab609862dd76f9b9f3485f468d1
Issue-ID: SDC-3723
Signed-off-by: andre.schmid <andre.schmid@est.tech>
catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
catalog-ui/src/app/view-models/workspace/workspace-view-model.ts

index dd1fa46..1bcf266 100644 (file)
@@ -468,18 +468,20 @@ export class GeneralViewModel {
 
         this.$scope.initModel = ():void => {
             this.$scope.isModelRequired = false;
-            this.$scope.models = [{id: '', name: 'SDC AID'}];
+            this.$scope.models = [];
+            this.$scope.defaultModelOption = 'SDC AID';
+            this.$scope.showDefaultModelOption = true;
             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};
-                    });
+                    const modelOptions = this.$scope.component.componentMetadata.models;
                     if (modelOptions.length == 1) {
                         this.$scope.models = modelOptions;
-                        this.$scope.component.model = modelOptions[0].id;
+                        this.$scope.component.model = modelOptions[0];
+                        this.$scope.showDefaultModelOption = false;
                     } else {
-                        this.$scope.models = [{id: '', name: 'Select'}, ...modelOptions];
+                        this.$scope.models = modelOptions.sort();
+                        this.$scope.defaultModelOption = 'Select';
                     }
                 }
                 return;
@@ -487,23 +489,13 @@ export class GeneralViewModel {
 
             if (!this.$scope.isCreateMode() && this.$scope.isVspImport()){
                 this.modelService.getModels().subscribe((modelsFound: Model[]) => {
-                    modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})});
-                });    
+                    modelsFound.sort().forEach(model => {this.$scope.models.push(model.name)});
+                });
             } else {
                 this.modelService.getModelsOfType("normative").subscribe((modelsFound: Model[]) => {
-                    modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})});
+                    modelsFound.sort().forEach(model => {this.$scope.models.push(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 => {
index 5035ef2..2366eea 100644 (file)
                           <div class="i-sdc-form-item">
                             <label class="i-sdc-form-label required">Model</label>
                             <select class="i-sdc-form-select"
-                                    name="modelName"
                                     data-ng-class="{'view-mode': isViewMode()}"
                                     data-ng-disabled="!isCreateMode()"
-                                    data-ng-model="component.model"
                                     data-ng-change="onModelChange()"
                                     data-tests-id="modelName"
-                                    ng-required="isModelRequired">
-                              <option ng-repeat="model in models" value="{{model.id}}">{{model.name}}</option>
+                                    data-ng-required="isModelRequired"
+                                    data-ng-model="component.model"
+                                    data-ng-options="model for model in models track by model"
+                            >
+                              <option ng-if="showDefaultModelOption" value="">{{defaultModelOption}}</option>
                             </select>
                           </div>
                           <!--------------------- Model -------------------->
index 411ef10..c72a5a4 100644 (file)
@@ -55,11 +55,6 @@ 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 {
 
     isLoading: boolean;
@@ -96,8 +91,7 @@ export interface IWorkspaceViewModelScope extends ng.IScope {
     unsavedChangesCallback: Function;
     unsavedFile: boolean;
     hasNoDependencies: boolean;
-    models: Array<ModelSelectOption>;
-
+    models: Array<string>;
 
     startProgress(message: string): void;
     stopProgress(): void;