Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

searchProjects.service.ts
1 1
import {Injectable} from '@angular/core';
2 2
import {Http, Response} from '@angular/http';
3
import {Observable}     from 'rxjs/Observable';
4
import 'rxjs/add/observable/of';
5
import 'rxjs/add/operator/do';
6
import 'rxjs/add/operator/share';
3
import {HttpClient} from "@angular/common/http";
4
import {Observable}     from 'rxjs';
5

  
6

  
7

  
7 8
import {SearchResult}     from '../utils/entities/searchResult';
8 9
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
9 10
import{EnvProperties} from '../utils/properties/env-properties';
10 11
import {StringUtils} from '../utils/string-utils.class';
12
import {map} from "rxjs/operators";
11 13
@Injectable()
12 14
export class SearchProjectsService {
13 15
    private sizeOfDescription: number = 270;
14 16

  
15
    constructor(private http: Http ) {}
17
    constructor(private http: HttpClient ) {}
16 18

  
17 19
    searchProjects (params: string, refineParams:string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any {
18 20

  
......
29 31

  
30 32

  
31 33
        return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
32
                    .map(res => <any> res.json())
33
                    .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]);
34
                    //.map(res => <any> res.json())
35
                    .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
34 36
    }
35 37
    getProjectsforDataProvider (datasourceId: string, page: number, size: number, properties:EnvProperties  ):any {
36 38
      let url = properties.searchResourcesAPIURL;
......
46 48
      url += "&format=json";
47 49

  
48 50
      return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
49
      .map(res => <any> res.json())
50
      .map(res => [res['meta'].total, this.parseResults(res['results'])]);
51
      //.map(res => <any> res.json())
52
      .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
51 53
    }
52 54
    advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties  ):any {
53 55
      let url = properties.searchResourcesAPIURL;
......
62 64
      url += "&page="+(page-1)+"&size="+size;
63 65
      url += "&format=json";
64 66
      return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
65
      .map(res => <any> res.json())
66
      .map(res => [res['meta'].total, this.parseResults(res['results'])]);
67
      //.map(res => <any> res.json())
68
      .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
67 69
    }
68 70
    getProjectsForOrganizations (organizationId: string, filterquery: string, page: number, size: number, refineFields:string[] , properties:EnvProperties  ):any {
69 71
      let url = properties.searchResourcesAPIURL;
......
84 86
      url += "&format=json";
85 87

  
86 88
      return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
87
                  .map(res => <any> res.json())
88
                  .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]);
89
                  //.map(res => <any> res.json())
90
                  .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
89 91
    }
90 92
    getFunders(properties:EnvProperties ):any {
91 93
       let url = properties.searchAPIURLLAst+"projects?refine=true&fields=funder&size=0"+ "&format=json";;
92 94

  
93 95
       return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
94
                   .map(res => <any> res.json())
95
                   .map(res => [res['meta'].total, res['refineResults']['funder']]);
96
                   //.map(res => <any> res.json())
97
                   .pipe(map(res => [res['meta'].total, res['refineResults']['funder']]));
96 98

  
97 99

  
98 100
      }
......
103 105

  
104 106
         return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise()
105 107
                    .then(request =>{
106
                      return (request.json().response.results)?request.json().response.results.result:request.json().response.result;
108
                      //return (request.json().response.results)?request.json().response.results.result:request.json().response.result;
109
                      return (request['response'].results)?request['response'].results.result:request['response'].result;
107 110

  
108
                }) ;
111
                    }) ;
109 112
        }
110 113
    parseResults(data: any): SearchResult[] {
111 114
        let results: SearchResult[] = [];
......
219 222
    numOfProjects(url: string, properties:EnvProperties ):any {
220 223

  
221 224
      return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
222
                  .map(res => <any> res.json())
223
                  .map(res => res.total);
225
                  //.map(res => <any> res.json())
226
                  .pipe(map(res => res['total']));
224 227
    }
225 228

  
226 229
    numOfEntityProjects(id: string, entity: string, properties:EnvProperties ):any {

Also available in: Unified diff