blob: 2a3b68fe258af5b68a69c437031c58df7adfcefd (
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
|
import { Injectable, Inject } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Http, Response} from '@angular/http';
import {IApi, IAppConfigurtaion, Plugin, Plugins, PluginsConfiguration} from "app/models";
import {ISdcConfig, SdcConfigToken} from "../config/sdc-config.config";
@Injectable()
export class PluginsService {
private baseUrl;
public configuration: IAppConfigurtaion;
public api: IApi;
constructor(private http: Http, @Inject(SdcConfigToken) private sdcConfig:ISdcConfig) {
this.api = this.sdcConfig.api;
this.baseUrl = this.api.root + this.sdcConfig.api.component_api_root;
}
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
};
public isPluginOnline = (pluginId: string): Observable<boolean> => {
let url:string = this.api.no_proxy_root + this.api.GET_plugin_online_state.replace(':pluginId', pluginId);
return this.http.get(url).map((res: Response) => {
return res.json()
})
.catch(error => Observable.of(false));
}
}
|