Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
community.service.ts | ||
---|---|---|
1 | 1 |
import { Injectable } from '@angular/core'; |
2 | 2 |
import { Http, Headers, RequestOptions } from '@angular/http'; |
3 |
import {HttpClient, HttpHeaders} from "@angular/common/http"; |
|
3 | 4 |
import { CommunityInfo } from './communityInfo'; |
4 | 5 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
6 |
import {map} from "rxjs/operators"; |
|
7 |
import {COOKIE} from "../../login/utils/helper.class"; |
|
5 | 8 |
|
6 | 9 |
@Injectable() |
7 | 10 |
export class CommunityService { |
8 | 11 |
|
9 |
constructor(private http: Http) { |
|
12 |
constructor(private http: HttpClient) {
|
|
10 | 13 |
} |
11 | 14 |
|
12 | 15 |
getCommunity(properties: EnvProperties, url: string) { |
13 | 16 |
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) |
14 |
.map(res => <any> res.json()).map(res => this.parseCommunity(res)); |
|
17 |
//.map(res => <any> res.json()) |
|
18 |
.pipe(map(res => this.parseCommunity(res))); |
|
15 | 19 |
} |
16 | 20 |
|
17 | 21 |
updateCommunity(url: string, community: any) { |
18 |
const headers = new Headers({'Content-Type': 'application/json'}); |
|
19 |
const options = new RequestOptions({headers: headers}); |
|
22 |
//const headers = new Headers({'Content-Type': 'application/json'}); |
|
23 |
//const options = new RequestOptions({headers: headers}); |
|
24 |
|
|
25 |
const options = { |
|
26 |
headers: new HttpHeaders({ |
|
27 |
'Content-Type': 'application/json', |
|
28 |
}) |
|
29 |
}; |
|
30 |
|
|
20 | 31 |
const body = JSON.stringify(community); |
21 | 32 |
return this.http.post(url, body, options); |
22 | 33 |
/*.map(res => res.json())*/ |
... | ... | |
24 | 35 |
|
25 | 36 |
isCommunityManager(properties: EnvProperties, url: string, manager: string) { |
26 | 37 |
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) |
27 |
.map(res => <any> res.json()).map(res => |
|
28 |
this.parseCommunity(res)).map(community => community.managers.indexOf(manager) !== -1); |
|
38 |
//.map(res => <any> res.json()) |
|
39 |
.pipe(map(res => this.parseCommunity(res))) |
|
40 |
.pipe(map(community => community.managers.indexOf(manager) !== -1)); |
|
29 | 41 |
} |
30 | 42 |
|
31 | 43 |
isRIType(properties: EnvProperties, url: string) { |
32 | 44 |
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) |
33 |
.map(res => <any> res.json()).map(res =>
|
|
34 |
this.parseCommunity(res)).map(community =>
|
|
35 |
(community && community.type && community.type === 'ri'));
|
|
45 |
//.map(res => <any> res.json())
|
|
46 |
.pipe(map(res => this.parseCommunity(res)))
|
|
47 |
.pipe(map(community => (community && community.type && community.type === 'ri')));
|
|
36 | 48 |
} |
37 | 49 |
|
38 | 50 |
isCommunityType(properties: EnvProperties, url: string) { |
39 | 51 |
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) |
40 |
.map(res => <any> res.json()).map(res =>
|
|
41 |
this.parseCommunity(res)).map(community =>
|
|
42 |
(community && community.type && community.type === 'community'));
|
|
52 |
//.map(res => <any> res.json())
|
|
53 |
.pipe(map(res => this.parseCommunity(res)))
|
|
54 |
.pipe(map(community => (community && community.type && community.type === 'community')));
|
|
43 | 55 |
} |
44 | 56 |
|
45 | 57 |
isSubscribedToCommunity(pid: string, email: string, url: string) { |
46 | 58 |
return this.http.get(url + '/community/' + pid + '/subscribers') |
47 |
.map(res => ((<any>res === '') ? {} : <any> res.json())) |
|
48 |
.map(res => { |
|
49 |
if (res.subscribers && res.subscribers != null) {
|
|
59 |
//.map(res => ((<any>res === '') ? {} : <any> res.json()))
|
|
60 |
.pipe(map(res => {
|
|
61 |
if (res['subscribers'] && res['subscribers'] != null) {
|
|
50 | 62 |
|
51 |
for (let i = 0; i < res.subscribers.length; i++ ) {
|
|
52 |
if (res.subscribers[i] != null && res.subscribers[i].email === email) {
|
|
63 |
for (let i = 0; i < res['subscribers'].length; i++ ) {
|
|
64 |
if (res['subscribers'][i] != null && res['subscribers'][i].email === email) {
|
|
53 | 65 |
return true; |
54 | 66 |
} |
55 | 67 |
} |
56 | 68 |
} |
57 | 69 |
return false; |
58 | 70 |
|
59 |
}); |
|
71 |
}));
|
|
60 | 72 |
} |
61 | 73 |
|
62 | 74 |
private parseCommunity(data: any): CommunityInfo { |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729