1 |
54074
|
konstantin
|
import { Component, ViewChild, ElementRef } from '@angular/core';
|
2 |
53600
|
argiro.kok
|
import { ActivatedRoute, Router } from "@angular/router";
|
3 |
|
|
import { DivContentFormComponent } from "./div-help-content-form.component";
|
4 |
|
|
import { DivHelpContent } from "../../domain/div-help-content";
|
5 |
|
|
import { HelpContentService } from "../../services/help-content.service";
|
6 |
|
|
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
|
7 |
|
|
|
8 |
53735
|
konstantin
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
9 |
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
10 |
55416
|
konstantin
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
11 |
56740
|
konstantin
|
import {Page} from "../../domain/page";
|
12 |
58371
|
k.triantaf
|
import {Title} from '@angular/platform-browser';
|
13 |
59468
|
konstantin
|
import {ClearCacheService} from "../../openaireLibrary/services/clear-cache.service";
|
14 |
53735
|
konstantin
|
|
15 |
53600
|
argiro.kok
|
@Component({
|
16 |
|
|
selector: 'new-div-help-content',
|
17 |
|
|
templateUrl: 'new-div-help-content.component.html',
|
18 |
|
|
})
|
19 |
|
|
|
20 |
|
|
export class NewDivHelpContentComponent {
|
21 |
|
|
|
22 |
|
|
@ViewChild(DivContentFormComponent)
|
23 |
|
|
public formComponent : DivContentFormComponent;
|
24 |
|
|
|
25 |
|
|
//private errorMessage : string = null;
|
26 |
|
|
|
27 |
56471
|
argiro.kok
|
public communityPid: string;
|
28 |
53600
|
argiro.kok
|
|
29 |
56740
|
konstantin
|
public pageId: string;
|
30 |
|
|
public page: Page;
|
31 |
|
|
|
32 |
53600
|
argiro.kok
|
public properties:EnvProperties = null;
|
33 |
|
|
|
34 |
56740
|
konstantin
|
public showLoading: boolean = true;
|
35 |
53600
|
argiro.kok
|
public errorMessage: string = '';
|
36 |
|
|
public updateErrorMessage: string = '';
|
37 |
|
|
|
38 |
|
|
constructor(
|
39 |
54074
|
konstantin
|
private element: ElementRef,
|
40 |
53600
|
argiro.kok
|
private route: ActivatedRoute,
|
41 |
|
|
private router: Router,
|
42 |
58371
|
k.triantaf
|
private title: Title,
|
43 |
59468
|
konstantin
|
private _helpContentService: HelpContentService,
|
44 |
|
|
private _clearCacheService: ClearCacheService) {}
|
45 |
53600
|
argiro.kok
|
|
46 |
|
|
ngOnInit() {
|
47 |
|
|
this.route.data
|
48 |
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
49 |
|
|
this.properties = data.envSpecific;
|
50 |
|
|
this.route.queryParams.subscribe(params => {
|
51 |
55416
|
konstantin
|
HelperFunctions.scroll();
|
52 |
58371
|
k.triantaf
|
this.title.setTitle('Administration Dashboard | New Class Help Text');
|
53 |
53600
|
argiro.kok
|
this.communityPid = params['communityId'];
|
54 |
|
|
this.pageId = params['pageId'];
|
55 |
56740
|
konstantin
|
|
56 |
|
|
|
57 |
|
|
if(this.pageId) {
|
58 |
|
|
this.getPage(this.pageId);
|
59 |
|
|
} else {
|
60 |
|
|
this.showLoading = false;
|
61 |
|
|
}
|
62 |
53600
|
argiro.kok
|
});
|
63 |
|
|
});
|
64 |
|
|
}
|
65 |
|
|
|
66 |
56740
|
konstantin
|
private getPage(pageId: string) {
|
67 |
59468
|
konstantin
|
this._helpContentService.getPageByPortal(pageId,this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
68 |
56740
|
konstantin
|
page => {
|
69 |
59468
|
konstantin
|
// if( (this.communityPid == 'openaire' && !page.openaire)
|
70 |
|
|
// || (this.communityPid == 'connect' && !page.connect)
|
71 |
|
|
// || (this.communityPid != 'openaire' && this.communityPid != 'connect' && !page.communities)) {
|
72 |
|
|
if(this.properties.adminToolsPortalType != page.portalType) {
|
73 |
56740
|
konstantin
|
this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid} });
|
74 |
|
|
} else {
|
75 |
|
|
this.page = page;
|
76 |
|
|
this.showLoading = false;
|
77 |
|
|
console.info(this.page);
|
78 |
|
|
}
|
79 |
|
|
},
|
80 |
|
|
error => this.handleError('System error retrieving page with id: '+pageId, error)
|
81 |
|
|
);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
public saveCustom() {
|
85 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
86 |
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} });
|
87 |
|
|
} else {
|
88 |
53600
|
argiro.kok
|
if(this.formComponent.myForm.valid) {
|
89 |
|
|
this.showLoading = true;
|
90 |
|
|
this.updateErrorMessage = "";
|
91 |
|
|
|
92 |
|
|
let divHelpContent : DivHelpContent = this.formComponent.myForm.value;
|
93 |
|
|
|
94 |
59468
|
konstantin
|
this._helpContentService.saveDivHelpContent(divHelpContent, this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
95 |
53600
|
argiro.kok
|
_ => {
|
96 |
|
|
if(this.pageId) {
|
97 |
|
|
this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
98 |
|
|
} else {
|
99 |
|
|
this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
|
100 |
|
|
}
|
101 |
|
|
this.showLoading = false;
|
102 |
59468
|
konstantin
|
this._clearCacheService.clearCache("class help content saved");
|
103 |
53600
|
argiro.kok
|
},
|
104 |
|
|
err => this.handleUpdateError('System error saving page content', err)
|
105 |
|
|
);
|
106 |
|
|
} else {
|
107 |
|
|
this.errorMessage = "Please fill all required fields";
|
108 |
|
|
}
|
109 |
53735
|
konstantin
|
}
|
110 |
53600
|
argiro.kok
|
}
|
111 |
|
|
|
112 |
56740
|
konstantin
|
public cancelCustom() {
|
113 |
53600
|
argiro.kok
|
if(this.pageId) {
|
114 |
|
|
this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
115 |
|
|
} else {
|
116 |
|
|
this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
handleUpdateError(message: string, error) {
|
121 |
|
|
this.errorMessage = message;
|
122 |
|
|
console.log('Server responded: ' + error);
|
123 |
|
|
this.showLoading = false;
|
124 |
|
|
}
|
125 |
56740
|
konstantin
|
|
126 |
|
|
handleError(message: string, error) {
|
127 |
|
|
this.errorMessage = message;
|
128 |
|
|
console.log('Server responded: ' + error);
|
129 |
|
|
this.showLoading = false;
|
130 |
|
|
}
|
131 |
53600
|
argiro.kok
|
}
|