CSIT Fix for SDC-2585
[sdc.git] / catalog-ui / src / app / view-models / plugins / plugins-tab-view-model.ts
1 /*
2
3 * Copyright (c) 2018 AT&T Intellectual Property.
4
5 *
6
7 * Licensed under the Apache License, Version 2.0 (the "License");
8
9 * you may not use this file except in compliance with the License.
10
11 * You may obtain a copy of the License at
12
13 *
14
15 *     http://www.apache.org/licenses/LICENSE-2.0
16
17 *
18
19 * Unless required by applicable law or agreed to in writing, software
20
21 * distributed under the License is distributed on an "AS IS" BASIS,
22
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
25 * See the License for the specific language governing permissions and
26
27 * limitations under the License.
28
29 */
30
31 import {IUserProperties, Plugin} from "app/models";
32 import {CacheService} from "app/services";
33 import {PluginsService} from "../../ng2/services/plugins.service";
34
35
36 interface IPluginsTabViewModelScope extends ng.IScope {
37     plugin: Plugin
38     user: IUserProperties;
39     version: string;
40     queryParams: Object;
41     isLoading: boolean;
42
43     onLoadingDone(plugin: Plugin): void;
44 }
45
46 export class PluginsTabViewModel {
47     static '$inject' = [
48         '$scope',
49         '$stateParams',
50         'Sdc.Services.CacheService',
51         'PluginsService'
52     ];
53
54     constructor(private $scope: IPluginsTabViewModelScope,
55                 private $stateParams: any,
56                 private cacheService: CacheService,
57                 private pluginsService: PluginsService) {
58
59         this.initScope();
60     }
61
62     private initScope = (): void => {
63         this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
64         this.$scope.version = this.cacheService.get('version');
65         this.$scope.user = this.cacheService.get('user');
66
67         this.$scope.isLoading = true;
68
69         this.$scope.queryParams = {
70             userId: this.$scope.user.userId,
71             userRole: this.$scope.user.role,
72             displayType: "tab",
73             parentUrl: window.location.origin,
74             eventsClientId: this.$scope.plugin.pluginId
75         };
76
77         this.$scope.onLoadingDone = (plugin: Plugin) => {
78             if (plugin.pluginId == this.$scope.plugin.pluginId) {
79                 this.$scope.isLoading = false;
80             }
81         };
82     }
83 }