1
|
import {SearchPeopleService} from '../../services/searchPeople.service';
|
2
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
3
|
import {SearchFields} from '../../utils/properties/searchFields';
|
4
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
5
|
|
6
|
export class FetchPeople {
|
7
|
public results =[];
|
8
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
9
|
public sub: any;
|
10
|
public searchFields:SearchFields = new SearchFields();
|
11
|
|
12
|
constructor ( private _searchPeopleService: SearchPeopleService ) {
|
13
|
|
14
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
15
|
this.searchUtils.status =errorCodes.LOADING;
|
16
|
|
17
|
}
|
18
|
|
19
|
|
20
|
|
21
|
public ngOnDestroy() {
|
22
|
this.sub.unsubscribe();
|
23
|
}
|
24
|
|
25
|
public getResultsByKeyword(keyword:string, page: number, size: number){
|
26
|
var parameters = "";
|
27
|
if(keyword.length > 0){
|
28
|
parameters = "q="+'"' + keyword + '"';
|
29
|
}
|
30
|
|
31
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
32
|
this.searchUtils.status = errorCodes.LOADING;
|
33
|
|
34
|
this._searchPeopleService.searchPeople(parameters, null, page, size,[]).subscribe(
|
35
|
data => {
|
36
|
this.searchUtils.totalResults = data[0];
|
37
|
console.info("search People: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
38
|
this.results = data[1];
|
39
|
|
40
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
41
|
this.searchUtils.status = errorCodes.DONE;
|
42
|
if(this.searchUtils.totalResults == 0 ){
|
43
|
this.searchUtils.status = errorCodes.NONE;
|
44
|
}
|
45
|
},
|
46
|
err => {
|
47
|
console.log(err);
|
48
|
//TODO check erros (service not available, bad request)
|
49
|
// if( ){
|
50
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
51
|
// }
|
52
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
53
|
this.searchUtils.status = errorCodes.ERROR;
|
54
|
}
|
55
|
);
|
56
|
}
|
57
|
|
58
|
|
59
|
}
|