1
|
import {Component, Input, ViewChild} from '@angular/core';
|
2
|
import { ActivatedRoute} from '@angular/router';
|
3
|
import {Location} from '@angular/common';
|
4
|
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
|
5
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
6
|
import {SearchResult} from '../../utils/entities/searchResult';
|
7
|
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
8
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
9
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
10
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
11
|
|
12
|
@Component({
|
13
|
selector: 'search-dataproviders',
|
14
|
template: `
|
15
|
|
16
|
<search-page pageTitle="Search Content Providers"
|
17
|
formPlaceholderText = "Search for Content Providers"
|
18
|
type="content providers" entityType="dataprovider" [(filters)] = "filters"
|
19
|
[(results)] = "results" [(searchUtils)] = "searchUtils" [baseUrl] = "baseUrl"
|
20
|
(queryChange)="queryChanged($event)"
|
21
|
[csvParams]="csvParams" csvPath="datasources" advancedSearchLink="/search/advanced/dataproviders"
|
22
|
[disableForms]="disableForms"
|
23
|
[loadPaging]="loadPaging"
|
24
|
[oldTotalResults]="oldTotalResults"
|
25
|
searchFormClass="datasourcesSearchForm">
|
26
|
</search-page>
|
27
|
|
28
|
`
|
29
|
})
|
30
|
export class SearchDataprovidersComponent {
|
31
|
private errorCodes: ErrorCodes;
|
32
|
|
33
|
public results =[];
|
34
|
public filters =[];
|
35
|
public totalResults:number = 0 ;
|
36
|
public baseUrl:string;
|
37
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
38
|
public sub: any; public subResults: any;
|
39
|
public _location:Location;
|
40
|
public searchFields:SearchFields = new SearchFields();
|
41
|
public refineFields: string[] = this.searchFields.DATASOURCE_REFINE_FIELDS;
|
42
|
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
43
|
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
44
|
"export":[]
|
45
|
};
|
46
|
public CSVDownloaded = false;
|
47
|
public csvParams: string;
|
48
|
|
49
|
public disableForms: boolean = false;
|
50
|
public loadPaging: boolean = true;
|
51
|
public oldTotalResults: number = 0;
|
52
|
|
53
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
54
|
|
55
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
56
|
this.errorCodes = new ErrorCodes();
|
57
|
this.searchUtils.status = this.errorCodes.LOADING;
|
58
|
this.searchUtils.page =1;
|
59
|
this.baseUrl = OpenaireProperties.getLinkToSearchDataProviders();
|
60
|
}
|
61
|
|
62
|
public ngOnInit() {
|
63
|
this.searchPage.refineFields = this.refineFields;
|
64
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
65
|
var firstLoad =true;
|
66
|
|
67
|
this.sub = this.route.queryParams.subscribe(params => {
|
68
|
if(params['page'] && this.searchUtils.page != params['page']) {
|
69
|
this.loadPaging = false;
|
70
|
this.oldTotalResults = this.searchUtils.totalResults;
|
71
|
}
|
72
|
|
73
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
74
|
var refine = true;
|
75
|
if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
|
76
|
refine = false;
|
77
|
|
78
|
}
|
79
|
firstLoad = false;
|
80
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
81
|
|
82
|
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
|
83
|
this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
|
84
|
});
|
85
|
}
|
86
|
|
87
|
public ngOnDestroy() {
|
88
|
if(this.sub){
|
89
|
this.sub.unsubscribe();
|
90
|
}
|
91
|
if(this.subResults){
|
92
|
this.subResults.unsubscribe();
|
93
|
}
|
94
|
}
|
95
|
|
96
|
public getNumForEntity(entity: string, id:string) {
|
97
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
98
|
this.searchUtils.status = this.errorCodes.LOADING;
|
99
|
|
100
|
if(id != "" && entity != "") {
|
101
|
|
102
|
this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
|
103
|
data => {
|
104
|
this.searchUtils.totalResults = data;
|
105
|
|
106
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
107
|
this.searchUtils.status = this.errorCodes.DONE;
|
108
|
if(this.searchUtils.totalResults == 0 ){
|
109
|
this.searchUtils.status = this.errorCodes.NONE;
|
110
|
}
|
111
|
},
|
112
|
err => {
|
113
|
console.log(err);
|
114
|
//TODO check erros (service not available, bad request)
|
115
|
// if( ){
|
116
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
117
|
// }
|
118
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
119
|
//this.searchUtils.status = errorCodes.ERROR;
|
120
|
|
121
|
if(err.status == '404') {
|
122
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
123
|
} else if(err.status == '500') {
|
124
|
this.searchUtils.status = this.errorCodes.ERROR;
|
125
|
} else {
|
126
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
127
|
}
|
128
|
}
|
129
|
);
|
130
|
}
|
131
|
}
|
132
|
|
133
|
public getNumForSearch(keyword: string) {
|
134
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
135
|
this.searchUtils.status = this.errorCodes.LOADING;
|
136
|
|
137
|
this._searchDataprovidersService.numOfDataproviders(keyword).subscribe(
|
138
|
data => {
|
139
|
this.searchUtils.totalResults = data;
|
140
|
|
141
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
142
|
this.searchUtils.status = this.errorCodes.DONE;
|
143
|
if(this.searchUtils.totalResults == 0 ){
|
144
|
this.searchUtils.status = this.errorCodes.NONE;
|
145
|
}
|
146
|
},
|
147
|
err => {
|
148
|
console.log(err);
|
149
|
//TODO check erros (service not available, bad request)
|
150
|
// if( ){
|
151
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
152
|
// }
|
153
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
154
|
//this.searchUtils.status = errorCodes.ERROR;
|
155
|
if(err.status == '404') {
|
156
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
157
|
} else if(err.status == '500') {
|
158
|
this.searchUtils.status = this.errorCodes.ERROR;
|
159
|
} else {
|
160
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
161
|
}
|
162
|
}
|
163
|
);
|
164
|
}
|
165
|
|
166
|
public getResultsForDeposit(id:string, type:string, page: number, size: number){
|
167
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
168
|
//this.status = errorCodes.LOADING;
|
169
|
if(id != "") {
|
170
|
|
171
|
this._searchDataprovidersService.searchDataprovidersForDeposit(id,type, page, size).subscribe(
|
172
|
data => {
|
173
|
this.searchUtils.totalResults = data[0];
|
174
|
console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ] [total results:"+this.totalResults+"]");
|
175
|
this.results = data[1];
|
176
|
|
177
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
178
|
this.searchUtils.status = this.errorCodes.DONE;
|
179
|
if(this.searchUtils.totalResults == 0 ){
|
180
|
this.searchUtils.status = this.errorCodes.NONE;
|
181
|
}
|
182
|
},
|
183
|
err => {
|
184
|
console.log(err);
|
185
|
//TODO check erros (service not available, bad request)
|
186
|
// if( ){
|
187
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
188
|
// }
|
189
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
190
|
//this.searchUtils.status = errorCodes.ERROR;
|
191
|
if(err.status == '404') {
|
192
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
193
|
} else if(err.status == '500') {
|
194
|
this.searchUtils.status = this.errorCodes.ERROR;
|
195
|
} else {
|
196
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
197
|
}
|
198
|
}
|
199
|
);
|
200
|
}
|
201
|
}
|
202
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
203
|
var parameters = "";
|
204
|
|
205
|
if(entity == "organization") {
|
206
|
parameters = "organizations/"+id;
|
207
|
}
|
208
|
|
209
|
if(parameters != "") {
|
210
|
|
211
|
this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size).subscribe(
|
212
|
data => {
|
213
|
this.searchUtils.totalResults = data[0];
|
214
|
console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
215
|
this.results = data[1];
|
216
|
|
217
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
218
|
this.searchUtils.status = this.errorCodes.DONE;
|
219
|
if(this.searchUtils.totalResults == 0 ){
|
220
|
this.searchUtils.status = this.errorCodes.NONE;
|
221
|
}
|
222
|
},
|
223
|
err => {
|
224
|
console.log(err);
|
225
|
//TODO check erros (service not available, bad request)
|
226
|
// if( ){
|
227
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
228
|
// }
|
229
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
230
|
//this.searchUtils.status = errorCodes.ERROR;
|
231
|
if(err.status == '404') {
|
232
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
233
|
} else if(err.status == '500') {
|
234
|
this.searchUtils.status = this.errorCodes.ERROR;
|
235
|
} else {
|
236
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
237
|
}
|
238
|
}
|
239
|
);
|
240
|
}
|
241
|
}
|
242
|
|
243
|
public getResultsForDataproviders(id:string, page: number, size: number){
|
244
|
|
245
|
this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size).subscribe(
|
246
|
data => {
|
247
|
this.searchUtils.totalResults = data[0];
|
248
|
console.info("search Dataproviders for Entity Registry: [Id:"+id+" ] [total results:"+this.searchUtils.totalResults+"]");
|
249
|
this.results = data[1];
|
250
|
|
251
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
252
|
this.searchUtils.status = this.errorCodes.DONE;
|
253
|
if(this.searchUtils.totalResults == 0 ){
|
254
|
this.searchUtils.status = this.errorCodes.NONE;
|
255
|
}
|
256
|
},
|
257
|
err => {
|
258
|
console.log(err);
|
259
|
//TODO check erros (service not available, bad request)
|
260
|
// if( ){
|
261
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
262
|
// }
|
263
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
264
|
//this.searchUtils.status = errorCodes.ERROR;
|
265
|
if(err.status == '404') {
|
266
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
267
|
} else if(err.status == '500') {
|
268
|
this.searchUtils.status = this.errorCodes.ERROR;
|
269
|
} else {
|
270
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
271
|
}
|
272
|
}
|
273
|
);
|
274
|
}
|
275
|
|
276
|
public getResults(keyword:string,refine:boolean, page: number, size: number){
|
277
|
var parameters = "";
|
278
|
if(keyword.length > 0){
|
279
|
parameters = "q="+ keyword;
|
280
|
}
|
281
|
this._getResults(parameters,refine,page,this.searchUtils.size);
|
282
|
}
|
283
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
284
|
this.csvParams = parameters;
|
285
|
|
286
|
// if(!refine && !this.searchPage){
|
287
|
// this.searchPage = new SearchPageComponent(this._location);
|
288
|
// }
|
289
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
290
|
this.searchUtils.status = this.errorCodes.LOADING;
|
291
|
|
292
|
//this.searchPage.openLoading();
|
293
|
this.disableForms = true;
|
294
|
this.results = [];
|
295
|
this.searchUtils.totalResults = 0;
|
296
|
|
297
|
this.subResults = this._searchDataprovidersService.searchDataproviders(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe(
|
298
|
data => {
|
299
|
this.searchUtils.totalResults = data[0];
|
300
|
console.info("search Content Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
301
|
this.results = data[1];
|
302
|
if(refine){
|
303
|
this.filters = data[2];
|
304
|
}
|
305
|
this.searchPage.checkSelectedFilters(this.filters);
|
306
|
// this.filters = this.searchPage.checkSelectedFilters(data[2]);
|
307
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
308
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
309
|
this.searchUtils.status = this.errorCodes.DONE;
|
310
|
if(this.searchUtils.totalResults == 0 ){
|
311
|
this.searchUtils.status = this.errorCodes.NONE;
|
312
|
}
|
313
|
//this.searchPage.closeLoading();
|
314
|
this.disableForms = false;
|
315
|
|
316
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
317
|
// Page out of limit!!!
|
318
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
319
|
if(!(Number.isInteger(totalPages))) {
|
320
|
totalPages = (parseInt(totalPages, 10) + 1);
|
321
|
}
|
322
|
if(totalPages < page) {
|
323
|
this.searchUtils.totalResults = 0;
|
324
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
325
|
}
|
326
|
}
|
327
|
},
|
328
|
err => {
|
329
|
console.log(err);
|
330
|
//TODO check erros (service not available, bad request)
|
331
|
// if( ){
|
332
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
333
|
// }
|
334
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
335
|
//this.searchUtils.status = errorCodes.ERROR;
|
336
|
if(err.status == '404') {
|
337
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
338
|
} else if(err.status == '500') {
|
339
|
this.searchUtils.status = this.errorCodes.ERROR;
|
340
|
} else {
|
341
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
342
|
}
|
343
|
|
344
|
//this.searchPage.closeLoading();
|
345
|
this.disableForms = false;
|
346
|
}
|
347
|
);
|
348
|
}
|
349
|
|
350
|
private setFilters(){
|
351
|
//TODO set filters from
|
352
|
}
|
353
|
|
354
|
public queryChanged($event) {
|
355
|
this.loadPaging = true;
|
356
|
|
357
|
var parameters = $event.value;
|
358
|
this._getResults(parameters, true, this.searchUtils.page, this.searchUtils.size);
|
359
|
}
|
360
|
}
|