2019-12-20 12:38:13 +01:00
|
|
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {HelpContentService} from '../../services/help-content.service';
|
2021-02-01 20:17:55 +01:00
|
|
|
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
|
2019-12-20 12:38:13 +01:00
|
|
|
import {CheckPage, Page} from '../../utils/entities/adminTool/page';
|
2021-02-01 20:17:55 +01:00
|
|
|
import {Entity} from '../../utils/entities/adminTool/entity';
|
2019-12-20 12:38:13 +01:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
|
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
|
|
|
import {UserManagementService} from '../../services/user-management.service';
|
2021-07-14 13:19:57 +02:00
|
|
|
import {Subscriber} from 'rxjs';
|
|
|
|
import {PortalUtils} from '../portal/portalHelper';
|
|
|
|
import {properties} from '../../../../environments/environment';
|
|
|
|
import {Option} from '../../sharedComponents/input/input.component';
|
|
|
|
import {AlertModal} from '../../utils/modal/alert';
|
|
|
|
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
|
|
|
|
import {Title} from '@angular/platform-browser';
|
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
2022-03-22 16:47:38 +01:00
|
|
|
import {StakeholderService} from '../../monitor/services/stakeholder.service';
|
2019-12-20 12:38:13 +01:00
|
|
|
|
2021-02-01 20:17:55 +01:00
|
|
|
declare var UIkit;
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'pages',
|
2022-03-22 16:47:38 +01:00
|
|
|
templateUrl: './pages.component.html'
|
2019-12-20 12:38:13 +01:00
|
|
|
})
|
|
|
|
export class PagesComponent implements OnInit {
|
2021-01-28 17:33:16 +01:00
|
|
|
|
|
|
|
@ViewChild('editModal') editModal: AlertModal;
|
|
|
|
@ViewChild('deleteModal') deleteModal: AlertModal;
|
2019-12-20 12:38:13 +01:00
|
|
|
private selectedPages: string[] = [];
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public checkboxes: CheckPage[] = [];
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public pages: Page[] = [];
|
|
|
|
public pageWithDivIds: string[] = [];
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
//public errorMessage: string;
|
2021-01-28 17:33:16 +01:00
|
|
|
|
|
|
|
public pageForm: FormGroup;
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
private searchText: RegExp = new RegExp('');
|
|
|
|
public keyword: string = '';
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-01-26 18:00:40 +01:00
|
|
|
public portal: string;
|
2022-03-22 16:47:38 +01:00
|
|
|
public name: string;
|
2022-03-24 13:56:55 +01:00
|
|
|
public logo: string;
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public pagesType: string;
|
2021-01-28 17:33:16 +01:00
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public showLoading: boolean = true;
|
|
|
|
public isPortalAdministrator = null;
|
2021-01-11 10:21:42 +01:00
|
|
|
public filterForm: FormGroup;
|
2021-01-28 17:33:16 +01:00
|
|
|
public typeOptions = [{label: 'Search', value: 'search'}, {
|
2019-12-20 12:38:13 +01:00
|
|
|
label: 'Share',
|
|
|
|
value: 'share'
|
|
|
|
}, {label: 'Landing', value: 'landing'}, {label: 'HTML', value: 'html'}, {
|
|
|
|
label: 'Link',
|
|
|
|
value: 'link'
|
2021-01-11 10:21:42 +01:00
|
|
|
}, {label: 'Other', value: 'other'}];
|
2019-12-20 12:38:13 +01:00
|
|
|
public entitiesCtrl: FormArray;
|
2021-01-28 17:33:16 +01:00
|
|
|
allEntities: Option[] = [];
|
2019-12-20 12:38:13 +01:00
|
|
|
private subscriptions: any[] = [];
|
2021-01-28 17:33:16 +01:00
|
|
|
public portalUtils: PortalUtils = new PortalUtils();
|
|
|
|
private index: number;
|
2021-03-31 13:23:24 +02:00
|
|
|
pageHelpContentsCount = {};
|
|
|
|
pageClassContentsCount = {};
|
2022-03-22 16:47:38 +01:00
|
|
|
public stickyPageHeader: boolean = false;
|
2021-03-19 17:51:02 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute,
|
2021-03-19 17:51:02 +01:00
|
|
|
private title: Title,
|
2019-12-20 12:38:13 +01:00
|
|
|
private _router: Router, private _helpContentService: HelpContentService,
|
2022-03-22 16:47:38 +01:00
|
|
|
private userManagementService: UserManagementService, private _fb: FormBuilder,
|
|
|
|
private stakeholderService: StakeholderService) {
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
ngOnInit() {
|
2021-01-28 17:33:16 +01:00
|
|
|
this.filterForm = this._fb.group({
|
2021-01-11 10:21:42 +01:00
|
|
|
keyword: [''],
|
2021-01-28 17:33:16 +01:00
|
|
|
type: ['all', Validators.required]
|
|
|
|
});
|
2021-01-11 10:21:42 +01:00
|
|
|
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
|
2021-01-29 11:47:37 +01:00
|
|
|
this.searchText = new RegExp(value, 'i');
|
|
|
|
this.applyFilters();
|
2019-12-20 12:38:13 +01:00
|
|
|
}));
|
2021-01-11 10:21:42 +01:00
|
|
|
this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => {
|
2021-01-29 11:47:37 +01:00
|
|
|
this.applyFilters();
|
2021-01-11 10:21:42 +01:00
|
|
|
}));
|
2020-12-18 16:09:38 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
this.pagesType = '';
|
|
|
|
if (params['type']) {
|
2021-01-11 10:21:42 +01:00
|
|
|
// this.pagesType = params['type'];
|
|
|
|
this.filterForm.get('type').setValue(params['type']);
|
2020-12-18 16:09:38 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
|
2021-03-19 17:51:02 +01:00
|
|
|
if (this.route.snapshot.data.portal) {
|
|
|
|
this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Pages');
|
|
|
|
} else if (this.route.snapshot.params[this.route.snapshot.data.param]) {
|
2022-03-22 16:47:38 +01:00
|
|
|
if(this.route.snapshot.data.param === 'stakeholder') {
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
if(stakeholder) {
|
|
|
|
this.name = stakeholder.name;
|
2022-03-24 13:56:55 +01:00
|
|
|
this.logo = stakeholder.logoUrl;
|
2022-03-22 16:47:38 +01:00
|
|
|
this.title.setTitle(stakeholder.name + ' | Pages');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
// TODO: for portals as well
|
|
|
|
this.title.setTitle(this.portal.toUpperCase() + ' | Pages');
|
|
|
|
}
|
2021-03-19 17:51:02 +01:00
|
|
|
} else {
|
|
|
|
this.title.setTitle('Administrator Dashboard | Pages');
|
|
|
|
}
|
2020-12-18 16:09:38 +01:00
|
|
|
this.keyword = '';
|
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
2021-01-26 18:00:40 +01:00
|
|
|
this.applyPortalFilter(this.portal);
|
|
|
|
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal;
|
2020-12-18 16:09:38 +01:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
entities => {
|
2021-01-28 17:33:16 +01:00
|
|
|
this.allEntities = [];
|
|
|
|
entities.forEach(entity => {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.allEntities.push({
|
|
|
|
label: entity.name,
|
|
|
|
value: entity
|
|
|
|
});
|
2021-01-28 17:33:16 +01:00
|
|
|
});
|
2020-12-18 16:09:38 +01:00
|
|
|
},
|
2021-01-11 10:21:42 +01:00
|
|
|
error => this.handleError('System error retrieving pages', error)));
|
2021-03-19 17:51:02 +01:00
|
|
|
if (this.portal) {
|
2021-03-31 13:23:24 +02:00
|
|
|
this.getPageHelpContentsCounts(this.portal);
|
2021-03-01 18:27:45 +01:00
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-01-26 18:00:40 +01:00
|
|
|
getPages(portal: string) {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.showLoading = true;
|
|
|
|
this.pageWithDivIds = [];
|
|
|
|
let parameters = '';
|
|
|
|
if (this.pagesType) {
|
|
|
|
parameters = '?page_type=' + this.pagesType;
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-19 17:51:02 +01:00
|
|
|
if (portal) {
|
|
|
|
this.subscriptions.push(this._helpContentService.getCommunityPagesByType(portal, parameters, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
pages => {
|
|
|
|
this.pagesReturned(pages);
|
|
|
|
//if(!this.pagesType || this.pagesType == "link") {
|
|
|
|
this.getPagesWithDivIds(portal);
|
|
|
|
//} else {
|
|
|
|
//this.showLoading = false;
|
|
|
|
//}
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving pages', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.subscriptions.push(this._helpContentService.getAllPagesFull(this.properties.adminToolsAPIURL).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
pages => {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.pagesReturned(pages);
|
2019-12-20 12:38:13 +01:00
|
|
|
this.showLoading = false;
|
|
|
|
},
|
2021-03-19 17:51:02 +01:00
|
|
|
error => this.handleError('System error retrieving pages', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-03-19 17:51:02 +01:00
|
|
|
getPagesWithDivIds(portal: string) {
|
|
|
|
this.subscriptions.push(this._helpContentService.getPageIdsFromDivIds(portal, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
pages => {
|
|
|
|
this.pageWithDivIds = pages;
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving information about pages\' classes', error)));
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
pagesReturned(pages: Page[]) {
|
|
|
|
this.pages = pages;
|
|
|
|
this.checkboxes = [];
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
if (pages) {
|
|
|
|
pages.forEach(_ => {
|
|
|
|
this.checkboxes.push(<CheckPage>{page: _, checked: false});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public toggleCheckBoxes(event) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = event.target.checked);
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public applyCheck(flag: boolean) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = flag);
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public getSelectedPages(): string[] {
|
|
|
|
return this.checkboxes.filter(page => page.checked == true).map(checkedPage => checkedPage.page).map(res => res._id);
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
private deletePagesFromArray(ids: string[]): void {
|
|
|
|
for (let id of ids) {
|
2021-01-28 17:33:16 +01:00
|
|
|
let i = this.pages.findIndex(_ => _._id == id);
|
|
|
|
this.pages.splice(i, 1);
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-29 11:47:37 +01:00
|
|
|
this.applyFilters();
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmDeletePage(id: string) {
|
|
|
|
this.selectedPages = [id];
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmDeleteSelectedPages() {
|
|
|
|
this.selectedPages = this.getSelectedPages();
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
private confirmModalOpen() {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.deleteModal.cancelButton = true;
|
|
|
|
this.deleteModal.okButton = true;
|
|
|
|
this.deleteModal.alertTitle = 'Delete Confirmation';
|
|
|
|
this.deleteModal.message = 'Are you sure you want to delete the selected page(s)?';
|
|
|
|
this.deleteModal.okButtonText = 'Yes';
|
|
|
|
this.deleteModal.open();
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmedDeletePages(data: any) {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpContentService.deletePages(this.selectedPages, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
_ => {
|
|
|
|
this.deletePagesFromArray(this.selectedPages);
|
|
|
|
UIkit.notification('Pages have been <b>successfully deleted</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error deleting the selected pages', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public editPage(i: number) {
|
|
|
|
this.entitiesCtrl = this._fb.array([]);
|
|
|
|
let page: Page = this.checkboxes[i].page;
|
2021-01-28 17:33:16 +01:00
|
|
|
this.index = this.pages.findIndex(value => value._id === page._id);
|
|
|
|
this.pageForm = this._fb.group({
|
|
|
|
_id: this._fb.control(page._id),
|
2022-01-14 14:55:24 +01:00
|
|
|
route: this._fb.control(page.route, Validators.required),
|
2021-01-28 17:33:16 +01:00
|
|
|
name: this._fb.control(page.name, Validators.required),
|
|
|
|
isEnabled: this._fb.control(page.isEnabled),
|
|
|
|
portalType: this._fb.control(page.portalType, Validators.required),
|
2022-01-11 11:05:40 +01:00
|
|
|
portalPid: this._fb.control(page.portalPid),
|
2021-01-28 17:33:16 +01:00
|
|
|
top: this._fb.control(page.top),
|
|
|
|
bottom: this._fb.control(page.bottom),
|
|
|
|
left: this._fb.control(page.left),
|
|
|
|
right: this._fb.control(page.right),
|
|
|
|
type: this._fb.control(page.type, Validators.required),
|
|
|
|
entities: this.entitiesCtrl
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pageForm.get('portalType').disable();
|
2019-12-20 12:38:13 +01:00
|
|
|
for (let i = 0; i < page.entities.length; i++) {
|
|
|
|
this.entitiesCtrl.push(this._fb.control(page.entities[i]));
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pagesModalOpen('Edit Page', 'Save changes');
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public newPage() {
|
2021-03-19 17:51:02 +01:00
|
|
|
if (this.pageForm) {
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pageForm.get('portalType').enable();
|
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
this.entitiesCtrl = this._fb.array([]);
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pageForm = this._fb.group({
|
|
|
|
_id: this._fb.control(null),
|
2022-01-14 14:55:24 +01:00
|
|
|
route: this._fb.control('', Validators.required),
|
2021-01-28 17:33:16 +01:00
|
|
|
name: this._fb.control('', Validators.required),
|
|
|
|
isEnabled: this._fb.control(true),
|
|
|
|
portalType: this._fb.control('', Validators.required),
|
2022-01-11 11:05:40 +01:00
|
|
|
portalPid: this._fb.control(null),
|
2021-01-28 17:33:16 +01:00
|
|
|
top: this._fb.control(true),
|
|
|
|
bottom: this._fb.control(true),
|
|
|
|
left: this._fb.control(true),
|
|
|
|
right: this._fb.control(true),
|
|
|
|
type: this._fb.control(this.typeOptions[0].value, Validators.required),
|
|
|
|
entities: this.entitiesCtrl,
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pagesModalOpen('Create Page', 'Create');
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
|
|
|
private pagesModalOpen(title: string, yesBtn: string) {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.editModal.cancelButton = true;
|
|
|
|
this.editModal.okButton = true;
|
|
|
|
this.editModal.okButtonLeft = false;
|
|
|
|
this.editModal.alertTitle = title;
|
|
|
|
this.editModal.okButtonText = yesBtn;
|
|
|
|
this.editModal.open();
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public pageSaveConfirmed(data: any) {
|
2021-02-01 20:17:55 +01:00
|
|
|
this.showLoading = true;
|
2021-03-19 17:51:02 +01:00
|
|
|
if (!this.pageForm.value._id) {
|
|
|
|
this.subscriptions.push(this._helpContentService.savePage(<Page>this.pageForm.value, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
page => {
|
|
|
|
this.pageSavedSuccessfully(page, true);
|
|
|
|
UIkit.notification('Page <b>' + page.name + '</b> has been <b>successfully created</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error creating page', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
2021-03-19 17:51:02 +01:00
|
|
|
this.pageForm.get('portalType').enable();
|
|
|
|
this.subscriptions.push(this._helpContentService.updatePage(<Page>this.pageForm.value, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
page => {
|
|
|
|
this.pageSavedSuccessfully(page, false);
|
|
|
|
UIkit.notification('Page <b>' + page.name + '</b> has been <b>successfully updated</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error updating page', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public pageSavedSuccessfully(page: Page, isNew: boolean) {
|
|
|
|
if (isNew) {
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pages.push(page);
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pages[this.index] = page;
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-29 11:47:37 +01:00
|
|
|
this.applyFilters();
|
2019-12-20 12:38:13 +01:00
|
|
|
this.applyCheck(false);
|
2021-02-01 20:17:55 +01:00
|
|
|
this.showLoading = false;
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-01-29 11:47:37 +01:00
|
|
|
public applyFilters() {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.checkboxes = [];
|
|
|
|
this.pages.filter(item => this.filterByType(item)).forEach(
|
|
|
|
_ => this.checkboxes.push(<CheckPage>{page: _, checked: false})
|
|
|
|
);
|
2021-01-29 11:47:37 +01:00
|
|
|
this.checkboxes = this.checkboxes.filter(item => this.filterPages(item.page));
|
2021-01-11 10:21:42 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-01-11 10:21:42 +01:00
|
|
|
public filterByType(page: Page): boolean {
|
|
|
|
let type = this.filterForm.get("type").value;
|
2021-01-28 17:33:16 +01:00
|
|
|
return type == "all" || (type == page.type);
|
2021-01-11 10:21:42 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public filterPages(page: Page): boolean {
|
2021-07-14 13:19:57 +02:00
|
|
|
return this.searchText.toString() == '' || (page.route + ' ' + page.name + ' ' + page.portalType).match(this.searchText) != null;
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
handleError(message: string, error) {
|
2021-03-18 15:11:41 +01:00
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2019-12-20 12:38:13 +01:00
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
handleUpdateError(message: string, error) {
|
|
|
|
if (error == null) {
|
|
|
|
// this.formComponent.reset();
|
2021-01-28 17:33:16 +01:00
|
|
|
this.pageForm = this._fb.group({
|
2022-01-14 14:55:24 +01:00
|
|
|
route: this._fb.control('', Validators.required),
|
2021-01-28 17:33:16 +01:00
|
|
|
name: this._fb.control('', Validators.required),
|
|
|
|
isEnabled: this._fb.control(true),
|
|
|
|
portalType: this._fb.control('', Validators.required),
|
|
|
|
top: this._fb.control(true),
|
|
|
|
bottom: this._fb.control(true),
|
|
|
|
left: this._fb.control(true),
|
|
|
|
right: this._fb.control(true),
|
|
|
|
type: this._fb.control(this.typeOptions[0].value, Validators.required),
|
|
|
|
entities: this.entitiesCtrl,
|
|
|
|
_id: this._fb.control(''),
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
|
|
|
} else {
|
2021-03-18 15:11:41 +01:00
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-02-01 20:17:55 +01:00
|
|
|
public getEntitiesAsString(page: Page): string {
|
2021-03-19 17:51:02 +01:00
|
|
|
if (page.entities) {
|
|
|
|
return (<any[]>page.entities).map((page: Entity) => page.name).join(',');
|
2021-02-01 20:17:55 +01:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-01-26 18:00:40 +01:00
|
|
|
public applyPortalFilter(portal: string) {
|
|
|
|
this.getPages(portal);
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public togglePages(status: boolean, ids: string[]) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
'errorCode': LoginErrorCodes.NOT_VALID,
|
|
|
|
'redirectUrl': this._router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2021-01-26 18:00:40 +01:00
|
|
|
this.subscriptions.push(this._helpContentService.togglePages(this.portal, ids, status, this.properties.adminToolsAPIURL).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
() => {
|
|
|
|
for (let id of ids) {
|
|
|
|
let i = this.checkboxes.findIndex(_ => _.page._id == id);
|
|
|
|
this.checkboxes[i].page.isEnabled = status;
|
|
|
|
}
|
|
|
|
this.applyCheck(false);
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error changing the status of the selected page(s)', error)
|
2020-12-18 16:09:38 +01:00
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 17:33:16 +01:00
|
|
|
|
2021-03-19 17:51:02 +01:00
|
|
|
selectAll() {
|
2021-07-14 13:19:57 +02:00
|
|
|
let checked = this.getSelectedPages().length != this.checkboxes.length;
|
2021-02-25 16:55:56 +01:00
|
|
|
for (let check of this.checkboxes) {
|
|
|
|
check.checked = checked;
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 17:51:02 +01:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
getPageHelpContentsCounts(community_pid: string) {
|
|
|
|
this.subscriptions.push(this._helpContentService.countCommunityPageHelpContents(community_pid, this.properties.adminToolsAPIURL, false).subscribe(
|
2021-02-26 11:36:17 +01:00
|
|
|
pageHelpContentsCount => {
|
2021-03-31 13:23:24 +02:00
|
|
|
this.pageHelpContentsCount = pageHelpContentsCount;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page contents', error)));
|
|
|
|
this.subscriptions.push(this._helpContentService.countCommunityPageHelpContents(community_pid, this.properties.adminToolsAPIURL, true).subscribe(
|
|
|
|
pageClassContentsCount => {
|
|
|
|
this.pageClassContentsCount = pageClassContentsCount;
|
2021-02-25 16:55:56 +01:00
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page contents', error)));
|
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|