improvements in manage Plugins

This commit is contained in:
argirok 2023-10-02 10:20:36 +03:00
parent 4dcb757c1b
commit d80db44df1
9 changed files with 288 additions and 210 deletions

View File

@ -88,7 +88,7 @@
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<ng-container *ngIf="!isPortalAdministrator">
<div >
<div *ngIf="pagePluginTemplatesCount[check.page._id]>0" >
<div class="uk-padding-small uk-padding-remove-horizontal">
<a class="uk-button uk-button-link uk-text-truncate"
[queryParams]="{pageId: check.page._id}"

View File

@ -70,7 +70,7 @@ export class PagesComponent implements OnInit {
pageHelpContentsCount = {};
pageClassContentsCount = {};
pagePluginsCount = {};
pagePluginTemplatesCount = {};
constructor(private element: ElementRef, private route: ActivatedRoute,
private title: Title,
private _router: Router, private _helpContentService: HelpContentService,
@ -445,5 +445,10 @@ export class PagesComponent implements OnInit {
this.pagePluginsCount = countPlugins;
},
error => this.handleError('System error retrieving page contents', error)));
this.subscriptions.push(this._pluginsService.countPluginTemplatePerPage( this.properties.adminToolsAPIURL, community_pid).subscribe(
countPlugins => {
this.pagePluginTemplatesCount = countPlugins;
},
error => this.handleError('System error retrieving page contents', error)));
}
}

View File

@ -2,6 +2,28 @@
<div header>
<div class="uk-section-xsmall uk-margin-top">
<div class="uk-flex-middle uk-grid" uk-grid>
<ng-container *ngIf="editView ">
<div class="uk-width-expand">
<a (click)="editView = false; selectedTemplate = null; selectedPlugin = null;" class="uk-flex uk-flex-middle uk-h5 uk-link-reset">
<span class="uk-margin-right">
<icon name="west" ratio="1.7" [flex]="true"></icon>
</span>
<h1 *ngIf="page" class="uk-h5 uk-margin-remove">{{page.name}} - {{selectedPlugin ? 'Update ' : 'Add new '}} plugin
<span *ngIf=" templateForm && templateForm.dirty" class="uk-text-large"> (unsaved changes)</span>
</h1>
</a>
</div>
<div *ngIf="templateForm" class="uk-width-auto">
<button class="uk-button uk-button-default uk-margin-right"
(click)="reset()" [class.uk-disabled]="!templateForm.dirty"
[disabled]="!templateForm.dirty || showLoading">Reset
</button>
<button class="uk-button uk-button-primary" [class.uk-disabled]="templateForm.invalid || !templateForm.dirty || templateForm.disabled"
(click)="saveConfirmed()" [disabled]="templateForm.invalid ||!templateForm.dirty || templateForm.disabled || showLoading">Save
</button>
</div>
</ng-container>
<ng-container *ngIf="!editView">
<div class="uk-width-expand">
<a routerLink="../pages" class="uk-flex uk-flex-middle uk-h5 uk-link-reset">
<span class="uk-margin-right">
@ -10,24 +32,26 @@
<h1 *ngIf="page" class="uk-h5 uk-margin-remove">{{page.name}}</h1>
</a>
</div>
<div search-input [disabled]="showLoading" [expandable]="true" [searchControl]="filterForm" searchInputClass="outer" placeholder="Search plugins" class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1">
<div search-input [disabled]="showLoading" [expandable]="true" [searchControl]="filterForm.get('keyword')" searchInputClass="outer" placeholder="Search plugins" class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1">
</div>
<div>
<button (click)="newPlugin()" [disabled]="showLoading" [class.uk-disabled]="showLoading || this.pluginTemplates.length ==0"
<button (click)="newPluginSelectTemplate()" [disabled]="showLoading" [class.uk-disabled]="showLoading || this.pluginTemplates.length ==0"
class="uk-flex uk-flex-middle uk-button uk-button-default" >
<icon [flex]="true" name="add"></icon>
<span class="uk-margin-small-left">Add new plugin</span>
</button>
</div>
</ng-container>
</div>
</div>
</div>
<div inner>
<div class="uk-section uk-section-small uk-position-relative" style="min-height: 60vh">
<div *ngIf="showLoading" class="uk-position-center">
<loading></loading>
</div>
<ng-container *ngIf="!showLoading">
<ng-container *ngIf="!showLoading && !editView">
<div *ngIf="checkboxes.length == 0"
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No plugins found</div>
@ -36,10 +60,6 @@
<div *ngFor="let check of checkboxes; let i=index">
<div class="uk-card uk-card-default">
<div class="uk-card-body uk-flex">
<!--<div *ngIf="!portal" class="uk-margin-right">
<input [id]="check.template._id" class="uk-checkbox" type="checkbox"
name="pagescb[]" value="{{check.page._id}}" [(ngModel)]="check.checked">
</div>-->
<div class="uk-width-expand uk-text-small">
<ng-container *ngIf="check.template">
<h6>{{check.template.name}}</h6>
@ -77,7 +97,7 @@
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<button
class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="edit(i)" [class.uk-disabled]="!check.template">
class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="edit(check.plugin, check.template)" [class.uk-disabled]="!check.template">
<icon name="edit" [flex]="true"></icon>
<span class="uk-margin-xsmall-left"> Edit</span>
</button>
@ -92,100 +112,100 @@
</button>
</div>
</div>
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<mat-slide-toggle [checked]="check.plugin.active"
(change)="($event.source.checked = check.plugin.active);togglePlugin(!check.plugin.active,check.plugin._id)"
>
<span class="uk-text-small">Enable</span>
</mat-slide-toggle>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</ng-container>
</div>
</div>
</div>
<modal-alert #editModal (alertOutput)="saveConfirmed($event)" [large]="true"
[okDisabled]="templateForm && (templateForm.invalid || !templateForm.dirty)" classTitle="uk-background-primary uk-light">
{{selectedPlugin}} {{selectedTemplate}} {{pluginTemplates.length}}
<div *ngIf="!selectedPlugin && !selectedTemplate">
<div *ngIf="pluginTemplates.length > 0" class="uk-grid uk-child-width-1-1" uk-height-match=".uk-card-body" uk-grid>
<div *ngFor="let template of pluginTemplates; let i=index">
<div class="uk-card uk-card-default">
<div class="uk-card-body uk-flex">
<div class="uk-width-expand uk-text-small">
<h6>{{template.name}}</h6>
<div class="uk-margin-small-bottom">
<span class="uk-text-meta">Placements: </span>{{template.placements.join(", ")}}
</div>
<div class="uk-margin-small-bottom">
{{template.description}}
</div>
<ng-container *ngIf="editView">
</div>
</div>
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div *ngIf="selectTemplateView">
<div> Select a Template for your plugin. </div>
<div *ngIf="pluginTemplates.length > 0" class="uk-grid uk-child-width-1-1" uk-height-match=".uk-card-body" uk-grid>
<div *ngFor="let template of pluginTemplates; let i=index">
<div class="uk-card uk-card-default">
<div class="uk-card-body uk-flex">
<div class="uk-width-expand uk-text-small">
<h6>{{template.name}}</h6>
<div class="uk-margin-small-bottom">
<span class="uk-text-meta">Placements: </span>{{template.placements.join(", ")}}
</div>
<div class="uk-margin-small-bottom">
{{template.description}}
</div>
</div>
</div>
<div class="uk-card-footer uk-padding-remove-vertical">
<div class="uk-grid uk-grid-small uk-flex-nowrap uk-grid-divider uk-flex-right" uk-grid>
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<button
class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="newPlugin(template)">
<!-- <icon name="edit" [flex]="true"></icon>-->
<span class="uk-margin-xsmall-left"> Select Template</span>
</button>
<div>
<div class="uk-padding-small uk-padding-remove-horizontal">
<button
class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="newPlugin(template)">
<!-- <icon name="edit" [flex]="true"></icon>-->
<span class="uk-margin-xsmall-left"> Select Template</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<form *ngIf="templateForm" [formGroup]="templateForm" class="uk-grid" uk-grid>
<ng-container *ngIf="selectedTemplate || selectedPlugin">
<div class="uk-text-large ">{{selectedTemplate.name}}</div>
<div class="uk-text-meta uk-width-1-1">{{selectedTemplate.description}}</div>
<div input [formInput]="templateForm.get('placement')" placeholder="Placements" [options]="placementsOptions" type="select" class="uk-width-1-2"></div>
<div *ngFor="let attrForm of attrFormArray.controls; let i=index" class="uk-width-1-1 uk-grid uk-child-width-1-2 uk-margin-top" uk-grid>
<div class="uk-heading-divider uk-text-small uk-width-1-1 uk-margin-bottom uk-text-meta">
<div class="uk-grid">
<div>Field #{{i +1}}</div>
<!--<div *ngIf="attrFormArray.length > 1" class=" uk-width-expand uk-text-right ">
<a class=" " (click)="removeAttr(i)">Remove</a>
</div>-->
</div>
</div>
<!-- <div input [formInput]="attrForm.get('value')" [placeholder]="attrForm.get"></div>
<div input [formInput]="attrForm.get('name')" placeholder="Name"></div>
<div input [formInput]="attrForm.get('type')" placeholder="Type" [options]="attrTypeOptions" type="select" (valueChange)="attributeTypeChanged(attrForm)"></div>
-->
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'text'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="text" ></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'URL'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="URL" [validators]="urlValidator"></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'boolean'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="select"
[options]="[{label: 'yes', value:true}, {label: 'no', value:false}]"></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'HTML'" class="uk-width-1-1">
<label>
{{selectedTemplate.attributes[attrForm.get('key').value].name}}:
</label>
<ckeditor [readonly]="false"
debounce="500"
[formControl]="attrForm.get('value')"
[config]="{ extraAllowedContent: '* [uk-*](*) ; span', disallowedContent: 'script; *[on*]',
<form *ngIf="!selectTemplateView" [formGroup]="templateForm" class="uk-grid" uk-grid>
<ng-container *ngIf="selectedTemplate || selectedPlugin">
<div class="uk-text-large ">{{selectedTemplate.name}}</div>
<div class="uk-text-meta uk-width-1-1">{{selectedTemplate.description}}</div>
<div input [formInput]="templateForm.get('placement')" placeholder="Placements" [options]="placementsOptions" type="select" class="uk-width-1-2"></div>
<div class="uk-heading-divider uk-text-small uk-width-1-1 uk-margin-bottom uk-text-meta">
<div class="uk-grid">
<div>Plugin Fields</div>
</div>
</div>
<div *ngFor="let attrForm of attrFormArray.controls; let i=index" class="uk-width-1-1 uk-grid uk-child-width-1-2 uk-margin-top" uk-grid>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'text'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="text" ></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'URL'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="URL" [validators]="urlValidator"></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'boolean'" input [formInput]="attrForm.get('value')" [placeholder]="selectedTemplate.attributes[attrForm.get('key').value].name" type="select"
[options]="[{label: 'yes', value:true}, {label: 'no', value:false}]"></div>
<div *ngIf="this.selectedTemplate.attributes[attrForm.get('key').value].type == 'HTML'" class="uk-width-1-1">
<label>
{{selectedTemplate.attributes[attrForm.get('key').value].name}}:
</label>
<ckeditor [readonly]="false"
debounce="500"
[formControl]="attrForm.get('value')"
[config]="{ extraAllowedContent: '* [uk-*](*) ; span', disallowedContent: 'script; *[on*]',
removeButtons: 'Save,NewPage,DocProps,Preview,Print,' +
'Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,' +
'CreateDiv,Flash,PageBreak,' +
'Subscript,Superscript,Anchor,Smiley,Iframe,Styles,Font,About,Language',
extraPlugins: 'divarea'}">
</ckeditor>
</div>
</div>
</ckeditor>
</div>
</div>
</ng-container>
</form>
</ng-container>
</div>
</div>
</div>
</ng-container>
</form>
</modal-alert>
<modal-alert #deleteModal (alertOutput)="confirmedDelete()" classTitle="uk-background-primary uk-light"></modal-alert>

View File

@ -9,7 +9,7 @@ import {
ValidatorFn,
Validators
} from "@angular/forms";
import {Page} from "../../utils/entities/adminTool/page";
import {CheckPage, Page} from "../../utils/entities/adminTool/page";
import {EnvProperties} from '../../utils/properties/env-properties';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {Subscriber} from "rxjs";
@ -31,18 +31,19 @@ import {PluginTemplate} from "../../utils/entities/adminTool/pluginTemplate";
templateUrl: './plugins.component.html',
})
export class PluginsComponent implements OnInit {
@ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal;
private selectedId: string;
public checkboxes: {
plugin: Plugin;
checked: boolean;
template:PluginTemplate
template: PluginTemplate
}[] = [];
public plugins: Plugin[] = [];
public pluginTemplates: PluginTemplate[] = [];
public selectedTemplate: PluginTemplate = null;
public selectedPlugin: Plugin = null;
public editView = false;
public selectTemplateView = false;
public templateForm: UntypedFormGroup;
public pagesCtrl: UntypedFormArray;
urlValidator: ValidatorFn = StringUtils.urlValidator;
@ -55,18 +56,18 @@ export class PluginsComponent implements OnInit {
private subscriptions: any[] = [];
public allPages: Option[] = [];
public attrTypeOptions: Option[] = [
{label:"Text", value:"text"},
{label:"HTML", value:"HTML"},
{label:"Boolean", value:"boolean"},
{label:"URL", value:"URL"},
{label: "Text", value: "text"},
{label: "HTML", value: "HTML"},
{label: "Boolean", value: "boolean"},
{label: "URL", value: "URL"},
];
public placementsOptions: Option[] = [
{label:"Top", value:"top"},
{label:"Bottom", value:"bottom"},
{label:"Top Right", value:"top-right"},
{label:"Center", value:"center"},
{label:"Right", value:"right"},
{label:"Left", value:"left"},
{label: "Top", value: "top"},
{label: "Bottom", value: "bottom"},
{label: "Top Right", value: "top-right"},
{label: "Center", value: "center"},
{label: "Right", value: "right"},
{label: "Left", value: "left"},
];
selectedCommunityPid = null;
public portalUtils: PortalUtils = new PortalUtils();
@ -77,13 +78,13 @@ export class PluginsComponent implements OnInit {
public page: Page;
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
private title: Title,private _helpContentService: HelpContentService,
private title: Title, private _helpContentService: HelpContentService,
private _pluginsService: PluginsService, private _fb: UntypedFormBuilder,
private _clearCacheService: ClearCacheService) {
}
ngOnInit() {
this.title.setTitle('Administrator Dashboard | Classes');
this.title.setTitle('Administrator Dashboard | Plugins');
this.filterForm = this._fb.group({
keyword: [''],
type: ['all', Validators.required]
@ -92,9 +93,9 @@ export class PluginsComponent implements OnInit {
this.searchText = new RegExp(value, 'i');
this.applyFilters();
}));
this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
/*this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
this.applyFilters();
}));
}));*/
this.subscriptions.push(this.route.params.subscribe(params => {
console.log(params)
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
@ -114,9 +115,9 @@ export class PluginsComponent implements OnInit {
}));
}));
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
@ -126,14 +127,16 @@ export class PluginsComponent implements OnInit {
}
});
}
getTemplateByCode(code){
for(let template of this.pluginTemplates){
if(template.code == code){
getTemplateByCode(code) {
for (let template of this.pluginTemplates) {
if (template.code == code) {
return template;
}
}
return null;
}
getPage(pageId: string) {
this.showLoading = true;
this.subscriptions.push(this._helpContentService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.portal).subscribe(
@ -147,20 +150,21 @@ export class PluginsComponent implements OnInit {
},
error => this.handleError('System error retrieving page', error)));
}
getPlugins() {
this.showLoading = true;
this.subscriptions.push(this._pluginsService.getPluginTemplatesByPage( this.properties.adminToolsAPIURL,this.selectedCommunityPid, this.selectedPageId).subscribe(
this.subscriptions.push(this._pluginsService.getPluginTemplatesByPage(this.properties.adminToolsAPIURL, this.selectedCommunityPid, this.selectedPageId).subscribe(
templates => {
this.pluginTemplates = templates;
this.subscriptions.push(this._pluginsService.getPluginsByPage( this.properties.adminToolsAPIURL, this.selectedCommunityPid, this.selectedPageId).subscribe(
this.subscriptions.push(this._pluginsService.getPluginsByPage(this.properties.adminToolsAPIURL, this.selectedCommunityPid, this.selectedPageId).subscribe(
plugins => {
this.plugins = plugins;
this.checkboxes = [];
let self = this;
this.plugins.forEach(_ => {
self.checkboxes.push( {plugin: _, checked: false, template:this.getTemplateByCode(_.code)});
self.checkboxes.push({plugin: _, checked: false, template: this.getTemplateByCode(_.code)});
});
this.showLoading = false;
@ -170,40 +174,36 @@ export class PluginsComponent implements OnInit {
},
error => this.handleError('System error retrieving templates', error)));
}
// public showModal():void {
// this.modal.showModal();
// }
public toggleCheckBoxes(event) {
this.checkboxes.forEach(_ => _.checked = event.target.checked);
}
public applyCheck(flag: boolean) {
this.checkboxes.forEach(_ => _.checked = flag);
}
private deleteFromArray(id: string): void {
let i = this.plugins.findIndex(_ => _._id == id);
this.plugins.splice(i, 1);
let i = this.plugins.findIndex(_ => _._id == id);
this.plugins.splice(i, 1);
this.applyFilters();
}
public confirmDelete(id: string) {
this.selectedId = id;
this.confirmModalOpen();
}
private confirmModalOpen() {
this.deleteModal.alertTitle = "Delete Confirmation";
this.deleteModal.message = "Are you sure you want to delete the selected template(s)?";
this.deleteModal.okButtonText = "Yes";
this.deleteModal.open();
}
public confirmedDelete() {
this.showLoading = true;
this.subscriptions.push(this._pluginsService.deletePluginTemplate(this.selectedId, this.properties.adminToolsAPIURL).subscribe(
@ -218,130 +218,147 @@ export class PluginsComponent implements OnInit {
}
public edit(i: number) {
let plugin:Plugin = this.checkboxes[i].plugin;
public edit(plugin, template) {
this.editView = true;
this.selectedPlugin = plugin;
this.selectedTemplate = this.checkboxes[i].template;
this.selectedTemplate = template;
this.index = this.plugins.findIndex(value => value._id === plugin._id);
// this.formPages = <Page[]>plugin.pages;
this.pagesCtrl = this._fb.array([], Validators.required);
this.templateForm = this._fb.group({
_id: this._fb.control(plugin._id),
pid: this._fb.control(this.selectedCommunityPid),
page: this._fb.control(plugin.page),
code: this._fb.control(plugin.code, Validators.required),
placement: this._fb.control(plugin.placement),
order: this._fb.control(plugin.order),
isActive: this._fb.control(plugin.isActive),
active: this._fb.control(plugin.active),
isPriorTo: this._fb.control(plugin.isPriorTo),
values:this._fb.array([])
values: this._fb.array([])
});
if(plugin.values) {
if (plugin.values) {
for (let attrKey of Object.keys(plugin.values)) {
(this.templateForm.get("values") as FormArray).push(this._fb.group({
'key': this._fb.control(attrKey),
'value': this._fb.control(plugin.values[attrKey])}
'key': this._fb.control(attrKey),
'value': this._fb.control(plugin.values[attrKey])
}
));
}
}
this.modalOpen("Edit Plugin", "Save Changes");
}
public newPlugin(template=null) {
this.selectedPlugin = null;
this.selectedTemplate = template;
if(this.selectedTemplate) {
if (this.templateForm) {
this.templateForm.get('portalType').enable();
}
this.templateForm = this._fb.group({
_id: this._fb.control(null),
page: this._fb.control(this.selectedPageId),
code: this._fb.control(this.selectedTemplate.code, Validators.required),
placement: this._fb.control(this.selectedTemplate.placements[0]),
order: this._fb.control(""),
isActive: this._fb.control(false),
isPriorTo: this._fb.control(false),
values: this._fb.array([])
});
// if(plugin.values) {
for (let attrKey of Object.keys(this.selectedTemplate.attributes)) {
(this.templateForm.get("values") as FormArray).push(this._fb.group({
key: this._fb.control(attrKey),
value: this._fb.control(this.selectedTemplate.attributes[attrKey].value?this.selectedTemplate.attributes[attrKey].value:""),
}));
}
// }
}else {
// this.addNewAttr();
this.modalOpen("Create plugin", "Create");
public newPluginSelectTemplate() {
this.selectedPlugin = null;
this.selectedTemplate = null;
this.editView = true;
this.selectTemplateView = true;
}
public newPlugin(template) {
this.selectedTemplate = template;
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),
placement: this._fb.control(this.selectedTemplate.placements[0]),
order: this._fb.control(""),
active: this._fb.control(false),
isPriorTo: this._fb.control(false),
values: this._fb.array([])
});
for (let attrKey of Object.keys(this.selectedTemplate.attributes)) {
(this.templateForm.get("values") as FormArray).push(this._fb.group({
key: this._fb.control(attrKey),
value: this._fb.control(this.selectedTemplate.attributes[attrKey].value ? this.selectedTemplate.attributes[attrKey].value : ""),
}));
}
this.selectTemplateView = false;
}
private modalOpen(title: string, yesBtn: string) {
this.editModal.okButtonLeft = false;
this.editModal.alertTitle = title;
this.editModal.okButtonText = yesBtn;
this.editModal.open();
}
public saveConfirmed(data: any) {
public saveConfirmed() {
this.showLoading = true;
let plugin:Plugin = <Plugin>this.templateForm.getRawValue();
let plugin: Plugin = <Plugin>this.templateForm.getRawValue();
// template.pages = this.pagesCtrl.getRawValue().map(page => page._id?page._id:page);
plugin.values = new Map<string, string>();
for (let fields of this.templateForm.getRawValue().values) {
plugin.values[fields.key]= fields.value;
plugin.values[fields.key] = fields.value;
}
let update = plugin._id?true:false;
this.subscriptions.push(this._pluginsService.savePlugin(plugin, this.properties.adminToolsAPIURL).subscribe(
saved => {
this.savedSuccessfully(saved, update );
NotificationHandler.rise('Plugin <b>' + this.selectedTemplate.name + '</b> has been <b>successfully' + (update?' updated ':' created ') + '</b>');
this._clearCacheService.clearCache("Plugin id saved");
},
error => this.handleUpdateError("System error creating template", error)
));
let update = (plugin._id ) ? true : false;
console.log("update:" + update);
this.subscriptions.push(this._pluginsService.savePlugin(plugin, this.properties.adminToolsAPIURL).subscribe(
saved => {
this.savedSuccessfully(saved, update);
NotificationHandler.rise('Plugin <b>' + this.selectedTemplate.name + '</b> has been <b>successfully' + (update ? ' updated ' : ' created ') + '</b>');
this._clearCacheService.clearCache("Plugin id saved");
this.editView = false;
this.selectTemplateView = false;
this.selectedTemplate = null;
this.selectedPlugin = null;
},
error => this.handleUpdateError("System error creating template", error)
));
}
public savedSuccessfully(template: Plugin, update:boolean) {
if(update){
this.plugins[this.index] = template;
}else{
this.plugins.push(template);
public savedSuccessfully(plugin: Plugin, update: boolean) {
if (update) {
this.plugins[this.index] = plugin;
} else {
this.plugins.push(plugin);
}
this.applyFilters();
this.applyCheck(false);
this.showLoading = false;
}
public applyFilters() {
/* this.checkboxes = [];
this.plugins.filter(item => this.filterByType(item)).forEach(
item => this.checkboxes.push({plugin: item, checked: false})
);
this.checkboxes = this.checkboxes.filter(item => this.filter(item.plugin));*/
/* this.checkboxes = [];
this.plugins.filter(item => this.filterByType(item)).forEach(
item => this.checkboxes.push({plugin: item, checked: false})
);
this.checkboxes = this.checkboxes.filter(item => this.filter(item.plugin));*/
this.checkboxes = [];
this.plugins.forEach(item => {
let template = this.getTemplateByCode(item.code);
if (this.filterPlugins(item, template)) {
this.checkboxes.push({plugin: item, checked: false, template: template});
}
});
}
public filterPlugins(plugin: Plugin, template: PluginTemplate): boolean {
let values =[];
for(let key of this.getKeys(plugin.values)){
values.push(plugin.values[key]);
}
return this.searchText.toString() == '' || (plugin.code + ' ' +values.join(' ') + template.name + ' ' + template.description).match(this.searchText) != null;
}
handleUpdateError(message: string, error = null) {
if (error) {
console.log('Server responded: ' + error);
}
NotificationHandler.rise(message,'danger');
NotificationHandler.rise(message, 'danger');
this.showLoading = false;
}
handleError(message: string, error = null) {
if (error) {
console.log('Server responded: ' + error);
}
NotificationHandler.rise(message,'danger');
NotificationHandler.rise(message, 'danger');
this.showLoading = false;
}
getPages() {
this.showLoading = true;
this.subscriptions.push(this._helpContentService.getAllPages(this.properties.adminToolsAPIURL).subscribe(
@ -359,39 +376,64 @@ export class PluginsComponent implements OnInit {
));
}
get attrFormArray(){
get attrFormArray() {
return this.templateForm.get("values") as FormArray;
}
attributeTypeChanged(form){
attributeTypeChanged(form) {
let type = form.get("value").get("type");
form.get("value").setValue("");
if(type == "boolean"){
if (type == "boolean") {
form.get("value").setValue(false);
}
}
public getPagesAsString(pageIds): string {
let pages = [];
for(let id of pageIds) {
for (let id of pageIds) {
pages.push(this.allPages.filter(option => option.value._id == id).map((option => option.value.name)));
}
return pages.join(", ");
}
public getPageById(pageId) {
for(let option of this.allPages) {
if(option.value._id == pageId){
for (let option of this.allPages) {
if (option.value._id == pageId) {
return option.value;
}
}
return pageId;
}
getKeys(obj){
getKeys(obj) {
return Object.keys(obj);
}
reset() {
if (this.selectedPlugin) {
this.edit(this.selectedPlugin, this.selectedTemplate)
} else {
this.newPlugin(this.selectedTemplate)
}
}
public togglePlugin(status: boolean, id: string) {
this.subscriptions.push(this._pluginsService.togglePages(id, status, this.properties.adminToolsAPIURL).subscribe(
() => {
let i = this.checkboxes.findIndex(_ => _.plugin._id == id);
this.checkboxes[i].plugin.active = status;
this.applyCheck(false);
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)
));
}
}

View File

@ -22,12 +22,14 @@ import {IconsModule} from "../../utils/icons/icons.module";
import {LoadingModule} from "../../utils/loading/loading.module";
import {PluginsService} from "../../services/plugins.service";
import {CKEditorModule} from "ng2-ckeditor";
import {MatSlideToggleModule} from "@angular/material/slide-toggle";
@NgModule({
imports: [
CommonModule, RouterModule, FormsModule,
AlertModalModule, ReactiveFormsModule, AdminToolServiceModule, InputModule, MatAutocompleteModule, MatFormFieldModule, MatChipsModule,
MatCheckboxModule, AdminTabsModule, PageContentModule, PluginsRoutingModule, SearchInputModule, IconsModule, LoadingModule, CKEditorModule
MatCheckboxModule, AdminTabsModule, PageContentModule, PluginsRoutingModule, SearchInputModule, IconsModule, LoadingModule, CKEditorModule,
MatSlideToggleModule
],
providers:[PluginsService],
declarations: [PluginsComponent],

View File

@ -114,7 +114,7 @@
</div>
</div>
<div input [formInput]="attrForm.get('key')" placeholder="Field key"></div>
<div input [formInput]="attrForm.get('key')" placeholder="Key"></div>
<div input [formInput]="attrForm.get('name')" placeholder="Name"></div>
<div input [formInput]="attrForm.get('type')" placeholder="Type" [options]="attrTypeOptions" type="select" (valueChange)="attributeTypeChanged(attrForm)"></div>

View File

@ -338,7 +338,7 @@ export class PluginTemplatesComponent implements OnInit {
let pages = [];
for(let id of pageIds) {
pages.push(this.allPages.filter(option => option.value._id == id).map((option => option.value.name)));
pages.push(this.allPages.filter(option => option.value._id == id).map((option => option.value.name + " [" + option.value.portalType + "]")));
}
return pages.join(", ");

View File

@ -4,6 +4,7 @@ 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 {
@ -36,10 +37,17 @@ export class PluginsService {
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');
}
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);
}
togglePages(id : string,status : boolean, api:string) {
return this.http.post(api + 'plugin/status/' + id, status, CustomOptions.getAuthOptionsWithBody());
}
}

View File

@ -2,10 +2,11 @@ export class Plugin {
_id: string;
code: string;
page: string;
pid:string;
placement: string;
order: string;
isActive:boolean;
isPriorTo:boolean;
active:boolean;
priorTo:boolean;
values:Map<string,string> = new Map<string, string>();
}