Project

General

Profile

« Previous | Next » 

Revision 55573

[angular7: Library]: Move uoa-services-library project to Angular 7 (using webpack)

View differences:

contexts.service.ts
1

  
2
import {throwError as observableThrowError, Observable} from 'rxjs';
1 3
import {Injectable} from '@angular/core';
2 4
import {Jsonp, URLSearchParams, RequestOptions, Headers} from '@angular/http';
3 5
import {Http, Response} from '@angular/http';
4
import {Observable}     from 'rxjs/Observable';
6
import { HttpClient } from '@angular/common/http';
5 7
import {Claim}           from '../claim';
6 8
import {AutoCompleteValue} from '../../../searchPages/searchUtils/searchHelperClasses.class';
7
import 'rxjs/add/observable/of';
8
import 'rxjs/add/operator/do';
9
import 'rxjs/add/operator/share';
9

  
10

  
11

  
12
import {catchError, map} from "rxjs/operators";
13

  
10 14
import { COOKIE  } from '../../../login/utils/helper.class';
11 15
@Injectable()
12 16
export class ContextsService {
13
  constructor(private http: Http ) {
17
  constructor(private http: HttpClient ) {
14 18
  }
15 19

  
16 20
  public getCommunities( apiUrl:string):any {
......
19 23
  let key = url;
20 24
    //console.info('ContextsService: request communities  '+url);
21 25
      return this.http.get(url)
22
                    .map(res => <any> res.json()).map(res => this.parseCommunities(res) )
26
                    //.map(res => <any> res.json())
27
                    .pipe(map(res => this.parseCommunities(res) ))
23 28
                    // .do(request => console.info("Get claims: offset = "))
24
                    .catch(this.handleError);
29
                    .pipe(catchError(this.handleError));
25 30
  }
26 31
  parseCommunities(data){
27 32
    var communities = [];
......
40 45

  
41 46

  
42 47
      return this.http.get(url)
43
                    .map(request => <any> request.json())
48
                    //.map(request => <any> request.json())
44 49
                    // .do(request => console.info("Get claims: offset = " ))
45
                    .catch(this.handleError);;
50
                    .pipe(catchError(this.handleError));
46 51
  }
47 52
  public getConcepts(categoryId :string, keyword: string, parsing:boolean, apiUrl:string):any {
48 53
    //console.info('ContextsService:  request concept for category  with id '+categoryId + ' and keyword '+ keyword);
......
51 56

  
52 57

  
53 58
      return this.http.get(url )
54
                    .map(request => <any> request.json())
55
                    .catch(this.handleError)
56
                    .map(res => (parsing)?this.parse(res):res);
59
                    //.map(request => <any> request.json())
60
                    .pipe(catchError(this.handleError))
61
                    .pipe(map(res => (parsing)?this.parse(res):res));
57 62
                    // .do(res => console.info("Result is "+ res.length ));
58 63
  }
59 64
  public getSubConcepts(subConceptID :string, keyword: string, parsing:boolean, apiUrl:string):any {
......
63 68

  
64 69

  
65 70
      return this.http.get(url )
66
                    .map(request => <any> request.json())
67
                    .catch(this.handleError)
68
                    .map(res => (parsing)?this.parseSubConcepts(res):res);
71
                    //.map(request => <any> request.json())
72
                    .pipe(catchError(this.handleError))
73
                    .pipe(map(res => (parsing)?this.parseSubConcepts(res):res));
69 74
                    // .do(res => console.info("Result is "+ res.length ));
70 75
  }
71 76
  parse (data: any):any {
......
118 123
    // in a real world app, we may send the error to some remote logging infrastructure
119 124
    // instead of just logging it to the console
120 125
    console.log(error);
121
    return Observable.throw(error  || 'Server error');
126
    return observableThrowError(error  || 'Server error');
122 127
  }
123 128
  private getAuthOptions():RequestOptions{
124 129
  let headers = new Headers();

Also available in: Unified diff