1
|
/**
|
2
|
* Created by stefania on 7/13/17.
|
3
|
*/
|
4
|
import {Injectable} from '@angular/core';
|
5
|
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
|
6
|
import {Observable, throwError} from 'rxjs';
|
7
|
import {Page} from '../domain/page';
|
8
|
import {PageHelpContent} from '../domain/page-help-content';
|
9
|
import {Portal} from '../domain/portal';
|
10
|
import {Entity} from '../domain/entity';
|
11
|
import {DivId} from '../domain/divId';
|
12
|
import {DivHelpContent} from '../domain/div-help-content';
|
13
|
import {StatisticsDisplay, StatisticsSummary} from '../openaireLibrary/connect/statistics/statisticsEntities';
|
14
|
import {CustomOptions} from '../openaireLibrary/services/servicesUtils/customOptions.class';
|
15
|
import {catchError, map} from 'rxjs/operators';
|
16
|
import {properties} from '../../environments/environment';
|
17
|
|
18
|
|
19
|
@Injectable()
|
20
|
export class HelpContentService {
|
21
|
|
22
|
constructor(private http:HttpClient) {
|
23
|
}
|
24
|
|
25
|
static removeNulls(obj){
|
26
|
var isArray = obj instanceof Array;
|
27
|
for (var k in obj){
|
28
|
if (obj[k]===null || obj[k]==='') isArray ? obj.splice(k,1) : delete obj[k];
|
29
|
else if (typeof obj[k]=="object") HelpContentService.removeNulls(obj[k]);
|
30
|
}
|
31
|
}
|
32
|
|
33
|
getEntities(helpContentUrl:string) {
|
34
|
return this.http.get<Array<Entity>>(helpContentUrl + 'entity')
|
35
|
//.map(res => <Array<Entity>> res.json())
|
36
|
.pipe(catchError(this.handleError));
|
37
|
}
|
38
|
|
39
|
saveEntity(entity: Entity, helpContentUrl:string) {
|
40
|
HelpContentService.removeNulls(entity);
|
41
|
|
42
|
return this.http.post<Entity>(helpContentUrl + 'entity/save', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody())
|
43
|
//.map(res => <Entity> res.json())
|
44
|
.pipe(catchError(this.handleError));
|
45
|
}
|
46
|
|
47
|
updateEntity(entity: Entity, helpContentUrl:string) {
|
48
|
HelpContentService.removeNulls(entity);
|
49
|
|
50
|
return this.http.post<Entity>(helpContentUrl + 'entity/update', JSON.stringify(entity), CustomOptions.getAuthOptionsWithBody())
|
51
|
//.map(res => <Entity> res.json())
|
52
|
.pipe(catchError(this.handleError));
|
53
|
}
|
54
|
|
55
|
deleteEntities(ids : string[], helpContentUrl:string) {
|
56
|
return this.http.post(helpContentUrl + 'entity/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
57
|
.pipe(catchError(this.handleError));
|
58
|
}
|
59
|
|
60
|
// toggleEntity(selectedCommunityId: string, id : string,status : boolean) {
|
61
|
// let headers = new Headers({'Content-Type': 'application/json'});
|
62
|
// let options = new RequestOptions({headers: headers});
|
63
|
//
|
64
|
// return this.http.post(helpContentUrl + 'community/'+selectedCommunityId+'/entity/toggle?status='+ status.toString()+'&entityId='+id.toString(), options)
|
65
|
// .catch(this.handleError);
|
66
|
// }
|
67
|
|
68
|
getCommunityEntities(pid: string, helpContentUrl:string) {
|
69
|
return this.http.get<Array<Entity>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/entities')
|
70
|
//.map(res => <Array<Entity>> res.json())
|
71
|
.pipe(catchError(this.handleError));
|
72
|
}
|
73
|
|
74
|
toggleEntities(pid: string, ids : string[],status : boolean, helpContentUrl:string) {
|
75
|
|
76
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/'+pid+ '/entity/toggle?status='+ status.toString(),
|
77
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
78
|
//.map( res => <string[]> res.json())
|
79
|
.pipe(catchError(this.handleError));
|
80
|
}
|
81
|
|
82
|
// unused
|
83
|
toggleEntityOfPage(pageId: string, entityId : string,status : boolean, helpContentUrl:string) {
|
84
|
return this.http.post(helpContentUrl + 'page/'+pageId+'/entity/toggle?status='+ status.toString()+'&entityId='+entityId.toString(),
|
85
|
CustomOptions.getAuthOptionsWithBody())
|
86
|
.pipe(catchError(this.handleError));
|
87
|
}
|
88
|
|
89
|
// getDivIdsFull(page_id: string, helpContentUrl:string, pid: string = null) {
|
90
|
// let parameters: string = "";
|
91
|
// if(page_id || pid) {
|
92
|
// parameters = "?";
|
93
|
// if(page_id) {
|
94
|
// parameters += "&page="+page_id;
|
95
|
// }
|
96
|
// if(pid) {
|
97
|
// parameters += "&portal="+pid;
|
98
|
// }
|
99
|
// }
|
100
|
//
|
101
|
// return this.http.get<Array<DivId>>(helpContentUrl + 'div/full'+parameters)
|
102
|
// //.map(res => <Array<DivId>> res.json())
|
103
|
// .pipe(catchError(this.handleError));
|
104
|
// }
|
105
|
|
106
|
// Replacing getDivIdsFull
|
107
|
getAllDivIdsFull(helpContentUrl:string) {
|
108
|
return this.http.get<Array<DivId>>(helpContentUrl + 'div/full')
|
109
|
//.map(res => <Array<DivId>> res.json())
|
110
|
.pipe(catchError(this.handleError));
|
111
|
}
|
112
|
|
113
|
getDivIdsFullByPortal(page_id: string, helpContentUrl:string, pid: string) {
|
114
|
let parameters: string = page_id ? "?&page="+page_id : "";
|
115
|
|
116
|
return this.http.get<Array<DivId>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid + '/div/full'+parameters)
|
117
|
.pipe(catchError(this.handleError));
|
118
|
}
|
119
|
// End of replacing getDivIdsFull
|
120
|
|
121
|
// unused
|
122
|
getDivId(divId: string, helpContentUrl:string) {
|
123
|
return this.http.get<DivId>(helpContentUrl + 'div/'+divId)
|
124
|
//.map(res => <DivId> res.json())
|
125
|
.pipe(catchError(this.handleError));
|
126
|
}
|
127
|
|
128
|
getDivIdFull(divId: string, helpContentUrl:string, pid: string) {
|
129
|
return this.http.get<DivId>(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/div/'+divId+"/full")
|
130
|
//.map(res => <DivId> res.json())
|
131
|
.pipe(catchError(this.handleError));
|
132
|
}
|
133
|
|
134
|
updateDivId(divId: DivId, helpContentUrl:string) {
|
135
|
HelpContentService.removeNulls(divId);
|
136
|
|
137
|
return this.http.post<DivId>(helpContentUrl + 'div/update', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody())
|
138
|
//.map(res => <DivId> res.json())
|
139
|
.pipe(catchError(this.handleError));
|
140
|
}
|
141
|
|
142
|
saveDivId(divId: DivId, helpContentUrl:string) {
|
143
|
HelpContentService.removeNulls(divId);
|
144
|
|
145
|
return this.http.post<DivId>(helpContentUrl + 'div/save', JSON.stringify(divId), CustomOptions.getAuthOptionsWithBody())
|
146
|
//.map(res => <DivId> res.json())
|
147
|
.pipe(catchError(this.handleError));
|
148
|
}
|
149
|
|
150
|
deleteDivIds(ids : string[], helpContentUrl:string) {
|
151
|
return this.http.post(helpContentUrl + 'div/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
152
|
.pipe(catchError(this.handleError));
|
153
|
}
|
154
|
|
155
|
getPageIdsFromDivIds(pid: string, helpContentUrl:string) {
|
156
|
//let parameters = (pid ? "?portal="+pid : "");
|
157
|
return this.http.get<Array<string>>(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/div/pages')
|
158
|
//.map(res => <Map<string, Set<string>>> res.json())
|
159
|
.pipe(catchError(this.handleError));
|
160
|
}
|
161
|
|
162
|
/*
|
163
|
getCommunitiesWithDivId(helpContentUrl:string) {
|
164
|
return this.http.get(helpContentUrl + 'community?div=true')
|
165
|
.map(res => <Array<Portal>> res.json())
|
166
|
.catch(this.handleError);
|
167
|
}
|
168
|
*/
|
169
|
|
170
|
getCommunityDivHelpContents(pid: string, helpContentUrl:string) {
|
171
|
return this.http.get<Array<DivHelpContent>>(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/divhelpcontent')
|
172
|
//.map(res => <Array<DivHelpContent>> res.json())
|
173
|
.pipe(catchError(this.handleError));
|
174
|
}
|
175
|
|
176
|
getDivHelpContent(id : string, helpContentUrl:string, pid: string) {
|
177
|
return this.http.get<DivHelpContent>(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/divhelpcontent/' + id)
|
178
|
//.map(res => <DivHelpContent> res.json())
|
179
|
.pipe(catchError(this.handleError));
|
180
|
}
|
181
|
|
182
|
// unused
|
183
|
insertOrUpdateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string, pid: string) {
|
184
|
HelpContentService.removeNulls(divHelpContent);
|
185
|
|
186
|
return this.http.post<DivHelpContent>(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/divhelpcontent',
|
187
|
JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody())
|
188
|
//.map(res => <DivHelpContent> res.json())
|
189
|
.pipe(catchError(this.handleError));
|
190
|
}
|
191
|
|
192
|
saveDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string, pid: string) {
|
193
|
HelpContentService.removeNulls(divHelpContent);
|
194
|
|
195
|
return this.http.post<DivHelpContent>(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/divhelpcontent/save',
|
196
|
JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody())
|
197
|
.pipe(catchError(this.handleError));
|
198
|
}
|
199
|
|
200
|
updateDivHelpContent(divHelpContent: DivHelpContent, helpContentUrl:string, pid: string) {
|
201
|
HelpContentService.removeNulls(divHelpContent);
|
202
|
|
203
|
return this.http.post<DivHelpContent>(helpContentUrl + properties.adminToolsPortalType + '/' + pid +'/divhelpcontent/update',
|
204
|
JSON.stringify(divHelpContent), CustomOptions.getAuthOptionsWithBody())
|
205
|
.pipe(catchError(this.handleError));
|
206
|
}
|
207
|
|
208
|
deleteDivHelpContents(ids : string[], helpContentUrl:string, pid: string) {
|
209
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + "/" + pid + '/divhelpcontent/delete',
|
210
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
211
|
.pipe(catchError(this.handleError));
|
212
|
}
|
213
|
|
214
|
toggleDivHelpContents(ids : string[],status : boolean, helpContentUrl:string, pid: string) {
|
215
|
|
216
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/divhelpcontent/toggle?status='+ status.toString(),
|
217
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
218
|
//.map( res => <string[]> res.json())
|
219
|
.pipe(catchError(this.handleError));
|
220
|
}
|
221
|
|
222
|
// unused
|
223
|
getPageHelpContents(helpContentUrl:string) {
|
224
|
return this.http.get<Array<PageHelpContent>>(helpContentUrl + 'pagehelpcontent')
|
225
|
//.map(res => <Array<PageHelpContent>> res.json())
|
226
|
.pipe(catchError(this.handleError));
|
227
|
}
|
228
|
|
229
|
getCommunityPageHelpContents(pid: string, helpContentUrl:string) {
|
230
|
return this.http.get<Array<PageHelpContent>>(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/pagehelpcontent')
|
231
|
//.map(res => <Array<PageHelpContent>> res.json())
|
232
|
.pipe(catchError(this.handleError));
|
233
|
}
|
234
|
|
235
|
getPageHelpContent(id : string, helpContentUrl:string, pid: string) {
|
236
|
return this.http.get<PageHelpContent>(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/pagehelpcontent/' + id)
|
237
|
//.map(res => <PageHelpContent> res.json())
|
238
|
.pipe(catchError(this.handleError));
|
239
|
}
|
240
|
|
241
|
savePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string, pid: string) {
|
242
|
HelpContentService.removeNulls(pageHelpContent);
|
243
|
|
244
|
return this.http.post<PageHelpContent>(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/pagehelpcontent/save',
|
245
|
JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody())
|
246
|
//.map(res => <PageHelpContent> res.json())
|
247
|
.pipe(catchError(this.handleError));
|
248
|
}
|
249
|
|
250
|
updatePageHelpContent(pageHelpContent: PageHelpContent, helpContentUrl:string, pid: string) {
|
251
|
HelpContentService.removeNulls(pageHelpContent);
|
252
|
|
253
|
return this.http.post<PageHelpContent>(helpContentUrl + properties.adminToolsPortalType + '/' + pid +'/pagehelpcontent/update',
|
254
|
JSON.stringify(pageHelpContent), CustomOptions.getAuthOptionsWithBody())
|
255
|
//.map(res => <PageHelpContent> res.json())
|
256
|
.pipe(catchError(this.handleError));
|
257
|
}
|
258
|
|
259
|
deletePageHelpContents(ids : string[], helpContentUrl:string, pid: string) {
|
260
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/pagehelpcontent/delete',
|
261
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
262
|
.pipe(catchError(this.handleError));
|
263
|
}
|
264
|
|
265
|
togglePageHelpContents(ids : string[],status : boolean, helpContentUrl:string, pid: string) {
|
266
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/pagehelpcontent/toggle?status='+ status.toString(),
|
267
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
268
|
//.map( res => <string[]> res.json())
|
269
|
.pipe(catchError(this.handleError));
|
270
|
}
|
271
|
|
272
|
getCommunityPagesWithDivId(pid: string, helpContentUrl:string) {
|
273
|
return this.http.get<Array<Page>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/pages?div=true')
|
274
|
//.map(res => <Array<Page>> res.json())
|
275
|
.pipe(catchError(this.handleError));
|
276
|
}
|
277
|
|
278
|
// getCommunityPages(pid: string, params: string, helpContentUrl:string) {
|
279
|
// return this.http.get<Array<Page>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/pages'+params, CustomOptions.getAuthOptions())
|
280
|
// //.map(res => <Array<Page>> res.json())
|
281
|
// .pipe(catchError(this.handleError));
|
282
|
// }
|
283
|
|
284
|
getCommunityPagesByRoute(pid: string, route: string, helpContentUrl:string) {
|
285
|
return this.http.get<Array<Page>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/pages'
|
286
|
+ (route ? '?page_route='+route : ''))
|
287
|
.pipe(map(pages => (pages.length>0?pages[0]:null)), catchError(this.handleError));
|
288
|
}
|
289
|
|
290
|
// Replacing getCommunityPages
|
291
|
getCommunityPagesByType(pid: string, type: string, helpContentUrl:string) {
|
292
|
return this.http.get<Array<Page>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/pages'
|
293
|
+ (type ? '?page_type='+type : ''))
|
294
|
.pipe(catchError(this.handleError));
|
295
|
}
|
296
|
// End of replacing getCommunityPages
|
297
|
|
298
|
// Replacing part of getPages (now getAllPages)
|
299
|
getCommunityPagesWithPositions(pid: string, helpContentUrl:string) {
|
300
|
return this.http.get<Array<Page>>(helpContentUrl + properties.adminToolsPortalType + '/'+pid+'/pages?with_positions=true')
|
301
|
//.map(res => <Array<Page>> res.json())
|
302
|
.pipe(catchError(this.handleError));
|
303
|
}
|
304
|
// End of replacing part of getPages (now getAllPages)
|
305
|
|
306
|
getAllPages(helpContentUrl:string) {//,pid:string,with_positions:boolean=null) {
|
307
|
// let parameters: string = "";
|
308
|
// if(pid || with_positions == true || with_positions == false) {
|
309
|
// parameters = "?";
|
310
|
// if(pid) {
|
311
|
// parameters += "&pid="+pid;
|
312
|
// }
|
313
|
// if(with_positions == true || with_positions == false) {
|
314
|
// parameters += "&with_positions="+with_positions;
|
315
|
// }
|
316
|
// }
|
317
|
return this.http.get<Array<Page>>(helpContentUrl + 'page')
|
318
|
//.map(res => <Array<Page>> res.json())
|
319
|
.pipe(catchError(this.handleError));
|
320
|
}
|
321
|
|
322
|
getAllPagesFull(helpContentUrl:string) {
|
323
|
return this.http.get<Array<Page>>(helpContentUrl + 'page/full')//+(pid?("?pid="+pid):""))
|
324
|
//.map(res => <Array<Page>> res.json())
|
325
|
.pipe(catchError(this.handleError));
|
326
|
}
|
327
|
|
328
|
getPageByPortal(pageId:string, helpContentUrl:string, pid: string) {
|
329
|
return this.http.get<Page>(helpContentUrl + properties.adminToolsPortalType + '/' + pid + '/page/'+pageId)
|
330
|
//.map(res => <Page> res.json())
|
331
|
.pipe(catchError(this.handleError));
|
332
|
}
|
333
|
|
334
|
getCommunityPageByRoute(route:string, helpContentUrl:string, pid: string) {
|
335
|
return this.http.get<Page>(helpContentUrl + properties.adminToolsPortalType +'/' + pid + '/page/?page_route='+route)
|
336
|
.pipe(catchError(this.handleError));
|
337
|
}
|
338
|
|
339
|
savePage(page: Page, helpContentUrl:string) {
|
340
|
HelpContentService.removeNulls(page);
|
341
|
|
342
|
return this.http.post<Page>(helpContentUrl + 'page/save', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody())
|
343
|
//.map(res => <Page> res.json())
|
344
|
.pipe(catchError(this.handleError));
|
345
|
}
|
346
|
|
347
|
updatePage(page: Page, helpContentUrl:string) {
|
348
|
|
349
|
HelpContentService.removeNulls(page);
|
350
|
|
351
|
return this.http.post<Page>(helpContentUrl + 'page/update', JSON.stringify(page), CustomOptions.getAuthOptionsWithBody())
|
352
|
//.map(res => <Page> res.json())
|
353
|
.pipe(catchError(this.handleError));
|
354
|
}
|
355
|
|
356
|
togglePages(selectedPortalPid: string, ids : string[],status : boolean, helpContentUrl:string) {
|
357
|
|
358
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/'+selectedPortalPid+'/page/toggle?status='+ status.toString(),
|
359
|
JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
360
|
.pipe(catchError(this.handleError));
|
361
|
}
|
362
|
|
363
|
deletePages(ids : string[], helpContentUrl:string) {
|
364
|
|
365
|
return this.http.post(helpContentUrl + 'page/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
366
|
.pipe(catchError(this.handleError));
|
367
|
}
|
368
|
|
369
|
// unused
|
370
|
getCommunities( helpContentUrl:string) {
|
371
|
return this.http.get<Array<Portal>>(helpContentUrl + properties.adminToolsPortalType)
|
372
|
//.map(res => <Array<Portal>> res.json())
|
373
|
.pipe(catchError(this.handleError));
|
374
|
}
|
375
|
|
376
|
getCommunity(pid: string, helpContentUrl:string) {
|
377
|
return this.http.get<Portal>(helpContentUrl + properties.adminToolsPortalType + '/'+pid)
|
378
|
//.map(res => <Portal> res.json())
|
379
|
.pipe(catchError(this.handleError));
|
380
|
}
|
381
|
|
382
|
getCommunitiesFull( helpContentUrl:string) {
|
383
|
return this.http.get<Array<Portal>>(helpContentUrl + properties.adminToolsPortalType + '/full')
|
384
|
//.map(res => <Array<Portal>> res.json())
|
385
|
.pipe(catchError(this.handleError));
|
386
|
}
|
387
|
|
388
|
getCommunityFull(portal_pid: string, helpContentUrl:string) {
|
389
|
return this.http.get<Portal>(helpContentUrl + properties.adminToolsPortalType + '/'+portal_pid+'/full')
|
390
|
//.map(res => <Portal> res.json())
|
391
|
.pipe(catchError(this.handleError));
|
392
|
}
|
393
|
|
394
|
saveCommunity(portal: Portal, helpContentUrl:string) {
|
395
|
// let headers = new Headers({'Content-Type': 'application/json'});
|
396
|
// let options = new RequestOptions({headers: headers});
|
397
|
|
398
|
HelpContentService.removeNulls(portal);
|
399
|
|
400
|
return this.http.post<Portal>(helpContentUrl + portal.type + '/save', JSON.stringify(portal), CustomOptions.getAuthOptionsWithBody())
|
401
|
//.map(res => <Portal> res.json())
|
402
|
.pipe(catchError(this.handleError));
|
403
|
}
|
404
|
|
405
|
updateCommunity(portal: Portal, helpContentUrl:string) {
|
406
|
// let headers = new Headers({'Content-Type': 'application/json'});
|
407
|
// let options = new RequestOptions({headers: headers});
|
408
|
|
409
|
HelpContentService.removeNulls(portal);
|
410
|
|
411
|
return this.http.post<Portal>(helpContentUrl + portal.type + '/update', JSON.stringify(portal), CustomOptions.getAuthOptionsWithBody())
|
412
|
//.map(res => <Portal> res.json())
|
413
|
.pipe(catchError(this.handleError));
|
414
|
}
|
415
|
|
416
|
deleteCommunities(ids : string[], helpContentUrl:string) {
|
417
|
// let headers = new Headers({'Content-Type': 'application/json'});
|
418
|
// let options = new RequestOptions({headers: headers});
|
419
|
|
420
|
return this.http.post(helpContentUrl + properties.adminToolsPortalType + '/delete',JSON.stringify(ids), CustomOptions.getAuthOptionsWithBody())
|
421
|
.pipe(catchError(this.handleError));
|
422
|
}
|
423
|
|
424
|
private handleError(error: HttpErrorResponse) {
|
425
|
// in a real world app, we may send the error to some remote logging infrastructure
|
426
|
// instead of just logging it to the console
|
427
|
console.error(error);
|
428
|
return throwError(error.error || 'Server error');
|
429
|
}
|
430
|
|
431
|
// getDataProviders() {
|
432
|
// 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);
|
433
|
// }
|
434
|
|
435
|
getCommunityStatistics(apiUrl: string, portalId: string): Observable<StatisticsSummary> {
|
436
|
const url = `${apiUrl}communities/${portalId}`;
|
437
|
//console.log(`getting statistics summary from: ${url}`);
|
438
|
return this.http.get(url)
|
439
|
//.map(res => <any>res.json())
|
440
|
.pipe(map(res => res['statistics']));
|
441
|
}
|
442
|
|
443
|
getCommunityAdminStatisticsChoices(apiUrl: string, portalId: string): Observable<StatisticsDisplay> {
|
444
|
const url = `${apiUrl}statistics/${portalId}`;
|
445
|
//console.log(`getting admin choices for statistics from: ${url}`);
|
446
|
return this.http.get<StatisticsDisplay>(url)
|
447
|
//.map(stats => <StatisticsDisplay>stats.json())
|
448
|
.pipe(catchError(this.handleError));
|
449
|
}
|
450
|
|
451
|
postCommunityAdminStatisticsChoices(apiUrl: string,
|
452
|
portalId: string,
|
453
|
entity: string,
|
454
|
chartsOrNumbers: string,
|
455
|
title: string,
|
456
|
status: boolean,
|
457
|
monitor: boolean): Observable<any> {
|
458
|
const url = `${apiUrl}statistics/${portalId}/${entity}/${chartsOrNumbers}?status=${status.toString()}&monitor=${monitor.toString()}`;
|
459
|
//console.log(`getting admin choices for statistics from: ${url}`);
|
460
|
|
461
|
return this.http.post(url, title, CustomOptions.getAuthOptionsWithBody())
|
462
|
//.map(stats => <any>stats.json())
|
463
|
.pipe(catchError(this.handleError));
|
464
|
}
|
465
|
|
466
|
statisticsIsActiveToggle(apiURL: string, id: string): Observable<boolean> {
|
467
|
const url = apiURL + '/statistics/' + encodeURIComponent(id) + '/toggle';
|
468
|
return this.http.post<boolean>(url, {}, CustomOptions.getAuthOptionsWithBody()).pipe(catchError(this.handleError));
|
469
|
}
|
470
|
}
|