2024-02-28 12:07:31 +01:00
|
|
|
import {Component, ElementRef, OnInit} from '@angular/core';
|
2023-09-26 16:32:27 +02:00
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {HelpContentService} from "../../services/help-content.service";
|
|
|
|
import {
|
2024-02-28 12:07:31 +01:00
|
|
|
FormArray,
|
|
|
|
FormGroup,
|
2023-09-26 16:32:27 +02:00
|
|
|
UntypedFormArray,
|
|
|
|
UntypedFormBuilder,
|
|
|
|
UntypedFormGroup,
|
|
|
|
ValidatorFn,
|
|
|
|
Validators
|
|
|
|
} from "@angular/forms";
|
2024-02-02 08:33:01 +01:00
|
|
|
import {Page} from "../../utils/entities/adminTool/page";
|
2023-09-26 16:32:27 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|
|
|
import {Subscriber} from "rxjs";
|
|
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
import {PortalUtils} from "../portal/portalHelper";
|
|
|
|
import {Option} from "../../sharedComponents/input/input.component";
|
|
|
|
import {Title} from "@angular/platform-browser";
|
|
|
|
import {ClearCacheService} from "../../services/clear-cache.service";
|
|
|
|
import {NotificationHandler} from "../../utils/notification-handler";
|
|
|
|
import {PluginsService} from "../../services/plugins.service";
|
|
|
|
import {Plugin} from "../../utils/entities/adminTool/plugin";
|
|
|
|
import {StringUtils} from "../../utils/string-utils.class";
|
|
|
|
import {Portal} from "../../utils/entities/adminTool/portal";
|
|
|
|
import {PluginTemplate} from "../../utils/entities/adminTool/pluginTemplate";
|
2024-02-02 08:33:01 +01:00
|
|
|
import {PluginUtils} from "./utils/pluginUtils";
|
2024-02-22 10:09:20 +01:00
|
|
|
import {CommunityService} from "../../connect/community/community.service";
|
|
|
|
import {CommunityInfo} from "../../connect/community/communityInfo";
|
2024-02-28 12:07:31 +01:00
|
|
|
import {PluginEditEvent} from "./utils/base-plugin.form.component";
|
2023-09-26 16:32:27 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'plugins',
|
|
|
|
templateUrl: './plugins.component.html',
|
|
|
|
})
|
|
|
|
export class PluginsComponent implements OnInit {
|
|
|
|
private selectedId: string;
|
2024-02-02 08:33:01 +01:00
|
|
|
public pluginsByPlacement: Map<string,{plugin:Plugin, template:PluginTemplate}[]> = new Map();
|
2023-09-26 16:32:27 +02:00
|
|
|
public plugins: Plugin[] = [];
|
|
|
|
public pluginTemplates: PluginTemplate[] = [];
|
|
|
|
public selectedTemplate: PluginTemplate = null;
|
|
|
|
public selectedPlugin: Plugin = null;
|
2023-10-02 09:20:36 +02:00
|
|
|
public editView = false;
|
|
|
|
public selectTemplateView = false;
|
2023-09-26 16:32:27 +02:00
|
|
|
public templateForm: UntypedFormGroup;
|
|
|
|
public pagesCtrl: UntypedFormArray;
|
|
|
|
urlValidator: ValidatorFn = StringUtils.urlValidator;
|
|
|
|
private searchText: RegExp = new RegExp('');
|
|
|
|
public keyword: string = "";
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public formPages: Page[] = [];
|
|
|
|
public showLoading: boolean = true;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
public allPages: Option[] = [];
|
2024-02-02 08:33:01 +01:00
|
|
|
public pluginUtils = new PluginUtils();
|
2023-09-26 16:32:27 +02:00
|
|
|
selectedCommunityPid = null;
|
|
|
|
public portalUtils: PortalUtils = new PortalUtils();
|
|
|
|
private index: number;
|
|
|
|
public portal: string;
|
|
|
|
public selectedPageId: string;
|
|
|
|
public community: Portal;
|
|
|
|
public page: Page;
|
2023-10-17 08:20:16 +02:00
|
|
|
public templateView = false;
|
|
|
|
public templateCode:string = null;
|
2024-02-02 08:33:01 +01:00
|
|
|
public template;
|
|
|
|
public selectedPlacementView = "all";
|
2024-02-22 10:09:20 +01:00
|
|
|
communityInfo:CommunityInfo = null;
|
2024-02-28 12:07:31 +01:00
|
|
|
editSubmenuOpen = false;
|
2023-09-26 16:32:27 +02:00
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
2024-02-22 10:09:20 +01:00
|
|
|
private communityService: CommunityService,
|
2023-10-02 09:20:36 +02:00
|
|
|
private title: Title, private _helpContentService: HelpContentService,
|
2023-09-26 16:32:27 +02:00
|
|
|
private _pluginsService: PluginsService, private _fb: UntypedFormBuilder,
|
|
|
|
private _clearCacheService: ClearCacheService) {
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
ngOnInit() {
|
2023-10-02 09:20:36 +02:00
|
|
|
this.title.setTitle('Administrator Dashboard | Plugins');
|
2024-02-22 10:09:20 +01:00
|
|
|
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(
|
|
|
|
community => {
|
|
|
|
this.communityInfo = community;
|
|
|
|
}));
|
2023-09-26 16:32:27 +02:00
|
|
|
this.subscriptions.push(this.route.params.subscribe(params => {
|
2023-10-17 08:20:16 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
|
|
|
|
this.selectedCommunityPid = params.community;
|
2024-02-22 10:09:20 +01:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.selectedPageId = params['pageId'];
|
|
|
|
if (this.portal && this.selectedPageId) {
|
|
|
|
this.getPage(this.selectedPageId);
|
|
|
|
}
|
2023-10-17 08:20:16 +02:00
|
|
|
if (!this.selectedPageId && !this.templateView) {
|
2023-09-26 16:32:27 +02:00
|
|
|
this._router.navigate(['../pages'], {relativeTo: this.route});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2024-02-02 08:33:01 +01:00
|
|
|
getTemplateById(id) {
|
2023-10-02 09:20:36 +02:00
|
|
|
for (let template of this.pluginTemplates) {
|
2024-02-02 08:33:01 +01:00
|
|
|
if (template._id == id) {
|
2023-09-26 16:32:27 +02:00
|
|
|
return template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
getPage(pageId: string) {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpContentService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.portal).subscribe(
|
|
|
|
page => {
|
|
|
|
if (this.properties.adminToolsPortalType != page.portalType) {
|
|
|
|
this._router.navigate(['./pageContents']);
|
|
|
|
} else {
|
|
|
|
this.page = page;
|
2023-10-17 08:20:16 +02:00
|
|
|
this.getPagePlugins();
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page', error)));
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-10-17 08:20:16 +02:00
|
|
|
getPagePlugins() {
|
2023-09-26 16:32:27 +02:00
|
|
|
this.showLoading = true;
|
2023-10-02 09:20:36 +02:00
|
|
|
this.subscriptions.push(this._pluginsService.getPluginTemplatesByPage(this.properties.adminToolsAPIURL, this.selectedCommunityPid, this.selectedPageId).subscribe(
|
2023-09-26 16:32:27 +02:00
|
|
|
templates => {
|
|
|
|
this.pluginTemplates = templates;
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
this.subscriptions.push(this._pluginsService.getPluginsByPage(this.properties.adminToolsAPIURL, this.selectedCommunityPid, this.selectedPageId).subscribe(
|
2023-09-26 16:32:27 +02:00
|
|
|
plugins => {
|
|
|
|
this.plugins = plugins;
|
2024-02-02 08:33:01 +01:00
|
|
|
this.pluginsByPlacement = new Map();
|
|
|
|
for(let pos of this.pluginUtils.placementsOptions){
|
|
|
|
this.pluginsByPlacement.set(pos.value,[]);
|
|
|
|
}
|
2023-09-26 16:32:27 +02:00
|
|
|
let self = this;
|
2024-01-19 09:53:17 +01:00
|
|
|
this.pluginTemplates.forEach(_ => {
|
|
|
|
let plugin:Plugin = null;
|
|
|
|
for(let pl of plugins){
|
2024-02-02 08:33:01 +01:00
|
|
|
if (pl.templateId == _._id){
|
2024-01-19 09:53:17 +01:00
|
|
|
plugin = pl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!plugin){
|
|
|
|
plugin = new Plugin(this.selectedPageId, this.selectedCommunityPid,_);
|
|
|
|
this.plugins.push(plugin);
|
|
|
|
}
|
2024-02-28 12:07:31 +01:00
|
|
|
plugin.object = PluginUtils.initializeObjectAndCompare(_.code,plugin.object)
|
2024-02-02 08:33:01 +01:00
|
|
|
this.pluginsByPlacement.get(plugin.placement).push({plugin: plugin, template: _ });
|
2023-10-17 08:20:16 +02:00
|
|
|
});
|
2024-02-02 08:33:01 +01:00
|
|
|
for(let placement of this.pluginUtils.placementsOptions){
|
|
|
|
this.pluginsByPlacement.get(placement.value).sort(function (a, b) {
|
|
|
|
return a.plugin.order - b.plugin.order;
|
|
|
|
})
|
|
|
|
}
|
2023-10-17 08:20:16 +02:00
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving plugins', error)));
|
|
|
|
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving templates', error)));
|
|
|
|
}
|
2023-09-26 16:32:27 +02:00
|
|
|
|
2024-02-02 08:33:01 +01:00
|
|
|
public edit(plugin:Plugin, template:PluginTemplate, placement, index) {
|
2023-10-02 09:20:36 +02:00
|
|
|
this.editView = true;
|
2024-02-28 12:07:31 +01:00
|
|
|
this.selectedPlugin = JSON.parse(JSON.stringify(plugin)); // deep copy object with nested objects
|
2023-10-02 09:20:36 +02:00
|
|
|
this.selectedTemplate = template;
|
2024-02-02 08:33:01 +01:00
|
|
|
this.index = index;
|
2023-09-26 16:32:27 +02:00
|
|
|
this.pagesCtrl = this._fb.array([], Validators.required);
|
|
|
|
this.templateForm = this._fb.group({
|
|
|
|
_id: this._fb.control(plugin._id),
|
2023-10-02 09:20:36 +02:00
|
|
|
pid: this._fb.control(this.selectedCommunityPid),
|
2023-09-26 16:32:27 +02:00
|
|
|
page: this._fb.control(plugin.page),
|
2024-02-02 08:33:01 +01:00
|
|
|
templateCode: this._fb.control(plugin.templateCode, Validators.required),
|
|
|
|
templateId: this._fb.control(plugin.templateId, Validators.required),
|
2023-09-26 16:32:27 +02:00
|
|
|
placement: this._fb.control(plugin.placement),
|
|
|
|
order: this._fb.control(plugin.order),
|
2023-10-02 09:20:36 +02:00
|
|
|
active: this._fb.control(plugin.active),
|
2024-01-19 09:53:17 +01:00
|
|
|
values: this._fb.array([]),
|
2023-09-26 16:32:27 +02:00
|
|
|
});
|
2024-02-22 10:09:20 +01:00
|
|
|
|
2024-01-19 09:53:17 +01:00
|
|
|
if (template.settings) {
|
|
|
|
for (let attrKey of Object.keys(template.settings)) {
|
2023-09-26 16:32:27 +02:00
|
|
|
(this.templateForm.get("values") as FormArray).push(this._fb.group({
|
2023-10-02 09:20:36 +02:00
|
|
|
'key': this._fb.control(attrKey),
|
2024-01-19 09:53:17 +01:00
|
|
|
'value': this._fb.control(plugin.settingsValues[attrKey]?plugin.settingsValues[attrKey]:template.settings[attrKey].value)
|
2023-10-02 09:20:36 +02:00
|
|
|
}
|
2023-09-26 16:32:27 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
|
|
|
public newPluginSelectTemplate() {
|
|
|
|
this.selectedPlugin = null;
|
|
|
|
this.editView = true;
|
2023-10-17 08:20:16 +02:00
|
|
|
if(!this.templateView) {
|
|
|
|
this.selectedTemplate = null;
|
|
|
|
this.selectTemplateView = true;
|
|
|
|
}else{
|
|
|
|
this.newPlugin( Object.assign({}, this.template));
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public newPlugin(template) {
|
2023-09-26 16:32:27 +02:00
|
|
|
this.selectedTemplate = template;
|
2023-10-02 09:20:36 +02:00
|
|
|
this.templateForm = this._fb.group({
|
|
|
|
_id: this._fb.control(null),
|
|
|
|
pid: this._fb.control(this.selectedCommunityPid),
|
|
|
|
page: this._fb.control(this.selectedPageId),
|
|
|
|
code: this._fb.control(this.selectedTemplate.code, Validators.required),
|
2024-02-02 08:33:01 +01:00
|
|
|
placement: this._fb.control(this.selectedTemplate.placement),
|
2023-10-02 09:20:36 +02:00
|
|
|
order: this._fb.control(""),
|
|
|
|
active: this._fb.control(false),
|
|
|
|
isPriorTo: this._fb.control(false),
|
2024-01-19 09:53:17 +01:00
|
|
|
values: this._fb.array([]),
|
2024-01-22 11:37:48 +01:00
|
|
|
object: this._fb.control({})
|
2023-10-02 09:20:36 +02:00
|
|
|
});
|
2024-01-19 09:53:17 +01:00
|
|
|
for (let attrKey of Object.keys(this.selectedTemplate.settings)) {
|
2023-10-02 09:20:36 +02:00
|
|
|
(this.templateForm.get("values") as FormArray).push(this._fb.group({
|
|
|
|
key: this._fb.control(attrKey),
|
2024-01-19 09:53:17 +01:00
|
|
|
value: this._fb.control(this.selectedTemplate.settings[attrKey].value ? this.selectedTemplate.settings[attrKey].value : ""),
|
2023-10-02 09:20:36 +02:00
|
|
|
}));
|
2023-09-26 16:32:27 +02:00
|
|
|
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
this.selectTemplateView = false;
|
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2024-02-22 10:09:20 +01:00
|
|
|
public saveConfirmed(index) {
|
2023-09-26 16:32:27 +02:00
|
|
|
this.showLoading = true;
|
2023-10-02 09:20:36 +02:00
|
|
|
let plugin: Plugin = <Plugin>this.templateForm.getRawValue();
|
2024-02-28 12:07:31 +01:00
|
|
|
plugin.object = this.selectedPlugin.object;
|
2024-01-19 09:53:17 +01:00
|
|
|
plugin.settingsValues = new Map<string, string>();
|
2023-09-26 16:32:27 +02:00
|
|
|
for (let fields of this.templateForm.getRawValue().values) {
|
2024-01-19 09:53:17 +01:00
|
|
|
plugin.settingsValues[fields.key] = fields.value;
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
2024-02-02 08:33:01 +01:00
|
|
|
let update = (plugin._id) ? true : false;
|
2024-02-22 10:09:20 +01:00
|
|
|
this.savePlugin(plugin,update, this.index)
|
2024-02-02 08:33:01 +01:00
|
|
|
}
|
|
|
|
public savePlugin(plugin, update, index){
|
2023-10-02 09:20:36 +02:00
|
|
|
this.subscriptions.push(this._pluginsService.savePlugin(plugin, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
saved => {
|
2024-02-02 08:33:01 +01:00
|
|
|
this.savedSuccessfully(saved, update, index);
|
2023-10-02 09:20:36 +02:00
|
|
|
this.editView = false;
|
|
|
|
this.selectTemplateView = false;
|
|
|
|
this.selectedTemplate = null;
|
|
|
|
this.selectedPlugin = null;
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError("System error creating template", error)
|
|
|
|
));
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2024-02-02 08:33:01 +01:00
|
|
|
public savedSuccessfully(plugin: Plugin, update: boolean, index) {
|
2024-02-22 10:09:20 +01:00
|
|
|
console.log(plugin.placement, index, update)
|
2023-10-02 09:20:36 +02:00
|
|
|
if (update) {
|
2024-02-02 08:33:01 +01:00
|
|
|
this.pluginsByPlacement.get(plugin.placement)[index].plugin = plugin;
|
2023-10-02 09:20:36 +02:00
|
|
|
} else {
|
|
|
|
this.plugins.push(plugin);
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
public filterPlugins(plugin: Plugin, template: PluginTemplate): boolean {
|
|
|
|
let values =[];
|
2024-01-19 09:53:17 +01:00
|
|
|
for(let key of this.getKeys(plugin.settingsValues)){
|
|
|
|
values.push(plugin.settingsValues[key]);
|
2023-10-02 09:20:36 +02:00
|
|
|
}
|
2024-02-02 08:33:01 +01:00
|
|
|
return this.searchText.toString() == '' || (plugin.templateCode + ' ' +values.join(' ') + (template?(template.name + ' ' +template.description):'')).match(this.searchText) != null;
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleUpdateError(message: string, error = null) {
|
|
|
|
if (error) {
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
NotificationHandler.rise(message, 'danger');
|
2023-09-26 16:32:27 +02:00
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
handleError(message: string, error = null) {
|
|
|
|
if (error) {
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
NotificationHandler.rise(message, 'danger');
|
2023-09-26 16:32:27 +02:00
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
getPages() {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpContentService.getAllPages(this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
pages => {
|
|
|
|
this.allPages = [];
|
|
|
|
pages.forEach(page => {
|
|
|
|
this.allPages.push({
|
|
|
|
label: page.name + " [" + page.portalType + "]",
|
|
|
|
value: page
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving pages', error)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
get attrFormArray() {
|
2023-09-26 16:32:27 +02:00
|
|
|
|
|
|
|
return this.templateForm.get("values") as FormArray;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
attributeTypeChanged(form) {
|
2023-09-26 16:32:27 +02:00
|
|
|
let type = form.get("value").get("type");
|
|
|
|
form.get("value").setValue("");
|
2023-10-02 09:20:36 +02:00
|
|
|
if (type == "boolean") {
|
2023-09-26 16:32:27 +02:00
|
|
|
form.get("value").setValue(false);
|
|
|
|
}
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
public getPagesAsString(pageIds): string {
|
|
|
|
|
|
|
|
let pages = [];
|
2023-10-02 09:20:36 +02:00
|
|
|
for (let id of pageIds) {
|
2023-09-26 16:32:27 +02:00
|
|
|
pages.push(this.allPages.filter(option => option.value._id == id).map((option => option.value.name)));
|
|
|
|
|
|
|
|
}
|
|
|
|
return pages.join(", ");
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2023-09-26 16:32:27 +02:00
|
|
|
public getPageById(pageId) {
|
2023-10-02 09:20:36 +02:00
|
|
|
for (let option of this.allPages) {
|
|
|
|
if (option.value._id == pageId) {
|
2023-09-26 16:32:27 +02:00
|
|
|
return option.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pageId;
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
getKeys(obj) {
|
2024-01-19 09:53:17 +01:00
|
|
|
return obj?Object.keys(obj):[];
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:20:36 +02:00
|
|
|
reset() {
|
|
|
|
if (this.selectedPlugin) {
|
2024-02-28 12:07:31 +01:00
|
|
|
|
|
|
|
this.edit(this.pluginsByPlacement.get(this.selectedTemplate.placement)[this.index].plugin, this.selectedTemplate, this.selectedTemplate.placement, this.index)
|
2023-10-02 09:20:36 +02:00
|
|
|
} else {
|
|
|
|
this.newPlugin(this.selectedTemplate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-02 08:33:01 +01:00
|
|
|
public togglePlugin(status: boolean, id: string,i, placement) {
|
|
|
|
this.index = i;
|
|
|
|
this.selectedTemplate = this.pluginsByPlacement.get(placement)[i].template;
|
|
|
|
if(id) {
|
|
|
|
this.subscriptions.push(this._pluginsService.togglePages(id, status, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
() => {
|
2023-10-02 09:20:36 +02:00
|
|
|
|
2024-02-02 08:33:01 +01:00
|
|
|
this.pluginsByPlacement.get(placement)[i].plugin.active = status;
|
|
|
|
this._clearCacheService.clearCache("Plugin's status changed");
|
|
|
|
this._clearCacheService.purgeBrowserCache("Plugin's status changed", this.portal);
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error changing the status of Plugin', error)
|
|
|
|
));
|
|
|
|
}else{
|
|
|
|
let plugin = this.pluginsByPlacement.get(placement)[i].plugin;
|
|
|
|
plugin.active = status;
|
|
|
|
this.savePlugin(plugin, true, i);
|
|
|
|
}
|
2023-10-02 09:20:36 +02:00
|
|
|
}
|
2024-01-19 09:53:17 +01:00
|
|
|
pluginFieldChanged($event:PluginEditEvent){
|
2024-02-28 12:07:31 +01:00
|
|
|
if($event.type == "open-submenu"){
|
|
|
|
this.editSubmenuOpen = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if($event.type == "close-submenu"){
|
2024-02-22 10:09:20 +01:00
|
|
|
|
2024-02-28 12:07:31 +01:00
|
|
|
this.editSubmenuOpen = false;
|
|
|
|
return;
|
2024-02-22 10:09:20 +01:00
|
|
|
}
|
2024-02-28 12:07:31 +01:00
|
|
|
this.selectedPlugin.object[$event.field]=$event.value;
|
2024-01-19 09:53:17 +01:00
|
|
|
this.templateForm.markAsDirty();
|
|
|
|
}
|
2024-02-02 08:33:01 +01:00
|
|
|
|
|
|
|
public swap(pluginToMoveUp, pluginToMoveDown, placement ){
|
|
|
|
this.showLoading = true;
|
|
|
|
let moveUpGroup = this.pluginsByPlacement.get(placement)[pluginToMoveUp];
|
|
|
|
let moveDownGroup = this.pluginsByPlacement.get(placement)[pluginToMoveDown];
|
|
|
|
this.pluginsByPlacement.get(placement)[pluginToMoveUp] = moveDownGroup;
|
|
|
|
this.pluginsByPlacement.get(placement)[pluginToMoveDown] = moveUpGroup;
|
|
|
|
this.move(moveUpGroup.plugin,true, pluginToMoveDown, placement);
|
|
|
|
this.move(moveDownGroup.plugin,false, pluginToMoveUp, placement);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
public move(plugin: Plugin, up:boolean, index, placement) {
|
|
|
|
if(plugin._id) {
|
|
|
|
this.subscriptions.push(this._pluginsService.updatePluginOrder(plugin, this.properties.adminToolsAPIURL, up ? -1 : 1).subscribe(
|
|
|
|
saved => {
|
|
|
|
this.pluginsByPlacement.get(placement)[index].plugin = saved;
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError("System error creating template", error)
|
|
|
|
));
|
|
|
|
}else{
|
|
|
|
|
|
|
|
plugin.order = plugin.order + (up ? -1 : 1)
|
|
|
|
this.savePlugin(plugin, true, index);
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 16:32:27 +02:00
|
|
|
}
|