Revision 57058
Added by Konstantinos Triantafyllou over 4 years ago
claimContextSearchForm.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input} from '@angular/core'; |
2 | 2 |
import {Router} from '@angular/router'; |
3 | 3 |
import {ContextsService} from './service/contexts.service'; |
4 |
import {ClaimContext, ClaimEntity} from './claimHelper.class';
|
|
4 |
import {ClaimEntity} from './claimHelper.class'; |
|
5 | 5 |
import {Session} from '../../login/utils/helper.class'; |
6 | 6 |
import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; |
7 | 7 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
8 |
import {UserManagementService} from "../../services/user-management.service"; |
|
8 | 9 |
|
9 | 10 |
declare var UIkit: any; |
10 | 11 |
|
... | ... | |
14 | 15 |
|
15 | 16 |
}) |
16 | 17 |
export class ClaimContextSearchFormComponent { |
17 |
@Input() public results:ClaimEntity[]; |
|
18 |
@Input() public results: ClaimEntity[];
|
|
18 | 19 |
@Input() public sources; |
19 | 20 |
@Input() public properties: EnvProperties; |
20 | 21 |
@Input() communityId: string = null; |
... | ... | |
44 | 45 |
this.getCommunities(); |
45 | 46 |
} |
46 | 47 |
|
47 |
constructor(private _contextService: ContextsService, private router: Router) { |
|
48 |
constructor(private _contextService: ContextsService, |
|
49 |
private router: Router, |
|
50 |
private userManagementService: UserManagementService) { |
|
48 | 51 |
|
49 | 52 |
} |
50 | 53 |
|
... | ... | |
95 | 98 |
// }); |
96 | 99 |
// return; |
97 | 100 |
// } |
98 |
const entity: ClaimEntity = new ClaimEntity() ;
|
|
101 |
const entity: ClaimEntity = new ClaimEntity(); |
|
99 | 102 |
entity.type = "community"; |
100 | 103 |
|
101 | 104 |
entity.context = {community: community, category: category, concept: concept}; |
... | ... | |
109 | 112 |
} |
110 | 113 |
|
111 | 114 |
getCommunities() { |
112 |
if (!Session.isLoggedIn()) { |
|
113 |
this.saveStateAndRedirectLogin(); |
|
114 |
|
|
115 |
} else { |
|
116 |
this.loading = true; |
|
117 |
this._contextService.getPublicCommunities(this.properties.contextsAPI).subscribe( |
|
118 |
data => { |
|
119 |
this.communities = data; |
|
120 |
if (this.communities.length > 0) { |
|
121 |
this.communities.sort((n1, n2) => n1.label > n2.label); |
|
122 |
} |
|
123 |
this.loading = false; |
|
124 |
if (this.communityId != null) { |
|
125 |
//preselect community |
|
126 |
this.selectedCommunityId = this.communityId; |
|
127 |
for (let i = 0; i < this.communities.length; i++) { |
|
128 |
if (this.communities[i].id == this.selectedCommunityId) { |
|
129 |
this.selectedCommunityLabel = this.communities[i].label; |
|
130 |
break; |
|
131 |
} |
|
132 |
} |
|
133 |
this.addNewContext(this.selectedCommunityLabel, null, { |
|
134 |
'id': this.selectedCommunityId, |
|
135 |
'label': this.selectedCommunityLabel |
|
136 |
}, false) |
|
137 |
|
|
138 |
} |
|
139 |
}, |
|
140 |
err => { |
|
141 |
//console.log(err); |
|
142 |
ClaimContextSearchFormComponent.handleError("Error getting communities", err); |
|
143 |
this.loading = false; |
|
144 |
this.error = true; |
|
145 |
} |
|
146 |
); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
getCategories() { |
|
151 |
this.loading = true; |
|
152 |
// this.categories=[]; |
|
153 |
if (this.selectedCommunityId != '0') { |
|
154 |
if (!Session.isLoggedIn()) { |
|
115 |
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { |
|
116 |
if (!isLoggedIn) { |
|
155 | 117 |
this.saveStateAndRedirectLogin(); |
156 | 118 |
|
157 |
|
|
158 | 119 |
} else { |
159 |
if (this.categories[this.selectedCommunityId]) { |
|
160 |
this.loading = false; |
|
161 |
return; |
|
162 |
} |
|
163 |
this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe( |
|
120 |
this.loading = true; |
|
121 |
this._contextService.getPublicCommunities(this.properties.contextsAPI).subscribe( |
|
164 | 122 |
data => { |
123 |
this.communities = data; |
|
124 |
if (this.communities.length > 0) { |
|
125 |
this.communities.sort((n1, n2) => n1.label > n2.label); |
|
126 |
} |
|
127 |
this.loading = false; |
|
128 |
if (this.communityId != null) { |
|
129 |
//preselect community |
|
130 |
this.selectedCommunityId = this.communityId; |
|
131 |
for (let i = 0; i < this.communities.length; i++) { |
|
132 |
if (this.communities[i].id == this.selectedCommunityId) { |
|
133 |
this.selectedCommunityLabel = this.communities[i].label; |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
this.addNewContext(this.selectedCommunityLabel, null, { |
|
138 |
'id': this.selectedCommunityId, |
|
139 |
'label': this.selectedCommunityLabel |
|
140 |
}, false) |
|
165 | 141 |
|
166 |
this.categories[this.selectedCommunityId] = data; |
|
167 |
this.concepts = []; |
|
168 |
if (this.query !== "") { |
|
169 |
const event = {value: ""}; |
|
170 |
event.value = this.query; |
|
171 | 142 |
} |
172 |
this.loading = false; |
|
173 | 143 |
}, |
174 | 144 |
err => { |
175 | 145 |
//console.log(err); |
176 |
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err);
|
|
146 |
ClaimContextSearchFormComponent.handleError("Error getting communities", err);
|
|
177 | 147 |
this.loading = false; |
148 |
this.error = true; |
|
178 | 149 |
} |
179 | 150 |
); |
180 | 151 |
} |
181 |
} |
|
152 |
});
|
|
182 | 153 |
} |
183 |
/* |
|
184 |
getConcepts() {
|
|
154 |
|
|
155 |
getCategories() {
|
|
185 | 156 |
this.loading = true; |
186 |
if (this.selectedCategoryId != '0') {
|
|
187 |
if (!Session.isLoggedIn()) {
|
|
188 |
this.saveStateAndRedirectLogin();
|
|
189 |
} else {
|
|
190 |
this.concepts = [];
|
|
157 |
// this.categories=[];
|
|
158 |
if (this.selectedCommunityId != '0') {
|
|
159 |
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
|
|
160 |
if (!isLoggedIn) {
|
|
161 |
this.saveStateAndRedirectLogin();
|
|
191 | 162 |
|
192 |
this._contextService.getConcepts(this.selectedCategoryId, "", true, this.properties.contextsAPI).subscribe( |
|
193 |
data => { |
|
163 |
} else { |
|
164 |
if (this.categories[this.selectedCommunityId]) { |
|
165 |
this.loading = false; |
|
166 |
return; |
|
167 |
} |
|
168 |
this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe( |
|
169 |
data => { |
|
194 | 170 |
|
195 |
this.concepts = data; |
|
196 |
for (var i = 0; i < data.length; i++) { |
|
197 |
if (data[i].hasSubConcept == true) { |
|
198 |
this.getSubConcepts(data[i].id); |
|
171 |
this.categories[this.selectedCommunityId] = data; |
|
172 |
this.concepts = []; |
|
173 |
if (this.query !== "") { |
|
174 |
const event = {value: ""}; |
|
175 |
event.value = this.query; |
|
199 | 176 |
} |
177 |
this.loading = false; |
|
178 |
}, |
|
179 |
err => { |
|
180 |
//console.log(err); |
|
181 |
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err); |
|
182 |
this.loading = false; |
|
200 | 183 |
} |
201 |
this.addCommunityInConcepts(); |
|
202 |
if (this.query !== "") { |
|
203 |
var event = {value: ""}; |
|
204 |
event.value = this.query; |
|
205 |
// this.filter(event); |
|
184 |
); |
|
185 |
} |
|
186 |
}); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
/* |
|
191 |
getConcepts() { |
|
192 |
this.loading = true; |
|
193 |
if (this.selectedCategoryId != '0') { |
|
194 |
if (!Session.isLoggedIn()) { |
|
195 |
this.saveStateAndRedirectLogin(); |
|
196 |
} else { |
|
197 |
this.concepts = []; |
|
198 |
|
|
199 |
this._contextService.getConcepts(this.selectedCategoryId, "", true, this.properties.contextsAPI).subscribe( |
|
200 |
data => { |
|
201 |
|
|
202 |
this.concepts = data; |
|
203 |
for (var i = 0; i < data.length; i++) { |
|
204 |
if (data[i].hasSubConcept == true) { |
|
205 |
this.getSubConcepts(data[i].id); |
|
206 |
} |
|
207 |
} |
|
208 |
this.addCommunityInConcepts(); |
|
209 |
if (this.query !== "") { |
|
210 |
var event = {value: ""}; |
|
211 |
event.value = this.query; |
|
212 |
// this.filter(event); |
|
213 |
} |
|
214 |
this.loading = false; |
|
215 |
}, |
|
216 |
err => { |
|
217 |
//console.log(err); |
|
218 |
this.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err); |
|
219 |
this.loading = false; |
|
206 | 220 |
} |
207 |
this.loading = false; |
|
208 |
}, |
|
209 |
err => { |
|
210 |
//console.log(err); |
|
211 |
this.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err); |
|
212 |
this.loading = false; |
|
213 |
} |
|
214 |
); |
|
221 |
); |
|
222 |
} |
|
223 |
} else { |
|
224 |
this.concepts = []; |
|
225 |
this.loading = false; |
|
215 | 226 |
} |
216 |
} else { |
|
217 |
this.concepts = []; |
|
218 |
this.loading = false; |
|
219 |
} |
|
220 |
}*/ |
|
221 |
/* |
|
222 |
getSubConcepts(conceptId) { |
|
223 |
this.loading = true; |
|
224 |
if (this.selectedCategoryId != '0') { |
|
225 |
if (!Session.isLoggedIn()) { |
|
226 |
this.saveStateAndRedirectLogin(); |
|
227 |
} else { |
|
228 |
this._contextService.getSubConcepts(conceptId, "", true, this.properties.contextsAPI).subscribe( |
|
229 |
data => { |
|
230 |
for (var i = 0; i < data.length; i++) { |
|
231 |
this.concepts.push(data[i]); |
|
232 |
} |
|
227 |
}*/ |
|
233 | 228 |
|
234 |
if (this.query !== "") { |
|
235 |
var event = {value: ""}; |
|
236 |
event.value = this.query; |
|
237 |
// this.filter(event); |
|
229 |
/* |
|
230 |
getSubConcepts(conceptId) { |
|
231 |
this.loading = true; |
|
232 |
if (this.selectedCategoryId != '0') { |
|
233 |
if (!Session.isLoggedIn()) { |
|
234 |
this.saveStateAndRedirectLogin(); |
|
235 |
} else { |
|
236 |
this._contextService.getSubConcepts(conceptId, "", true, this.properties.contextsAPI).subscribe( |
|
237 |
data => { |
|
238 |
for (var i = 0; i < data.length; i++) { |
|
239 |
this.concepts.push(data[i]); |
|
240 |
} |
|
241 |
|
|
242 |
if (this.query !== "") { |
|
243 |
var event = {value: ""}; |
|
244 |
event.value = this.query; |
|
245 |
// this.filter(event); |
|
246 |
} |
|
247 |
this.loading = false; |
|
248 |
}, |
|
249 |
err => { |
|
250 |
//console.log(err); |
|
251 |
this.handleError("Error getting subconcepts for concept with id: " + conceptId, err); |
|
252 |
this.loading = false; |
|
238 | 253 |
} |
239 |
this.loading = false; |
|
240 |
}, |
|
241 |
err => { |
|
242 |
//console.log(err); |
|
243 |
this.handleError("Error getting subconcepts for concept with id: " + conceptId, err); |
|
244 |
this.loading = false; |
|
245 |
} |
|
246 |
); |
|
254 |
); |
|
255 |
} |
|
256 |
} else { |
|
257 |
this.concepts = []; |
|
258 |
this.loading = false; |
|
247 | 259 |
} |
248 |
} else { |
|
249 |
this.concepts = []; |
|
250 |
this.loading = false; |
|
251 |
} |
|
252 |
}*/ |
|
260 |
}*/ |
|
253 | 261 |
|
254 | 262 |
displaySubcategory(id) { |
255 | 263 |
if (this.conceptsClassDisplay[id] != null) { |
... | ... | |
261 | 269 |
} |
262 | 270 |
|
263 | 271 |
browseConcepts(categoryId) { |
264 |
if (!Session.isLoggedIn()) { |
|
265 |
this.saveStateAndRedirectLogin(); |
|
266 |
} else { |
|
267 |
if (this.conceptsClass[categoryId] != null) { |
|
268 |
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId]; |
|
269 |
return; |
|
272 |
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => { |
|
273 |
if (!isLoggedIn) { |
|
274 |
this.saveStateAndRedirectLogin(); |
|
275 |
|
|
270 | 276 |
} else { |
271 |
this.conceptsClassDisplay[categoryId] = true; |
|
272 |
} |
|
273 |
this.conceptsClass[categoryId] = []; |
|
274 |
this.conceptsCategoryLoading[categoryId] = true; |
|
275 |
this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe( |
|
276 |
data => { |
|
277 |
// var concepts = data; |
|
278 |
this.conceptsClass[categoryId] = []; |
|
279 |
for (let i = 0; i < data.length; i++) { |
|
280 |
if (data[i].hasSubConcept == true) { |
|
281 |
this.browseSubConcepts(categoryId, data[i].id); |
|
282 |
} else { |
|
283 |
this.conceptsClass[categoryId].push(data[i]); |
|
277 |
if (this.conceptsClass[categoryId] != null) { |
|
278 |
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId]; |
|
279 |
return; |
|
280 |
} else { |
|
281 |
this.conceptsClassDisplay[categoryId] = true; |
|
282 |
} |
|
283 |
this.conceptsClass[categoryId] = []; |
|
284 |
this.conceptsCategoryLoading[categoryId] = true; |
|
285 |
this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe( |
|
286 |
data => { |
|
287 |
// var concepts = data; |
|
288 |
this.conceptsClass[categoryId] = []; |
|
289 |
for (let i = 0; i < data.length; i++) { |
|
290 |
if (data[i].hasSubConcept == true) { |
|
291 |
this.browseSubConcepts(categoryId, data[i].id); |
|
292 |
} else { |
|
293 |
this.conceptsClass[categoryId].push(data[i]); |
|
294 |
} |
|
284 | 295 |
} |
296 |
this.conceptsCategoryLoading[categoryId] = false; |
|
297 |
}, |
|
298 |
err => { |
|
299 |
//console.log(err); |
|
300 |
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err); |
|
301 |
this.conceptsCategoryLoading[categoryId] = false; |
|
285 | 302 |
} |
286 |
this.conceptsCategoryLoading[categoryId] = false; |
|
287 |
}, |
|
288 |
err => { |
|
289 |
//console.log(err); |
|
290 |
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err); |
|
291 |
this.conceptsCategoryLoading[categoryId] = false; |
|
292 |
} |
|
293 |
); |
|
294 |
} |
|
295 |
|
|
303 |
); |
|
304 |
} |
|
305 |
}); |
|
296 | 306 |
} |
297 | 307 |
|
298 | 308 |
browseSubConcepts(categoryId, conceptId) { |
... | ... | |
340 | 350 |
// } |
341 | 351 |
// this.getConcepts(); |
342 | 352 |
// } |
343 |
/* addCommunityInConcepts() { |
|
344 |
this.concepts.push({"id": this.selectedCommunityId, "label": this.selectedCommunityLabel}); |
|
345 |
// if(this.autocomplete){ |
|
346 |
// this.autocomplete.updateList(this.concepts); |
|
347 |
// } |
|
348 |
}*/ |
|
353 |
/* addCommunityInConcepts() {
|
|
354 |
this.concepts.push({"id": this.selectedCommunityId, "label": this.selectedCommunityLabel});
|
|
355 |
// if(this.autocomplete){
|
|
356 |
// this.autocomplete.updateList(this.concepts);
|
|
357 |
// }
|
|
358 |
}*/
|
|
349 | 359 |
|
350 | 360 |
saveStateAndRedirectLogin() { |
351 | 361 |
// if(this.projects != null){ |
Also available in: Unified diff
[Library]: Add user management service and change all session methods with new ones.