openaire-library/services/plugins.service.ts

69 lines
3.1 KiB
TypeScript

import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {CustomOptions} from "./servicesUtils/customOptions.class";
import {PluginTemplate} from "../utils/entities/adminTool/pluginTemplate";
import {Plugin} from "../utils/entities/adminTool/plugin";
import {properties} from "../../../environments/environment";
import {catchError} from "rxjs/operators";
@Injectable()
export class PluginsService {
constructor(private http:HttpClient) {
}
getPluginTemplate(api:string, code:string) {
return this.http.get<PluginTemplate>(api + 'pluginTemplates/' + code)
}
getPluginTemplates(api:string,pageId) {
return this.http.get<Array<PluginTemplate>>(api + 'pluginTemplates' + (pageId?'/page/'+pageId:''))
}
savePluginTemplate(pluginTemplate:PluginTemplate, api:string) {
// console.log(pluginTemplate, pluginTemplate.toJsonObj())
return this.http.post<PluginTemplate>(api + 'pluginTemplate/save', pluginTemplate, CustomOptions.getAuthOptionsWithBody());
}
updatePluginTemplateOrder(pluginTemplate:PluginTemplate, api:string, position) {
return this.http.post<PluginTemplate>(api + 'pluginTemplate/save/order/'+position, pluginTemplate, CustomOptions.getAuthOptionsWithBody());
}
updatePluginOrder(plugin:Plugin, api:string, position) {
return this.http.post<Plugin>(api + 'plugin/save/order/'+position, plugin, CustomOptions.getAuthOptionsWithBody());
}
savePlugin(plugin, api:string) {
return this.http.post<Plugin>(api + 'plugin/save', JSON.stringify(plugin), CustomOptions.getAuthOptionsWithBody());
}
deletePlugin(id, api:string) {
return this.http.delete<Plugin>(api + 'plugin/'+id, CustomOptions.getAuthOptionsWithBody());
}
deletePluginTemplate(id, api:string) {
return this.http.delete<PluginTemplate>(api + 'pluginTemplate/'+id, CustomOptions.getAuthOptionsWithBody());
}
countPluginPerPage( api:string, pid:string){
return this.http.get(api + properties.adminToolsPortalType + '/' +pid+'/plugin/page/count');
}
countPluginTemplatePerPage( api:string, pid:string){
return this.http.get(api + properties.adminToolsPortalType + '/' +pid+'/pluginTemplate/page/count');
}
countPluginTemplatePerPageForAllPortals( api:string){
return this.http.get(api + '/pluginTemplate/page/count');
}
countPluginPerTemplate( api:string){
return this.http.get(api + '/plugin/template/count');
}
getPluginsByPage(api:string, pid:string, pageId:string){
return this.http.get<Array<Plugin>>(api + properties.adminToolsPortalType + '/' +pid+'/plugins/page/' + pageId);
}
getPluginTemplatesByPage(api:string, pid:string, pageId:string){
return this.http.get<Array<PluginTemplate>>(api + properties.adminToolsPortalType + '/' +pid+'/pluginTemplates/page/' + pageId);
}
getPluginsByTemplatesCode(api:string, pid:string, code:string){
return this.http.get<Array<Plugin>>(api +'/plugins/template/' + code);
}
togglePages(id : string,status : boolean, api:string) {
return this.http.post(api + 'plugin/status/' + id, status, CustomOptions.getAuthOptionsWithBody());
}
}