2018-10-30 16:31:16 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-06-03 16:52:33 +02:00
|
|
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
|
|
|
import { Observable } from 'rxjs';
|
2018-10-30 16:31:16 +01:00
|
|
|
import {COOKIE} from "../../openaireLibrary/login/utils/helper.class"
|
|
|
|
import { HtmlPageContent } from "../../domain/html-page-content";
|
2019-01-16 12:29:26 +01:00
|
|
|
import { CustomOptions } from '../../openaireLibrary/services/servicesUtils/customOptions.class';
|
2019-06-03 16:52:33 +02:00
|
|
|
import {catchError} from "rxjs/operators";
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HtmlPageContentService {
|
|
|
|
|
2019-06-03 16:52:33 +02:00
|
|
|
constructor(private http:HttpClient) {
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static removeNulls(obj){
|
|
|
|
var isArray = obj instanceof Array;
|
|
|
|
for (var k in obj){
|
|
|
|
if (obj[k]===null || obj[k]==='') isArray ? obj.splice(k,1) : delete obj[k];
|
|
|
|
else if (typeof obj[k]=="object") HtmlPageContentService.removeNulls(obj[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getHtmlPageContent(community : string, page: string, adminToolsAPIURL:string) {
|
2019-06-03 16:52:33 +02:00
|
|
|
return this.http.get<Array<HtmlPageContent>>(adminToolsAPIURL + 'htmlpagecontent?community=' + community + "&page="+page)
|
|
|
|
//.map(res => <HtmlPageContent> res.json())
|
|
|
|
.pipe(catchError(this.handleError));
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateHtmlPageContent(htmlPageContent: HtmlPageContent, adminToolsAPIURL:string) {
|
2019-01-16 12:29:26 +01:00
|
|
|
//let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
//let options = new RequestOptions({headers: headers});
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
HtmlPageContentService.removeNulls(htmlPageContent);
|
|
|
|
|
2019-06-03 16:52:33 +02:00
|
|
|
return this.http.post<HtmlPageContent>(adminToolsAPIURL + 'htmlpagecontent/update', JSON.stringify(htmlPageContent), CustomOptions.getAuthOptionsWithBody())
|
2019-01-16 12:29:26 +01:00
|
|
|
//return this.http.post(adminToolsAPIURL + 'htmlpagecontent/update', JSON.stringify(htmlPageContent), options)
|
2019-06-03 16:52:33 +02:00
|
|
|
//.map(res => <HtmlPageContent> res.json())
|
|
|
|
.pipe(catchError(this.handleError));
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 16:52:33 +02:00
|
|
|
private handleError(error: HttpErrorResponse) {
|
2018-10-30 16:31:16 +01:00
|
|
|
// 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);
|
2019-06-03 16:52:33 +02:00
|
|
|
return Observable.throw(error.error || 'Server error');
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|