plugins-functionality #43
|
@ -0,0 +1,13 @@
|
||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
import {RouterModule} from '@angular/router';
|
||||||
|
import {PluginTemplatesComponent} from "./pluginTemplates.component";
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
RouterModule.forChild([
|
||||||
|
{ path: '', component: PluginTemplatesComponent}
|
||||||
|
])
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class PluginTemplatesRoutingModule { }
|
|
@ -0,0 +1,144 @@
|
||||||
|
<div page-content>
|
||||||
|
<div header>
|
||||||
|
<admin-tabs tab="template"></admin-tabs>
|
||||||
|
<ul class="uk-subnav uk-subnav-pill uk-margin-medium-top">
|
||||||
|
<li [class.uk-active]="filterForm.get('type').value === 'all'" class="uk-margin-small-bottom"><a
|
||||||
|
(click)="filterForm.get('type').setValue('all')"><span
|
||||||
|
class="title">All portals</span></a></li>
|
||||||
|
<li *ngFor="let type of portalUtils.portalTypes; let i=index"
|
||||||
|
[class.uk-active]="filterForm.get('type').value === type.value" class="uk-margin-small-bottom"><a
|
||||||
|
(click)="filterForm.get('type').setValue(type.value)"><span
|
||||||
|
class="title">{{type.label}}</span></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div actions>
|
||||||
|
<div class="uk-section-xsmall">
|
||||||
|
<div class="uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle uk-grid" uk-grid>
|
||||||
|
<div search-input [disabled]="showLoading" [expandable]="true" [searchControl]="filterForm.get('keyword')" searchInputClass="outer" placeholder="Search class" class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1"></div>
|
||||||
|
<div>
|
||||||
|
<button class="uk-button uk-button-default uk-flex uk-flex-middle" (click)="newPlugin()"
|
||||||
|
[disabled]="showLoading" [class.uk-disabled]="showLoading">
|
||||||
|
<icon name="add" [flex]="true"></icon>
|
||||||
|
<span class="uk-margin-small-left uk-text-bold uk-text-uppercase">Add plugin template</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</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">
|
||||||
|
<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 templates found</div>
|
||||||
|
</div>
|
||||||
|
<div *ngIf="checkboxes.length > 0" class="uk-grid uk-child-width-1-1" uk-height-match=".uk-card-body" uk-grid>
|
||||||
|
<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">
|
||||||
|
<h6>{{check.template.name}}</h6>
|
||||||
|
<div *ngIf="check.template.pages && check.template.pages.length > 0" class="uk-margin-small-bottom">
|
||||||
|
<span class="uk-text-meta">Pages: </span>{{getPagesAsString(check.template.pages)}}
|
||||||
|
</div>
|
||||||
|
<div class="uk-margin-small-bottom">
|
||||||
|
<span class="uk-text-meta">Placements: </span>{{check.template.placements.join(", ")}}
|
||||||
|
</div>
|
||||||
|
<div class="uk-margin-small-bottom">
|
||||||
|
<span class="uk-text-meta">Portal type: </span>{{check.template.portalType}}
|
||||||
|
</div>
|
||||||
|
<div class="uk-margin-small-bottom">
|
||||||
|
{{check.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)="edit(i)">
|
||||||
|
<icon name="edit" [flex]="true"></icon>
|
||||||
|
<span class="uk-margin-xsmall-left"> Edit</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="uk-padding-small uk-padding-remove-horizontal">
|
||||||
|
<button class="uk-button uk-button-link uk-flex uk-flex-middle"
|
||||||
|
(click)="confirmDelete(check.template._id)">
|
||||||
|
<icon name="delete" [flex]="true"></icon>
|
||||||
|
<span class="uk-margin-xsmall-left"> Delete</span>
|
||||||
|
</button>
|
||||||
|
</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">
|
||||||
|
<form *ngIf="templateForm" [formGroup]="templateForm" class="uk-grid uk-child-width-1-2" uk-grid>
|
||||||
|
<div input [formInput]="templateForm.get('name')" placeholder="Template Name"></div>
|
||||||
|
<div input [formInput]="templateForm.get('code')" placeholder="Template Code"></div>
|
||||||
|
<div class="uk-width-1-1" input [formInput]="templateForm.get('description')" placeholder="Description" type="textarea"> </div>
|
||||||
|
<div input [formInput]="templateForm.get('image')" placeholder="Image"></div>
|
||||||
|
<div input [formInput]="templateForm.get('portalType')" placeholder="Portal Type" [options]="portalUtils.portalTypes" type="select"></div>
|
||||||
|
<div input [formInput]="templateForm.get('placements')" placeholder="Placements" type="chips"></div>
|
||||||
|
<div input [formInput]="templateForm.get('pages')" placeholder="Pages" [options]="allPages" type="chips"></div>
|
||||||
|
|
||||||
|
<div *ngFor="let attrForm of attrFormArray.controls; let i=index" class="uk-width-1-1 uk-grid uk-child-width-1-2" 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('key')" placeholder="Field 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>
|
||||||
|
|
||||||
|
<div *ngIf="attrForm.get('type').value == 'text'" input [formInput]="attrForm.get('value')" placeholder="Default value" [type]="attrForm.get('type').value" ></div>
|
||||||
|
<div *ngIf="attrForm.get('type').value == 'URL'" input [formInput]="attrForm.get('value')" placeholder="Default value" [type]="attrForm.get('type').value" [validators]="urlValidator"></div>
|
||||||
|
<div *ngIf="attrForm.get('type').value == 'boolean'" input [formInput]="attrForm.get('value')" placeholder="Default value" type="select"
|
||||||
|
[options]="[{label: 'yes', value:true}, {label: 'no', value:false}]"></div>
|
||||||
|
<div *ngIf="attrForm.get('type').value == 'HTML'" class="uk-width-1-1">
|
||||||
|
<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>
|
||||||
|
<hr class="uk-width-1-1">
|
||||||
|
<div class="uk-width-1-1 uk-text-center ">
|
||||||
|
<a (click)="addNewAttr()">Add more fields</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</modal-alert>
|
||||||
|
<modal-alert #deleteModal (alertOutput)="confirmedDelete()" classTitle="uk-background-primary uk-light"></modal-alert>
|
|
@ -0,0 +1,347 @@
|
||||||
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||||
|
import {ActivatedRoute, Router} from "@angular/router";
|
||||||
|
import {HelpContentService} from "../../../services/help-content.service";
|
||||||
|
import {
|
||||||
|
FormArray,
|
||||||
|
UntypedFormArray,
|
||||||
|
UntypedFormBuilder,
|
||||||
|
UntypedFormGroup,
|
||||||
|
ValidatorFn,
|
||||||
|
Validators
|
||||||
|
} from "@angular/forms";
|
||||||
|
import {Page} from "../../../utils/entities/adminTool/page";
|
||||||
|
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 {AlertModal} from "../../../utils/modal/alert";
|
||||||
|
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 {PluginTemplate} from "../../../utils/entities/adminTool/pluginTemplate";
|
||||||
|
import {Entity} from "../../../utils/entities/adminTool/entity";
|
||||||
|
import {StringUtils} from "../../../utils/string-utils.class";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'plugin-templates',
|
||||||
|
templateUrl: './pluginTemplates.component.html',
|
||||||
|
})
|
||||||
|
export class PluginTemplatesComponent implements OnInit {
|
||||||
|
@ViewChild('editModal') editModal: AlertModal;
|
||||||
|
@ViewChild('deleteModal') deleteModal: AlertModal;
|
||||||
|
private selectedId: string;
|
||||||
|
public checkboxes: {
|
||||||
|
template: PluginTemplate;
|
||||||
|
checked: boolean;
|
||||||
|
}[] = [];
|
||||||
|
public templates: PluginTemplate[] = [];
|
||||||
|
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;
|
||||||
|
public filterForm: UntypedFormGroup;
|
||||||
|
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"},
|
||||||
|
];
|
||||||
|
selectedCommunityPid = null;
|
||||||
|
public portalUtils: PortalUtils = new PortalUtils();
|
||||||
|
private index: number;
|
||||||
|
|
||||||
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
|
||||||
|
private title: Title,private _helpContentService: HelpContentService,
|
||||||
|
private _pluginsService: PluginsService, private _fb: UntypedFormBuilder,
|
||||||
|
private _clearCacheService: ClearCacheService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.title.setTitle('Administrator Dashboard | Classes');
|
||||||
|
this.filterForm = this._fb.group({
|
||||||
|
keyword: [''],
|
||||||
|
type: ['all', Validators.required]
|
||||||
|
});
|
||||||
|
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
|
||||||
|
this.searchText = new RegExp(value, 'i');
|
||||||
|
this.applyFilters();
|
||||||
|
}));
|
||||||
|
this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
|
||||||
|
this.applyFilters();
|
||||||
|
}));
|
||||||
|
this.getTemplates();
|
||||||
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||||
|
HelperFunctions.scroll();
|
||||||
|
this.selectedCommunityPid = params['communityId'];
|
||||||
|
this.getPages();
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subscriptions.forEach(value => {
|
||||||
|
if (value instanceof Subscriber) {
|
||||||
|
value.unsubscribe();
|
||||||
|
} else if (value instanceof Function) {
|
||||||
|
value();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getTemplates() {
|
||||||
|
this.showLoading = true;
|
||||||
|
this.subscriptions.push(this._pluginsService.getAllPluginTemplates(this.properties.adminToolsAPIURL).subscribe(
|
||||||
|
templates => {
|
||||||
|
this.templates = templates;
|
||||||
|
this.checkboxes = [];
|
||||||
|
|
||||||
|
let self = this;
|
||||||
|
templates.forEach(_ => {
|
||||||
|
self.checkboxes.push( {template: _, checked: false});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.showLoading = false;
|
||||||
|
},
|
||||||
|
error => this.handleError('System error retrieving classes', 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.templates.findIndex(_ => _._id == id);
|
||||||
|
this.templates.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(
|
||||||
|
_ => {
|
||||||
|
this.deleteFromArray(this.selectedId);
|
||||||
|
NotificationHandler.rise('Template have been <b>successfully deleted</b>');
|
||||||
|
this.showLoading = false;
|
||||||
|
this._clearCacheService.clearCache("Template id deleted");
|
||||||
|
},
|
||||||
|
error => this.handleUpdateError('System error deleting the selected Template', error)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public edit(i: number) {
|
||||||
|
let pluginTemplate: PluginTemplate = this.checkboxes[i].template;
|
||||||
|
this.index = this.templates.findIndex(value => value._id === pluginTemplate._id);
|
||||||
|
// this.formPages = <Page[]>pluginTemplate.pages;
|
||||||
|
this.pagesCtrl = this._fb.array([], Validators.required);
|
||||||
|
this.templateForm = this._fb.group({
|
||||||
|
_id: this._fb.control(pluginTemplate._id),
|
||||||
|
name: this._fb.control(pluginTemplate.name, Validators.required),
|
||||||
|
pages: this.pagesCtrl,
|
||||||
|
portalType: this._fb.control(pluginTemplate.portalType, Validators.required),
|
||||||
|
|
||||||
|
code: this._fb.control(pluginTemplate.code, Validators.required),
|
||||||
|
description: this._fb.control(pluginTemplate.description),
|
||||||
|
placements: this._fb.array(pluginTemplate.placements),
|
||||||
|
attributes:this._fb.array([])
|
||||||
|
});
|
||||||
|
this.templateForm.get('portalType').disable();
|
||||||
|
for (let i = 0; i < pluginTemplate.pages.length; i++) {
|
||||||
|
this.pagesCtrl.push(this._fb.control(this.getPageById(pluginTemplate.pages[i])));
|
||||||
|
}
|
||||||
|
if(pluginTemplate.attributes) {
|
||||||
|
for (let attrKey of Object.keys(pluginTemplate.attributes)) {
|
||||||
|
(this.templateForm.get("attributes") as FormArray).push(this._fb.group({
|
||||||
|
key: this._fb.control(attrKey, Validators.required),
|
||||||
|
name: this._fb.control(pluginTemplate.attributes[attrKey].name, Validators.required),
|
||||||
|
type: this._fb.control(pluginTemplate.attributes[attrKey].type, Validators.required),
|
||||||
|
value: this._fb.control(pluginTemplate.attributes[attrKey].value)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.modalOpen("Edit Template", "Save Changes");
|
||||||
|
}
|
||||||
|
|
||||||
|
public newPlugin() {
|
||||||
|
this.pagesCtrl = this._fb.array([], Validators.required);
|
||||||
|
if (this.templateForm) {
|
||||||
|
this.templateForm.get('portalType').enable();
|
||||||
|
}
|
||||||
|
this.templateForm = this._fb.group({
|
||||||
|
_id: this._fb.control(null),
|
||||||
|
name: this._fb.control('aa', Validators.required),
|
||||||
|
code: this._fb.control('aa', Validators.required),
|
||||||
|
description: this._fb.control('aa'),
|
||||||
|
pages: this.pagesCtrl,
|
||||||
|
portalType: this._fb.control('community', Validators.required),
|
||||||
|
placements: this._fb.array([]),
|
||||||
|
attributes:this._fb.array([])
|
||||||
|
});
|
||||||
|
this.addNewAttr();
|
||||||
|
this.modalOpen("Create template", "Create");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
this.showLoading = true;
|
||||||
|
let template:PluginTemplate = <PluginTemplate>this.templateForm.getRawValue();
|
||||||
|
template.pages = this.pagesCtrl.getRawValue().map(page => page._id?page._id:page);
|
||||||
|
template.attributes = new Map<string, {name: string; type: string; value: string}>();
|
||||||
|
for (let attr of this.templateForm.getRawValue().attributes) {
|
||||||
|
template.attributes[attr.key]={name: attr.name, type: attr.type, value: attr.value};
|
||||||
|
}
|
||||||
|
let update = template._id?true:false;
|
||||||
|
this.subscriptions.push(this._pluginsService.savePluginTemplate(template, this.properties.adminToolsAPIURL).subscribe(
|
||||||
|
saved => {
|
||||||
|
this.savedSuccessfully(saved, update );
|
||||||
|
NotificationHandler.rise('Template <b>' + saved.name + '</b> has been <b>successfully' + (update?' updated ':' created ') + '</b>');
|
||||||
|
this._clearCacheService.clearCache("Template id saved");
|
||||||
|
},
|
||||||
|
error => this.handleUpdateError("System error creating template", error)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public savedSuccessfully(template: PluginTemplate, update:boolean) {
|
||||||
|
if(update){
|
||||||
|
this.templates[this.index] = template;
|
||||||
|
}else{
|
||||||
|
this.templates.push(template);
|
||||||
|
}
|
||||||
|
this.applyFilters();
|
||||||
|
this.applyCheck(false);
|
||||||
|
this.showLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public applyFilters() {
|
||||||
|
this.checkboxes = [];
|
||||||
|
this.templates.filter(item => this.filterByType(item)).forEach(
|
||||||
|
item => this.checkboxes.push({template: item, checked: false})
|
||||||
|
);
|
||||||
|
this.checkboxes = this.checkboxes.filter(item => this.filter(item.template));
|
||||||
|
}
|
||||||
|
|
||||||
|
public filterByType(template: PluginTemplate): boolean {
|
||||||
|
let type = this.filterForm.get("type").value;
|
||||||
|
return type == "all" || (type == template.portalType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public filter(plugin: PluginTemplate): boolean {
|
||||||
|
return this.searchText.toString() == '' || (plugin.name + ' ' + plugin.portalType).match(this.searchText) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdateError(message: string, error = null) {
|
||||||
|
if (error) {
|
||||||
|
console.log('Server responded: ' + error);
|
||||||
|
}
|
||||||
|
NotificationHandler.rise(message,'danger');
|
||||||
|
this.showLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleError(message: string, error = null) {
|
||||||
|
if (error) {
|
||||||
|
console.log('Server responded: ' + error);
|
||||||
|
}
|
||||||
|
NotificationHandler.rise(message,'danger');
|
||||||
|
this.showLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
addNewAttr(){
|
||||||
|
(this.templateForm.get("attributes") as FormArray).push(this._fb.group({
|
||||||
|
key:this._fb.control("", Validators.required),
|
||||||
|
name: this._fb.control("", Validators.required),
|
||||||
|
type: this._fb.control("text", Validators.required),
|
||||||
|
value: this._fb.control("")
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
removeAttr(index){
|
||||||
|
this.attrFormArray.removeAt(index);
|
||||||
|
this.attrFormArray.markAsDirty();
|
||||||
|
}
|
||||||
|
get attrFormArray(){
|
||||||
|
|
||||||
|
return this.templateForm.get("attributes") as FormArray;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeTypeChanged(form){
|
||||||
|
let type = form.get("value").get("type");
|
||||||
|
form.get("value").setValue("");
|
||||||
|
if(type == "boolean"){
|
||||||
|
form.get("value").setValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public getPagesAsString(pageIds): string {
|
||||||
|
|
||||||
|
let pages = [];
|
||||||
|
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){
|
||||||
|
return option.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
import {RouterModule} from '@angular/router';
|
||||||
|
import {CommonModule} from '@angular/common';
|
||||||
|
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||||
|
import {AlertModalModule} from '../../../utils/modal/alertModal.module';
|
||||||
|
import {PluginTemplatesComponent} from './pluginTemplates.component';
|
||||||
|
import {AdminToolServiceModule} from "../../../services/adminToolService.module";
|
||||||
|
import {InputModule} from "../../../sharedComponents/input/input.module";
|
||||||
|
|
||||||
|
|
||||||
|
import {MatAutocompleteModule} from '@angular/material/autocomplete';
|
||||||
|
import { MatCheckboxModule } from "@angular/material/checkbox";
|
||||||
|
import { MatFormFieldModule } from "@angular/material/form-field";
|
||||||
|
|
||||||
|
|
||||||
|
import {MatChipsModule} from '@angular/material/chips';
|
||||||
|
import {AdminTabsModule} from "../../sharedComponents/admin-tabs/admin-tabs.module";
|
||||||
|
import {PageContentModule} from "../../sharedComponents/page-content/page-content.module";
|
||||||
|
import {PluginTemplatesRoutingModule} from "./pluginTemplates-routing.module";
|
||||||
|
import {SearchInputModule} from "../../../sharedComponents/search-input/search-input.module";
|
||||||
|
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";
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule, RouterModule, FormsModule,
|
||||||
|
AlertModalModule, ReactiveFormsModule, AdminToolServiceModule, InputModule, MatAutocompleteModule, MatFormFieldModule, MatChipsModule,
|
||||||
|
MatCheckboxModule, AdminTabsModule, PageContentModule, PluginTemplatesRoutingModule, SearchInputModule, IconsModule, LoadingModule, CKEditorModule
|
||||||
|
],
|
||||||
|
providers:[PluginsService],
|
||||||
|
declarations: [PluginTemplatesComponent],
|
||||||
|
exports: [PluginTemplatesComponent]
|
||||||
|
})
|
||||||
|
export class PluginTemplatesModule {}
|
|
@ -13,6 +13,7 @@ import {ActivatedRoute} from "@angular/router";
|
||||||
<li [class.uk-active]="tab === 'entity'"><a routerLink="../entities">Entities</a></li>
|
<li [class.uk-active]="tab === 'entity'"><a routerLink="../entities">Entities</a></li>
|
||||||
<li *ngIf="portal && type === 'community'" [class.uk-active]="tab === 'menu'"><a routerLink="../menu">Menus</a></li>
|
<li *ngIf="portal && type === 'community'" [class.uk-active]="tab === 'menu'"><a routerLink="../menu">Menus</a></li>
|
||||||
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../classes">Classes</a></li>
|
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../classes">Classes</a></li>
|
||||||
|
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'template'"><a routerLink="../templates">Templates</a></li>
|
||||||
<li *ngIf="isPortalAdmin && portal=='connect'" [class.uk-active]="tab === 'customization'"><a routerLink="../customization">Customization</a></li>
|
<li *ngIf="isPortalAdmin && portal=='connect'" [class.uk-active]="tab === 'customization'"><a routerLink="../customization">Customization</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
|
@ -25,7 +26,7 @@ export class AdminTabsComponent implements OnInit {
|
||||||
@Input()
|
@Input()
|
||||||
public user: User;
|
public user: User;
|
||||||
@Input()
|
@Input()
|
||||||
public tab: "portal" | "page" | "entity" | "menu" | "class" | "customization" = 'page';
|
public tab: "portal" | "page" | "entity" | "menu" | "class" | "customization" | "template" = 'page';
|
||||||
private subscriptions: any[] = [];
|
private subscriptions: any[] = [];
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private userManagementService: UserManagementService) {
|
constructor(private route: ActivatedRoute, private userManagementService: UserManagementService) {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {DivId} from "../utils/entities/adminTool/divId";
|
||||||
|
import {catchError} from "rxjs/operators";
|
||||||
|
import {CustomOptions} from "./servicesUtils/customOptions.class";
|
||||||
|
import {PluginTemplate} from "../utils/entities/adminTool/pluginTemplate";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PluginsService {
|
||||||
|
|
||||||
|
constructor(private http:HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllPluginTemplates(api:string) {
|
||||||
|
return this.http.get<Array<PluginTemplate>>(api + 'pluginTemplates')
|
||||||
|
|
||||||
|
}
|
||||||
|
getAllPlugins(api:string) {
|
||||||
|
return this.http.get<Array<PluginTemplate>>(api + 'plugins')
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
savePluginTemplate(pluginTemplate:PluginTemplate, api:string) {
|
||||||
|
// console.log(pluginTemplate, pluginTemplate.toJsonObj())
|
||||||
|
return this.http.post<PluginTemplate>(api + 'pluginTemplate/save', pluginTemplate, CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
savePlugin(plugin, api:string) {
|
||||||
|
return this.http.post<PluginTemplate>(api + 'plugin/save', JSON.stringify(plugin), CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
deletePlugin(id, api:string) {
|
||||||
|
return this.http.delete<PluginTemplate>(api + 'plugin/'+id, CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
deletePluginTemplate(id, api:string) {
|
||||||
|
return this.http.delete<PluginTemplate>(api + 'pluginTemplate/'+id, CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
export class Plugin {
|
||||||
|
_id: string;
|
||||||
|
code: string;
|
||||||
|
page: string;
|
||||||
|
placement: string;
|
||||||
|
order: string;
|
||||||
|
isActive:boolean;
|
||||||
|
isPriorTo:boolean;
|
||||||
|
values:Map<string,string> = new Map<string, string>();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
|
||||||
|
export class PluginTemplate /*extends Map*/ {
|
||||||
|
_id: string;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
description: string;
|
||||||
|
image: string;
|
||||||
|
pages: string[];
|
||||||
|
placements: string[];
|
||||||
|
portalType: string;
|
||||||
|
attributes: {};//Map<string,{name:string, type:string, value:string}> = new Map<string, {name: string; type: string; value: string}>();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
toJsonObj(){
|
||||||
|
let jsonObj = Object.assign({}, this);
|
||||||
|
var objectMap = { };
|
||||||
|
for (let [key, value] of jsonObj['attributes']) objectMap[key] = value;
|
||||||
|
jsonObj['attributes'] = objectMap;
|
||||||
|
return jsonObj;
|
||||||
|
}
|
||||||
|
*//*
|
||||||
|
toJSON() {
|
||||||
|
// this.attributes
|
||||||
|
var object = { };
|
||||||
|
for (let [key, value] of this.attributes) object[key] = value;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue