2019-12-20 12:38:13 +01:00
|
|
|
import { Component, ViewChild, ElementRef } from '@angular/core';
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
import { PageContentFormComponent } from "./page-help-content-form.component";
|
|
|
|
import { PageHelpContent } from "../../utils/entities/adminTool/page-help-content";
|
|
|
|
import { HelpContentService } from "../../services/help-content.service";
|
|
|
|
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";
|
2020-12-18 16:09:38 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
2019-12-20 12:38:13 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'new-page-help-content',
|
|
|
|
templateUrl: 'new-page-help-content.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class NewPageHelpContentComponent {
|
|
|
|
|
|
|
|
@ViewChild(PageContentFormComponent)
|
|
|
|
public formComponent : PageContentFormComponent;
|
|
|
|
|
|
|
|
//private errorMessage : string = null;
|
|
|
|
|
|
|
|
public communityPid: string;
|
|
|
|
|
|
|
|
public pageId: string;
|
|
|
|
public page: Page;
|
|
|
|
|
|
|
|
public properties:EnvProperties = null;
|
|
|
|
|
|
|
|
public showLoading: boolean = true;
|
|
|
|
public errorMessage: string = '';
|
|
|
|
public updateErrorMessage: string = '';
|
2020-12-18 16:09:38 +01:00
|
|
|
private subs: Subscription[]=[];
|
2019-12-20 12:38:13 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
this.communityPid = params['communityId'];
|
|
|
|
this.pageId = params['pageId'];
|
|
|
|
|
|
|
|
if(this.pageId) {
|
|
|
|
this.getPage(this.pageId);
|
|
|
|
} else {
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subs.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-12-20 12:38:13 +01:00
|
|
|
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} });
|
2019-12-20 12:38:13 +01:00
|
|
|
} else {
|
|
|
|
this.page = page;
|
|
|
|
this.formComponent.setPlacements(this.page);
|
|
|
|
this.showLoading = false;
|
|
|
|
console.info(this.page);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
//this.errorMessage = null;
|
|
|
|
|
|
|
|
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.savePageHelpContent(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 saving 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() {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUpdateError(message: string, error) {
|
|
|
|
this.updateErrorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string, error) {
|
|
|
|
this.errorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
}
|