import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import { ResultInfo } from '../results/resultInfo'; import { CommunityInfo } from './communityInfo'; import{EnvProperties} from '../../utils/properties/env-properties'; @Injectable() export class CommunityService { constructor(private http:Http) { } getCommunity(properties:EnvProperties, url: string) { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) .map(res => res.json()).map(res => this.parseCommunity(res)); } updateCommunity(url: string, community:any) { let headers = new Headers({'Content-Type': 'application/json'}); let options = new RequestOptions({headers: headers}); let body = JSON.stringify(community); console.log(body); return this.http.post(url, body, options) /*.map(res => res.json())*/ .do(request => console.log("Insert Response:"+request.status)); } iscommunityManager(properties:EnvProperties, url: string, manager:string){ return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) .map(res => res.json()).map(res => this.parseCommunity(res)).map(community => community.managers.indexOf(manager)!=-1); } iscommunityRI(properties:EnvProperties, url: string){ return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) .map(res => res.json()).map(res => this.parseCommunity(res)).map(community => (community && community.type && community.type !="community")); } isSubscribedToCommunity(pid:string, email:string, url:string){ return this.http.get(url+"/community/"+pid+"/subscribers") .map(res => ((res =="")?{}: res.json())) .map(res => { if(res.subscribers && res.subscribers != null){ for(var i =0; i< res.subscribers.length; i++ ){ if(res.subscribers[i]!=null && res.subscribers[i].email == email){ return true; } } } return false; }).do(res => {console.log("Response is "+res)}); } parseCommunity(data:any): CommunityInfo { let length = Array.isArray(data) ? data.length :1; for (let i=0; i(); } let managers = resData[0].managers; let length = Array.isArray(managers) ? managers.length : 1; for(let i=0; i(); } let subjects = resData[0].subjects; let length = Array.isArray(subjects) ? subjects.length : 1; for(let i=0; i(); } let managers = resData.managers; let length = Array.isArray(managers) ? managers.length : 1; for(let i=0; i(); } let subjects = resData.subjects; let length = Array.isArray(subjects) ? subjects.length : 1; for(let i=0; i