Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

layout.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 {CustomOptions} from './servicesUtils/customOptions.class';
6
import {catchError} from "rxjs/operators";
5 7

  
6 8
@Injectable()
7 9
export class LayoutService {
8
    constructor(private http: Http) {
10
    constructor(private http: HttpClient) {
9 11
    }
10 12

  
11 13
    static removeNulls(obj) {
......
22 24
    saveLayout(pid: string, url: string, layout: any) {
23 25
        LayoutService.removeNulls(layout);
24 26
        return this.http.post(url + 'community/' + pid + '/updateLayout', JSON.stringify(layout), CustomOptions.getAuthOptionsWithBody())
25
            .map(res => res.json())
26
            .catch(this.handleError);
27
            //.map(res => res.json())
28
            .pipe(catchError(this.handleError));
27 29
    }
28 30

  
29 31
    getLayout(pid: string, url: string) {
30 32
        return this.http.get(url + 'community/' + pid + '/layout')
31
            .map(res => res.json())
32
            .catch(this.handleError);
33
            //.map(res => res.json())
34
            .pipe(catchError(this.handleError));
33 35
    }
34 36

  
35 37
    loadDefaultLayout(pid: string, url: string) {
36 38
        return this.http.post(url + 'community/' + pid + '/resetLayout', null, CustomOptions.getAuthOptionsWithBody())
37
            .map(res => res.json())
38
            .catch(this.handleError);
39
            //.map(res => res.json())
40
            .pipe(catchError(this.handleError));
39 41
    }
40 42

  
41
    private handleError(error: Response) {
43
    private handleError(error: HttpErrorResponse) {
42 44
        // in a real world app, we may send the error to some remote logging infrastructure
43 45
        // instead of just logging it to the console
44 46
        console.error(error);
45
        return Observable.throw(error.json().error || 'Server error');
47
        return throwError(error.error || 'Server error');
46 48
    }
47 49
}

Also available in: Unified diff