Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
entitySearch.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {Http, Response} from '@angular/http'; |
3 |
import {Observable} from 'rxjs/Observable'; |
|
3 |
import {HttpClient, HttpErrorResponse} from "@angular/common/http"; |
|
4 |
import {Observable, throwError} from 'rxjs'; |
|
4 | 5 |
import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class'; |
5 |
import 'rxjs/add/observable/of'; |
|
6 |
import 'rxjs/add/operator/do'; |
|
7 |
import 'rxjs/add/operator/share'; |
|
6 |
|
|
7 |
|
|
8 |
|
|
8 | 9 |
import{EnvProperties} from '../properties/env-properties'; |
9 | 10 |
|
10 | 11 |
import {StringUtils} from '../string-utils.class'; |
12 |
import {catchError, map} from "rxjs/operators"; |
|
11 | 13 |
@Injectable() |
12 | 14 |
export class EntitiesSearchService { |
13 | 15 |
public ready:boolean = false; |
14 |
constructor(private http: Http ) {} |
|
16 |
constructor(private http: HttpClient ) {}
|
|
15 | 17 |
|
16 | 18 |
searchProjectsByFunder(keyword:string, funderId:string, properties:EnvProperties ):any { |
17 | 19 |
this.ready = false; |
... | ... | |
30 | 32 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() |
31 | 33 |
.then(request => |
32 | 34 |
{ |
33 |
request = request.json().results; |
|
35 |
//request = request.json().results; |
|
36 |
request = request['results']; |
|
34 | 37 |
this.ready = true; |
35 | 38 |
return this.parse(request,"oaf:project","project"); |
36 | 39 |
}).catch((ex) => { |
... | ... | |
71 | 74 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() |
72 | 75 |
.then(request => |
73 | 76 |
{ |
74 |
request = request.json().results; |
|
77 |
//request = request.json().results; |
|
78 |
request = request['results']; |
|
75 | 79 |
//console.log(request); |
76 | 80 |
this.ready = true; |
77 | 81 |
return this.parse(request,"oaf:organization","organization"); |
... | ... | |
124 | 128 |
this.ready = false; |
125 | 129 |
let url = link+"/"+id+"?format=json"; |
126 | 130 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
127 |
.map(request => <any> request.json()) |
|
131 |
//.map(request => <any> request.json())
|
|
128 | 132 |
// .do(res => console.info(res)) |
129 |
.map(request => { |
|
133 |
.pipe(map(request => {
|
|
130 | 134 |
this.ready = true; |
131 | 135 |
return this.parse(request,oafEntityType,type); |
132 |
}).catch((ex) => { |
|
136 |
})) |
|
137 |
.pipe(catchError((ex) => { |
|
133 | 138 |
console.error('An error occured', ex); |
134 | 139 |
return [{id:'-2',label:'Error'}];; |
135 |
}); |
|
140 |
}));
|
|
136 | 141 |
|
137 | 142 |
} |
138 | 143 |
private search (link,keyword,oafEntityType,type, properties:EnvProperties ){ |
... | ... | |
154 | 159 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() |
155 | 160 |
.then(request => |
156 | 161 |
{ |
157 |
request = request.json().results; |
|
162 |
//request = request.json().results; |
|
163 |
request = request['results']; |
|
158 | 164 |
this.ready = true; |
159 | 165 |
return this.parse(request,oafEntityType,type); |
160 | 166 |
}).catch((ex) => { |
... | ... | |
266 | 272 |
return array; |
267 | 273 |
} |
268 | 274 |
|
269 |
private handleError (error: Response) { |
|
275 |
private handleError (error: HttpErrorResponse) {
|
|
270 | 276 |
// in a real world app, we may send the error to some remote logging infrastructure |
271 | 277 |
// instead of just logging it to the console |
272 | 278 |
console.log(error); |
273 |
return Observable.throw(error || 'Server error');
|
|
279 |
return throwError(error || 'Server error');
|
|
274 | 280 |
} |
275 | 281 |
} |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729