summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services/plugins.service.ts
blob: 7a85b6e1b6db6da41b0a8d0bc82faf62ee6f2ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Injectable } from '@angular/core';
import {Plugin, PluginsConfiguration} from "app/models";

@Injectable()
export class PluginsService {

    constructor() {
    }

    public getPluginByStateUrl = (stateUrl: string) => {
        let pluginKey: any = _.findKey(PluginsConfiguration.plugins, (pluginConfig: Plugin) =>{
            return pluginConfig.pluginStateUrl ===  stateUrl;
        });

        return PluginsConfiguration.plugins[pluginKey];
    };

    public isPluginDisplayedInContext = (plugin: Plugin ,userRole: string, contextType: string) => {
        return plugin.pluginDisplayOptions["context"] &&
               plugin.pluginDisplayOptions["context"].displayRoles.includes(userRole) &&
               plugin.pluginDisplayOptions["context"].displayContext.indexOf(contextType) !== -1
    };
}