Add designer service

Fixed a bug in the configuration

Change-Id: I6a40bff70ed71d72d6b75104ffb1002d83ade1b2
Issue-ID: SDC-958
Signed-off-by: Idan Amit <ia096e@intl.att.com>
diff --git a/catalog-ui/src/app/models/designers-config.ts b/catalog-ui/src/app/models/designers-config.ts
index 6b4233f..b60e420 100644
--- a/catalog-ui/src/app/models/designers-config.ts
+++ b/catalog-ui/src/app/models/designers-config.ts
@@ -2,7 +2,7 @@
 export class Designer {
     designerId: string;
     designerHost: string;
-    designerPort: number;
+    designerPort: string;
     designerPath: string;
     designerStateUrl: string;
     designerProtocol: string;
diff --git a/catalog-ui/src/app/modules/service-module.ts b/catalog-ui/src/app/modules/service-module.ts
index b677a6d..c2ee61e 100644
--- a/catalog-ui/src/app/modules/service-module.ts
+++ b/catalog-ui/src/app/modules/service-module.ts
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -51,6 +51,7 @@
 import {ConnectionWizardService} from "../ng2/pages/connection-wizard/connection-wizard.service";
 import {ComponentInstanceServiceNg2} from "../ng2/services/component-instance-services/component-instance.service";
 import {UserService as UserServiceNg2} from "../ng2/services/user.service";
+import {DesignersService} from "../ng2/services/designers.service";
 
 let moduleName:string = 'Sdc.Services';
 let serviceModule:ng.IModule = angular.module(moduleName, []);
@@ -94,4 +95,5 @@
 serviceModule.factory('ModalServiceNg2', downgradeInjectable(ModalService));
 serviceModule.factory('ConnectionWizardServiceNg2', downgradeInjectable(ConnectionWizardService));
 serviceModule.factory('ComponentInstanceServiceNg2', downgradeInjectable(ComponentInstanceServiceNg2));
-serviceModule.factory('UserServiceNg2', downgradeInjectable(UserServiceNg2));
\ No newline at end of file
+serviceModule.factory('UserServiceNg2', downgradeInjectable(UserServiceNg2));
+serviceModule.factory('DesignersService', downgradeInjectable(DesignersService));
diff --git a/catalog-ui/src/app/ng2/app.module.ts b/catalog-ui/src/app/ng2/app.module.ts
index ecaa26e..5cf4d80 100644
--- a/catalog-ui/src/app/ng2/app.module.ts
+++ b/catalog-ui/src/app/ng2/app.module.ts
@@ -47,6 +47,7 @@
 import { TranslateModule } from "./shared/translator/translate.module";
 import { TranslationServiceConfig } from "./config/translation.service.config";
 import {DesignerFrameModule} from "./components/ui/designer/designer-frame.module";
+import {DesignersService} from "./services/designers.service";
 
 export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
 
@@ -97,6 +98,7 @@
         SdcConfig,
         ComponentInstanceServiceNg2,
         TranslationServiceConfig,
+        DesignersService,
         {
             provide: APP_INITIALIZER,
             useFactory: configServiceFactory,
diff --git a/catalog-ui/src/app/ng2/services/designers.service.ts b/catalog-ui/src/app/ng2/services/designers.service.ts
new file mode 100644
index 0000000..283b54b
--- /dev/null
+++ b/catalog-ui/src/app/ng2/services/designers.service.ts
@@ -0,0 +1,17 @@
+import { Injectable } from '@angular/core';
+import {Designer, DesignersConfiguration} from "app/models";
+
+@Injectable()
+export class DesignersService {
+
+    constructor() {
+    }
+
+    public getDesignerByStateUrl = (stateUrl: string) => {
+        let designerKey: any = _.findKey(DesignersConfiguration.designers, (designerConfig: Designer) =>{
+            return designerConfig.designerStateUrl ===  stateUrl;
+        });
+
+        return DesignersConfiguration.designers[designerKey];
+    }
+}
diff --git a/catalog-ui/src/app/view-models/designers/designers-view-model.ts b/catalog-ui/src/app/view-models/designers/designers-view-model.ts
index 42c1194..380e093 100644
--- a/catalog-ui/src/app/view-models/designers/designers-view-model.ts
+++ b/catalog-ui/src/app/view-models/designers/designers-view-model.ts
@@ -1,6 +1,7 @@
-import {Designer, IUserProperties, DesignersConfiguration} from "app/models";
+import {Designer, IUserProperties} from "app/models";
 import {CacheService} from "app/services";
 import {MenuItemGroup} from "app/utils";
+import {DesignersService} from "../../ng2/services/designers.service";
 
 
 interface IDesignerViewModelScope extends ng.IScope {
@@ -14,25 +15,20 @@
     static '$inject' = [
         '$scope',
         '$stateParams',
-        '$sce',
-        'Sdc.Services.CacheService'
+        'Sdc.Services.CacheService',
+        'DesignersService'
     ];
 
     constructor(private $scope:IDesignerViewModelScope,
                 private $stateParams:any,
-                private $sce:any,
-                private cacheService:CacheService) {
+                private cacheService:CacheService,
+                private designersService:DesignersService) {
 
         this.initScope();
     }
 
     private initScope = ():void => {
-        // get the designer object by using the path parameter
-        let designerKey: any = _.findKey(DesignersConfiguration.designers, (designerConfig: Designer) =>{
-            return designerConfig.designerStateUrl ===  this.$stateParams.path;
-        });
-
-        this.$scope.designer = DesignersConfiguration.designers[designerKey];
+        this.$scope.designer = this.designersService.getDesignerByStateUrl(this.$stateParams.path);
 
         this.$scope.version = this.cacheService.get('version');
         this.$scope.topNavMenuModel = [];
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/designers/designers-tab-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/designers/designers-tab-view-model.ts
index 03ce83e..2f4e1da 100644
--- a/catalog-ui/src/app/view-models/workspace/tabs/designers/designers-tab-view-model.ts
+++ b/catalog-ui/src/app/view-models/workspace/tabs/designers/designers-tab-view-model.ts
@@ -1,4 +1,5 @@
-import {Designer, DesignersConfiguration} from "app/models";
+import {Designer} from "app/models";
+import {DesignersService} from "../../../../ng2/services/designers.service";
 
 
 interface IDesignerTabViewModelScope extends ng.IScope {
@@ -8,21 +9,18 @@
 export class DesignersTabViewModel {
     static '$inject' = [
         '$scope',
-        '$stateParams'
+        '$stateParams',
+        'DesignersService'
     ];
 
     constructor(private $scope:IDesignerTabViewModelScope,
-                private $stateParams:any) {
+                private $stateParams:any,
+                private designersService:DesignersService) {
 
         this.initScope();
     }
 
     private initScope = ():void => {
-        // get the designer object by using the path parameter
-        let designerKey: any = _.findKey(DesignersConfiguration.designers, (designerConfig: Designer) =>{
-            return designerConfig.designerStateUrl ===  this.$stateParams.path;
-        });
-
-        this.$scope.designer = DesignersConfiguration.designers[designerKey];
+        this.$scope.designer = this.designersService.getDesignerByStateUrl(this.$stateParams.path);
     }
 }
diff --git a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts
index 3846cf0..87d8367 100644
--- a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts
+++ b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts
@@ -725,7 +725,7 @@
                 if (designer.designerDisplayOptions["context"]) {
                     let displayOptions : DesignerDisplayOptions = designer.designerDisplayOptions["context"];
 
-                    if (displayOptions.displayContext.indexOf(this.$scope.component.getComponentSubType()) !== -1) {
+                    if (displayOptions.displayContext.indexOf(this.$scope.component.componentType) !== -1) {
                         menuItemsObjects.push({
                             text: displayOptions.displayName,
                             action: 'onMenuItemPressed',