3 * Copyright (c) 2018 AT&T Intellectual Property.
7 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
27 * limitations under the License.
31 import {IUserProperties, Plugin} from "app/models";
32 import {CacheService} from "app/services";
33 import {PluginsService} from "../../../../ng2/services/plugins.service";
34 import {IWorkspaceViewModelScope} from "../../workspace-view-model";
37 interface IPluginsContextViewModelScope extends IWorkspaceViewModelScope {
39 user: IUserProperties;
44 onLoadingDone(plugin: Plugin): void;
47 export class PluginsContextViewModel {
51 'Sdc.Services.CacheService',
55 constructor(private $scope: IPluginsContextViewModelScope,
56 private $stateParams: any,
57 private cacheService: CacheService,
58 private pluginsService: PluginsService) {
63 private initScope = (): void => {
64 this.$scope.show = false;
65 this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
66 this.$scope.user = this.cacheService.get('user');
68 this.$scope.isLoading = true;
70 this.$scope.queryParams = {
71 userId: this.$scope.user.userId,
72 userRole: this.$scope.user.role,
73 displayType: "context",
74 contextType: this.$scope.component.getComponentSubType(),
75 uuid: this.$scope.component.uuid,
76 lifecycleState: this.$scope.component.lifecycleState,
77 isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId,
78 version: this.$scope.component.version,
79 parentUrl: window.location.origin,
80 eventsClientId: this.$scope.plugin.pluginId
83 if (this.$stateParams.queryParams) {
84 _.assign(this.$scope.queryParams, this.$stateParams.queryParams);
87 this.$scope.onLoadingDone = (plugin: Plugin) => {
88 if (plugin.pluginId == this.$scope.plugin.pluginId) {
89 this.$scope.isLoading = false;