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';
|
2021-03-31 13:23:24 +02:00
|
|
|
import {PageHelpContentFilterOptions} from '../../utils/entities/adminTool/page-help-content';
|
2021-07-14 13:19:57 +02:00
|
|
|
import {Page} from '../../utils/entities/adminTool/page';
|
|
|
|
import {Portal} from '../../utils/entities/adminTool/portal';
|
2021-03-31 13:23:24 +02: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-03-31 13:23:24 +02:00
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
|
|
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
|
|
|
|
import {CheckDivHelpContent, DivHelpContent} from '../../utils/entities/adminTool/div-help-content';
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'class-help-contents',
|
|
|
|
templateUrl: './class-help-contents.component.html',
|
|
|
|
})
|
|
|
|
export class ClassHelpContentsComponent implements OnInit {
|
|
|
|
@ViewChild('AlertModalDeletePageHelpContents') alertModalDeletePageHelpContents;
|
|
|
|
private selectedPageContents: string[] = [];
|
|
|
|
public checkboxes: CheckDivHelpContent[] = [];
|
2021-07-14 13:19:57 +02:00
|
|
|
public divHelpContents: DivHelpContent[] = [];
|
2021-03-31 13:23:24 +02:00
|
|
|
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 = '';
|
2021-03-31 13:23:24 +02:00
|
|
|
public counter = {all: 0, active: 0, inactive: 0};
|
|
|
|
public communities: Portal[] = [];
|
|
|
|
public portal: string;
|
|
|
|
public selectedPageId: string;
|
|
|
|
public community: Portal;
|
|
|
|
public page: Page;
|
2021-07-14 13:19:57 +02:00
|
|
|
public properties: EnvProperties = properties;
|
2021-03-31 13:23:24 +02:00
|
|
|
public showLoading: boolean = true;
|
|
|
|
public filterForm: FormControl;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
public selectedKeyword: string;
|
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
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) {
|
|
|
|
}
|
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.filterForm = this._fb.control('');
|
|
|
|
this.subscriptions.push(this.filterForm.valueChanges.subscribe(value => {
|
|
|
|
this.filterBySearch(value);
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.route.params.subscribe(params => {
|
|
|
|
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
|
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
this.selectedPageId = params['pageId'];
|
|
|
|
if (this.portal && this.selectedPageId) {
|
|
|
|
this.getPage(this.selectedPageId);
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
if (!this.selectedPageId) {
|
|
|
|
this.router.navigate(['../pages'], {relativeTo: this.route});
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02: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'], {queryParams: {'communityId': this.portal}});
|
|
|
|
} else {
|
|
|
|
this.page = page;
|
|
|
|
this.getPageHelpContents(this.portal);
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page', error)));
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
public countClassHelpContents() {
|
2021-03-31 13:23:24 +02:00
|
|
|
this.counter = {all: 0, active: 0, inactive: 0};
|
|
|
|
let filter = Object.assign({}, this.filters);
|
|
|
|
filter.active = null;
|
2021-07-14 13:19:57 +02:00
|
|
|
this.divHelpContents.forEach(_ => {
|
2021-03-31 13:23:24 +02:00
|
|
|
if (this.filterPageHelpContent(_, filter)) {
|
2021-07-14 13:19:57 +02:00
|
|
|
if (_.isActive == true) {
|
|
|
|
this.counter.active++;
|
|
|
|
} else {
|
|
|
|
this.counter.inactive++;
|
|
|
|
}
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.counter.all = this.counter.active + this.counter.inactive;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
getPageHelpContents(community_pid: string) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.subscriptions.push(this._helpService.getCommunityDivHelpContents(community_pid, this.properties.adminToolsAPIURL, this.selectedPageId).subscribe(
|
|
|
|
pageHelpContents => {
|
|
|
|
this.divHelpContents = pageHelpContents as Array<DivHelpContent>;
|
|
|
|
this.counter.all = this.divHelpContents.length;
|
|
|
|
this.checkboxes = [];
|
|
|
|
|
|
|
|
for (let i = this.divHelpContents.length - 1; i >= 0; i -= 1) {
|
|
|
|
this.checkboxes.unshift(<CheckDivHelpContent>{divHelpContent: this.divHelpContents[i], checked: false});
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
this.countClassHelpContents();
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page contents', error)));
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public applyCheck(flag: boolean) {
|
|
|
|
this.checkboxes.forEach(_ => _.checked = flag);
|
|
|
|
this.checkboxAll = false;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public getSelectedPageHelpContents(): string[] {
|
|
|
|
return this.checkboxes.filter(pageHelpContent => pageHelpContent.checked == true)
|
|
|
|
.map(checkedPageHelpContent => checkedPageHelpContent.divHelpContent).map(res => res._id);
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public confirmDeletePageHelpContent(id: string) {
|
|
|
|
this.selectedPageContents = [id];
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public confirmDeleteSelectedPageHelpContents() {
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
this.selectedPageContents = this.getSelectedPageHelpContents();
|
|
|
|
this.confirmModalOpen();
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02: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();
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public confirmedDeletePageHelpContents(data: any) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(this._helpService.deleteDivHelpContents(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)
|
|
|
|
));
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
private deletePageHelpContentsFromArray(ids: string[]): void {
|
|
|
|
for (let id of ids) {
|
2021-07-14 13:19:57 +02:00
|
|
|
let i = this.checkboxes.findIndex(_ => _.divHelpContent._id == id);
|
|
|
|
let j = this.divHelpContents.findIndex(_ => _._id == id);
|
|
|
|
this.checkboxes.splice(i, 1);
|
|
|
|
this.divHelpContents.splice(j, 1);
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
this.countClassHelpContents();
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public editPageHelpContent(id: string) {
|
|
|
|
if (this.selectedPageId) {
|
|
|
|
this.router.navigate(['edit/'], {
|
|
|
|
queryParams: {
|
2021-07-14 13:19:57 +02:00
|
|
|
'pageContentId': id,
|
|
|
|
'pageId': this.selectedPageId
|
2021-03-31 13:23:24 +02:00
|
|
|
}, relativeTo: this.route
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['edit/'], {
|
|
|
|
queryParams: {
|
2021-07-14 13:19:57 +02:00
|
|
|
'pageContentId': id,
|
2021-03-31 13:23:24 +02:00
|
|
|
}, relativeTo: this.route
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public togglePageHelpContents(status: boolean, ids: string[]) {
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this.router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
2021-07-14 13:19:57 +02:00
|
|
|
'errorCode': LoginErrorCodes.NOT_VALID,
|
|
|
|
'redirectUrl': this.router.url
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.subscriptions.push(this._helpService.toggleDivHelpContents(ids, status, this.properties.adminToolsAPIURL, this.portal).subscribe(
|
|
|
|
() => {
|
|
|
|
for (let id of ids) {
|
|
|
|
let i = this.checkboxes.findIndex(_ => _.divHelpContent._id == id);
|
|
|
|
this.checkboxes[i].divHelpContent.isActive = status;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
this.countClassHelpContents();
|
2021-03-31 13:23:24 +02:00
|
|
|
this.applyCheck(false);
|
|
|
|
UIkit.notification('Page content(s) has been <b>successfully updated</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
error => this.handleUpdateError('System error changing the status of the selected page content(s)', error)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
public filterPageHelpContent(divHelpContent: DivHelpContent, filters: PageHelpContentFilterOptions): boolean {
|
|
|
|
let activeFlag = filters.active == null || divHelpContent.isActive == filters.active;
|
|
|
|
let textFlag = filters.text.toString() == '' || (divHelpContent.content && divHelpContent.content.match(filters.text) != null);
|
|
|
|
return activeFlag && textFlag;
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public applyFilter() {
|
|
|
|
this.checkboxes = [];
|
2021-07-14 13:19:57 +02:00
|
|
|
this.divHelpContents.filter(item => this.filterPageHelpContent(item, this.filters)).forEach(
|
2021-03-31 13:23:24 +02:00
|
|
|
_ => {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.checkboxes.push(<CheckDivHelpContent>{divHelpContent: _, checked: false});
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public filterBySearch(text: string) {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.filters.text = new RegExp(text, 'i');
|
2021-03-31 13:23:24 +02:00
|
|
|
this.applyFilter();
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
handleError(message: string, error) {
|
2021-07-14 13:19:57 +02:00
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2021-03-31 13:23:24 +02:00
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
handleUpdateError(message: string, error) {
|
2021-07-14 13:19:57 +02:00
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2021-03-31 13:23:24 +02:00
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public newPageContent() {
|
2021-07-14 13:19:57 +02:00
|
|
|
this.router.navigate(['edit'], {
|
|
|
|
queryParams: {
|
|
|
|
pageId: this.selectedPageId
|
|
|
|
}, relativeTo: this.route
|
|
|
|
});
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public onSearchClose() {
|
|
|
|
this.selectedKeyword = this.filterForm.value;
|
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
2021-03-31 13:23:24 +02:00
|
|
|
public reset() {
|
|
|
|
this.selectedKeyword = null;
|
2021-07-14 13:19:57 +02:00
|
|
|
this.searchInputComponent.reset();
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
2021-07-14 13:19:57 +02:00
|
|
|
|
|
|
|
selectAll() {
|
|
|
|
let checked = (this.getSelectedPageHelpContents().length != this.checkboxes.length);
|
|
|
|
for (let check of this.checkboxes) {
|
|
|
|
check.checked = checked;
|
|
|
|
}
|
2021-03-31 13:23:24 +02:00
|
|
|
}
|
|
|
|
}
|