aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/app/scripts/view-models/workspace/tabs/deployment/deployment-view-model.ts
blob: f8afc0b75840584af1b3ca1dfb92e26d9f3d4d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
/// <reference path="../../../../references"/>
module Sdc.ViewModels {
    'use strict';

    export interface IDeploymentViewModelScope extends IWorkspaceViewModelScope {

        currentComponent: Models.Components.Component;
        selectedComponent: Models.Components.Component;
        isLoading: boolean;
        sharingService:Sdc.Services.SharingService;
        sdcMenu:Models.IAppMenu;
        version:string;
        isViewOnly:boolean;
        tabs:Array<Models.Tab>;

        setComponent(component: Models.Components.Component);
        isComponentInstanceSelected():boolean;
        updateSelectedComponent(): void
        openUpdateModal();
        deleteSelectedComponentInstance():void;
        onBackgroundClick():void;
        setSelectedInstance(componentInstance: Models.ComponentsInstances.ComponentInstance): void;
        printScreen():void;

    }

    export class DeploymentViewModel {

        static '$inject' = [
            '$scope',
            'sdcMenu',
            'MenuHandler',
            '$modal',
            '$templateCache',
            '$state',
            'Sdc.Services.SharingService',
            '$filter',
            'Sdc.Services.CacheService',
            'ComponentFactory',
            'ChangeLifecycleStateHandler',
            'LeftPaletteLoaderService',
            'ModalsHandler'
        ];

        constructor(private $scope:IDeploymentViewModelScope,
                    private sdcMenu:Models.IAppMenu,
                    private MenuHandler: Utils.MenuHandler,
                    private $modal:ng.ui.bootstrap.IModalService,
                    private $templateCache:ng.ITemplateCacheService,
                    private $state:ng.ui.IStateService,
                    private sharingService:Services.SharingService,
                    private $filter:ng.IFilterService,
                    private cacheService:Services.CacheService,
                    private ComponentFactory: Utils.ComponentFactory,
                    private ChangeLifecycleStateHandler: Sdc.Utils.ChangeLifecycleStateHandler,
                    private LeftPaletteLoaderService: Services.Components.LeftPaletteLoaderService,
                    private ModalsHandler: Sdc.Utils.ModalsHandler) {

            this.$scope.setValidState(true);
            this.initScope();
            this.$scope.updateSelectedMenuItem();
        }


        private initComponent = ():void => {

            this.$scope.currentComponent = this.$scope.component;
            this.$scope.selectedComponent = this.$scope.currentComponent;
            this.updateUuidMap();
            this.$scope.isViewOnly = this.$scope.isViewMode();
        };


        private updateUuidMap = ():void => {
            /**
             * In case user press F5, the page is refreshed and this.sharingService.currentEntity will be undefined,
             * but after loadService or loadResource this.sharingService.currentEntity will be defined.
             * Need to update the uuidMap with the new resource or service.
             */
            this.sharingService.addUuidValue(this.$scope.currentComponent.uniqueId,this.$scope.currentComponent.uuid);
        };

        private initRightTabs = ()=> {
            if(this.$scope.currentComponent.groups){

                let hierarchyTab = new Models.Tab('/app/scripts/view-models/tabs/hierarchy/hierarchy-view.html', 'Sdc.ViewModels.HierarchyViewModel', 'hierarchy', this.$scope.currentComponent, 'hierarchy');
                this.$scope.tabs = Array<Models.Tab>();
                this.$scope.tabs.push(hierarchyTab)
            }

        }
        private initScope = ():void => {

            this.$scope.sharingService = this.sharingService;
            this.$scope.sdcMenu = this.sdcMenu;
            this.$scope.isLoading = false;

            this.$scope.version = this.cacheService.get('version');
            this.initComponent();

            this.$scope.setComponent = (component: Models.Components.Product):void => {
                this.$scope.currentComponent = component;
            }
            
            this.initRightTabs();
        }
    }
}