2019-12-20 12:38:13 +01:00
|
|
|
import { Component, ViewChild, OnInit, OnDestroy, ElementRef } from '@angular/core';
|
|
|
|
import { PageContentFormComponent } from "./page-help-content-form.component";
|
2020-12-18 16:09:38 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
2019-12-20 12:38:13 +01:00
|
|
|
import { HelpContentService } from "../../services/help-content.service";
|
|
|
|
import { PageHelpContent } from "../../utils/entities/adminTool/page-help-content";
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
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 {Page} from "../../utils/entities/adminTool/page";
|
2020-09-21 09:27:19 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'edit-page-help-content',
|
|
|
|
templateUrl: 'edit-page-help-content.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class EditPageHelpContentComponent implements OnInit, OnDestroy{
|
|
|
|
|
|
|
|
@ViewChild(PageContentFormComponent)
|
|
|
|
public formComponent : PageContentFormComponent;
|
|
|
|
|
|
|
|
public communityPid: string;
|
|
|
|
|
|
|
|
public pageId: string;
|
|
|
|
public page: Page;
|
|
|
|
|
2020-12-18 16:09:38 +01:00
|
|
|
private subs: Subscription[]=[];
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
private pageHelpContent: PageHelpContent;
|
|
|
|
|
|
|
|
//private errorMessage : string = null;
|
|
|
|
public properties:EnvProperties = null;
|
|
|
|
|
|
|
|
public showLoading: boolean = true;
|
|
|
|
public errorMessage: string = '';
|
|
|
|
public updateErrorMessage: string = '';
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private element: ElementRef,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private _helpContentService: HelpContentService) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-18 16:09:38 +01:00
|
|
|
|
|
|
|
this.properties = properties;
|
|
|
|
this.subs.push(this.route.queryParams.subscribe(params => {
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
|
|
|
|
let pageContentId = params['pageContentId'];
|
|
|
|
this.communityPid = params['communityId'];
|
|
|
|
this.pageId = params['pageId'];
|
|
|
|
|
|
|
|
if(!pageContentId) {
|
|
|
|
this.router.navigate(['../../'], { queryParams: { "communityId": this.communityPid}, relativeTo: this.route});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getPageHelpContent(pageContentId);
|
|
|
|
}));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
ngOnDestroy() {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.subs.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getPage(pageId: string) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.subs.push(this._helpContentService.getPageByPortal(pageId,this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
page => {
|
2020-09-24 13:18:24 +02:00
|
|
|
if(this.properties.adminToolsPortalType != page.portalType) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['../../'], { queryParams: { "communityId": this.communityPid} , relativeTo: this.route});
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
this.page = page;
|
|
|
|
this.formComponent.setPlacements(this.page);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => this.handleError('System error retrieving page with id: '+pageId, error)
|
2020-12-18 16:09:38 +01:00
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private getPageHelpContent(pageContentId: string) {
|
|
|
|
if(!Session.isLoggedIn()){
|
2020-09-21 09:27:19 +02:00
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} });
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.errorMessage = "";
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
2020-12-18 16:09:38 +01:00
|
|
|
this.subs.push(this._helpContentService.getPageHelpContent(pageContentId as string, this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
pageHelpContent => {
|
|
|
|
if(this.pageId && this.pageId != pageHelpContent.page) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['../../'], { queryParams: { "communityId": this.communityPid} , relativeTo: this.route});
|
2019-12-20 12:38:13 +01:00
|
|
|
} else if(this.pageId) {
|
|
|
|
this.getPage(this.pageId);
|
|
|
|
} else {
|
|
|
|
this.getPage(<string>pageHelpContent.page);
|
|
|
|
}
|
|
|
|
this.updateForm(pageHelpContent);
|
|
|
|
//this.showLoading = false;
|
|
|
|
},
|
2020-12-18 16:09:38 +01:00
|
|
|
error => this.handleError('System error retrieving page help content', error)));
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateForm(pageHelpContent : PageHelpContent) {
|
|
|
|
this.pageHelpContent = pageHelpContent;
|
|
|
|
this.formComponent.myForm.patchValue((pageHelpContent));
|
|
|
|
// console.log("patching",pageHelpContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public saveCustom() {
|
|
|
|
if(!Session.isLoggedIn()){
|
2020-09-21 09:27:19 +02:00
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} });
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
if(this.formComponent.myForm.valid) {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
|
|
|
let pageHelpContent : PageHelpContent = this.formComponent.myForm.value;
|
2020-12-18 16:09:38 +01:00
|
|
|
this.subs.push(this._helpContentService.updatePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
2019-12-20 12:38:13 +01:00
|
|
|
_ => {
|
|
|
|
if(this.pageId) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate( ['../../'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId }, relativeTo: this.route } );
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['../../'], { queryParams: { "communityId": this.communityPid}, relativeTo: this.route } );
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
this.showLoading = false;
|
|
|
|
},
|
|
|
|
err => this.handleUpdateError('System error updating page content', err)
|
2020-12-18 16:09:38 +01:00
|
|
|
));
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
this.errorMessage = "Please fill all required fields";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public cancelCustom() {
|
|
|
|
this.errorMessage = "";
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
|
|
|
if(this.pageId) {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate( ['../../'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId }, relativeTo: this.route } );
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
2020-12-18 16:09:38 +01:00
|
|
|
this.router.navigate(['../../'], { queryParams: { "communityId": this.communityPid}, relativeTo: this.route } );
|
2019-12-20 12:38:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|