2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
23 import {ComponentFactory, MenuHandler, ChangeLifecycleStateHandler, ModalsHandler} from "app/utils";
24 import {LeftPaletteLoaderService, CacheService, SharingService} from "app/services";
25 import {Component, IAppMenu, Tab, ComponentInstance} from "app/models";
26 import {GRAPH_EVENTS} from "../../../../utils/constants";
27 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
28 import {EventListenerService} from "../../../../services/event-listener-service";
29 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
31 export interface IDeploymentViewModelScope extends IWorkspaceViewModelScope {
33 currentComponent:Component;
34 selectedComponent:Component;
36 sharingService:SharingService;
42 isComponentInstanceSelected():boolean;
43 updateSelectedComponent():void
45 deleteSelectedComponentInstance():void;
46 onBackgroundClick():void;
47 setSelectedInstance(componentInstance:ComponentInstance):void;
52 export class DeploymentViewModel {
60 'Sdc.Services.SharingService',
62 'Sdc.Services.CacheService',
64 'ChangeLifecycleStateHandler',
65 'LeftPaletteLoaderService',
67 'EventListenerService',
71 constructor(private $scope:IDeploymentViewModelScope,
72 private $templateCache:ng.ITemplateCacheService,
73 private sdcMenu:IAppMenu,
74 private MenuHandler:MenuHandler,
75 private $state:ng.ui.IStateService,
76 private sharingService:SharingService,
77 private $filter:ng.IFilterService,
78 private cacheService:CacheService,
79 private ComponentFactory:ComponentFactory,
80 private ChangeLifecycleStateHandler:ChangeLifecycleStateHandler,
81 private LeftPaletteLoaderService:LeftPaletteLoaderService,
82 private ModalsHandler:ModalsHandler,
83 private eventListenerService: EventListenerService,
84 private ComponentServiceNg2: ComponentServiceNg2) {
86 this.$scope.setValidState(true);
92 private initComponent = ():void => {
94 this.$scope.currentComponent = this.$scope.component;
95 this.$scope.selectedComponent = this.$scope.currentComponent;
97 this.$scope.isViewOnly = this.$scope.isViewMode();
101 private updateUuidMap = ():void => {
103 * In case user press F5, the page is refreshed and this.sharingService.currentEntity will be undefined,
104 * but after loadService or loadResource this.sharingService.currentEntity will be defined.
105 * Need to update the uuidMap with the new resource or service.
107 this.sharingService.addUuidValue(this.$scope.currentComponent.uniqueId, this.$scope.currentComponent.uuid);
110 private initRightTabs = ()=> {
111 if (this.$scope.currentComponent.modules) {
112 this.$templateCache.put("hierarchy-view.html", require('app/view-models/tabs/hierarchy/hierarchy-view.html'));
113 let hierarchyTab = new Tab("hierarchy-view.html", 'Sdc.ViewModels.HierarchyViewModel', 'hierarchy', this.$scope.isViewMode(), this.$scope.currentComponent, 'hierarchy');
114 this.$scope.tabs.push(hierarchyTab)
118 private initGraphData = ():void => {
119 if(!this.$scope.component.componentInstances || !this.$scope.component.componentInstancesRelations || !this.$scope.component.modules) {
120 this.ComponentServiceNg2.getDeploymentGraphData(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
121 this.$scope.component.componentInstances = response.componentInstances;
122 this.$scope.component.componentInstancesRelations = response.componentInstancesRelations;
123 this.$scope.component.modules = response.modules;
124 this.$scope.isLoading = false;
125 this.initComponent();
126 this.initRightTabs();
127 this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_DEPLOYMENT_GRAPH_DATA_LOADED);
128 this.$scope.selectedTab = this.$scope.tabs[0];
131 this.$scope.isLoading = false;
132 this.initRightTabs();
133 this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_DEPLOYMENT_GRAPH_DATA_LOADED);
138 private initScope = ():void => {
139 this.$scope.isLoading = true;
140 this.$scope.sharingService = this.sharingService;
141 this.$scope.sdcMenu = this.sdcMenu;
142 this.$scope.version = this.cacheService.get('version');
143 this.initComponent();
144 this.$scope.tabs = Array<Tab>();