2019-03-18 16:02:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-10-08 12:56:04 +02:00
|
|
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
2019-10-08 15:37:11 +02:00
|
|
|
import {Observable, throwError} from 'rxjs';
|
2019-03-18 16:02:46 +01:00
|
|
|
import {CustomOptions} from './servicesUtils/customOptions.class';
|
2019-10-08 16:16:15 +02:00
|
|
|
import {CustomizationOptions} from '../connect/community/CustomizationOptions';
|
[Trunk | Library]:
1. community.service.ts: Mark unused method "isSubscribedToCommunity()" as "deprecated" (This service calls community API - made in Italy, not uoa-admin-tools - made in Greece).
2. connectSubscriber.guard.ts: Call "isSubscribedToCommunity()" method from "subscribe.service.ts" (not "community.service.ts").
3. curator.service.ts: getCurators(properties: EnvProperties, url: string) --> getCurators(properties: EnvProperties, emails: string): Build path for request in service.
4. email.service.ts: Build request path in service
a. sendEmail(url: string, email: Email) --> sendEmail(properties: EnvProperties, email: Email)
b. contact(url: string, email: Email, recaptcha: string = null) --> contact(properties: EnvProperties, email: Email, recaptcha: string = null)
c. Create method "notifyForNewManagers(properties: EnvProperties, communityId: string, email: Email)" (sendEmail was used for everything).
5. subscribe.service.ts:
a. subscribeToCommunity(pid: string, email: string, url: string) --> subscribeToCommunity(properties: EnvProperties, pid: string, email: string)
b. unSubscribeToCommunity(pid: string, email: string, url: string) --> unSubscribeToCommunity(properties: EnvProperties, pid: string, email: string)
6. layout.service.ts: getLayout(communityId: string, url: string) --> getLayout(properties: EnvProperties, communityId: string): Build path for request in service.
7. feedback.component.ts: In method "contact" from "emailService", build request path in service.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58420 d315682c-612b-4755-9ff5-7f18f6832af3
2020-04-07 16:57:26 +02:00
|
|
|
import {EnvProperties} from "../utils/properties/env-properties";
|
2019-03-18 16:02:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class LayoutService {
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient) {
|
2019-03-18 16:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:25:41 +02:00
|
|
|
saveLayout(properties: EnvProperties, pid: string, layout: CustomizationOptions): Observable<CustomizationOptions> {
|
2019-03-18 16:02:46 +01:00
|
|
|
LayoutService.removeNulls(layout);
|
2020-09-24 13:18:24 +02:00
|
|
|
return this.http.post<CustomizationOptions>(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/'
|
2020-04-08 13:25:41 +02:00
|
|
|
+ pid + '/layout', layout, CustomOptions.getAuthOptionsWithBody());
|
2019-03-18 16:02:46 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 13:25:41 +02:00
|
|
|
getLayout(properties: EnvProperties, pid: string): Observable<CustomizationOptions> {
|
2020-09-24 13:18:24 +02:00
|
|
|
return this.http.get<CustomizationOptions>(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/'
|
|
|
|
+ pid + '/layout');
|
2019-03-18 16:02:46 +01:00
|
|
|
}
|
2019-07-22 16:15:23 +02:00
|
|
|
|
2019-10-08 12:56:04 +02:00
|
|
|
mockLayout(): any {
|
|
|
|
return this.http.get('./assets/customizationOptions.json') ;
|
2019-07-22 16:15:23 +02:00
|
|
|
|
|
|
|
}
|
2019-03-18 16:02:46 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
private handleError(error: HttpErrorResponse) {
|
2019-03-18 16:02:46 +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 15:20:36 +02:00
|
|
|
return throwError(error.error || 'Server error');
|
2019-03-18 16:02:46 +01:00
|
|
|
}
|
|
|
|
}
|