2019-12-20 12:38:13 +01:00
|
|
|
import {Component, ViewChild, OnInit, ElementRef} from '@angular/core';
|
|
|
|
import {Router, ActivatedRoute} from "@angular/router";
|
|
|
|
import {FormBuilder, FormControl, FormGroup} from "@angular/forms";
|
|
|
|
import {HelpContentService} from "../../services/help-content.service";
|
|
|
|
import {
|
|
|
|
DivHelpContent,
|
|
|
|
CheckDivHelpContent,
|
|
|
|
DivHelpContentFilterOptions
|
|
|
|
} from "../../utils/entities/adminTool/div-help-content";
|
|
|
|
import {Page} from "../../utils/entities/adminTool/page";
|
2020-09-24 13:18:24 +02:00
|
|
|
import {Portal} from "../../utils/entities/adminTool/portal";
|
2019-12-20 12:38:13 +01:00
|
|
|
import {DivId} from "../../utils/entities/adminTool/divId";
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
|
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|
|
|
import {Subscriber} from "rxjs";
|
2021-01-11 10:21:42 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2021-03-12 15:49:12 +01:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'div-help-contents',
|
|
|
|
templateUrl: './div-help-contents.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class DivHelpContentsComponent implements OnInit {
|
|
|
|
// @ViewChild('deleteConfirmationModal')
|
|
|
|
// public deleteConfirmationModal : DeleteConfirmationDialogComponent;
|
|
|
|
@ViewChild('AlertModalDeleteDivHelpContents') alertModalDeleteDivHelpContents;
|
|
|
|
private selectedDivContents: string[] = [];
|
|
|
|
|
|
|
|
public checkboxes: CheckDivHelpContent[] = [];
|
|
|
|
|
|
|
|
public divHelpContents: DivHelpContent[] = [];
|
|
|
|
|
|
|
|
//public errorMessage: string;
|
|
|
|
|
|
|
|
public formGroup: FormGroup;
|
|
|
|
|
|
|
|
public pages: Page[];
|
|
|
|
|
|
|
|
public checkboxAll: boolean = false;
|
|
|
|
|
|
|
|
public filters: DivHelpContentFilterOptions = {id: '', active: null, text: new RegExp('')};
|
|
|
|
public keyword: string = "";
|
|
|
|
|
|
|
|
public counter = {all: 0, active: 0, inactive: 0};
|
|
|
|
|
2020-09-24 13:18:24 +02:00
|
|
|
public communities: Portal[] = [];
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
public selectedCommunityPid: string;
|
|
|
|
|
|
|
|
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;
|
|
|
|
public properties: EnvProperties = null;
|
|
|
|
|
|
|
|
public showLoading: boolean = true;
|
|
|
|
public errorMessage: string = '';
|
|
|
|
public updateErrorMessage: string = '';
|
|
|
|
public filterForm: FormControl;
|
|
|
|
public selectForm: FormControl;
|
|
|
|
public selectOptions = [];
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.filterForm = this._fb.control('');
|
|
|
|
this.selectForm = this._fb.control('');
|
|
|
|
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
|
|
|
|
this.filterBySearch(value);
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.selectForm.valueChanges.subscribe(value => {
|
|
|
|
this.filterByPage(value);
|
|
|
|
}));
|
|
|
|
|
2021-01-11 10:21:42 +01:00
|
|
|
this.properties = properties;
|
2019-12-20 12:38:13 +01:00
|
|
|
|
2021-01-11 10:21:42 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
HelperFunctions.scroll();
|
2019-12-20 12:38:13 +01:00
|
|
|
|
2021-01-11 10:21:42 +01:00
|
|
|
this.selectedCommunityPid = params['communityId'];
|
|
|
|
this.selectedPageId = params['pageId'];
|
|
|
|
|
|
|
|
if (this.selectedCommunityPid && this.selectedPageId) {
|
|
|
|
this.getPage(this.selectedPageId);
|
|
|
|
} else if (this.selectedCommunityPid) {
|
|
|
|
this.selectedPageId = "";
|
|
|
|
this.getPages(this.selectedCommunityPid);
|
|
|
|
}
|
|
|
|
}));
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute, private _helpService: HelpContentService, private router: Router, private _fb: FormBuilder) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getPage(pageId: string) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
2020-09-21 09:27:19 +02:00
|
|
|
"redirectUrl": this.router.url
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
this.errorMessage = "";
|
|
|
|
|
2020-10-30 15:01:44 +01:00
|
|
|
this._helpService.getPageByPortal(pageId, this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
page => {
|
2020-09-24 13:18:24 +02:00
|
|
|
if (this.properties.adminToolsPortalType != page.portalType) {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.router.navigate(['../../classContents'], {queryParams: {"communityId": this.selectedCommunityPid}});
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
this.page = page;
|
|
|
|
this.getDivHelpContents(this.selectedCommunityPid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page', error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getPages(community_pid: string) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
2020-09-21 09:27:19 +02:00
|
|
|
"redirectUrl": this.router.url
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
this.errorMessage = "";
|
|
|
|
|
|
|
|
this._helpService.getCommunityPagesWithDivId(community_pid, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
//this._helpService.getPagesWithDivIds(community_pid, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
pages => {
|
|
|
|
this.pages = pages;
|
|
|
|
this.getDivHelpContents(this.selectedCommunityPid);
|
|
|
|
this.selectOptions = [{label:'All pages', value: ''}];
|
|
|
|
for (let page of this.pages) {
|
|
|
|
this.selectOptions.push({label:page.name, value: page._id})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving pages', error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public countDivHelpContents() {
|
|
|
|
this.counter = {all: 0, active: 0, inactive: 0};
|
|
|
|
let filter = Object.assign({}, this.filters);
|
|
|
|
filter.active = null;
|
|
|
|
this.divHelpContents.forEach(_ => {
|
|
|
|
if (this.filterDivHelpContent(_, filter)) {
|
|
|
|
if (_.isActive == true) this.counter.active++;
|
|
|
|
else this.counter.inactive++
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.counter.all = this.counter.active + this.counter.inactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDivHelpContents(community_pid: string) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
2020-09-21 09:27:19 +02:00
|
|
|
"redirectUrl": this.router.url
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this._helpService.getCommunityDivHelpContents(community_pid, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
divHelpContents => {
|
|
|
|
this.divHelpContents = divHelpContents as Array<DivHelpContent>;
|
|
|
|
this.counter.all = this.divHelpContents.length;
|
|
|
|
this.checkboxes = [];
|
|
|
|
|
|
|
|
for (let i = this.divHelpContents.length - 1; i >= 0; i -= 1) {
|
|
|
|
//for (let i = 0; i < this.divHelpContents.length; i++) {
|
|
|
|
let divId: DivId = this.divHelpContents[i].divId as DivId;
|
|
|
|
let pages: Page[] = divId.pages as Page[];
|
|
|
|
const pageIds = pages.map(x => x._id);
|
|
|
|
|
|
|
|
if (!this.selectedPageId || pageIds.includes(this.selectedPageId)) {
|
|
|
|
this.cutContent(this.divHelpContents[i]);
|
|
|
|
this.checkboxes.unshift(<CheckDivHelpContent>{divHelpContent: this.divHelpContents[i], checked: false});
|
|
|
|
} else {
|
|
|
|
this.divHelpContents.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.countDivHelpContents();
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page contents', error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public toggleCheckBoxes(event) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = event.target.checked);
|
|
|
|
this.checkboxAll = event.target.checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
public applyCheck(flag: boolean) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = flag);
|
|
|
|
this.checkboxAll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSelectedDivHelpContents(): string[] {
|
|
|
|
return this.checkboxes.filter(divHelpContent => divHelpContent.checked == true)
|
|
|
|
.map(checkedDivHelpContent => checkedDivHelpContent.divHelpContent).map(res => res._id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public confirmDeleteDivHelpContent(id: string) {
|
|
|
|
//this.deleteConfirmationModal.ids = [id];
|
|
|
|
//this.deleteConfirmationModal.showModal();
|
|
|
|
this.selectedDivContents = [id];
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
public confirmDeleteSelectedDivHelpContents() {
|
|
|
|
//this.deleteConfirmationModal.ids = this.getSelectedDivHelpContents();
|
|
|
|
//this.deleteConfirmationModal.showModal();
|
|
|
|
this.selectedDivContents = this.getSelectedDivHelpContents();
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
private confirmModalOpen() {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
2020-09-21 09:27:19 +02:00
|
|
|
"redirectUrl": this.router.url
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.alertModalDeleteDivHelpContents.cancelButton = true;
|
|
|
|
this.alertModalDeleteDivHelpContents.okButton = true;
|
|
|
|
this.alertModalDeleteDivHelpContents.alertTitle = "Delete Confirmation";
|
|
|
|
this.alertModalDeleteDivHelpContents.message = "Are you sure you want to delete the help text(s)?";
|
|
|
|
this.alertModalDeleteDivHelpContents.okButtonText = "Yes";
|
|
|
|
this.alertModalDeleteDivHelpContents.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public confirmedDeleteDivHelpContents(data: any) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
2020-09-21 09:27:19 +02:00
|
|
|
"redirectUrl": this.router.url
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
2020-10-30 15:01:44 +01:00
|
|
|
this._helpService.deleteDivHelpContents(this.selectedDivContents, this.properties.adminToolsAPIURL, this.selectedCommunityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
_ => {
|
|
|
|
this.deleteDivHelpContentsFromArray(this.selectedDivContents);
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error deleting the selected class content(s)', error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private deleteDivHelpContentsFromArray(ids: string[]): void {
|
|
|
|
for (let id of ids) {
|
|
|
|
let iqc = this.checkboxes.findIndex(_ => _.divHelpContent._id == id);
|
|
|
|
let iq = this.divHelpContents.findIndex(_ => _._id == id);
|
|
|
|
this.checkboxes.splice(iqc, 1);
|
|
|
|
this.divHelpContents.splice(iqc, 1);
|
|
|
|
}
|
|
|
|
this.countDivHelpContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public editDivHelpContent(id: string) {
|
|
|
|
//this.router.navigate(['/pageContents/edit/', _id]);
|
|
|
|
if (this.selectedPageId) {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.router.navigate(['../../classContents/edit/'], {
|
2019-12-20 12:38:13 +01:00
|
|
|
queryParams: {
|
|
|
|
"classContentId": id,
|
|
|
|
"communityId": this.selectedCommunityPid,
|
|
|
|
"pageId": this.selectedPageId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.router.navigate(['../../classContents/edit/'], {
|
2019-12-20 12:38:13 +01:00
|
|
|
queryParams: {
|
|
|
|
"classContentId": id,
|
|
|
|
"communityId": this.selectedCommunityPid
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public toggleDivHelpContents(status: boolean, ids: string[]) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
|
|
|
"redirectUrl": this.router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
2020-10-30 15:01:44 +01:00
|
|
|
this._helpService.toggleDivHelpContents(ids, status, this.properties.adminToolsAPIURL,this.selectedCommunityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
() => {
|
|
|
|
for (let id of ids) {
|
|
|
|
let i = this.checkboxes.findIndex(_ => _.divHelpContent._id == id);
|
|
|
|
this.checkboxes[i].divHelpContent.isActive = status;
|
|
|
|
}
|
|
|
|
this.countDivHelpContents();
|
|
|
|
this.applyCheck(false);
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error changing the status of the selected page content(s)', error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public divHelpContentSavedSuccessfully(divHelpContent: DivHelpContent) {
|
|
|
|
this.cutContent(divHelpContent);
|
|
|
|
this.checkboxes.push(<CheckDivHelpContent>{divHelpContent: divHelpContent, checked: false});
|
|
|
|
this.divHelpContents.push(divHelpContent);
|
|
|
|
this.applyCheck(false);
|
|
|
|
this.countDivHelpContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public divHelpContentUpdatedSuccessfully(divHelpContent: DivHelpContent) {
|
|
|
|
this.checkboxes.find(checkItem => checkItem.divHelpContent._id == divHelpContent._id).divHelpContent = divHelpContent;
|
|
|
|
let index = this.divHelpContents.findIndex(checkItem => checkItem._id == divHelpContent._id);
|
|
|
|
this.divHelpContents[index] = divHelpContent;
|
|
|
|
this.applyCheck(false);
|
|
|
|
this.countDivHelpContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public filterDivHelpContent(divHelpContent: DivHelpContent, filters: DivHelpContentFilterOptions): boolean {
|
|
|
|
let divId: DivId = divHelpContent.divId as DivId;
|
|
|
|
let pages: Page[] = <Page[]>divId.pages;
|
|
|
|
let pageIds: string[] = pages.map(x => x._id);
|
|
|
|
|
|
|
|
let idFlag = filters.id == '' || /*(<Page[]>divId.pages)._id == filters.id*/ pageIds.includes(filters.id);
|
|
|
|
let activeFlag = filters.active == null || divHelpContent.isActive == filters.active;
|
|
|
|
let textFlag = filters.text.toString() == '' || (divHelpContent.content).match(filters.text) != null
|
|
|
|
|| ((<DivId>divHelpContent.divId).name).match(filters.text) != null;
|
|
|
|
return idFlag && activeFlag && textFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public cutContent(divHelpContent: DivHelpContent) {
|
2021-03-12 15:49:12 +01:00
|
|
|
divHelpContent.content = StringUtils.HTMLToString(divHelpContent.content);
|
2019-12-20 12:38:13 +01:00
|
|
|
if (divHelpContent.content.length > 200) {
|
|
|
|
divHelpContent.content = divHelpContent.content.substr(0, 200) + "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public applyFilter() {
|
|
|
|
this.checkboxes = [];
|
|
|
|
this.divHelpContents.filter(item => this.filterDivHelpContent(item, this.filters)).forEach(
|
|
|
|
_ => {
|
|
|
|
this.cutContent(_);
|
|
|
|
this.checkboxes.push(<CheckDivHelpContent>{divHelpContent: _, checked: false})
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.countDivHelpContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public filterByPage(value: any) {
|
|
|
|
this.filters.id = value;
|
|
|
|
this.applyFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
public displayAllDivHelpContents() {
|
|
|
|
this.filters.active = null;
|
|
|
|
this.applyFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
public displayActiveDivHelpContents() {
|
|
|
|
this.filters.active = true;
|
|
|
|
this.applyFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
public filterBySearch(text: string) {
|
|
|
|
this.filters.text = new RegExp(text, "i");
|
|
|
|
this.applyFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
public displayInactiveDivHelpContents() {
|
|
|
|
this.filters.active = false;
|
|
|
|
this.applyFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string, error) {
|
|
|
|
this.errorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUpdateError(message: string, error) {
|
|
|
|
this.updateErrorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public newClassContent() {
|
2021-01-11 10:21:42 +01:00
|
|
|
console.log("AAA")
|
2019-12-20 12:38:13 +01:00
|
|
|
if (this.selectedPageId) {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.router.navigate(['../../classContents/new'], {
|
2019-12-20 12:38:13 +01:00
|
|
|
queryParams: {
|
|
|
|
communityId: this.selectedCommunityPid,
|
|
|
|
pageId: this.selectedPageId
|
2021-01-11 10:21:42 +01:00
|
|
|
}, relativeTo: this.route
|
2019-12-20 12:38:13 +01:00
|
|
|
});
|
|
|
|
} else {
|
2021-01-11 10:21:42 +01:00
|
|
|
this.router.navigate(['../../classContents/new'], {queryParams: {communityId: this.selectedCommunityPid}, relativeTo: this.route});
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|