Add events hub notify calls
[sdc.git] / catalog-ui / src / app / view-models / workspace / tabs / plugins / plugins-context-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 import {IWorkspaceViewModelScope} from "../../workspace-view-model";
5
6
7 interface IPluginsContextViewModelScope extends IWorkspaceViewModelScope {
8     plugin: Plugin;
9     user:IUserProperties;
10     queryParams: Object;
11     isLoading: boolean;
12
13     onLoadingDone(plugin: Plugin): void;
14 }
15
16 export class PluginsContextViewModel {
17     static '$inject' = [
18         '$scope',
19         '$stateParams',
20         'Sdc.Services.CacheService',
21         'PluginsService'
22     ];
23
24     constructor(private $scope:IPluginsContextViewModelScope,
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.user = this.cacheService.get('user');
36
37         this.$scope.queryParams = {
38             userId: this.$scope.user.userId,
39             userRole: this.$scope.user.role,
40             displayType: "context",
41             contextType: this.$scope.component.getComponentSubType(),
42             uuid: this.$scope.component.uuid,
43             lifecycleState: this.$scope.component.lifecycleState,
44             isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId,
45             version: this.$scope.component.version ,
46             parentUrl: window.location.origin,
47             eventsClientId: this.$scope.plugin.pluginId
48         };
49
50         this.$scope.onLoadingDone = (plugin: Plugin) => {
51             if (plugin.pluginId == this.$scope.plugin.pluginId) {
52                 this.$scope.isLoading = false;
53             }
54         };
55
56     }
57 }