1
|
import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {ContextsService} from './service/contexts.service';
|
4
|
import {ClaimContext} from './claimEntities.class';
|
5
|
import { StaticAutoCompleteComponent } from '../../utils/staticAutoComplete/staticAutoComplete.component';
|
6
|
declare var UIkit:any;
|
7
|
|
8
|
@Component({
|
9
|
// moduleId: module.id,
|
10
|
selector: 'claim-contexts-search-form',
|
11
|
template: `
|
12
|
|
13
|
<div class="uk-form uk-animation uk-panel uk-panel-box uk-panel-box-default " >
|
14
|
<div>Search for Communities:</div>
|
15
|
<table>
|
16
|
<tr>
|
17
|
<td >
|
18
|
<select class="custom-select-mini" name="select_funder" >
|
19
|
<option value="0" (click)="communityChanged('0','Community:')">Select Community:</option>
|
20
|
<option *ngIf="communities" (click)="communityChanged(communities.id, communities.label)" [value]="communities.id" >{{communities.label}}</option>
|
21
|
</select>
|
22
|
</td>
|
23
|
<td *ngIf="selectedCommunityId != 0 && categories.length > 0"><select class="custom-select-mini" name="select_funder" >
|
24
|
<option value="0" (click)="categoryChanged('0','Category:')">Select Category:</option>
|
25
|
<option *ngFor="let category of categories" (click)="categoryChanged(category.id, category.label)" [value]="category.id" >{{category.label}}</option>
|
26
|
</select>
|
27
|
</td><td >
|
28
|
<static-autocomplete [(list)] = concepts [allowDuplicates]=true [showSelected]=false [placeHolderMessage] = "'Type keywords...'" title = "Concepts:" [multipleSelections]=true (addItem) = "select($event)" > </static-autocomplete>
|
29
|
</td></tr>
|
30
|
|
31
|
</table>
|
32
|
<div *ngIf="loading" class="uk-alert uk-alert-info" role="alert">Loading...</div>
|
33
|
<div *ngIf="warningMessage.length > 0" class="uk-alert uk-alert-warning" role="alert">{{warningMessage}}</div>
|
34
|
<div *ngIf="infoMessage.length > 0" class="uk-alert uk-alert-info" role="alert">{{infoMessage}}</div>
|
35
|
</div>
|
36
|
|
37
|
`
|
38
|
|
39
|
})
|
40
|
export class ClaimContextSearchFormComponent {
|
41
|
// @Input() public inline:boolean = false ; // for claimed started from landing pages
|
42
|
public showComponent:boolean = true ; // for claimed started from landing pages
|
43
|
@Input() public selectedList = [];
|
44
|
public selectedCommunityId:string = "0";
|
45
|
public selectedCategoryId:string ="0";
|
46
|
@Output() contextSelected = new EventEmitter();
|
47
|
|
48
|
@ViewChild (StaticAutoCompleteComponent) autocomplete : StaticAutoCompleteComponent ;
|
49
|
|
50
|
public query = '';
|
51
|
public filteredList = [];
|
52
|
public communities:string[];
|
53
|
public selectedCommunityLabel:string = "Community:";
|
54
|
|
55
|
public categories:string[];
|
56
|
public selectedCategoryLabel:string ="Category:";
|
57
|
public concepts = [];
|
58
|
public warningMessage = "";
|
59
|
public infoMessage = "";
|
60
|
public loading:boolean = false;
|
61
|
ngOnInit() {
|
62
|
this.getCommunities();
|
63
|
}
|
64
|
constructor(private _contextService: ContextsService) {
|
65
|
|
66
|
}
|
67
|
|
68
|
select($event){
|
69
|
var item = $event.value;
|
70
|
|
71
|
var context: ClaimContext= { community: this.selectedCommunityLabel, category: this.selectedCategoryLabel, concept: item };
|
72
|
var found:boolean = false;
|
73
|
this.warningMessage = "";
|
74
|
for (var _i = 0; _i < this.selectedList.length; _i++) {
|
75
|
let item = this.selectedList[_i];
|
76
|
if(item.concept.id == context.concept.id){
|
77
|
found=true;
|
78
|
// this.warningMessage = "Concept already in selected list";
|
79
|
}
|
80
|
}
|
81
|
// var UIkit:any;
|
82
|
if (!found) {
|
83
|
this.contextSelected.emit({
|
84
|
value: true
|
85
|
});
|
86
|
this.selectedList.push(context);
|
87
|
UIkit.notify({
|
88
|
message : 'A context is selected.',
|
89
|
status : 'info',
|
90
|
timeout : 1000,
|
91
|
pos : 'top-center'
|
92
|
});
|
93
|
|
94
|
}else{
|
95
|
UIkit.notify({
|
96
|
message : 'The context is already on your list.',
|
97
|
status : 'warning',
|
98
|
timeout : 1000,
|
99
|
pos : 'top-center'
|
100
|
});
|
101
|
}
|
102
|
}
|
103
|
|
104
|
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
|
);
|
116
|
}
|
117
|
getCategories () {
|
118
|
console.log(" Getting Categories... ");
|
119
|
this.loading = true;
|
120
|
this.categories=[];
|
121
|
if(this.selectedCommunityId != '0'){
|
122
|
this._contextService.getCategories(this.selectedCommunityId).subscribe(
|
123
|
data => {
|
124
|
this.categories = data.category;
|
125
|
this.concepts = [];
|
126
|
this.filteredList = [];
|
127
|
if (this.query !== ""){
|
128
|
var event = {value: ""};
|
129
|
event.value = this.query;
|
130
|
}
|
131
|
this.loading = false;
|
132
|
},
|
133
|
err => {
|
134
|
console.log(err);
|
135
|
this.loading = false;
|
136
|
}
|
137
|
);
|
138
|
}
|
139
|
}
|
140
|
getConcepts () {
|
141
|
this.loading = true;
|
142
|
if(this.selectedCategoryId != '0'){
|
143
|
this._contextService.getConcepts(this.selectedCategoryId, "").subscribe(
|
144
|
data => {
|
145
|
this.concepts = data;
|
146
|
this.autocomplete.updateList(this.concepts);
|
147
|
if (this.query !== ""){
|
148
|
var event = {value: ""};
|
149
|
event.value = this.query;
|
150
|
// this.filter(event);
|
151
|
}
|
152
|
this.loading = false;
|
153
|
},
|
154
|
err => {
|
155
|
console.log(err);
|
156
|
this.loading = false;
|
157
|
}
|
158
|
);
|
159
|
}else{
|
160
|
this.concepts=[];
|
161
|
this.loading = false;
|
162
|
}
|
163
|
}
|
164
|
communityChanged(communityId:string, communityLabel:string){
|
165
|
console.log(communityId +" "+communityLabel);
|
166
|
console.log(this.selectedCommunityId +" ");
|
167
|
this.warningMessage = "";
|
168
|
this.infoMessage = "";
|
169
|
if(this.selectedCommunityId != communityId){
|
170
|
console.log( " here");
|
171
|
|
172
|
this.selectedCommunityId = communityId;
|
173
|
this.selectedCommunityLabel = communityLabel;
|
174
|
this.getCategories();
|
175
|
}
|
176
|
|
177
|
}
|
178
|
categoryChanged(categoryId:string, categoryLabel:string){
|
179
|
this.warningMessage = "";
|
180
|
this.infoMessage = "";
|
181
|
if(this.selectedCategoryId != categoryId){
|
182
|
this.selectedCategoryId = categoryId;
|
183
|
this.selectedCategoryLabel = categoryLabel;
|
184
|
this.getConcepts();
|
185
|
}
|
186
|
|
187
|
}
|
188
|
|
189
|
}
|