improvements in manage Plugin Templates

add manage plugins per page + create plugin based on a template
This commit is contained in:
argirok 2023-09-26 17:32:27 +03:00
parent f19d9b3d87
commit 4dcb757c1b
10 changed files with 684 additions and 10 deletions

View File

@ -88,6 +88,17 @@
<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 class="uk-padding-small uk-padding-remove-horizontal">
<a class="uk-button uk-button-link uk-text-truncate"
[queryParams]="{pageId: check.page._id}"
routerLink="../plugins">
Manage plugins
<span *ngIf="pagePluginsCount[check.page._id]">({{pagePluginsCount[check.page._id]}}
)</span>
</a>
</div>
</div>
<div *ngIf="check.page.top || check.page.bottom || check.page.left || check.page.right">
<div class="uk-padding-small uk-padding-remove-horizontal">
<a class="uk-button uk-button-link uk-text-truncate"

View File

@ -20,6 +20,7 @@ import {Stakeholder} from "../../monitor/entities/stakeholder";
import {CommunityService} from "../../connect/community/community.service";
import {ClearCacheService} from "../../services/clear-cache.service";
import {NotificationHandler} from "../../utils/notification-handler";
import {PluginsService} from "../../services/plugins.service";
@Component({
selector: 'pages',
@ -68,10 +69,12 @@ export class PagesComponent implements OnInit {
private index: number;
pageHelpContentsCount = {};
pageClassContentsCount = {};
pagePluginsCount = {};
constructor(private element: ElementRef, private route: ActivatedRoute,
private title: Title,
private _router: Router, private _helpContentService: HelpContentService,
private _pluginsService: PluginsService,
private userManagementService: UserManagementService, private _fb: UntypedFormBuilder,
private communityService: CommunityService,
private stakeholderService: StakeholderService,
@ -437,5 +440,10 @@ export class PagesComponent implements OnInit {
this.pageClassContentsCount = pageClassContentsCount;
},
error => this.handleError('System error retrieving page contents', error)));
this.subscriptions.push(this._pluginsService.countPluginPerPage( this.properties.adminToolsAPIURL, community_pid).subscribe(
countPlugins => {
this.pagePluginsCount = countPlugins;
},
error => this.handleError('System error retrieving page contents', error)));
}
}

View File

@ -0,0 +1,13 @@
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
import {PluginsComponent} from "./plugins.component";
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', component: PluginsComponent}
])
]
})
export class PluginsRoutingModule { }

View File

@ -0,0 +1,191 @@
<div page-content>
<div header>
<div class="uk-section-xsmall uk-margin-top">
<div class="uk-flex-middle uk-grid" uk-grid>
<div class="uk-width-expand">
<a routerLink="../pages" 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}}</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>
<div>
<button (click)="newPlugin()" [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>
</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 plugins 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">
<ng-container *ngIf="check.template">
<h6>{{check.template.name}}</h6>
<div class="uk-margin-small-bottom">
{{check.template.description}}
</div>
</ng-container>
<ng-container *ngIf="!check.template">
<h6>{{check.plugin.code}}</h6>
<div class="uk-margin-small-bottom uk-text-warning">
Plugin is not supported anymore!
</div>
</ng-container>
<div class="uk-margin-small-bottom">
<span class="uk-text-meta">Placement: </span>{{check.plugin.placement}}
</div>
<div *ngFor="let key of getKeys(check.template.attributes)">
<div *ngIf="check.template.attributes[key]['type'] =='HTML' ">
{{check.template.attributes[key]['name']}}:
<div [innerHTML]="check.plugin.values[key]"></div>
</div>
<div *ngIf="check.template.attributes[key]['type'] =='text' ">
{{check.template.attributes[key]['name']}}:
<div >{{check.plugin.values[key]}}</div>
</div>
</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)" [class.uk-disabled]="!check.template">
<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.plugin._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">
{{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>
</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>
</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*]',
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>
</ng-container>
</form>
</modal-alert>
<modal-alert #deleteModal (alertOutput)="confirmedDelete()" classTitle="uk-background-primary uk-light"></modal-alert>

View File

@ -0,0 +1,397 @@
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 {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";
@Component({
selector: 'plugins',
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
}[] = [];
public plugins: Plugin[] = [];
public pluginTemplates: PluginTemplate[] = [];
public selectedTemplate: PluginTemplate = null;
public selectedPlugin: Plugin = null;
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"},
];
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"},
];
selectedCommunityPid = null;
public portalUtils: PortalUtils = new PortalUtils();
private index: number;
public portal: string;
public selectedPageId: string;
public community: Portal;
public page: Page;
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.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];
this.selectedCommunityPid = params.community;
this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
console.log(params)
// this.selectedCommunityPid = params['communityId'];
this.selectedPageId = params['pageId'];
if (this.portal && this.selectedPageId) {
this.getPage(this.selectedPageId);
}
if (!this.selectedPageId) {
this._router.navigate(['../pages'], {relativeTo: this.route});
}
}));
}));
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
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(
page => {
if (this.properties.adminToolsPortalType != page.portalType) {
this._router.navigate(['./pageContents']);
} else {
this.page = page;
this.getPlugins();
}
},
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(
templates => {
this.pluginTemplates = templates;
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)});
});
this.showLoading = false;
},
error => this.handleError('System error retrieving plugins', error)));
},
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);
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 plugin:Plugin = this.checkboxes[i].plugin;
this.selectedPlugin = plugin;
this.selectedTemplate = this.checkboxes[i].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),
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),
isPriorTo: this._fb.control(plugin.isPriorTo),
values:this._fb.array([])
});
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])}
));
}
}
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");
}
}
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 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;
}
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)
));
}
public savedSuccessfully(template: Plugin, update:boolean) {
if(update){
this.plugins[this.index] = template;
}else{
this.plugins.push(template);
}
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));*/
}
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)
));
}
get attrFormArray(){
return this.templateForm.get("values") 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;
}
getKeys(obj){
return Object.keys(obj);
}
}

View File

@ -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 {PluginsComponent} from './plugins.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 {PluginsRoutingModule} from "./plugins-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, PluginsRoutingModule, SearchInputModule, IconsModule, LoadingModule, CKEditorModule
],
providers:[PluginsService],
declarations: [PluginsComponent],
exports: [PluginsComponent]
})
export class PluginsModule {}

View File

@ -99,7 +99,7 @@
<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('placements')" placeholder="Placements" [options]="placementsOptions" 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>

View File

@ -55,6 +55,14 @@ export class PluginTemplatesComponent implements OnInit {
{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"},
];
selectedCommunityPid = null;
public portalUtils: PortalUtils = new PortalUtils();
private index: number;
@ -200,9 +208,9 @@ export class PluginTemplatesComponent implements OnInit {
}
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'),
name: this._fb.control('', Validators.required),
code: this._fb.control('', Validators.required),
description: this._fb.control(''),
pages: this.pagesCtrl,
portalType: this._fb.control('community', Validators.required),
placements: this._fb.array([]),

View File

@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {HelpContentService} from "./help-content.service";
import {PluginsService} from "./plugins.service";
@NgModule({
@ -8,7 +9,7 @@ import {HelpContentService} from "./help-content.service";
CommonModule,
],
declarations:[ ],
providers: [HelpContentService],
providers: [HelpContentService, PluginsService],
})

View File

@ -1,9 +1,9 @@
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";
import {Plugin} from "../utils/entities/adminTool/plugin";
import {properties} from "../../../environments/environment";
@Injectable()
export class PluginsService {
@ -16,7 +16,7 @@ export class PluginsService {
}
getAllPlugins(api:string) {
return this.http.get<Array<PluginTemplate>>(api + 'plugins')
return this.http.get<Array<Plugin>>(api + 'plugins')
}
@ -25,12 +25,21 @@ export class PluginsService {
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());
return this.http.post<Plugin>(api + 'plugin/save', JSON.stringify(plugin), CustomOptions.getAuthOptionsWithBody());
}
deletePlugin(id, api:string) {
return this.http.delete<PluginTemplate>(api + 'plugin/'+id, CustomOptions.getAuthOptionsWithBody());
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');
}
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);
}
}