1
|
import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import { Router} from '@angular/router';
|
4
|
import {ContextsService} from './service/contexts.service';
|
5
|
import {ClaimContext} from './claimEntities.class';
|
6
|
import { StaticAutoCompleteComponent } from '../../utils/staticAutoComplete/staticAutoComplete.component';
|
7
|
declare var UIkit:any;
|
8
|
import {Session} from '../../login/utils/helper.class';
|
9
|
import {ErrorCodes} from '../../login/utils/guardHelper.class';
|
10
|
|
11
|
@Component({
|
12
|
// moduleId: module.id,
|
13
|
selector: 'claim-contexts-search-form',
|
14
|
template: `
|
15
|
|
16
|
<div class=" uk-animation uk-padding-small uk-panel uk-background-muted " >
|
17
|
<div>Search for Communities</div>
|
18
|
<table class="uk-width-1-1 uk-table uk-table-responsive" ><tr>
|
19
|
<tr>
|
20
|
<td >
|
21
|
<select [(ngModel)]="selectedCommunityId" (ngModelChange)="communityChanged()" class=" " name="select_funder" >
|
22
|
<option value="0" >Select Community:</option>
|
23
|
<option *ngFor="let community of communities" [value]="community.id" >{{community.label}}</option>
|
24
|
</select>
|
25
|
</td>
|
26
|
<td *ngIf="selectedCommunityId != '0' && categories.length > 0">
|
27
|
<select [(ngModel)]="selectedCategoryId" (ngModelChange)="categoryChanged()" class=" " name="select_funder" >
|
28
|
<option value="0" >Select Category:</option>
|
29
|
<option *ngFor="let category of categories" [value]="category.id" >{{category.label}}</option>
|
30
|
</select>
|
31
|
</td><td >
|
32
|
<static-autocomplete [(list)] = concepts [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Type keywords...'" title = "Concepts:" [multipleSelections]=true (addItem) = "select($event)" > </static-autocomplete>
|
33
|
</td></tr>
|
34
|
|
35
|
</table>
|
36
|
<div *ngIf="loading" class="uk-alert uk-alert-primary" role="alert">Loading communities information...</div>
|
37
|
<div *ngIf="error" class="uk-alert uk-alert-warning" role="alert">An error occured while loading communities...</div>
|
38
|
<div>Or <a uk-toggle="target: #browse; animation: uk-animation-fade"> Browse </a> through categories </div>
|
39
|
<div id="browse" class="uk-card uk-card-default uk-card-body uk-margin-small" hidden>
|
40
|
<a uk-toggle="target: #browse; animation: uk-animation-fade" class="uk-float-right"><span class="uk-icon">
|
41
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="close" ratio="1"><path fill="none" stroke="#000" stroke-width="1.06" d="M16,16 L4,4"></path><path fill="none" stroke="#000" stroke-width="1.06" d="M16,4 L4,16"></path></svg>
|
42
|
</span></a>
|
43
|
<div *ngIf="selectedCommunityId =='0'" class="uk-alert uk-alert-warning" >Please select community first...</div>
|
44
|
<ul *ngIf="selectedCommunityId !='0'" class="uk-list ">
|
45
|
<li>
|
46
|
<span (click)="displaySubcategory(selectedCommunityId)" >
|
47
|
<span *ngIf="!conceptsClassDisplay[selectedCommunityId]" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-down" ratio="1"><polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
48
|
|
49
|
<span *ngIf="conceptsClassDisplay[selectedCommunityId]" class="uk-icon">
|
50
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-up" ratio="1"><polygon points="5 13 10 8 15 13"></polygon></svg></span>{{selectedCommunityLabel}}
|
51
|
</span>
|
52
|
<a *ngIf="!isSelected(selectedCommunityId)" (click)="addNewContext(selectedCommunityLabel,null,{'id':selectedCommunityId, 'label':selectedCommunityLabel})" class="uk-button-default uk-align-right" class="uk-icon-button uk-icon">
|
53
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg> </a>
|
54
|
<ul *ngIf="conceptsClassDisplay[selectedCommunityId]" class="uk-animation-fade" >
|
55
|
<li *ngFor="let category of categories" >
|
56
|
<span (click)="browseConcepts(category.id)" >
|
57
|
<span *ngIf="!conceptsClassDisplay[category.id]" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-down" ratio="1"><polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
58
|
|
59
|
<span *ngIf="conceptsClassDisplay[category.id]" class="uk-icon">
|
60
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-up" ratio="1"><polygon points="5 13 10 8 15 13"></polygon></svg></span>
|
61
|
{{category.label}}</span><a *ngIf="!isSelected(category.id)" (click)="addNewContext(selectedCommunityLabel,category.label,{'id':category.id, 'label':category.label})" class="uk-button-default uk-align-right" class="uk-icon-button" >
|
62
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg></a>
|
63
|
<div *ngIf="conceptsCategoryLoading[category.id]" class="uk-alert uk-alert-primary" role="alert">Loading category information...</div>
|
64
|
|
65
|
<ul *ngIf="conceptsClass[category.id] && conceptsClassDisplay[category.id]" class="uk-list uk-animation-fade" id="ul_{{category.id}}" >
|
66
|
<li *ngFor="let concept1 of conceptsClass[category.id]" >
|
67
|
<span (click)="displaySubcategory(concept1.id)" >
|
68
|
<span *ngIf="!conceptsClassDisplay[concept1.id] && concept1.concept" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-down" ratio="1"><polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
69
|
|
70
|
<span *ngIf="conceptsClassDisplay[concept1.id] && concept1.concept" class="uk-icon">
|
71
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-up" ratio="1"><polygon points="5 13 10 8 15 13"></polygon></svg></span>
|
72
|
{{concept1.label}}
|
73
|
</span>
|
74
|
<a *ngIf="!isSelected(concept1.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept1)" class="uk-button-default uk-align-right" class="uk-icon-button"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg></a>
|
75
|
<ul *ngIf="concept1.concept && conceptsClassDisplay[concept1.id] " class="uk-animation-fade" >
|
76
|
<li *ngFor="let concept2 of concept1.concept"><span (click)="displaySubcategory(concept2.id)" >
|
77
|
<span *ngIf="!conceptsClassDisplay[concept2.id] && concept2.concept" class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-down" ratio="1"><polygon points="5 7 15 7 10 12"></polygon></svg></span>
|
78
|
|
79
|
<span *ngIf="conceptsClassDisplay[concept2.id] && concept2.concept" class="uk-icon">
|
80
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="triangle-up" ratio="1"><polygon points="5 13 10 8 15 13"></polygon></svg></span>
|
81
|
{{concept2.label}}</span>
|
82
|
<a *ngIf="!isSelected(concept2.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept2)" class="uk-button-default uk-align-right" class="uk-icon-button"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg></a>
|
83
|
<ul *ngIf="concept2.concept && conceptsClassDisplay[concept2.id] " class="uk-animation-fade" >
|
84
|
<li *ngFor="let concept3 of concept2.concept">{{concept3.label}}
|
85
|
<a *ngIf="!isSelected(concept3.id)" (click)="addNewContext(selectedCommunityLabel,category.label,concept3)" class="uk-button-default uk-align-right" class="uk-icon-button"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus" ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17" height="1"></rect></svg></a>
|
86
|
</li>
|
87
|
</ul>
|
88
|
</li>
|
89
|
</ul>
|
90
|
</li>
|
91
|
</ul>
|
92
|
</li>
|
93
|
</ul>
|
94
|
</ul>
|
95
|
</div>
|
96
|
<div *ngIf="warningMessage.length > 0" class="uk-alert uk-alert-warning" role="alert">{{warningMessage}}</div>
|
97
|
<div *ngIf="infoMessage.length > 0" class="uk-alert uk-alert-primary" role="alert">{{infoMessage}}</div>
|
98
|
</div>
|
99
|
|
100
|
`
|
101
|
|
102
|
})
|
103
|
export class ClaimContextSearchFormComponent {
|
104
|
// @Input() public inline:boolean = false ; // for claimed started from landing pages
|
105
|
public showComponent:boolean = true ; // for claimed started from landing pages
|
106
|
@Input() public selectedList;
|
107
|
//The following need to be kept in case we have to save the current state
|
108
|
@Input() public projects;
|
109
|
@Input() public results;
|
110
|
@Input() public inlineEntity;
|
111
|
public selectedCommunityId:string = "0";
|
112
|
public selectedCategoryId:string ="0";
|
113
|
// @Output() contextSelected = new EventEmitter();
|
114
|
|
115
|
@ViewChild (StaticAutoCompleteComponent) autocomplete : StaticAutoCompleteComponent ;
|
116
|
|
117
|
public query = '';
|
118
|
public filteredList = [];
|
119
|
public communities:any;
|
120
|
public selectedCommunityLabel:string = "Community:";
|
121
|
|
122
|
public categories:any;
|
123
|
public selectedCategoryLabel:string ="Category:";
|
124
|
public concepts = [];
|
125
|
public conceptsClass = [];
|
126
|
public conceptsClassDisplay = [];
|
127
|
public conceptsCategoryLoading = [];
|
128
|
public warningMessage = "";
|
129
|
public infoMessage = "";
|
130
|
public loading:boolean = false;
|
131
|
public error:boolean = false;
|
132
|
|
133
|
ngOnInit() {
|
134
|
this.getCommunities();
|
135
|
}
|
136
|
constructor(private _contextService: ContextsService,private router: Router) {
|
137
|
|
138
|
}
|
139
|
|
140
|
select($event){
|
141
|
var item = $event.value;
|
142
|
this.addNewContext( this.selectedCommunityLabel, this.selectedCategoryLabel, item);
|
143
|
}
|
144
|
isSelected(id):boolean{
|
145
|
for (var _i = 0; _i < this.selectedList.length; _i++) {
|
146
|
let item = this.selectedList[_i];
|
147
|
if(item.concept.id == id){
|
148
|
return true;
|
149
|
// this.warningMessage = "Concept already in selected list";
|
150
|
}
|
151
|
}
|
152
|
return false;
|
153
|
}
|
154
|
addNewContext(community,category,concept){
|
155
|
var context: ClaimContext= { community: community, category: category, concept: concept };
|
156
|
var found:boolean = false;
|
157
|
this.warningMessage = "";
|
158
|
if (!this.isSelected(context.concept.id)) {
|
159
|
|
160
|
this.selectedList.push(context);
|
161
|
UIkit.notification({
|
162
|
message : 'A new concept is selected.',
|
163
|
status : 'info',
|
164
|
timeout : 1000,
|
165
|
pos : 'top-center'
|
166
|
});
|
167
|
|
168
|
}else{
|
169
|
UIkit.notification({
|
170
|
message : 'The concept is already on your list.',
|
171
|
status : 'warning',
|
172
|
timeout : 1000,
|
173
|
pos : 'top-center'
|
174
|
});
|
175
|
}
|
176
|
}
|
177
|
|
178
|
getCommunities () {
|
179
|
if(!Session.isValidAndRemove()){
|
180
|
this.saveStateAndRedirectLogin();
|
181
|
|
182
|
}else{
|
183
|
this.loading = true;
|
184
|
var token=Session.getUserJwt();
|
185
|
this._contextService.getCommunities().subscribe(
|
186
|
data => {
|
187
|
this.communities = data.communities;
|
188
|
this.loading = false;
|
189
|
},
|
190
|
err => {
|
191
|
console.log(err);
|
192
|
this.loading = false;
|
193
|
this.error = true;
|
194
|
}
|
195
|
);
|
196
|
}
|
197
|
}
|
198
|
getCategories () {
|
199
|
this.loading = true;
|
200
|
this.categories=[];
|
201
|
if(this.selectedCommunityId != '0'){
|
202
|
if(!Session.isValidAndRemove()){
|
203
|
this.saveStateAndRedirectLogin();
|
204
|
|
205
|
}else{
|
206
|
var token=Session.getUserJwt();
|
207
|
this._contextService.getCategories(this.selectedCommunityId).subscribe(
|
208
|
data => {
|
209
|
|
210
|
this.categories = (Array.isArray(data.category))? data.category:[data.category];
|
211
|
this.concepts = [];
|
212
|
this.addCommunityInConcepts();
|
213
|
this.filteredList = [];
|
214
|
if (this.query !== ""){
|
215
|
var event = {value: ""};
|
216
|
event.value = this.query;
|
217
|
}
|
218
|
this.loading = false;
|
219
|
},
|
220
|
err => {
|
221
|
console.log(err);
|
222
|
this.loading = false;
|
223
|
}
|
224
|
);
|
225
|
}
|
226
|
}
|
227
|
}
|
228
|
getConcepts () {
|
229
|
this.loading = true;
|
230
|
if(this.selectedCategoryId != '0'){
|
231
|
if(!Session.isValidAndRemove()){
|
232
|
this.saveStateAndRedirectLogin();
|
233
|
}else{
|
234
|
this.concepts = [];
|
235
|
var token=Session.getUserJwt();
|
236
|
this._contextService.getConcepts(this.selectedCategoryId, "",true).subscribe(
|
237
|
data => {
|
238
|
|
239
|
this.concepts =data;
|
240
|
this.addCommunityInConcepts();
|
241
|
if (this.query !== ""){
|
242
|
var event = {value: ""};
|
243
|
event.value = this.query;
|
244
|
// this.filter(event);
|
245
|
}
|
246
|
this.loading = false;
|
247
|
},
|
248
|
err => {
|
249
|
console.log(err);
|
250
|
this.loading = false;
|
251
|
}
|
252
|
);
|
253
|
}
|
254
|
}else{
|
255
|
this.concepts=[];
|
256
|
this.loading = false;
|
257
|
}
|
258
|
}
|
259
|
displaySubcategory(id) {
|
260
|
if(this.conceptsClassDisplay[id] != null){
|
261
|
this.conceptsClassDisplay[id] = !this.conceptsClassDisplay[id];
|
262
|
|
263
|
}else{
|
264
|
this.conceptsClassDisplay[id] = true;
|
265
|
}
|
266
|
}
|
267
|
browseConcepts (categoryId) {
|
268
|
if(!Session.isValidAndRemove()){
|
269
|
this.saveStateAndRedirectLogin();
|
270
|
}else{
|
271
|
if(this.conceptsClass[categoryId] != null){
|
272
|
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
|
273
|
return;
|
274
|
}else{
|
275
|
this.conceptsClassDisplay[categoryId] = true;
|
276
|
}
|
277
|
this.conceptsClass[categoryId] = [];
|
278
|
var token=Session.getUserJwt();
|
279
|
this.conceptsCategoryLoading[categoryId] = true;
|
280
|
this._contextService.getConcepts(categoryId, "",false).subscribe(
|
281
|
data => {
|
282
|
var concepts = (Array.isArray(data))? data:[data];
|
283
|
for(var i=0;i<concepts.length; i++){
|
284
|
console.log("Data"+concepts[i]);
|
285
|
if(concepts[i].id.split("::").length==3){
|
286
|
this.conceptsClass[categoryId].push(concepts[i]);
|
287
|
}
|
288
|
}
|
289
|
console.log(this.conceptsClass[categoryId]);
|
290
|
this.conceptsCategoryLoading[categoryId] = false;
|
291
|
},
|
292
|
err => {
|
293
|
console.log(err);
|
294
|
this.conceptsCategoryLoading[categoryId] = false;
|
295
|
}
|
296
|
);
|
297
|
}
|
298
|
|
299
|
}
|
300
|
communityChanged(){
|
301
|
console.log(this.selectedCommunityId +" ");
|
302
|
this.warningMessage = "";
|
303
|
this.infoMessage = "";
|
304
|
for(var i = 0; i< this.communities.length; i++){
|
305
|
if(this.communities[i].id==this.selectedCommunityId){
|
306
|
this.selectedCommunityLabel = this.communities[i].label;
|
307
|
break;
|
308
|
}
|
309
|
}
|
310
|
this.selectedCategoryId = "0";
|
311
|
this.selectedCategoryLabel="Select Category:";
|
312
|
this.getCategories();
|
313
|
}
|
314
|
categoryChanged(){
|
315
|
this.warningMessage = "";
|
316
|
this.infoMessage = "";
|
317
|
for(var i = 0; i< this.categories.length; i++){
|
318
|
if(this.categories[i].id==this.selectedCategoryId){
|
319
|
this.selectedCategoryLabel = this.categories[i].label;
|
320
|
break;
|
321
|
}
|
322
|
}
|
323
|
this.getConcepts();
|
324
|
}
|
325
|
addCommunityInConcepts(){
|
326
|
this.concepts.push({"id":this.selectedCommunityId, "label":this.selectedCommunityLabel});
|
327
|
this.autocomplete.updateList(this.concepts);
|
328
|
}
|
329
|
saveStateAndRedirectLogin(){
|
330
|
if(this.projects != null){
|
331
|
localStorage.setItem("projects", JSON.stringify(this.projects));
|
332
|
}
|
333
|
localStorage.setItem("contexts", JSON.stringify(this.selectedList));
|
334
|
if(this.results != null){
|
335
|
localStorage.setItem("results", JSON.stringify(this.results));
|
336
|
}
|
337
|
if(this.inlineEntity != null){
|
338
|
localStorage.setItem("inlineEntity", JSON.stringify(this.inlineEntity));
|
339
|
}
|
340
|
|
341
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": ErrorCodes.NOT_VALID, "redirectUrl": this.router.url } });
|
342
|
}
|
343
|
}
|