import {Injectable} from '@angular/core'; import {HttpClient, HttpErrorResponse} from '@angular/common/http'; import {Observable, throwError} from 'rxjs'; import {CustomOptions} from './servicesUtils/customOptions.class'; import {CustomizationOptions} from '../connect/community/CustomizationOptions'; import {EnvProperties} from "../utils/properties/env-properties"; @Injectable() export class LayoutService { constructor(private http: HttpClient) { } static removeNulls(obj) { const isArray = obj instanceof Array; for (let k in obj) { if (obj[k] === null || obj[k] === '') { isArray ? obj.splice(k, 1) : delete obj[k]; } else if (typeof obj[k] === 'object') { LayoutService.removeNulls(obj[k]); } } } saveLayout(properties: EnvProperties, pid: string, layout: CustomizationOptions): Observable { LayoutService.removeNulls(layout); return this.http.post(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/' + pid + '/layout', layout, CustomOptions.getAuthOptionsWithBody()); } getLayout(properties: EnvProperties, pid: string): Observable { return this.http.get(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/' + pid + '/layout'); } mockLayout(): any { return this.http.get('./assets/customizationOptions.json') ; } private handleError(error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.error(error); return throwError(error.error || 'Server error'); } }