2021-07-14 13:19:57 +02:00
|
|
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {HelpContentService} from '../../services/help-content.service';
|
2019-12-20 12:38:13 +01:00
|
|
|
import {
|
|
|
|
CheckPageHelpContent,
|
2021-07-14 13:19:57 +02:00
|
|
|
PageHelpContent,
|
2019-12-20 12:38:13 +01:00
|
|
|
PageHelpContentFilterOptions
|
2021-07-14 13:19:57 +02:00
|
|
|
} from '../../utils/entities/adminTool/page-help-content';
|
|
|
|
import {CheckPage, Page} from '../../utils/entities/adminTool/page';
|
|
|
|
import {Portal} from '../../utils/entities/adminTool/portal';
|
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';
|
2021-07-14 13:19:57 +02:00
|
|
|
import {HelperFunctions} from '../../utils/HelperFunctions.class';
|
|
|
|
import {Subscriber} from 'rxjs';
|
|
|
|
import {properties} from '../../../../environments/environment';
|
2021-02-25 16:55:56 +01:00
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
|
|
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
|
|
|
|
|
2021-03-18 15:11:41 +01:00
|
|
|
declare var UIkit;
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'page-help-contents',
|
|
|
|
templateUrl: './page-help-contents.component.html',
|
|
|
|
})
|
|
|
|
export class PageHelpContentsComponent implements OnInit {
|
|
|
|
@ViewChild('AlertModalDeletePageHelpContents') alertModalDeletePageHelpContents;
|
|
|
|
private selectedPageContents: string[] = [];
|
|
|
|
public checkboxes: CheckPageHelpContent[] = [];
|
|
|
|
public pageHelpContents: PageHelpContent[] = [];
|
|
|
|
public formGroup: FormGroup;
|
|
|
|
public pages: Page[];
|
|
|
|
public checkboxAll: boolean = false;
|
|
|
|
public filters: PageHelpContentFilterOptions = {id: '', active: null, text: new RegExp('')};
|
2021-07-14 13:19:57 +02:00
|
|
|
public keyword: string = '';
|
2019-12-20 12:38:13 +01:00
|
|
|
public counter = {all: 0, active: 0, inactive: 0};
|
2020-09-24 13:18:24 +02:00
|
|
|
public communities: Portal[] = [];
|
2021-03-02 16:52:09 +01:00
|
|
|
public portal: string;
|
2019-12-20 12:38:13 +01:00
|
|
|
public selectedPageId: string;
|
2020-09-24 13:18:24 +02:00
|
|
|
public community: Portal;
|
2019-12-20 12:38:13 +01:00
|
|
|
public page: Page;
|
2021-03-18 15:11:41 +01:00
|
|
|
public properties: EnvProperties = properties;
|
2019-12-20 12:38:13 +01:00
|
|
|
public showLoading: boolean = true;
|
|
|
|
public filterForm: FormControl;
|
|
|
|
private subscriptions: any[] = [];
|
2021-02-25 16:55:56 +01:00
|
|
|
public selectedKeyword: string;
|
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2021-07-14 13:19:57 +02:00
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute, private router: Router, private _helpService: HelpContentService, private _fb: FormBuilder, private sanitizer: DomSanitizer) {
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
ngOnInit() {
|
|
|
|
this.filterForm = this._fb.control('');
|
|
|
|
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
|
|
|
|
this.filterBySearch(value);
|
|
|
|
}));
|
2021-02-25 16:55:56 +01:00
|
|
|
this.subscriptions.push(this.route.params.subscribe(params => {
|
2021-03-02 16:52:09 +01:00
|
|
|
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
|
2021-02-25 16:55:56 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.selectedPageId = params['pageId'];
|
2021-03-02 16:52:09 +01:00
|
|
|
if (this.portal && this.selectedPageId) {
|
2021-02-25 16:55:56 +01:00
|
|
|
this.getPage(this.selectedPageId);
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
if (!this.selectedPageId) {
|
|
|
|
this.router.navigate(['../pages'], {relativeTo: this.route});
|
2021-02-25 16:55:56 +01:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +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();
|
|
|
|
}
|
|
|
|
});
|
2020-12-18 16:09:38 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
getPage(pageId: string) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.portal).subscribe(
|
|
|
|
page => {
|
|
|
|
if (this.properties.adminToolsPortalType != page.portalType) {
|
|
|
|
this.router.navigate(['./pageContents']);
|
|
|
|
} else {
|
|
|
|
this.page = page;
|
|
|
|
this.getPageHelpContents(this.portal);
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page', error)));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public countPageHelpContents() {
|
|
|
|
this.counter = {all: 0, active: 0, inactive: 0};
|
|
|
|
let filter = Object.assign({}, this.filters);
|
|
|
|
filter.active = null;
|
|
|
|
this.pageHelpContents.forEach(_ => {
|
|
|
|
if (this.filterPageHelpContent(_, filter)) {
|
2021-07-14 13:19:57 +02:00
|
|
|
if (_.isActive == true) {
|
|
|
|
this.counter.active++;
|
|
|
|
} else {
|
|
|
|
this.counter.inactive++;
|
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.counter.all = this.counter.active + this.counter.inactive;
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
getPageHelpContents(community_pid: string) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.subscriptions.push(this._helpService.getCommunityPageHelpContents(community_pid, this.properties.adminToolsAPIURL, this.selectedPageId).subscribe(
|
|
|
|
pageHelpContents => {
|
|
|
|
this.pageHelpContents = pageHelpContents as Array<PageHelpContent>;
|
|
|
|
this.counter.all = this.pageHelpContents.length;
|
|
|
|
this.checkboxes = [];
|
|
|
|
|
|
|
|
for (let i = this.pageHelpContents.length - 1; i >= 0; i -= 1) {
|
|
|
|
this.checkboxes.unshift(<CheckPageHelpContent>{
|
|
|
|
pageHelpContent: this.pageHelpContents[i],
|
|
|
|
checked: false
|
|
|
|
});
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
this.countPageHelpContents();
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page contents', error)));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public applyCheck(flag: boolean) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = flag);
|
|
|
|
this.checkboxAll = false;
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public getSelectedPageHelpContents(): string[] {
|
|
|
|
return this.checkboxes.filter(pageHelpContent => pageHelpContent.checked == true)
|
|
|
|
.map(checkedPageHelpContent => checkedPageHelpContent.pageHelpContent).map(res => res._id);
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmDeletePageHelpContent(id: string) {
|
|
|
|
this.selectedPageContents = [id];
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmDeleteSelectedPageHelpContents() {
|
|
|
|
this.selectedPageContents = this.getSelectedPageHelpContents();
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
private confirmModalOpen() {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.alertModalDeletePageHelpContents.cancelButton = true;
|
|
|
|
this.alertModalDeletePageHelpContents.okButton = true;
|
|
|
|
this.alertModalDeletePageHelpContents.alertTitle = 'Delete Confirmation';
|
|
|
|
this.alertModalDeletePageHelpContents.message = 'Are you sure you want to delete the selected page content(s)?';
|
|
|
|
this.alertModalDeletePageHelpContents.okButtonText = 'Yes';
|
|
|
|
this.alertModalDeletePageHelpContents.open();
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public confirmedDeletePageHelpContents(data: any) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpService.deletePageHelpContents(this.selectedPageContents, this.properties.adminToolsAPIURL, this.portal).subscribe(
|
|
|
|
_ => {
|
|
|
|
this.deletePageHelpContentsFromArray(this.selectedPageContents);
|
|
|
|
UIkit.notification('Page content(s) has been <b>successfully deleted</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error deleting the selected page content(s)', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
private deletePageHelpContentsFromArray(ids: string[]): void {
|
|
|
|
for (let id of ids) {
|
2021-07-14 13:19:57 +02:00
|
|
|
let i = this.checkboxes.findIndex(_ => _.pageHelpContent._id == id);
|
|
|
|
let j = this.pageHelpContents.findIndex(_ => _._id == id);
|
|
|
|
this.checkboxes.splice(i, 1);
|
|
|
|
this.pageHelpContents.splice(j, 1);
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
this.countPageHelpContents();
|
2021-07-14 13:19:57 +02:00
|
|
|
this.filterBySearch(this.filterForm.value);
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public editPageHelpContent(id: string) {
|
|
|
|
//this.router.navigate(['/pageContents/edit/', _id]);
|
|
|
|
if (this.selectedPageId) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['edit/'], {
|
2019-12-20 12:38:13 +01:00
|
|
|
queryParams: {
|
2021-07-14 13:19:57 +02:00
|
|
|
'pageContentId': id,
|
|
|
|
'pageId': this.selectedPageId
|
2020-12-18 16:09:38 +01:00
|
|
|
}, relativeTo: this.route
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
|
|
|
} else {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['edit/'], {
|
2019-12-20 12:38:13 +01:00
|
|
|
queryParams: {
|
2021-07-14 13:19:57 +02:00
|
|
|
'pageContentId': id
|
2020-12-18 16:09:38 +01:00
|
|
|
}, relativeTo: this.route
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public togglePageHelpContents(status: boolean, ids: string[]) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.subscriptions.push(this._helpService.togglePageHelpContents(ids, status, this.properties.adminToolsAPIURL, this.portal).subscribe(
|
|
|
|
() => {
|
|
|
|
for (let id of ids) {
|
|
|
|
let i = this.checkboxes.findIndex(_ => _.pageHelpContent._id == id);
|
|
|
|
this.checkboxes[i].pageHelpContent.isActive = status;
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
UIkit.notification('Page content(s) has been <b>successfully updated</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.countPageHelpContents();
|
|
|
|
this.applyCheck(false);
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error changing the status of the selected page content(s)', error)
|
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public filterPageHelpContent(pageHelpContent: PageHelpContent, filters: PageHelpContentFilterOptions): boolean {
|
|
|
|
let idFlag = filters.id == '' || (<Page>pageHelpContent.page)._id == filters.id;
|
|
|
|
let activeFlag = filters.active == null || pageHelpContent.isActive == filters.active;
|
2021-07-14 13:19:57 +02:00
|
|
|
let textFlag = filters.text.toString() == '' || (pageHelpContent.content && pageHelpContent.content.match(filters.text) != null)
|
|
|
|
|| (pageHelpContent.page && (<Page>pageHelpContent.page).name && (<Page>pageHelpContent.page).name.match(filters.text) != null);
|
2019-12-20 12:38:13 +01:00
|
|
|
return idFlag && activeFlag && textFlag;
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public applyFilter() {
|
|
|
|
this.checkboxes = [];
|
|
|
|
this.pageHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach(
|
|
|
|
_ => {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.checkboxes.push(<CheckPageHelpContent>{pageHelpContent: _, checked: false});
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public filterBySearch(text: string) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.filters.text = new RegExp(text, 'i');
|
2019-12-20 12:38:13 +01:00
|
|
|
this.applyFilter();
|
|
|
|
}
|
2021-03-18 15:11:41 +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-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
handleUpdateError(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-03-18 15:11:41 +01:00
|
|
|
|
2019-12-20 12:38:13 +01:00
|
|
|
public newPageContent() {
|
2021-03-18 15:11:41 +01:00
|
|
|
this.router.navigate(['edit'], {
|
|
|
|
queryParams: {
|
|
|
|
pageId: this.selectedPageId
|
|
|
|
}, relativeTo: this.route
|
|
|
|
});
|
2021-02-25 16:55:56 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2021-02-25 16:55:56 +01:00
|
|
|
public onSearchClose() {
|
|
|
|
this.selectedKeyword = this.filterForm.value;
|
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
2021-02-25 16:55:56 +01:00
|
|
|
public reset() {
|
|
|
|
this.selectedKeyword = null;
|
2021-07-14 13:19:57 +02:00
|
|
|
this.searchInputComponent.reset();
|
2021-02-25 16:55:56 +01:00
|
|
|
}
|
2021-03-18 15:11:41 +01:00
|
|
|
|
|
|
|
selectAll() {
|
|
|
|
let checked = (this.getSelectedPageHelpContents().length != this.checkboxes.length);
|
|
|
|
for (let check of this.checkboxes) {
|
|
|
|
check.checked = checked;
|
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|