1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
3
|
import {Observable, throwError} from 'rxjs';
|
4
|
import {CustomOptions} from './servicesUtils/customOptions.class';
|
5
|
import {CustomizationOptions, Layout} from '../connect/community/CustomizationOptions';
|
6
|
import {EnvProperties} from "../utils/properties/env-properties";
|
7
|
|
8
|
@Injectable()
|
9
|
export class LayoutService {
|
10
|
constructor(private http: HttpClient) {
|
11
|
}
|
12
|
|
13
|
static removeNulls(obj) {
|
14
|
const isArray = obj instanceof Array;
|
15
|
for (let k in obj) {
|
16
|
if (obj[k] === null || obj[k] === '') {
|
17
|
isArray ? obj.splice(k, 1) : delete obj[k];
|
18
|
} else if (typeof obj[k] === 'object') {
|
19
|
LayoutService.removeNulls(obj[k]);
|
20
|
}
|
21
|
}
|
22
|
}
|
23
|
|
24
|
saveLayout(properties: EnvProperties, pid: string, layout: Layout): Observable<Layout> {
|
25
|
LayoutService.removeNulls(layout);
|
26
|
return this.http.post<Layout>(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/'
|
27
|
+ pid + '/layout', layout, CustomOptions.getAuthOptionsWithBody());
|
28
|
}
|
29
|
|
30
|
getLayout(properties: EnvProperties, pid: string): Observable<Layout> {
|
31
|
return this.http.get<Layout>(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/'
|
32
|
+ pid + '/layout');
|
33
|
}
|
34
|
|
35
|
mockLayout(): any {
|
36
|
return this.http.get('./assets/customizationOptions.json') ;
|
37
|
|
38
|
}
|
39
|
|
40
|
private handleError(error: HttpErrorResponse) {
|
41
|
// in a real world app, we may send the error to some remote logging infrastructure
|
42
|
// instead of just logging it to the console
|
43
|
console.error(error);
|
44
|
return throwError(error.error || 'Server error');
|
45
|
}
|
46
|
}
|