1 |
50169
|
argiro.kok
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
2 |
50761
|
argiro.kok
|
import { ErrorCodes} from '../../utils/properties/errorCodes';
|
3 |
50169
|
argiro.kok
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
4 |
50586
|
argiro.kok
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
5 |
50169
|
argiro.kok
|
|
6 |
|
|
export class FetchOrganizations {
|
7 |
|
|
private errorCodes: ErrorCodes;
|
8 |
|
|
|
9 |
|
|
public results =[];
|
10 |
|
|
|
11 |
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
12 |
|
|
public sub: any;
|
13 |
|
|
public subResults: any;
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
constructor ( private _searchOrganizationsService: SearchOrganizationsService ) {
|
18 |
|
|
|
19 |
|
|
this.errorCodes = new ErrorCodes();
|
20 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
21 |
|
|
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
public ngOnDestroy() {
|
26 |
|
|
if(this.sub){
|
27 |
|
|
this.sub.unsubscribe();
|
28 |
|
|
}
|
29 |
|
|
if(this.subResults){
|
30 |
|
|
this.subResults.unsubscribe();
|
31 |
|
|
}
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
|
35 |
50586
|
argiro.kok
|
public getResultsByKeyword(keyword:string , page: number, size: number, properties:EnvProperties){
|
36 |
50169
|
argiro.kok
|
var parameters = "";
|
37 |
|
|
if(keyword.length > 0){
|
38 |
|
|
parameters = "q=" + keyword;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
42 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
43 |
|
|
|
44 |
50586
|
argiro.kok
|
this.subResults = this._searchOrganizationsService.searchOrganizations(parameters, null, page, size, [], properties).subscribe(
|
45 |
50169
|
argiro.kok
|
data => {
|
46 |
|
|
this.searchUtils.totalResults = data[0];
|
47 |
|
|
console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
48 |
|
|
this.results = data[1];
|
49 |
|
|
|
50 |
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
51 |
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
52 |
|
|
if(this.searchUtils.totalResults == 0 ){
|
53 |
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
54 |
|
|
}
|
55 |
|
|
},
|
56 |
|
|
err => {
|
57 |
|
|
console.log(err);
|
58 |
|
|
//TODO check erros (service not available, bad request)
|
59 |
|
|
// if( ){
|
60 |
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
61 |
|
|
// }
|
62 |
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
63 |
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
64 |
|
|
|
65 |
|
|
if(err.status == '404') {
|
66 |
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
67 |
|
|
} else if(err.status == '500') {
|
68 |
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
69 |
|
|
} else {
|
70 |
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
}
|