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