Catalog alignment
[sdc.git] / catalog-ui / src / app / view-models / admin-dashboard / admin-dashboard-view-model.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 'use strict';
22 import {CacheService} from "app/services-ng2";
23 import {IAppConfigurtaion} from "app/models";
24
25 interface IAdminDashboardViewModelScope extends ng.IScope {
26     version:string;
27     sdcConfig:IAppConfigurtaion;
28     isLoading:boolean;
29     currentTab:string;
30     templateUrl:string;
31     monitorUrl:string;
32     moveToTab(tab:string):void;
33     isSelected(tab:string):boolean;
34 }
35
36
37 export class AdminDashboardViewModel {
38     static '$inject' = [
39         '$scope',
40         '$templateCache',
41         'Sdc.Services.CacheService',
42         'sdcConfig'
43     ];
44
45     constructor(private $scope:IAdminDashboardViewModelScope,
46                 private $templateCache:ng.ITemplateCacheService,
47                 private cacheService:CacheService,
48                 private sdcConfig:IAppConfigurtaion) {
49
50         this.initScope();
51     }
52
53     private initScope = ():void => {
54
55         this.$scope.version = this.cacheService.get('version');
56         this.$scope.sdcConfig = this.sdcConfig;
57         this.$scope.monitorUrl = this.$scope.sdcConfig.api.kibana;
58         this.$scope.isSelected = (tab:string):boolean => {
59             return tab === this.$scope.currentTab;
60         }
61
62         this.$scope.moveToTab = (tab:string):void => {
63             if (tab === this.$scope.currentTab) {
64                 return;
65             }
66             else if (tab === 'USER_MANAGEMENT') {
67                 this.$scope.templateUrl="user-management-view.html";
68                 this.$templateCache.put("user-management-view.html", require('app/view-models/admin-dashboard/user-management/user-management-view.html'));
69             }
70             else if (tab === 'CATEGORY_MANAGEMENT') {
71                 this.$scope.templateUrl="category-management-view.html";
72                 this.$templateCache.put("category-management-view.html", require('app/view-models/admin-dashboard/category-management/category-management-view.html'));
73             }
74             this.$scope.currentTab = tab;
75         };
76
77         this.$scope.moveToTab('USER_MANAGEMENT');
78
79
80     }
81 }