Specify model at service creation
[sdc.git] / catalog-ui / src / app / view-models / workspace / tabs / general / general-view-model.ts
index b456bec..9b7a92b 100644 (file)
@@ -33,7 +33,7 @@ import {
     ValidationUtils
 } from "app/utils";
 import {EventListenerService, ProgressService} from "app/services";
-import {CacheService, ElementService, ImportVSPService, OnboardingService} from "app/services-ng2";
+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";
@@ -53,6 +53,10 @@ export class componentCategories {//categories field bind to this obj in order t
     selectedCategory:string;
 }
 
+export class componentModel {
+    selectedModel:string;
+}
+
 export interface IEnvironmentContext {
     defaultValue:string;
     validValues:Array<string>;
@@ -73,6 +77,7 @@ export interface IGeneralScope extends IWorkspaceViewModelScope {
     importCsarProProgressKey:string;
     browseFileLabel:string;
     componentCategories:componentCategories;
+    componentModel:componentModel;
     instantiationTypes:Array<instantiationType>;
     isHiddenCategorySelected: boolean;
 
@@ -95,6 +100,7 @@ export interface IGeneralScope extends IWorkspaceViewModelScope {
     onInstantiationTypeChange():void;
     updateIcon():void;
     possibleToUpdateIcon():boolean;
+    initModel():void;
 }
 
 // tslint:disable-next-line:max-classes-per-file
@@ -124,6 +130,7 @@ export class GeneralViewModel {
         'ComponentFactory',
         'ImportVSPService',
         'ElementService',
+        'ModelService',
         '$stateParams'
     ];
 
@@ -150,6 +157,7 @@ export class GeneralViewModel {
                 private ComponentFactory:ComponentFactory,
                 private importVSPService: ImportVSPService,
                 private elementService: ElementService,
+                private modelService: ModelService,
                 private $stateParams: any) {
 
         this.initScopeValidation();
@@ -270,6 +278,7 @@ export class GeneralViewModel {
             // Init Instantiation types
             this.$scope.initInstantiationTypes();
             this.$scope.initBaseTypes();
+            this.$scope.initModel();
         }
 
         if (this.cacheService.get(PREVIOUS_CSAR_COMPONENT)) { //keep the old component in the cache until checkout, so we dont need to pass it around
@@ -451,6 +460,15 @@ export class GeneralViewModel {
             }
         };
 
+        this.$scope.initModel = ():void => {
+            if (this.$scope.componentType === ComponentType.SERVICE) {
+                this.$scope.models = new Array();
+                this.modelService.getModels().subscribe((modelsFound: Model[]) => {
+                    modelsFound.forEach(model => {this.$scope.models.push(model.name)});})
+                this.$scope.models.filter(model => model.name === (<Service>this.$scope.component).model);
+            }
+        };
+
         this.$scope.initEnvironmentContext = ():void => {
             if (this.$scope.componentType === ComponentType.SERVICE) {
                 this.$scope.environmentContextObj = this.cacheService.get('UIConfiguration').environmentContext;