Add events hub notify calls
[sdc.git] / catalog-ui / src / app / view-models / plugins / plugins-tab-view-model.ts
1 import {Plugin, IUserProperties} from "app/models";
2 import {CacheService} from "app/services";
3 import {PluginsService} from "../../ng2/services/plugins.service";
4
5
6 interface IPluginsTabViewModelScope extends ng.IScope {
7     plugin: Plugin
8     user: IUserProperties;
9     version: string;
10     queryParams: Object;
11     isLoading: boolean;
12
13     onLoadingDone(plugin: Plugin): void;
14 }
15
16 export class PluginsTabViewModel {
17     static '$inject' = [
18         '$scope',
19         '$stateParams',
20         'Sdc.Services.CacheService',
21         'PluginsService'
22     ];
23
24     constructor(private $scope:IPluginsTabViewModelScope,
25                 private $stateParams:any,
26                 private cacheService:CacheService,
27                 private pluginsService:PluginsService) {
28
29         this.initScope();
30     }
31
32     private initScope = ():void => {
33         this.$scope.isLoading = true;
34         this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
35         this.$scope.version = this.cacheService.get('version');
36         this.$scope.user = this.cacheService.get('user');
37
38         this.$scope.queryParams = {
39             userId: this.$scope.user.userId,
40             userRole: this.$scope.user.role,
41             displayType: "tab",
42             parentUrl: window.location.origin,
43             eventsClientId: this.$scope.plugin.pluginId
44         };
45
46         this.$scope.onLoadingDone = (plugin: Plugin) => {
47             if (plugin.pluginId == this.$scope.plugin.pluginId) {
48                 this.$scope.isLoading = false;
49             }
50         };
51     }
52 }