1 |
53600
|
argiro.kok
|
import { Component, OnInit, Input } from '@angular/core';
|
2 |
53735
|
konstantin
|
import { ActivatedRoute, Router } from "@angular/router";
|
3 |
53600
|
argiro.kok
|
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
|
4 |
|
|
import { Page } from "../../domain/page";
|
5 |
|
|
import { DivId } from "../../domain/divId";
|
6 |
|
|
import { HelpContentService } from "../../services/help-content.service";
|
7 |
|
|
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
|
8 |
|
|
|
9 |
53735
|
konstantin
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
10 |
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
11 |
53600
|
argiro.kok
|
|
12 |
|
|
@Component({
|
13 |
|
|
selector: 'div-content-form',
|
14 |
|
|
templateUrl: './div-help-content-form.component.html',
|
15 |
|
|
})
|
16 |
|
|
|
17 |
|
|
export class DivContentFormComponent implements OnInit{
|
18 |
|
|
|
19 |
|
|
@Input('group')
|
20 |
|
|
myForm: FormGroup;
|
21 |
|
|
@Input('communityPid')
|
22 |
|
|
communityPid: string;
|
23 |
|
|
@Input('pageId')
|
24 |
|
|
pageId: string;
|
25 |
|
|
@Input('editMode')
|
26 |
|
|
editMode: boolean = false;
|
27 |
|
|
|
28 |
|
|
//public divIdName: string = '';
|
29 |
|
|
|
30 |
|
|
private communityId: string = '';
|
31 |
|
|
|
32 |
|
|
showPageSelect: boolean = true;
|
33 |
|
|
selectedDiv: DivId;
|
34 |
|
|
|
35 |
|
|
private availablePages : Page[] = [];
|
36 |
|
|
private availableDivs : DivId[] = [];
|
37 |
|
|
|
38 |
|
|
private ckeditorContent : string;
|
39 |
|
|
|
40 |
|
|
public properties:EnvProperties = null;
|
41 |
|
|
|
42 |
|
|
public showLoading: boolean = true;
|
43 |
|
|
public errorMessage: string = '';
|
44 |
|
|
@Input() updateErrorMessage: string = '';
|
45 |
|
|
|
46 |
53735
|
konstantin
|
constructor(private route: ActivatedRoute, private _router: Router, private _fb: FormBuilder, private _helpContentService: HelpContentService){}
|
47 |
53600
|
argiro.kok
|
|
48 |
|
|
ngOnInit() {
|
49 |
|
|
this.myForm = this.form;
|
50 |
|
|
this.route.data
|
51 |
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
52 |
|
|
this.properties = data.envSpecific;
|
53 |
|
|
this.route.queryParams.subscribe(params => {
|
54 |
|
|
|
55 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
56 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
57 |
53600
|
argiro.kok
|
} else {
|
58 |
53735
|
konstantin
|
if(this.pageId) {
|
59 |
|
|
this.showPageSelect = false;
|
60 |
|
|
this.getDivs(this.pageId);
|
61 |
|
|
} else {
|
62 |
|
|
if(!this.editMode) {
|
63 |
|
|
this._helpContentService.getCommunityPagesWithDivId(this.communityPid, this.properties.adminToolsAPIURL).subscribe(
|
64 |
|
|
pages => {
|
65 |
|
|
this.availablePages = pages;
|
66 |
|
|
this.showLoading = false;
|
67 |
|
|
},
|
68 |
|
|
error => this.handleError('System error retrieving pages', error));
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
this.getCommunity(this.communityPid);
|
73 |
53600
|
argiro.kok
|
}
|
74 |
|
|
});
|
75 |
|
|
});
|
76 |
|
|
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
public pageSelected(event) {
|
80 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
81 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
82 |
|
|
} else {
|
83 |
|
|
this.getDivs(event.target.value);
|
84 |
|
|
}
|
85 |
53600
|
argiro.kok
|
}
|
86 |
|
|
|
87 |
|
|
public divIdSelected(div: DivId) {
|
88 |
|
|
this.selectedDiv = div;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
public getCommunity(communityPid: string) {
|
92 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
93 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
94 |
|
|
} else {
|
95 |
|
|
this.showLoading = true;
|
96 |
|
|
this.errorMessage = '';
|
97 |
53600
|
argiro.kok
|
|
98 |
53735
|
konstantin
|
this._helpContentService.getCommunity(this.communityPid, this.properties.adminToolsAPIURL).subscribe(
|
99 |
|
|
community => {
|
100 |
|
|
this.communityId = community._id;
|
101 |
53600
|
argiro.kok
|
|
102 |
53735
|
konstantin
|
this.myForm.patchValue({
|
103 |
|
|
community: this.communityId
|
104 |
|
|
});
|
105 |
|
|
this.showLoading = false;
|
106 |
|
|
},
|
107 |
|
|
error => this.handleError('System error retrieving community', error)
|
108 |
|
|
);
|
109 |
|
|
}
|
110 |
53600
|
argiro.kok
|
}
|
111 |
|
|
|
112 |
|
|
public getDivs(pageId: string) {
|
113 |
53735
|
konstantin
|
if(!Session.isLoggedIn()){
|
114 |
|
|
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
|
115 |
|
|
} else {
|
116 |
56740
|
konstantin
|
//this.showLoading = true;
|
117 |
53735
|
konstantin
|
this.errorMessage = '';
|
118 |
53600
|
argiro.kok
|
|
119 |
56740
|
konstantin
|
this._helpContentService.getDivIdsFull(pageId, this.properties.adminToolsAPIURL, this.communityPid).subscribe(
|
120 |
53735
|
konstantin
|
divs => {
|
121 |
|
|
this.availableDivs = divs;
|
122 |
|
|
this.pageId = pageId;
|
123 |
53600
|
argiro.kok
|
|
124 |
53735
|
konstantin
|
this.showLoading = false;
|
125 |
|
|
},
|
126 |
|
|
error => this.handleError('System error retrieving pages', error));
|
127 |
|
|
}
|
128 |
53600
|
argiro.kok
|
}
|
129 |
|
|
|
130 |
|
|
// public selectedDiv(event) {
|
131 |
|
|
// console.info(event.target.value);
|
132 |
|
|
// }
|
133 |
|
|
|
134 |
|
|
public get form() {
|
135 |
|
|
return this._fb.group({
|
136 |
|
|
divId: ['', Validators.required],
|
137 |
|
|
content: ['', Validators.required],
|
138 |
|
|
isActive: true,
|
139 |
|
|
community: '',
|
140 |
|
|
_id : '',
|
141 |
|
|
});
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
public reset() {
|
145 |
|
|
this.myForm.patchValue({
|
146 |
|
|
divId: '',
|
147 |
|
|
content: '',
|
148 |
|
|
isActive: true,
|
149 |
|
|
community: '',
|
150 |
|
|
_id : ''
|
151 |
|
|
});
|
152 |
|
|
this.myForm.markAsPristine();
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
handleError(message: string, error) {
|
156 |
|
|
this.errorMessage = message;
|
157 |
|
|
console.log('Server responded: ' + error);
|
158 |
|
|
|
159 |
|
|
this.showLoading = false;
|
160 |
|
|
}
|
161 |
|
|
}
|