summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/view-models/workspace/tabs/plugins/plugins-context-view-model.ts
blob: 1aff3db882ee8d68fbb42f71b2d59c6f88560b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Plugin, IUserProperties} from "app/models";
import {CacheService} from "app/services";
import {PluginsService} from "../../../../ng2/services/plugins.service";
import {IWorkspaceViewModelScope} from "../../workspace-view-model";


interface IPluginsContextViewModelScope extends IWorkspaceViewModelScope {
    plugin: Plugin;
    user:IUserProperties;
    queryParams: Object;
    isLoading: boolean;
    show: boolean;

    onLoadingDone(plugin: Plugin): void;
}

export class PluginsContextViewModel {
    static '$inject' = [
        '$scope',
        '$stateParams',
        'Sdc.Services.CacheService',
        'PluginsService'
    ];

    constructor(private $scope:IPluginsContextViewModelScope,
                private $stateParams:any,
                private cacheService:CacheService,
                private pluginsService:PluginsService) {

        this.initScope();
    }

    private initScope = ():void => {
        this.$scope.show = false;
        this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
        this.$scope.user = this.cacheService.get('user');

        // Don't show loader if the plugin isn't online
        if (this.$scope.plugin.isOnline) {
            this.$scope.isLoading = true;
        }

        this.$scope.queryParams = {
            userId: this.$scope.user.userId,
            userRole: this.$scope.user.role,
            displayType: "context",
            contextType: this.$scope.component.getComponentSubType(),
            uuid: this.$scope.component.uuid,
            lifecycleState: this.$scope.component.lifecycleState,
            isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId,
            version: this.$scope.component.version,
            parentUrl: window.location.origin,
            eventsClientId: this.$scope.plugin.pluginId
        };

        if (this.$stateParams.queryParams) {
            _.assign(this.$scope.queryParams, this.$stateParams.queryParams);
        }

        this.$scope.onLoadingDone = (plugin: Plugin) => {
            if (plugin.pluginId == this.$scope.plugin.pluginId) {
                this.$scope.isLoading = false;
            }
        };

    }
}
var message = { title: heading, text: messageBody }; return message; } } }); }; this.showMessage = function(heading, messageBody){ var modalInstance = $modal.open({ templateUrl: 'modal_message.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: heading, text: messageBody }; return message; } } }); }; this.showWarning = function(heading, messageBody){ var modalInstance = $modal.open({ templateUrl: 'modal_warning_message.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: heading, text: messageBody }; return message; } } }); }; this.popupConfirmWin = function(title, msgBody, callback){ var modalInstance = $modal.open({ templateUrl: 'confirmation_informative.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: title, text: msgBody }; return message; } } }); var args = Array.prototype.slice.call( arguments, 0 ); args.splice( 0, 3); modalInstance.result.then(function(){ callback.apply(null, args); }, function() { })['finally'](function(){ modalInstance = undefined; }); }; this.popupConfirmWinWithCancel = function(title, msgBody, callback,dismissCallback){ var modalInstance = $modal.open({ templateUrl: 'confirmation_informative.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: title, text: msgBody }; return message; } } }); var args = Array.prototype.slice.call( arguments, 0 ); args.splice( 0, 3); modalInstance.result.then(function(){ callback.apply(null, args); }, function() { dismissCallback(); })['finally'](function(){ modalInstance = undefined; }); }; this.popupDeleteConfirmWin = function(title, msgBody, callback, argForCallBack){ var modalInstance = $modal.open({ templateUrl: 'confirmation_for_delete.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: title, text: msgBody }; return message; } } }); modalInstance.result.then(function(){ callback(argForCallBack); }, function() { })['finally'](function(){ modalInstance = undefined; }); }; this.popupSuccessRedirectWin = function(title, msgBody, redirectUrl){ var modalInstance = $modal.open({ templateUrl: 'modal_informative.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: title, text: msgBody }; return message; } } }); modalInstance.result.then(function() { }, function() { window.location.href=redirectUrl; })['finally'](function(){ modalInstance = undefined; }); }; this.popupWarningRedirectWin = function(title, msgBody, redirectUrl){ var modalInstance = $modal.open({ templateUrl: 'modal_warning_message.html', controller: 'modalpopupController', resolve: { message: function () { var message = { title: title, text: msgBody }; return message; } } }); modalInstance.result.then(function() { }, function() { window.location.href=redirectUrl; })['finally'](function(){ modalInstance = undefined; }); }; }]);