2017-12-19 13:53:46 +01:00
|
|
|
import {SearchOrganizationsService} from '../../services/searchOrganizations.service';
|
2018-02-15 11:36:12 +01:00
|
|
|
import { ErrorCodes} from '../../utils/properties/errorCodes';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2018-10-30 12:37:52 +01:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
2017-12-19 13:53:46 +01:00
|
|
|
export class FetchOrganizations {
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
|
|
|
|
public results =[];
|
|
|
|
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public sub: any;
|
|
|
|
public subResults: any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor ( private _searchOrganizationsService: SearchOrganizationsService ) {
|
|
|
|
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
if(this.subResults){
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
public getResultsByKeyword(keyword:string , page: number, size: number, properties:EnvProperties){
|
2017-12-19 13:53:46 +01:00
|
|
|
var parameters = "";
|
|
|
|
if(keyword.length > 0){
|
2018-10-30 12:37:52 +01:00
|
|
|
parameters = "q=" + StringUtils.URIEncode(keyword);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
this.subResults = this._searchOrganizationsService.searchOrganizations(parameters, null, page, size, [], properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("search Organizations: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
2017-12-19 13:53:46 +01:00
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|