Revision 46951
Added by Argiro Kokogiannaki about 7 years ago
claimContextSearchForm.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core'; |
2 | 2 |
import {Observable} from 'rxjs/Observable'; |
3 |
import { Router} from '@angular/router'; |
|
3 | 4 |
import {ContextsService} from './service/contexts.service'; |
4 | 5 |
import {ClaimContext} from './claimEntities.class'; |
5 | 6 |
import { StaticAutoCompleteComponent } from '../../utils/staticAutoComplete/staticAutoComplete.component'; |
6 | 7 |
declare var UIkit:any; |
8 |
import {Session} from '../../login/utils/helper.class'; |
|
9 |
import {ErrorCodes} from '../../login/utils/guardHelper.class'; |
|
7 | 10 |
|
8 | 11 |
@Component({ |
9 | 12 |
// moduleId: module.id, |
... | ... | |
40 | 43 |
export class ClaimContextSearchFormComponent { |
41 | 44 |
// @Input() public inline:boolean = false ; // for claimed started from landing pages |
42 | 45 |
public showComponent:boolean = true ; // for claimed started from landing pages |
43 |
@Input() public selectedList = []; |
|
46 |
@Input() public selectedList; |
|
47 |
//The following need to be kept in case we have to save the current state |
|
48 |
@Input() public projects; |
|
49 |
@Input() public results; |
|
50 |
@Input() public inlineEntity; |
|
44 | 51 |
public selectedCommunityId:string = "0"; |
45 | 52 |
public selectedCategoryId:string ="0"; |
46 |
@Output() contextSelected = new EventEmitter(); |
|
53 |
// @Output() contextSelected = new EventEmitter();
|
|
47 | 54 |
|
48 | 55 |
@ViewChild (StaticAutoCompleteComponent) autocomplete : StaticAutoCompleteComponent ; |
49 | 56 |
|
... | ... | |
61 | 68 |
ngOnInit() { |
62 | 69 |
this.getCommunities(); |
63 | 70 |
} |
64 |
constructor(private _contextService: ContextsService) { |
|
71 |
constructor(private _contextService: ContextsService,private router: Router) {
|
|
65 | 72 |
|
66 | 73 |
} |
67 | 74 |
|
... | ... | |
78 | 85 |
// this.warningMessage = "Concept already in selected list"; |
79 | 86 |
} |
80 | 87 |
} |
81 |
// var UIkit:any; |
|
82 | 88 |
if (!found) { |
83 |
this.contextSelected.emit({ |
|
84 |
value: true |
|
85 |
}); |
|
89 |
|
|
86 | 90 |
this.selectedList.push(context); |
87 | 91 |
UIkit.notify({ |
88 | 92 |
message : 'A context is selected.', |
... | ... | |
102 | 106 |
} |
103 | 107 |
|
104 | 108 |
getCommunities () { |
105 |
this.loading = true; |
|
106 |
this._contextService.getCommunities().subscribe( |
|
107 |
data => { |
|
108 |
this.communities = data.communities; |
|
109 |
this.loading = false; |
|
110 |
}, |
|
111 |
err => { |
|
112 |
console.log(err); |
|
113 |
this.loading = false; |
|
114 |
} |
|
115 |
); |
|
109 |
if(!Session.isValidAndRemove()){ |
|
110 |
this.saveStateAndRedirectLogin(); |
|
111 |
|
|
112 |
}else{ |
|
113 |
this.loading = true; |
|
114 |
var token=Session.getUserJwt(); |
|
115 |
this._contextService.getCommunities(token).subscribe( |
|
116 |
data => { |
|
117 |
this.communities = data.communities; |
|
118 |
this.loading = false; |
|
119 |
}, |
|
120 |
err => { |
|
121 |
console.log(err); |
|
122 |
this.loading = false; |
|
123 |
} |
|
124 |
); |
|
125 |
} |
|
116 | 126 |
} |
117 | 127 |
getCategories () { |
118 | 128 |
console.log(" Getting Categories... "); |
119 | 129 |
this.loading = true; |
120 | 130 |
this.categories=[]; |
121 | 131 |
if(this.selectedCommunityId != '0'){ |
122 |
this._contextService.getCategories(this.selectedCommunityId).subscribe( |
|
123 |
data => { |
|
124 |
this.categories = data.category; |
|
125 |
this.concepts = []; |
|
126 |
this.addCommunityInConcepts(); |
|
127 |
this.filteredList = []; |
|
128 |
if (this.query !== ""){ |
|
129 |
var event = {value: ""}; |
|
130 |
event.value = this.query; |
|
132 |
if(!Session.isValidAndRemove()){ |
|
133 |
this.saveStateAndRedirectLogin(); |
|
134 |
|
|
135 |
}else{ |
|
136 |
var token=Session.getUserJwt(); |
|
137 |
this._contextService.getCategories(this.selectedCommunityId, token).subscribe( |
|
138 |
data => { |
|
139 |
this.categories = data.category; |
|
140 |
this.concepts = []; |
|
141 |
this.addCommunityInConcepts(); |
|
142 |
this.filteredList = []; |
|
143 |
if (this.query !== ""){ |
|
144 |
var event = {value: ""}; |
|
145 |
event.value = this.query; |
|
146 |
} |
|
147 |
this.loading = false; |
|
148 |
}, |
|
149 |
err => { |
|
150 |
console.log(err); |
|
151 |
this.loading = false; |
|
131 | 152 |
} |
132 |
this.loading = false; |
|
133 |
}, |
|
134 |
err => { |
|
135 |
console.log(err); |
|
136 |
this.loading = false; |
|
137 |
} |
|
138 |
); |
|
153 |
); |
|
154 |
} |
|
139 | 155 |
} |
140 | 156 |
} |
141 | 157 |
getConcepts () { |
142 | 158 |
this.loading = true; |
143 | 159 |
if(this.selectedCategoryId != '0'){ |
144 |
this.concepts = []; |
|
145 |
this.addCommunityInConcepts(); |
|
146 |
this._contextService.getConcepts(this.selectedCategoryId, "").subscribe( |
|
147 |
data => { |
|
148 |
this.concepts = data; |
|
149 |
this.addCommunityInConcepts(); |
|
150 |
if (this.query !== ""){ |
|
151 |
var event = {value: ""}; |
|
152 |
event.value = this.query; |
|
153 |
// this.filter(event); |
|
154 |
} |
|
155 |
this.loading = false; |
|
156 |
}, |
|
157 |
err => { |
|
158 |
console.log(err); |
|
159 |
this.loading = false; |
|
160 |
} |
|
161 |
); |
|
160 |
if(!Session.isValidAndRemove()){ |
|
161 |
this.saveStateAndRedirectLogin(); |
|
162 |
}else{ |
|
163 |
this.concepts = []; |
|
164 |
this.addCommunityInConcepts(); |
|
165 |
var token=Session.getUserJwt(); |
|
166 |
this._contextService.getConcepts(this.selectedCategoryId, "",token).subscribe( |
|
167 |
data => { |
|
168 |
this.concepts = data; |
|
169 |
this.addCommunityInConcepts(); |
|
170 |
if (this.query !== ""){ |
|
171 |
var event = {value: ""}; |
|
172 |
event.value = this.query; |
|
173 |
// this.filter(event); |
|
174 |
} |
|
175 |
this.loading = false; |
|
176 |
}, |
|
177 |
err => { |
|
178 |
console.log(err); |
|
179 |
this.loading = false; |
|
180 |
} |
|
181 |
); |
|
182 |
} |
|
162 | 183 |
}else{ |
163 | 184 |
this.concepts=[]; |
164 | 185 |
this.loading = false; |
... | ... | |
190 | 211 |
this.concepts.push({"id":this.selectedCommunityId, "label":this.selectedCommunityLabel}); |
191 | 212 |
this.autocomplete.updateList(this.concepts); |
192 | 213 |
} |
214 |
saveStateAndRedirectLogin(){ |
|
215 |
if(this.projects != null){ |
|
216 |
localStorage.setItem("projects", JSON.stringify(this.projects)); |
|
217 |
} |
|
218 |
localStorage.setItem("contexts", JSON.stringify(this.selectedList)); |
|
219 |
if(this.results != null){ |
|
220 |
localStorage.setItem("results", JSON.stringify(this.results)); |
|
221 |
} |
|
222 |
if(this.inlineEntity != null){ |
|
223 |
localStorage.setItem("inlineEntity", JSON.stringify(this.inlineEntity)); |
|
224 |
} |
|
193 | 225 |
|
226 |
this.router.navigate(['/user-info'], { queryParams: { "errorCode": ErrorCodes.NOT_VALID, "redirectUrl": this.router.url } }); |
|
194 | 227 |
} |
228 |
} |
Also available in: Unified diff
Adding login token parameter in claim API requests | check for user session expiration before every API call| redirect to login page if needed | keep the current state and current url if needed