2017-09-22 12:26:08 +02:00
|
|
|
/**
|
|
|
|
* Created by stefania on 7/13/17.
|
|
|
|
*/
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
import { Page } from "../domain/page";
|
2017-12-13 12:15:19 +01:00
|
|
|
import { PageHelpContent } from "../domain/page-help-content";
|
|
|
|
import { Community } from "../domain/community";
|
|
|
|
import { Entity } from "../domain/entity";
|
2018-02-06 12:06:43 +01:00
|
|
|
import { DivId } from "../domain/divId";
|
|
|
|
import { DivHelpContent } from "../domain/div-help-content";
|
2018-03-05 17:10:19 +01:00
|
|
|
import {CommunityStatistics} from "../domain/statistics-classes";
|
2017-09-22 12:26:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HelpContentService {
|
|
|
|
|
|
|
|
constructor(private http:Http) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private _helpContentUrl = process.env.API_ENDPOINT;
|
|
|
|
|
|
|
|
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") HelpContentService.removeNulls(obj[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 12:06:43 +01:00
|
|
|
getDivIdsFull(community_pid: string, page_id: string) {
|
|
|
|
if(page_id) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'divFull?community='+community_pid+'&page='+page_id)
|
|
|
|
.map(res => <Array<DivId>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
} else {
|
|
|
|
return this.http.get(this._helpContentUrl + 'divFull?community='+community_pid)
|
|
|
|
.map(res => <Array<DivId>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDivId(divId: DivId) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(divId);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'div/update', JSON.stringify(divId), options)
|
|
|
|
.map(res => <DivId> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDivId(divId: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'div/'+divId)
|
|
|
|
.map(res => <DivId> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveDivId(divId: DivId) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(divId);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'div/save', JSON.stringify(divId), options)
|
|
|
|
.map(res => <DivId> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommunitiesWithDivId() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community?div=true')
|
|
|
|
.map(res => <Array<Community>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommunityPagesWithDivId(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community/'+community_pid+'/pages?div=true')
|
|
|
|
.map(res => <Array<Page>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommunityDivHelpContents(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'divhelpcontent?community='+community_pid)
|
|
|
|
.map(res => <Array<DivHelpContent>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDivHelpContent(id : string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'divhelpcontent/' + id)
|
|
|
|
.map(res => <DivHelpContent> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent) {
|
|
|
|
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(divHelpContent);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'divhelpcontent', JSON.stringify(divHelpContent), options)
|
|
|
|
.map(res => <DivHelpContent> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDivIds(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'div/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDivHelpContents(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'divhelpcontent/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleDivHelpContents(ids : string[],status : boolean) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'divhelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), options)
|
|
|
|
//.map( res => <string[]> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPagesWithDivIds(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'div/pages?communtity='+community_pid)
|
|
|
|
.map(res => <Map<string, Set<string>>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
getPages() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'page')
|
|
|
|
.map(res => <Array<Page>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-20 15:26:30 +01:00
|
|
|
getPage(pageId:string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'page/'+pageId)
|
|
|
|
.map(res => <Page> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
getCommunities() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community')
|
|
|
|
.map(res => <Array<Community>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunity(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community/'+community_pid)
|
2018-01-08 10:29:40 +01:00
|
|
|
.map(res => <Community> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-20 15:26:30 +01:00
|
|
|
getCommunitiesFull() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'communityFull')
|
|
|
|
.map(res => <Array<Community>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunityFull(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'communityFull/'+community_pid)
|
2017-12-20 15:26:30 +01:00
|
|
|
.map(res => <Community> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveCommunity(community: Community) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(community);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'community/save', JSON.stringify(community), options)
|
|
|
|
.map(res => <Community> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCommunity(community: Community) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(community);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'community/update', JSON.stringify(community), options)
|
|
|
|
.map(res => <Community> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteCommunities(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'community/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunityPages(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community/'+community_pid+'/pages')
|
2017-12-13 12:15:19 +01:00
|
|
|
.map(res => <Array<Page>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunityPagesByType(community_pid: string, params: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community/'+community_pid+'/pages'+params)
|
2017-12-20 15:26:30 +01:00
|
|
|
.map(res => <Array<Page>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
getEntities() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'entity')
|
|
|
|
.map(res => <Array<Entity>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunityEntities(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'community/'+community_pid+'/entities')
|
2017-12-13 12:15:19 +01:00
|
|
|
.map(res => <Array<Entity>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
saveEntity(entity: Entity) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(entity);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'entity/save', JSON.stringify(entity), options)
|
|
|
|
.map(res => <Entity> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateEntity(entity: Entity) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(entity);
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'entity/update', JSON.stringify(entity), options)
|
|
|
|
.map(res => <Entity> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-08 10:29:40 +01:00
|
|
|
// toggleEntity(selectedCommunityId: string, id : string,status : boolean) {
|
|
|
|
// let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
// let options = new RequestOptions({headers: headers});
|
|
|
|
//
|
|
|
|
// return this.http.post(this._helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options)
|
|
|
|
// .catch(this.handleError);
|
|
|
|
// }
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
toggleEntities(selectedCommunityPid: string, ids : string[],status : boolean) {
|
2017-12-13 12:15:19 +01:00
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
return this.http.post(this._helpContentUrl +'community/'+selectedCommunityPid+ '/entity/toggle?status='+ status.toString(), JSON.stringify(ids), options)
|
2018-01-08 10:29:40 +01:00
|
|
|
//.map( res => <string[]> res.json())
|
2017-12-13 12:15:19 +01:00
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteEntities(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'entity/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
toggleEntityOfPage(pageId: string, entityId : string,status : boolean) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
savePage(page: Page) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(page);
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
return this.http.post(this._helpContentUrl + 'page/save', JSON.stringify(page), options)
|
2017-09-22 12:26:08 +02:00
|
|
|
.map(res => <Page> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePage(page: Page) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(page);
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
return this.http.post(this._helpContentUrl + 'page/update', JSON.stringify(page), options)
|
2017-09-22 12:26:08 +02:00
|
|
|
.map(res => <Page> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
togglePages(selectedCommunityPid: string, ids : string[],status : boolean) {
|
2017-12-13 12:15:19 +01:00
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
return this.http.post(this._helpContentUrl + 'community/'+selectedCommunityPid+'/page/toggle?status='+ status.toString(),JSON.stringify(ids), options)
|
2017-12-13 12:15:19 +01:00
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
deletePages(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'page/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPageHelpContents() {
|
|
|
|
return this.http.get(this._helpContentUrl + 'pagehelpcontent')
|
|
|
|
.map(res => <Array<PageHelpContent>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
getCommunityPageHelpContents(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'pagehelpcontent?community='+community_pid)
|
2017-12-13 12:15:19 +01:00
|
|
|
.map(res => <Array<PageHelpContent>> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
getPageHelpContent(id : string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'pagehelpcontent/' + id)
|
|
|
|
.map(res => <PageHelpContent> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
savePageHelpContent(pageHelpContent: PageHelpContent) {
|
|
|
|
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(pageHelpContent);
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
return this.http.post(this._helpContentUrl + 'pagehelpcontent/save', JSON.stringify(pageHelpContent), options)
|
2017-09-22 12:26:08 +02:00
|
|
|
.map(res => <PageHelpContent> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePageHelpContent(pageHelpContent: PageHelpContent) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
HelpContentService.removeNulls(pageHelpContent);
|
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
return this.http.post(this._helpContentUrl + 'pagehelpcontent/update', JSON.stringify(pageHelpContent), options)
|
2017-09-22 12:26:08 +02:00
|
|
|
.map(res => <PageHelpContent> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
deletePageHelpContents(ids : string[]) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'pagehelpcontent/delete',JSON.stringify(ids), options)
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePageHelpContents(ids : string[],status : boolean) {
|
|
|
|
let headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
let options = new RequestOptions({headers: headers});
|
|
|
|
|
|
|
|
return this.http.post(this._helpContentUrl + 'pagehelpcontent/toggle?status='+ status.toString(), JSON.stringify(ids), options)
|
2017-12-13 12:15:19 +01:00
|
|
|
//.map( res => <string[]> res.json())
|
2017-09-22 12:26:08 +02:00
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleError(error: Response) {
|
|
|
|
// 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 Observable.throw(error.json().error || 'Server error');
|
|
|
|
}
|
2017-12-13 12:15:19 +01:00
|
|
|
|
2018-03-06 15:33:59 +01:00
|
|
|
getDataProviders() {
|
|
|
|
return this.http.get('https://beta.services.openaire.eu/search/v2/api/datasources?format=json').map(res => <any> res.json()).map(res => res.results).do(res => {console.log(res)}).catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2018-03-05 17:10:19 +01:00
|
|
|
getStatistics(community_pid: string) {
|
|
|
|
return this.http.get(this._helpContentUrl + 'statistics/'+community_pid)
|
|
|
|
.map(res => <CommunityStatistics> res.json())
|
|
|
|
.catch(this.handleError);
|
|
|
|
}
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
}
|