diff --git a/connect/communities/communities.service.ts b/connect/communities/communities.service.ts index 53dbb81a..ddcee2de 100644 --- a/connect/communities/communities.service.ts +++ b/connect/communities/communities.service.ts @@ -1,10 +1,9 @@ import {Injectable} from '@angular/core'; -import {Http} from '@angular/http'; import {HttpClient} from "@angular/common/http"; import {CommunityInfo} from '../community/communityInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; -import {BehaviorSubject, Observable} from "rxjs"; +import {BehaviorSubject} from "rxjs"; import {map} from "rxjs/operators"; @Injectable() diff --git a/connect/contentProviders/searchDataproviders.service.ts b/connect/contentProviders/searchDataproviders.service.ts index f9bb279e..bce044d9 100644 --- a/connect/contentProviders/searchDataproviders.service.ts +++ b/connect/contentProviders/searchDataproviders.service.ts @@ -1,16 +1,19 @@ import {Injectable} from '@angular/core'; -import {Http} from '@angular/http'; import {HttpClient} from "@angular/common/http"; -import{EnvProperties} from '../../utils/properties/env-properties'; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class SearchCommunityDataprovidersService { constructor(private http: HttpClient ) {} - searchDataproviders (properties:EnvProperties, communityId: string):any { let url = properties.communityAPI+communityId+"/contentproviders"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); - //.map(res => res.json()) + } + countTotalDataproviders(properties:EnvProperties,communityId:string) { + let url = properties.communityAPI+communityId+"/contentproviders"; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) + .pipe(map(res => res['length'])); } } diff --git a/connect/projects/searchProjects.service.ts b/connect/projects/searchProjects.service.ts index 62ff1aa3..56e7f6a9 100644 --- a/connect/projects/searchProjects.service.ts +++ b/connect/projects/searchProjects.service.ts @@ -2,6 +2,7 @@ import {Injectable} from '@angular/core'; import {Http} from '@angular/http'; import {HttpClient} from "@angular/common/http"; import{EnvProperties} from '../../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class SearchCommunityProjectsService { @@ -13,4 +14,9 @@ export class SearchCommunityProjectsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); //.map(res => res.json()) } + countTotalProjects(properties:EnvProperties,communityId:string) { + let url = properties.communityAPI+communityId+"/projects"; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) + .pipe(map(res => res['length'])); + } } diff --git a/searchPages/find/search.component.ts b/searchPages/find/search.component.ts index 2161466d..3a09303f 100644 --- a/searchPages/find/search.component.ts +++ b/searchPages/find/search.component.ts @@ -153,7 +153,7 @@ public subPub;public subData; public subSoftware; public subOrps; public subProj - this.config.getCommunityInformation(this.properties.adminToolsAPIURL, (this.connectCommunityId)?this.connectCommunityId:this.properties.adminToolsCommunity ).subscribe(data => { + this.config.getCommunityInformation(this.properties, (this.connectCommunityId)?this.connectCommunityId:this.properties.adminToolsCommunity ).subscribe(data => { var showEntity = {}; for(var i=0; i< data['entities'].length; i++){ diff --git a/searchPages/searchUtils/searchResult.component.html b/searchPages/searchUtils/searchResult.component.html index 747a6a55..c88bc573 100644 --- a/searchPages/searchUtils/searchResult.component.html +++ b/searchPages/searchUtils/searchResult.component.html @@ -3,26 +3,28 @@
  • -
    +
    - {{result.types.join(", ")}} - {{result.programmingLanguages.join(", ")}} - {{result.languages.join(", ")}} - {{result.countriesForResults.join(", ")}} - {{result.title.accessMode}} - {{result['funderShortname']}} + + {{result.types.join(", ")}}{{' '}} + {{result.programmingLanguages.join(", ")}}{{' '}} + {{result.languages.join(", ")}}{{' '}} + {{result.countriesForResults.join(", ")}}{{' '}} + {{result.title.accessMode}}{{' '}} + {{result['funderShortname']}}{{' '}} Open Access mandate for Publications + class="uk-label custom-label label-openaccessmandate " title="Open Access mandate for Publications">Open Access mandate for Publications{{' '}} Open Access mandate for Research Data + class="uk-label custom-label label-openaccessmandate " title="Open Access mandate for Research Data">Open Access mandate for Research Data{{' '}} Open Access mandate for Publications and Research Data + class="uk-label custom-label label-openaccessmandate " title="Open Access mandate for Publications and Research Data">Open Access mandate for Publications and Research Data{{' '}} - Special Clause 39 + Special Clause 39{{' '}}
    diff --git a/searchPages/searchUtils/searchResults.module.ts b/searchPages/searchUtils/searchResults.module.ts index ea2a46c8..9f80f083 100644 --- a/searchPages/searchUtils/searchResults.module.ts +++ b/searchPages/searchUtils/searchResults.module.ts @@ -1,12 +1,10 @@ -import { NgModule} from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; -import { RouterModule } from '@angular/router'; +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; -import {ErrorMessagesModule} from '../../utils/errorMessages.module'; - -import {SearchResult} from '../../utils/entities/searchResult'; -import {SearchResultComponent} from './searchResult.component'; +import {ErrorMessagesModule} from '../../utils/errorMessages.module'; +import {SearchResultComponent} from './searchResult.component'; import {ApprovedByCommunityModule} from '../../connect/approvedByCommunity/approved.module'; import {ShowAuthorsModule} from "../../utils/authors/showAuthors.module"; diff --git a/services/searchResearchResults.service.ts b/services/searchResearchResults.service.ts new file mode 100644 index 00000000..e77784cf --- /dev/null +++ b/services/searchResearchResults.service.ts @@ -0,0 +1,398 @@ +import {Injectable} from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {SearchResult} from '../utils/entities/searchResult'; +import {RefineResultsUtils} from './servicesUtils/refineResults.class'; +import {DOI, StringUtils} from '../utils/string-utils.class'; +import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; + + +@Injectable() +export class SearchResearchResultsService { + private sizeOfDescription: number = 270; + public parsingFunctions: ParsingFunctions = new ParsingFunctions(); + + constructor(private http: HttpClient ) {} + + search (resultType:string, params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[] , properties:EnvProperties):any { + let link = properties.searchAPIURLLAst+this.getEntityName(resultType,true); + + let url = link+"?"; + if(params!= null && params != '' ) { + url += params; + } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + if(sortBy) { + url += "&sortBy=" + sortBy; + } + url += "&page="+(page-1)+"&size="+size+"&format=json"; + + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")])); + } + searchById (resultType:string, id: string, properties:EnvProperties ):any { + + let url = properties.searchAPIURLLAst+this.getEntityName(resultType,true) +"/"+id+"?format=json"; + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + .pipe(map(res => this.parseResults(resultType, res, properties))); + } +//??? + searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { + + let link = properties.searchAPIURLLAst+"publications"; + + let url = link+"?"+"&format=json"; + if(params!= null && params != '' ) { + url += params; + } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + url += "&page="+(page-1)+"&size="+size; + + + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))); + } + + searchByListOfDOI (resultType:string, DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { + + let link = properties.searchAPIURLLAst+ this.getEntityName(resultType,true); + + let url = link+"?"+"&format=json&"; + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"'; + } + if(doisParams.length > 0){ + url +="&"+doisParams; + + } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + url += "&page="+(page-1)+"&size="+size; + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + //.do(res => console.info(res)) + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")])); + } + + advancedSearch (resultType:string, params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { + let url = properties.searchResourcesAPIURL; + var basicQuery = "(oaftype exact result) and (resulttypeid exact "+this.getEntityName(resultType,false) + ") "; + url += "?query="; + if(params!= null && params != '' ) { + url +=" ( "+basicQuery+ " ) " +" and (" + params + ")"; + }else{ + url +=" ( "+basicQuery+ " ) "; + } + + if(sortBy) { + let sortOptions = sortBy.split(","); + url += "sortBy "+sortOptions[0]+"/sort."+sortOptions[1]+" "; + } + + url += "&page="+(page-1)+"&size="+size; + url += "&format=json"; + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + //.do(res => console.info(res)) + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); + } + searchResultForEntity (resultType:string, params: string, page: number, size: number, properties:EnvProperties):any { + let link = properties.searchAPIURLLAst; + let url = link+params+"/"+this.getEntityName(resultType,true)+ "?format=json"; + url += "&page="+(page-1)+"&size="+size; + + + + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); + } +//???? why different from above? + searchForDataproviders(resultType:string, params: string, page: number, size: number, properties:EnvProperties):any { + let link = properties.searchAPIURLLAst; + let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); + } + + parseResults(resultType:string, data: any, properties: EnvProperties): SearchResult[] { + let results: SearchResult[] = []; + + let length = Array.isArray(data) ? data.length : 1; + + for(let i=0; i(); + let types = new Set(); + + let instance; + let length = Array.isArray(resData['children']['instance']) ? resData['children']['instance'].length : 1; + + for(let i=0; i(); + + if(!Array.isArray(resData['language'])) { + if(resData['language'].classname != "Undetermined" && resData['language'].classname) { + result.languages.push(resData['language'].classname); + } + } else { + for(let i=0; i(); + + if(!Array.isArray(resData['country'])) { + if(resData['country'].classname != "Undetermined" && resData['country'].classname) { + result.countriesForResults.push(resData['country'].classname); + } + } else { + for(let i=0; i(); + } + + result['authors'].push({"name": relation.fullname, "id": relation['to'].content}); + } else */if(relation['to'].class == "isProducedBy") { + result['projects'] = this.parseProjects(result['projects'], relation); + } + } + } + } + + if(resData.hasOwnProperty("creator") && resData['creator'] != null) { + if(result['authors'] == undefined) { + result['authors'] = new Array<{"fullName": string, "orcid": string}>(); + } + + let authors = resData['creator']; + let length = Array.isArray(authors) ? authors.length : 1; + + for(let i=0; i this.sizeOfDescription) { + result.description = result.description.substring(0, this.sizeOfDescription) + "..."; + } + + + result.embargoEndDate = resData.embargoenddate; + + results.push(result); + } + + return results; + } + + parseProjects(projects: { "id": string, "acronym": string, "title": string, + "funderShortname": string, "funderName": string, + "code": string }[], relation: any ) : { + "id": string, "acronym": string, "title": string, + "funderShortname": string, "funderName": string, + "code": string }[] { + if(projects == undefined) { + projects = new Array< + { "id": string, "acronym": string, "title": string, + "funderShortname": string, "funderName": string, + "code": string + }>(); + } + + let countProjects = projects.length; + + projects[countProjects] = { + "id": "", "acronym": "", "title": "", + "funderShortname": "", "funderName": "", + "code": "" + } + + if(relation.title != 'unidentified') { + projects[countProjects]['id'] = + /*OpenaireProperties.getsearchLinkToProject() + */relation['to'].content; + projects[countProjects]['acronym'] = relation.acronym; + projects[countProjects]['title'] = relation.title; + projects[countProjects]['code'] = relation.code; + } else { + projects[countProjects]['id'] = ""; + projects[countProjects]['acronym'] = ""; + projects[countProjects]['title'] = ""; + projects[countProjects]['code'] = ""; + } + + if(relation.hasOwnProperty("funding")) { + let fundingLength = Array.isArray(relation['funding']) ? relation['funding'].length : 1; + + for(let z=0; z res.json()) + .pipe(map(res => res['total'])); + } + + numOfEntityResults(resultType:string, id: string, entity: string, properties:EnvProperties):any { + var parameters: string = ""; + parameters = this.getEntityName(entity, true) + "/"+id+"/"+this.getEntityName(resultType, true)+"/count"; + let url = properties.searchAPIURLLAst+parameters+"?format=json"; + return this.numOfResults(url , properties); + } + + numOfSearchResults(resultType:string, params: string, properties:EnvProperties, refineParams:string=null):any { + let url = properties.searchAPIURLLAst+this.getEntityName(resultType, true)+"/count?format=json"; + if(params.length > 0){ + var DOIs:string[] = DOI.getDOIsFromString(params); + var doisParams = ""; + + for(var i =0 ;i < DOIs.length; i++){ + doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"'; + } + if(doisParams.length > 0){ + url += "&"+doisParams; + }else{ + url += "&q=" + StringUtils.URIEncode(params); + } + } + // if(params != "") { + // url += "&q=" + StringUtils.URIEncode(params); + // } + if(refineParams!= null && refineParams != '' ) { + url += refineParams; + } + return this.numOfResults(url, properties); + } + countTotalResults(resultType:string, properties:EnvProperties, refineParams:string=null):any { + let url = properties.searchAPIURLLAst+this.getEntityName(resultType, true)+"/count?format=json"+refineParams; + return this.numOfResults(url, properties); + } +/* + private quote(word: any): string { + return '"'+word+'"'; + } +*/ + + private getEntityName (entityType:string, plural:boolean){ + if(entityType == "publication" ||entityType == "dataset" || entityType == "organization" || entityType == "datasource" || entityType == "project" ){ + if(plural){ + return entityType+ "s"; + }else{ + return entityType; + } + }else{ + return entityType; + } + } +} diff --git a/services/searchResearchResultsService.module.ts b/services/searchResearchResultsService.module.ts new file mode 100644 index 00000000..98f0b6eb --- /dev/null +++ b/services/searchResearchResultsService.module.ts @@ -0,0 +1,19 @@ +import { NgModule} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import {SearchResearchResultsService} from "./searchResearchResults.service"; + +@NgModule({ + imports: [ + CommonModule, FormsModule + ], + declarations: [ + ], + providers: [ + SearchResearchResultsService + ], + exports: [ + ] +}) + +export class SearchResearchResultsServiceModule { } diff --git a/sharedComponents/bottom.component.html b/sharedComponents/bottom.component.html index a7fbb4d4..4de6cc91 100644 --- a/sharedComponents/bottom.component.html +++ b/sharedComponents/bottom.component.html @@ -99,10 +99,10 @@ diff --git a/sharedComponents/bottom.component.ts b/sharedComponents/bottom.component.ts index 04d5cf10..6a0dec1a 100644 --- a/sharedComponents/bottom.component.ts +++ b/sharedComponents/bottom.component.ts @@ -3,6 +3,7 @@ import {ActivatedRoute} from '@angular/router'; import 'rxjs'; import{MenuItem} from './menu'; import { ConfigurationService } from '../utils/configuration/configuration.service'; +import {EnvProperties} from "../utils/properties/env-properties"; @Component({ selector: 'bottom', @@ -17,14 +18,13 @@ export class BottomComponent { @Input() assetsPath:string ='assets/common-assets/'; @Input() menuItems:MenuItem []; -@Input() APIUrl; @Input() communityId; -@Input() environment:string = "beta"; +// @Input() environment:string = "beta"; showPage ={}; @Input() grantAdvance:boolean = true; grantAdvanceText = "OpenAIRE-Advance receives funding from the European Union's Horizon 2020 Research and Innovation programme under Grant Agreement No. 777541." grantConenctText = "OpenAIRE-Connect receives funding from the European Union's Horizon 2020 Research and Innovation programme under grant agreement No. 731011." - +@Input() properties:EnvProperties; constructor(private config: ConfigurationService, private route: ActivatedRoute,) { } @@ -32,8 +32,8 @@ constructor(private config: ConfigurationService, private route: ActivatedRoute ngOnInit() { this.route.queryParams.subscribe(params => { if(this.showMenuItems){ - if( this.APIUrl && this.communityId ){ - this.config.getCommunityInformation(this.APIUrl, this.communityId ).subscribe(data => { + if( this.properties.adminToolsAPIURL && this.communityId ){ + this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => { for(var i=0; i< data['pages'].length; i++){ this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"]; diff --git a/sharedComponents/navigationBar.component.html b/sharedComponents/navigationBar.component.html index 860ca9fb..534dbfa4 100644 --- a/sharedComponents/navigationBar.component.html +++ b/sharedComponents/navigationBar.component.html @@ -10,7 +10,7 @@ - @@ -34,10 +34,10 @@
  • Dashboards
  • @@ -64,7 +64,7 @@ - + @@ -84,13 +84,13 @@ diff --git a/sharedComponents/navigationBar.component.ts b/sharedComponents/navigationBar.component.ts index 28d86613..ddbb9e00 100644 --- a/sharedComponents/navigationBar.component.ts +++ b/sharedComponents/navigationBar.component.ts @@ -6,26 +6,27 @@ import {Observable} from 'rxjs'; import {Session} from '../login/utils/helper.class'; import { ConfigurationService } from '../utils/configuration/configuration.service'; import{MenuItem,RootMenuItem} from './menu'; +import {EnvProperties} from "../utils/properties/env-properties"; @Component({ selector: 'navbar', templateUrl: 'navigationBar.component.html' }) export class NavigationBarComponent { + // [APIUrl]="properties.adminToolsAPIURL" [logOutUrl]="properties.logoutUrl" [cookieDomain]="properties.cookieDomain" @Input() portal:string = "connect"; @Input() onlyTop:boolean ; @Input() logoPath:string = "assets/common-assets/"; @Input() userMenu:boolean = true; - @Input() logInUrl; - @Input() logOutUrl; - @Input() APIUrl; + // @Input() logOutUrl; + // @Input() APIUrl; @Input() communityId; - @Input() cookieDomain; + // @Input() cookieDomain; @Input() userMenuItems:MenuItem[] ; @Input() menuItems:RootMenuItem [] ; @Input() community: {id:string, name:string, logoUrl:string}; @Input() showMenu:boolean = true; @Input() homeurl:boolean = true; - @Input() environment:string = "beta"; + @Input() properties:EnvProperties; public isAuthorized: boolean = false; sub:any; @@ -61,8 +62,8 @@ export class NavigationBarComponent { this.isAuthorized = false; } -if( this.APIUrl && this.communityId ){ - this.config.getCommunityInformation(this.APIUrl, this.communityId ).subscribe(data => { +if( this.properties.adminToolsAPIURL && this.communityId ){ + this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => { for(var i=0; i< data['entities'].length; i++){ this.showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"]; diff --git a/utils/authors/showAuthors.component.ts b/utils/authors/showAuthors.component.ts index 260b3dc7..2c8f49ef 100644 --- a/utils/authors/showAuthors.component.ts +++ b/utils/authors/showAuthors.component.ts @@ -63,7 +63,7 @@ import {EnvProperties} from '../properties/env-properties'; ; + >;{{" "}} ... diff --git a/utils/configuration/configuration.service.ts b/utils/configuration/configuration.service.ts index 2e9d5120..bb02073e 100644 --- a/utils/configuration/configuration.service.ts +++ b/utils/configuration/configuration.service.ts @@ -7,14 +7,16 @@ import {Observable} from 'rxjs'; // import 'rxjs/add/operator/do'; // import 'rxjs/add/operator/share'; import {map, mapTo} from 'rxjs/operators'; +import {EnvProperties} from "../properties/env-properties"; @Injectable() export class ConfigurationService { constructor(private http: HttpClient ) {} - getCommunityInformation(APIUrl:string, community:string){ - return this.http.get(APIUrl + "/communityFull/" + community); + getCommunityInformation(properties:EnvProperties, community:string){ + let url = properties.adminToolsAPIURL +"/communityFull/" + community; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); //.map(res => res.json()); } @@ -30,8 +32,9 @@ export class ConfigurationService { .pipe(map(res => true)); } - isPageEnabled(APIUrl:string, community:string,router: string){ - return this.http.get(APIUrl + "/community/" + community+"/pages?page_route="+router) + isPageEnabled(properties:EnvProperties, community:string,router: string){ + let url = properties.adminToolsAPIURL + "/community/" + community+"/pages?page_route="+router; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) //.map(res => res.json()) .pipe(map(res => { let result = false; diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index b6b1ce40..13378b72 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -1,26 +1,22 @@ -import { Injectable } from '@angular/core'; -import { Http, Response, Headers, RequestOptions } from '@angular/http'; -import { HttpClient } from '@angular/common/http'; -import { HttpHeaders } from '@angular/common/http'; -import { Observable } from 'rxjs'; -import {COOKIE} from "../../login/utils/helper.class" -import { map } from "rxjs/operators"; +import {Injectable} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {map} from "rxjs/operators"; import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; +import {EnvProperties} from "../properties/env-properties"; @Injectable() export class SubscribeService { constructor(private http:HttpClient) { } - getCommunitySubscribers(pid:string, url:string){ - return this.http.get(url+"/community/"+pid+"/subscribers"); - //.map(res => res.json()); + getCommunitySubscribers(properties: EnvProperties, pid:string){ + let url = properties.adminToolsAPIURL+ "/community/"+pid+"/subscribers"; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } - isSubscribedToCommunity(pid:string, email:string, url:string){ - return this.http.get(url+"/community/"+pid+"/subscribers") - //.map(res => ((res =="")?{}: res.json())) - + isSubscribedToCommunity(properties: EnvProperties, pid:string, email:string){ + let url = properties.adminToolsAPIURL + "/community/"+pid+"/subscribers"; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) .pipe(map(res => { if(res['status'] && res['status'] != 200) { return null; @@ -38,36 +34,14 @@ export class SubscribeService { })); } subscribeToCommunity(pid:string, email:string, url:string){ - var subscriber = {"email":email}; + let subscriber = {"email":email}; return this.http.post(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody()); - //.map(res => res.json()); } unSubscribeToCommunity(pid:string, email:string, url:string){ - return this.http.post(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody()); - //.map(res => res.json()); } - getCommunitiesSubscribedTo(email:string, url:string){ - return this.http.get(url+"/subscriber/communities?email="+email); - //.map(res => res.json()); + getCommunitiesSubscribedTo(properties: EnvProperties, email:string){ + let url = properties.adminToolsAPIURL+"/subscriber/communities?email="+email; + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } - - /* - public getAuthOptionsWithBody():RequestOptions{ - let headers = new Headers(); - headers.append('Content-Type', 'application/json'); - headers.append('X-XSRF-TOKEN', COOKIE.getCookie(COOKIE.cookieName_id)); - let options = new RequestOptions({ headers: headers, withCredentials:true }); - return options; - } - */ - - public getAuthOptionsWithBody():any { - return { - headers: new HttpHeaders({ - 'Content-Type': 'application/json', - 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id) - }), withCredentials: true - }; - } }