From f8913dfdbdec3f2799b9094e51481781cedba264 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Mon, 3 Jun 2019 13:20:36 +0000 Subject: [PATCH] [Library|Trunk] Merge into trunk branch angular7 rev 55729 git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@55964 d315682c-612b-4755-9ff5-7f18f6832af3 --- app.component.ts | 4 +- app.module.ts | 8 +- .../claimContextSearchForm.component.ts | 2 +- .../claimProjectSearchForm.component.ts | 4 +- .../displayClaims/displayClaims.component.ts | 9 +- claims/claim-utils/service/claims.service.ts | 44 +++++---- .../claim-utils/service/contexts.service.ts | 37 ++++---- .../service/searchCrossref.service.ts | 31 +++--- .../service/searchDatacite.service.ts | 23 +++-- .../service/searchOrcid.service.ts | 46 +++++---- claims/claimsAdmin/claimsAdmin.component.ts | 2 +- .../claimsByToken/claimsByToken.component.ts | 3 +- claims/claimsByToken/claimsByToken.service.ts | 34 +++---- .../directLinking/directLinking.component.ts | 2 +- .../linking/bulkClaim/bulkClaim.component.ts | 2 +- .../insertClaim/insertClaim.component.ts | 2 +- claims/linking/linkingGeneric.component.ts | 2 +- claims/myClaims/myClaims.component.ts | 2 +- connect/communities/communities.service.ts | 7 +- connect/community/community.service.ts | 48 ++++++---- .../connectAdminLoginGuard.guard.ts | 14 +-- .../connectCommunityGuard.guard.ts | 17 ++-- .../communityGuard/connectRIGuard.guard.ts | 14 +-- .../communityGuard/connectSubscriber.guard.ts | 17 ++-- connect/communityGuard/isCommunity.guard.ts | 8 +- .../searchDataproviders.service.ts | 7 +- connect/curators/curator.service.ts | 15 +-- connect/projects/searchProjects.service.ts | 7 +- .../mailPrefs.component.ts | 2 +- .../userEmailPreferences/mailPrefs.service.ts | 21 +++-- .../searchZenodoCommunities.service.ts | 7 +- .../zenodo-communities.service.ts | 17 ++-- .../datasets/depositBySubject.component.ts | 2 +- .../depositBySubjectResult.component.ts | 2 +- deposit/deposit.component.ts | 2 +- deposit/depositResult.component.ts | 2 +- error/isRouteEnabled.guard.ts | 23 +++-- .../dataProvider/dataProvider.component.ts | 8 +- .../dataProvider/dataProvider.service.ts | 44 +++++---- .../relatedDatasourcesTab.component.ts | 2 +- landingPages/dataset/dataset.component.ts | 2 +- landingPages/dataset/dataset.service.ts | 25 ++--- .../htmlProjectReport.component.ts | 2 +- .../htmlProjectReport.service.ts | 13 ++- .../deletedByInference.component.ts | 8 +- .../deletedByInference.service.ts | 22 ++--- .../landing-utils/metrics.component.ts | 2 +- .../organization/organization.component.ts | 3 +- landingPages/orp/orp.component.ts | 2 +- landingPages/orp/orp.service.ts | 28 +++--- landingPages/project/project.component.ts | 2 +- landingPages/project/project.service.ts | 54 ++++++----- .../publication/publication.component.ts | 2 +- .../publication/publication.service.ts | 37 +++----- landingPages/software/software.component.ts | 2 +- landingPages/software/software.service.ts | 28 +++--- login/adminLoginGuard.guard.ts | 26 +++-- login/claimsCuratorGuard.guard.ts | 26 +++-- login/freeGuard.guard.ts | 7 +- login/loginGuard.guard.ts | 27 ++++-- .../advancedSearchDataProviders.component.ts | 2 +- .../advancedSearchDatasets.component.ts | 2 +- .../advancedSearchOrganizations.component.ts | 2 +- .../advanced/advancedSearchOrps.component.ts | 2 +- .../advancedSearchProjects.component.ts | 2 +- .../advancedSearchPublications.component.ts | 2 +- .../advancedSearchSoftware.component.ts | 2 +- searchPages/find/search.component.ts | 6 +- .../advancedSearchForm.component.ts | 12 +-- .../advancedSearchPage.component.ts | 2 +- .../searchUtils/dateFilter.component.ts | 94 +++++++++++++++---- searchPages/searchUtils/dateFilter.module.ts | 9 +- .../searchUtils/searchDownload.component.ts | 4 +- .../searchUtils/searchFilter.component.ts | 2 +- .../searchPageTableView.component.ts | 3 +- .../searchUtils/searchPaging.component.ts | 2 +- services/curatorPhoto.service.ts | 16 +--- services/layout.service.ts | 22 +++-- services/metrics.service.ts | 14 +-- services/organization.service.ts | 28 +++--- services/refineFieldResults.service.ts | 26 ++--- services/reports.service.ts | 38 ++++---- services/searchDataproviders.service.ts | 73 +++++++------- services/searchDatasets.service.ts | 52 +++++----- services/searchOrganizations.service.ts | 24 ++--- services/searchOrps.service.ts | 48 +++++----- services/searchProjects.service.ts | 41 ++++---- services/searchPublications.service.ts | 46 ++++----- services/searchSoftware.service.ts | 42 ++++----- services/servicesUtils/customOptions.class.ts | 26 ++++- sharedComponents/bottom.component.ts | 6 +- .../cookie-law/cookie-law.component.ts | 10 +- sharedComponents/navigationBar.component.ts | 10 +- test/test.component.ts | 3 +- utils/configuration/configuration.service.ts | 30 +++--- utils/email/email.service.ts | 11 ++- .../entitiesAutoComplete.component.ts | 35 +++---- .../entitySearch.service.ts | 34 ++++--- .../fetchDatasets.class.ts | 2 +- utils/fetchEntitiesClasses/fetchOrps.class.ts | 2 +- .../fetchPublications.class.ts | 2 +- .../fetchSoftware.class.ts | 2 +- utils/helper/helper.component.ts | 2 +- utils/helper/helper.service.ts | 15 +-- .../my-date-picker.focus.directive.ts | 4 + ...y-date-picker.input.auto.fill.directive.ts | 2 + .../my-date-picker.component.ts | 4 +- utils/piwik/piwik.service.ts | 11 ++- utils/piwik/previousRouteRecorder.guard.ts | 2 +- .../environment-specific.service.ts | 58 +++++++----- .../ISVocabularies.service.ts | 23 +++-- utils/subscribe/subscribe.service.ts | 49 ++++++---- 112 files changed, 998 insertions(+), 824 deletions(-) diff --git a/app.component.ts b/app.component.ts index 849ab411..1976919f 100644 --- a/app.component.ts +++ b/app.component.ts @@ -1,6 +1,6 @@ -import { Component, Directive, ElementRef, Renderer, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core'; +import { Component, Directive, ElementRef, Renderer2, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core'; import { ConfigurationService } from './utils/configuration/configuration.service'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { EnvProperties } from './utils/properties/env-properties'; import {ActivatedRoute} from '@angular/router'; import{EnvironmentSpecificService} from './utils/properties/environment-specific.service'; diff --git a/app.module.ts b/app.module.ts index 31590d66..8a253a93 100755 --- a/app.module.ts +++ b/app.module.ts @@ -4,7 +4,7 @@ import { SharedModule } from './shared/shared.module'; import { BrowserModule } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { APP_BASE_HREF, CommonModule } from '@angular/common'; -import { HttpModule } from '@angular/http'; +import { HttpClientModule } from '@angular/common/http'; import { RouterModule } from '@angular/router'; import { AppComponent } from './app.component'; import {NavigationBarModule} from './sharedComponents/navigationBar.module'; @@ -69,10 +69,10 @@ import { AppRoutingModule } from './app-routing.module'; SharedModule, NoopAnimationsModule, CommonModule, - CookieLawModule, BottomModule, - HttpModule, - NavigationBarModule, CookieLawModule, + BottomModule, + HttpClientModule, + NavigationBarModule, MainSearchModule, ErrorModule, DepositDatasetsModule,DepositDatasetsResultsModule, DepositBySubjectResultsModule,DepositPublicationsModule , DepositPublicationsResultsModule, diff --git a/claims/claim-utils/claimContextSearchForm.component.ts b/claims/claim-utils/claimContextSearchForm.component.ts index 54cb3ab3..039480cd 100644 --- a/claims/claim-utils/claimContextSearchForm.component.ts +++ b/claims/claim-utils/claimContextSearchForm.component.ts @@ -1,5 +1,5 @@ import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router} from '@angular/router'; import {ContextsService} from './service/contexts.service'; import {ClaimContext} from './claimEntities.class'; diff --git a/claims/claim-utils/claimProjectSearchForm.component.ts b/claims/claim-utils/claimProjectSearchForm.component.ts index c18137c5..8420fcbd 100644 --- a/claims/claim-utils/claimProjectSearchForm.component.ts +++ b/claims/claim-utils/claimProjectSearchForm.component.ts @@ -1,9 +1,7 @@ import {Component, Input,Output, ElementRef, EventEmitter, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable, Subject } from 'rxjs'; import {SearchProjectsService} from '../../services/searchProjects.service'; import {ProjectService} from '../../landingPages/project/project.service'; -// import {ModalLoading} from '../../utils/modal/loading.component'; -import { Subject } from 'rxjs/Subject'; import {ClaimProject} from './claimEntities.class'; declare var UIkit:any; import{EnvProperties} from '../../utils/properties/env-properties'; diff --git a/claims/claim-utils/displayClaims/displayClaims.component.ts b/claims/claim-utils/displayClaims/displayClaims.component.ts index 2960a2d4..e4a1f78e 100644 --- a/claims/claim-utils/displayClaims/displayClaims.component.ts +++ b/claims/claim-utils/displayClaims/displayClaims.component.ts @@ -1,8 +1,9 @@ + +import {distinctUntilChanged, debounceTime} from 'rxjs/operators'; import {Component, ViewChild, Input} from '@angular/core'; import {Location} from '@angular/common'; -import {Observable} from 'rxjs/Observable'; +import {Observable, Subject} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; -import {Subject} from 'rxjs/Subject'; import {ClaimsService} from '../service/claims.service'; import {ModalLoading} from '../../../utils/modal/loading.component'; import {AlertModal} from '../../../utils/modal/alert'; @@ -58,8 +59,8 @@ private seoService: SEOService) { this.setTypes(params['types']); // check the appropriate checkboxes this.setSortby(params['sort']); this.getClaims(); - this.searchTermStream - .debounceTime(300).distinctUntilChanged() + this.searchTermStream.pipe( + debounceTime(300),distinctUntilChanged(),) .subscribe((term: string) => { this.keyword = this.inputkeyword; //console.log("keyword: "+this.keyword + " VS inputkeyword: "+this.inputkeyword); diff --git a/claims/claim-utils/service/claims.service.ts b/claims/claim-utils/service/claims.service.ts index c2e0d157..e340e414 100644 --- a/claims/claim-utils/service/claims.service.ts +++ b/claims/claim-utils/service/claims.service.ts @@ -1,24 +1,28 @@ + +import {throwError as observableThrowError, Observable} from 'rxjs'; import {Injectable} from '@angular/core'; import {URLSearchParams } from '@angular/http'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; // import {Claim} from '../claim'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + +import { catchError } from 'rxjs/operators'; + import { CustomOptions } from '../../../services/servicesUtils/customOptions.class'; @Injectable() export class ClaimsService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { } private getClaimRequest(size : number, page : number, url :string, fromCache:boolean):any { //console.info('ClaimsService: Claims request: '+url); let key = url; return this.http.get(url, CustomOptions.getAuthOptions()) - .map(request => request.json()) + //.map(request => request.json()) //.do(request => console.info("Get claims: offset = "+(size*(page-1)) + " limit ="+size )) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string):any { let url = apiUrl +"claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; @@ -54,9 +58,9 @@ export class ClaimsService { let url = apiUrl +"claims/"+claimId; // let headers = new Headers({ 'Content-Type': 'application/json' }); // let options = new RequestOptions({ headers: headers }); - return this.http.delete( url, CustomOptions.getAuthOptionsWithBody()).map(request => request.json()) + return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => request.json()) // .do(request => console.info("After delete" )) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } deleteBulk(claimIds:string[], apiUrl:string):any{ @@ -71,9 +75,9 @@ export class ClaimsService { // let headers = new Headers({ 'Content-Type': 'application/json' }); // let options = new RequestOptions({ headers: headers }); - return this.http.delete( url, CustomOptions.getAuthOptions()).map(request => request.json()) + return this.http.delete( url, CustomOptions.getAuthOptions())//.map(request => request.json()) // .do(request => console.info("After delete" )) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } insertBulkClaims(claims, apiUrl:string):any{ @@ -84,9 +88,9 @@ export class ClaimsService { // let headers = new Headers({ 'Content-Type': 'application/json' }); // let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) + //.map(res => res.json()) //.do(request => console.info("Insert Response:"+request.status) ) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } insertClaim(claim, apiUrl:string):any{ @@ -96,9 +100,9 @@ export class ClaimsService { // let headers = new Headers({ 'Content-Type': 'application/json' }); // let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) + //.map(res => res.json()) //.do(request => console.info("Insert Response:"+request.status) ) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } insertDirectRecords(records, apiUrl:string):any{ @@ -109,26 +113,26 @@ export class ClaimsService { // let headers = new Headers({ 'Content-Type': 'application/json' }); // let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) + //.map(res => res.json()) //.do(request => console.info("Insert Response:"+request) ) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } private handleError (error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return observableThrowError(error || 'Server error'); } getClaim(id:string, apiUrl:string):any { let url = apiUrl+"claims/"+id; return new Promise((resolve, reject) => { this.http.get(url) - .map(res => res.json()) + //.map(res => res.json()) .subscribe( data => { - resolve(data.data); + resolve(data['data']); }, err => { reject(err); diff --git a/claims/claim-utils/service/contexts.service.ts b/claims/claim-utils/service/contexts.service.ts index 47f257a7..e6017604 100644 --- a/claims/claim-utils/service/contexts.service.ts +++ b/claims/claim-utils/service/contexts.service.ts @@ -1,16 +1,16 @@ + +import {throwError as observableThrowError, Observable} from 'rxjs'; import {Injectable} from '@angular/core'; import {Jsonp, URLSearchParams, RequestOptions, Headers} from '@angular/http'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; import {Claim} from '../claim'; import {AutoCompleteValue} from '../../../searchPages/searchUtils/searchHelperClasses.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {catchError, map} from "rxjs/operators"; import { COOKIE } from '../../../login/utils/helper.class'; @Injectable() export class ContextsService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { } public getCommunities( apiUrl:string):any { @@ -19,9 +19,10 @@ export class ContextsService { let key = url; //console.info('ContextsService: request communities '+url); return this.http.get(url) - .map(res => res.json()).map(res => this.parseCommunities(res, true) ) + //.map(res => res.json()) + .pipe(map(res => this.parseCommunities(res, true) )) // .do(request => console.info("Get claims: offset = ")) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } public getPublicCommunities( apiUrl:string):any { let url = apiUrl + 's/'; @@ -29,9 +30,7 @@ export class ContextsService { let key = url; //console.info('ContextsService: request communities '+url); return this.http.get(url) - .map(res => res.json()).map(res => this.parseCommunities(res, false) ) - // .do(request => console.info("Get claims: offset = ")) - .catch(this.handleError); + .pipe(map(res => this.parseCommunities(res, true) )); } parseCommunities(data, getall){ var communities = []; @@ -52,9 +51,9 @@ export class ContextsService { return this.http.get(url) - .map(request => request.json()) + //.map(request => request.json()) // .do(request => console.info("Get claims: offset = " )) - .catch(this.handleError);; + .pipe(catchError(this.handleError)); } public getConcepts(categoryId :string, keyword: string, parsing:boolean, apiUrl:string):any { //console.info('ContextsService: request concept for category with id '+categoryId + ' and keyword '+ keyword); @@ -63,9 +62,9 @@ export class ContextsService { return this.http.get(url ) - .map(request => request.json()) - .catch(this.handleError) - .map(res => (parsing)?this.parse(res):res); + //.map(request => request.json()) + .pipe(catchError(this.handleError)) + .pipe(map(res => (parsing)?this.parse(res):res)); // .do(res => console.info("Result is "+ res.length )); } public getSubConcepts(subConceptID :string, keyword: string, parsing:boolean, apiUrl:string):any { @@ -75,9 +74,9 @@ export class ContextsService { return this.http.get(url ) - .map(request => request.json()) - .catch(this.handleError) - .map(res => (parsing)?this.parseSubConcepts(res):res); + //.map(request => request.json()) + .pipe(catchError(this.handleError)) + .pipe(map(res => (parsing)?this.parseSubConcepts(res):res)); // .do(res => console.info("Result is "+ res.length )); } parse (data: any):any { @@ -130,7 +129,7 @@ export class ContextsService { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return observableThrowError(error || 'Server error'); } private getAuthOptions():RequestOptions{ let headers = new Headers(); diff --git a/claims/claim-utils/service/searchCrossref.service.ts b/claims/claim-utils/service/searchCrossref.service.ts index d14b9c8d..81e7afaf 100644 --- a/claims/claim-utils/service/searchCrossref.service.ts +++ b/claims/claim-utils/service/searchCrossref.service.ts @@ -1,13 +1,17 @@ + +import {throwError as observableThrowError, Observable} from 'rxjs'; import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + +import { HttpClient } from '@angular/common/http'; + import { ClaimResult} from '../claimEntities.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchCrossrefService { - constructor( private http: Http ) {} + constructor( private http: HttpClient ) {} searchCrossrefResults (term: string, size : number, page : number, apiUrl:string, parse:boolean = false):any { @@ -15,8 +19,9 @@ export class SearchCrossrefService { let key = url; return this.http.get(url) - .map(request => request.json().message) - .map(request => (parse?this.parse(request.items):request)) + //.map(request => request.json().message) + .pipe(map(request => request['message'])) + .pipe(map(request => (parse?this.parse(request.items):request))) //.catch(this.handleError); } @@ -31,8 +36,9 @@ export class SearchCrossrefService { return this.http.get(url) - .map(request => request.json().message) - .map(request => (parse?this.parse(request.items):request)) + //.map(request => request.json().message) + .pipe(map(request => request['message'])) + .pipe(map(request => (parse?this.parse(request.items):request))) //.catch(this.handleError); } @@ -46,8 +52,9 @@ export class SearchCrossrefService { return this.http.get(url) - .map(request => request.json().message) - .map(request => (parse?this.parse(request.items):request)) + //.map(request => request.json().message) + .pipe(map(request => request['message'])) + .pipe(map(request => (parse?this.parse(request.items):request))) //.catch(this.handleError); } @@ -56,7 +63,7 @@ export class SearchCrossrefService { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return observableThrowError(error || 'Server error'); } parse(response):ClaimResult[]{ var results:ClaimResult[] = []; diff --git a/claims/claim-utils/service/searchDatacite.service.ts b/claims/claim-utils/service/searchDatacite.service.ts index 595a7c15..65eb165f 100644 --- a/claims/claim-utils/service/searchDatacite.service.ts +++ b/claims/claim-utils/service/searchDatacite.service.ts @@ -1,15 +1,18 @@ + +import {throwError as observableThrowError, Observable} from 'rxjs'; import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import { HttpClient } from '@angular/common/http'; + + + import{EnvProperties} from '../../../utils/properties/env-properties'; import { ClaimResult} from '../claimEntities.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchDataciteService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchDataciteResults (term: string, size : number, page : number, properties:EnvProperties, parse:boolean = false):any { //console.info("In search datacite results "+term+ " "+properties.searchDataciteAPIURL); @@ -17,8 +20,8 @@ export class SearchDataciteService { let key = url; return this.http.get( ( properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(request => request.json()) - .map(request => (parse?this.parse(request.data):request)) + //.map(request => request.json()) + .pipe(map(request => (parse?this.parse(request['data']):request))) //.catch(this.handleError); } getDataciteResultByDOI (doi: string, properties:EnvProperties, parse:boolean = false):any { @@ -26,8 +29,8 @@ export class SearchDataciteService { let key = url; return this.http.get( (properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(request => request.json()) - .map(request => (parse?this.parse(request.data):request)) + //.map(request => request.json()) + .pipe(map(request => (parse?this.parse(request['data']):request))) // .do(items => console.log("Datacite Results: total results = "+items.meta.total+" doi = "+doi)) @@ -39,7 +42,7 @@ export class SearchDataciteService { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return observableThrowError(error || 'Server error'); } private extractData(res: Response) { if (res.status < 200 || res.status >= 300) { diff --git a/claims/claim-utils/service/searchOrcid.service.ts b/claims/claim-utils/service/searchOrcid.service.ts index 172ad5f1..05cdb966 100644 --- a/claims/claim-utils/service/searchOrcid.service.ts +++ b/claims/claim-utils/service/searchOrcid.service.ts @@ -2,60 +2,68 @@ import {Injectable} from '@angular/core'; import {URLSearchParams} from '@angular/http'; import {Http, Response} from '@angular/http'; import { Headers, RequestOptions } from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {Observable} from 'rxjs'; import{EnvProperties} from '../../../utils/properties/env-properties'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import { ClaimResult} from '../claimEntities.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchOrcidService { - constructor( private http: Http ) {} + constructor( private http: HttpClient ) {} searchOrcidAuthor (term: string, authorIds: string[], authors, properties:EnvProperties, addId):any { - var headers = new Headers(); - headers.append('Accept', 'application/orcid+json'); + //var headers = new Headers(); + //headers.append('Accept', 'application/orcid+json'); + let headers = new HttpHeaders({'Accept': 'application/orcid+json'}); let url = properties.searchOrcidURL + term+'/record'; let key = url; return this.http.get(url, { headers: headers }) - .map(res => res.json()['person']) - .map(res => [res['name']['given-names'], + //.map(res => res.json()['person']) + .pipe(map(res => res['person'])) + .pipe(map(res => [res['name']['given-names'], res['name']['family-name'], - res['name']]) - .map(res => this.parseOrcidAuthor(res, authorIds, authors, addId)); + res['name']])) + .pipe(map(res => this.parseOrcidAuthor(res, authorIds, authors, addId))); } searchOrcidAuthors (term: string, authorIds: string[], properties:EnvProperties):any { - var headers = new Headers(); - headers.append('Accept', 'application/orcid+json'); + //var headers = new Headers(); + //headers.append('Accept', 'application/orcid+json'); + let headers = new HttpHeaders({'Accept': 'application/orcid+json'}); let url = properties.searchOrcidURL+'search?defType=edismax&q='+term+'&qf=given-name^1.0+family-name^2.0+other-names^1.0+credit-name^1.0&start=0&rows=10'; let key = url; return this.http.get(url, { headers: headers }) - .map(res => res.json()['result']) - .map(res => this.parseOrcidAuthors(res, authorIds)); + //.map(res => res.json()['result']) + .pipe(map(res => res['result'])) + .pipe(map(res => this.parseOrcidAuthors(res, authorIds))); } searchOrcidPublications (id: string, properties:EnvProperties, parse:boolean = false):any { - var headers = new Headers(); - headers.append('Accept', 'application/orcid+json'); + //var headers = new Headers(); + //headers.append('Accept', 'application/orcid+json'); + let headers = new HttpHeaders({'Accept': 'application/orcid+json'}); let url =properties.searchOrcidURL+id+'/works'; let key = url; return this.http.get(url, { headers: headers }) - .map(res => res.json()['group']) - .map(request => (parse?this.parse(id, request):request)); + //.map(res => res.json()['group']) + .pipe(map(res => res['group'])) + .pipe(map(request => (parse?this.parse(id, request):request))); //.map(res => res['orcid-work']); } diff --git a/claims/claimsAdmin/claimsAdmin.component.ts b/claims/claimsAdmin/claimsAdmin.component.ts index 08e6eb01..2841a5cb 100644 --- a/claims/claimsAdmin/claimsAdmin.component.ts +++ b/claims/claimsAdmin/claimsAdmin.component.ts @@ -2,7 +2,7 @@ import {Component, ViewChild, Input} from '@angular/core'; import {Location} from '@angular/common'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; @Component({ diff --git a/claims/claimsByToken/claimsByToken.component.ts b/claims/claimsByToken/claimsByToken.component.ts index d4031a39..9c477d6b 100644 --- a/claims/claimsByToken/claimsByToken.component.ts +++ b/claims/claimsByToken/claimsByToken.component.ts @@ -4,8 +4,7 @@ import {ActivatedRoute, Params, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; import {DataTableDirective} from 'angular-datatables'; -import {Observable} from 'rxjs/Observable'; -import { Subject } from 'rxjs/Subject'; +import {Observable, Subject } from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; import {ErrorCodes} from '../../utils/properties/errorCodes'; diff --git a/claims/claimsByToken/claimsByToken.service.ts b/claims/claimsByToken/claimsByToken.service.ts index 044b9d83..8b90b72a 100644 --- a/claims/claimsByToken/claimsByToken.service.ts +++ b/claims/claimsByToken/claimsByToken.service.ts @@ -1,15 +1,16 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Jsonp, URLSearchParams,ResponseOptions, RequestOptions, Headers} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/do'; +import {RequestOptions, Headers} from '@angular/http'; +import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; +import {throwError} from 'rxjs'; + import { CustomOptions } from '../../services/servicesUtils/customOptions.class'; +import {catchError} from "rxjs/operators"; @Injectable() export class ClaimsByTokenService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getClaims(openaireId: string, apiURL:string):any { @@ -18,9 +19,9 @@ export class ClaimsByTokenService { let key = url; - return this.http.get(url, CustomOptions.getAuthOptions()) + return this.http.get(url, CustomOptions.getAuthOptions()); //.map(res => res.text()) - .map(request => request.json()); + //.map(request => request.json()); } @@ -57,12 +58,11 @@ export class ClaimsByTokenService { let body = JSON.stringify( claimsCurationInfo ); //console.warn('Json body: : '+body); - let headers = new Headers({ 'Content-Type': 'application/json' }); - let options = new RequestOptions({ headers: headers }); + return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) + //.map(res => res.json()) //.do(request => console.info("Insert Response:"+request.status) ) - .catch(this.handleError); + .pipe(catchError(this.handleError)); } @@ -74,17 +74,17 @@ export class ClaimsByTokenService { let body = JSON.stringify( claimsCurationInfo ); //console.warn('Json body: : '+body); - let headers = new Headers({ 'Content-Type': 'application/json' }); - let options = new RequestOptions({ headers: headers }); + return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) - .catch(this.handleError); + //.map(res => res.json()) + .pipe(catchError(this.handleError)); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); + //return Observable.throw(error || 'Server error'); } } diff --git a/claims/directLinking/directLinking.component.ts b/claims/directLinking/directLinking.component.ts index 0a253614..dfe81d84 100644 --- a/claims/directLinking/directLinking.component.ts +++ b/claims/directLinking/directLinking.component.ts @@ -1,5 +1,5 @@ import {Component, Input} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; diff --git a/claims/linking/bulkClaim/bulkClaim.component.ts b/claims/linking/bulkClaim/bulkClaim.component.ts index 87c14a3a..b3e3c8f0 100644 --- a/claims/linking/bulkClaim/bulkClaim.component.ts +++ b/claims/linking/bulkClaim/bulkClaim.component.ts @@ -1,5 +1,5 @@ import {Component, Input, Output, EventEmitter,ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {SearchCrossrefService} from '../../claim-utils/service/searchCrossref.service'; import {SearchDataciteService} from '../../claim-utils/service/searchDatacite.service'; diff --git a/claims/linking/insertClaim/insertClaim.component.ts b/claims/linking/insertClaim/insertClaim.component.ts index f18c5dfe..d3d1358b 100644 --- a/claims/linking/insertClaim/insertClaim.component.ts +++ b/claims/linking/insertClaim/insertClaim.component.ts @@ -1,5 +1,5 @@ import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Router, ActivatedRoute} from '@angular/router'; import {ClaimsService} from '../../claim-utils/service/claims.service'; diff --git a/claims/linking/linkingGeneric.component.ts b/claims/linking/linkingGeneric.component.ts index e31cb1dd..02de3439 100644 --- a/claims/linking/linkingGeneric.component.ts +++ b/claims/linking/linkingGeneric.component.ts @@ -1,7 +1,7 @@ import {Component, Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/claims/myClaims/myClaims.component.ts b/claims/myClaims/myClaims.component.ts index b50ef1a9..06c91cbc 100644 --- a/claims/myClaims/myClaims.component.ts +++ b/claims/myClaims/myClaims.component.ts @@ -1,5 +1,5 @@ import {Component, Input} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Title, Meta} from '@angular/platform-browser'; @Component({ diff --git a/connect/communities/communities.service.ts b/connect/communities/communities.service.ts index eae9c9d0..53dbb81a 100644 --- a/connect/communities/communities.service.ts +++ b/connect/communities/communities.service.ts @@ -1,16 +1,18 @@ 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 {map} from "rxjs/operators"; @Injectable() export class CommunitiesService { public communities: BehaviorSubject = null; - constructor(private http: Http) { + constructor(private http: HttpClient) { this.communities = new BehaviorSubject([]); } @@ -26,7 +28,8 @@ export class CommunitiesService { getCommunities(properties: EnvProperties, url: string) { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .map(res => res.json()).map(res => this.parseCommunities(res)); + //.map(res => res.json()) + .pipe(map(res => this.parseCommunities(res))); } parseCommunities(data: any): CommunityInfo[] { diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index aa718b67..231f9dff 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -1,22 +1,33 @@ import { Injectable } from '@angular/core'; import { Http, Headers, RequestOptions } from '@angular/http'; +import {HttpClient, HttpHeaders} from "@angular/common/http"; import { CommunityInfo } from './communityInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; +import {map} from "rxjs/operators"; +import {COOKIE} from "../../login/utils/helper.class"; @Injectable() export class CommunityService { - constructor(private http: Http) { + constructor(private http: HttpClient) { } 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)); + //.map(res => res.json()) + .pipe(map(res => this.parseCommunity(res))); } updateCommunity(url: string, community: any) { - const headers = new Headers({'Content-Type': 'application/json'}); - const options = new RequestOptions({headers: headers}); + //const headers = new Headers({'Content-Type': 'application/json'}); + //const options = new RequestOptions({headers: headers}); + + const options = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + }) + }; + const body = JSON.stringify(community); return this.http.post(url, body, options); /*.map(res => res.json())*/ @@ -24,39 +35,40 @@ export class CommunityService { 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); + //.map(res => res.json()) + .pipe(map(res => this.parseCommunity(res))) + .pipe(map(community => community.managers.indexOf(manager) !== -1)); } isRIType(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 === 'ri')); + //.map(res => res.json()) + .pipe(map(res => this.parseCommunity(res))) + .pipe(map(community => (community && community.type && community.type === 'ri'))); } isCommunityType(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')); + //.map(res => res.json()) + .pipe(map(res => this.parseCommunity(res))) + .pipe(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) { + //.map(res => ((res === '') ? {} : res.json())) + .pipe(map(res => { + if (res['subscribers'] && res['subscribers'] != null) { - for (let i = 0; i < res.subscribers.length; i++ ) { - if (res.subscribers[i] != null && res.subscribers[i].email === email) { + for (let i = 0; i < res['subscribers'].length; i++ ) { + if (res['subscribers'][i] != null && res['subscribers'][i].email === email) { return true; } } } return false; - }); + })); } private parseCommunity(data: any): CommunityInfo { diff --git a/connect/communityGuard/connectAdminLoginGuard.guard.ts b/connect/communityGuard/connectAdminLoginGuard.guard.ts index 332a8ea2..b34497fc 100644 --- a/connect/communityGuard/connectAdminLoginGuard.guard.ts +++ b/connect/communityGuard/connectAdminLoginGuard.guard.ts @@ -1,12 +1,14 @@ + +import {map, filter, mergeMap} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, - CanLoad, Route + CanLoad, Route, UrlSegment } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Session} from '../../login/utils/helper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {CommunityService} from '../community/community.service'; @@ -25,10 +27,10 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad { if (Session.isPortalAdministrator() || Session.isCommunityCurator()) { return true; } else { - const obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => { + const obs = this.propertiesService.subscribeEnvironment().pipe(map(res => res),mergeMap(properties => { return this.communityService.isCommunityManager(properties, properties['communityAPI'] + community, Session.getUserEmail()); - }); - obs.filter(enabled => !enabled) + }),); + obs.pipe(filter(enabled => !enabled)) .subscribe(() => this.router.navigate(['/user-info'], { queryParams: { 'errorCode': errorCode, @@ -49,7 +51,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad { return this.check(route.queryParams['communityId'], state.url); } - canLoad(route: Route): Observable | Promise | boolean { + canLoad(route: Route, segments: UrlSegment[]): Observable | Promise | boolean { const path = '/' + route.path + document.location.search; return this.check(ConnectHelper.getCommunityFromPath(path), path); } diff --git a/connect/communityGuard/connectCommunityGuard.guard.ts b/connect/communityGuard/connectCommunityGuard.guard.ts index 9f1e47c2..2426ef49 100644 --- a/connect/communityGuard/connectCommunityGuard.guard.ts +++ b/connect/communityGuard/connectCommunityGuard.guard.ts @@ -1,3 +1,5 @@ + +import {filter, mergeMap} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Router, @@ -7,13 +9,13 @@ import { CanLoad, Route } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {CommunityService} from '../community/community.service'; import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service'; import {ConnectHelper} from '../connectHelper'; @Injectable() -export class ConnectCommunityGuard implements CanActivate, CanLoad { +export class ConnectCommunityGuard implements CanActivate { constructor(private router: Router, private communityService: CommunityService, @@ -21,10 +23,10 @@ export class ConnectCommunityGuard implements CanActivate, CanLoad { } check(community: string): Observable | boolean { - const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => { + const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { return this.communityService.isCommunityType(properties, properties['communityAPI'] + community); - }); - obs.filter(enabled => !enabled) + })); + obs.pipe(filter(enabled => !enabled)) .subscribe(() => this.router.navigate(['errorcommunity'])); return obs; } @@ -32,9 +34,4 @@ export class ConnectCommunityGuard implements CanActivate, CanLoad { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { return this.check(route.queryParams['communityId']); } - - canLoad(route: Route): Observable | Promise | boolean { - const path = '/' + route.path + document.location.search; - return this.check(ConnectHelper.getCommunityFromPath(path)); - } } diff --git a/connect/communityGuard/connectRIGuard.guard.ts b/connect/communityGuard/connectRIGuard.guard.ts index ddad2bcf..ad11f6c5 100644 --- a/connect/communityGuard/connectRIGuard.guard.ts +++ b/connect/communityGuard/connectRIGuard.guard.ts @@ -1,3 +1,5 @@ + +import {filter, mergeMap} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Router, @@ -5,9 +7,9 @@ import { ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, - Route + Route, UrlSegment } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {CommunityService} from '../community/community.service'; import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service'; import {ConnectHelper} from '../connectHelper'; @@ -21,10 +23,10 @@ export class ConnectRIGuard implements CanActivate, CanLoad { } check(community: string): Observable | boolean { - const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => { + const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { return this.communityService.isRIType(properties, properties['communityAPI'] + community); - }); - obs.filter(enabled => !enabled) + })); + obs.pipe(filter(enabled => !enabled)) .subscribe(() => this.router.navigate(['errorcommunity'])); return obs; } @@ -33,7 +35,7 @@ export class ConnectRIGuard implements CanActivate, CanLoad { return this.check(route.queryParams['communityId']); } - canLoad(route: Route): Observable | Promise | boolean { + canLoad(route: Route, segments: UrlSegment[]): Observable | Promise | boolean { const path = '/' + route.path + document.location.search; return this.check(ConnectHelper.getCommunityFromPath(path)); } diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index c074ac10..5f04f92b 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -1,6 +1,8 @@ + +import {filter, mergeMap} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Session} from '../../login/utils/helper.class'; import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {CommunityService} from '../community/community.service'; @@ -8,7 +10,7 @@ import { EnvironmentSpecificService} from '../../utils/properties/environment-sp import {ConnectHelper} from '../connectHelper'; @Injectable() -export class ConnectSubscriberGuard implements CanActivate, CanLoad { +export class ConnectSubscriberGuard implements CanActivate { constructor(private router: Router, private communityService: CommunityService, private propertiesService: EnvironmentSpecificService) {} @@ -20,13 +22,13 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad { this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path, communityId:community}}); return false; } else { - const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => { + const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => { if(!community){ community = ConnectHelper.getCommunityFromDomain(properties.domain); } return this.communityService.isSubscribedToCommunity( community, Session.getUserEmail(), properties["adminToolsAPIURL"]) - }); - obs.filter(enabled => !enabled) + })); + obs.pipe(filter(enabled => !enabled)) .subscribe(() => this.router.navigate(['/user-info'], { queryParams: { 'errorCode': errorCode, @@ -41,10 +43,5 @@ export class ConnectSubscriberGuard implements CanActivate, CanLoad { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { return this.check(route.queryParams['communityId'], state.url); } - canLoad(route: Route): Observable | Promise | boolean { - const path = '/' + route.path + document.location.search; - return this.check(ConnectHelper.getCommunityFromPath(path), path); - - } } diff --git a/connect/communityGuard/isCommunity.guard.ts b/connect/communityGuard/isCommunity.guard.ts index 566714c2..6287353a 100644 --- a/connect/communityGuard/isCommunity.guard.ts +++ b/connect/communityGuard/isCommunity.guard.ts @@ -4,10 +4,10 @@ import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, - CanLoad, Route + CanLoad, Route, UrlSegment } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/filter'; +import {Observable} from 'rxjs'; + import {ConnectHelper} from '../connectHelper'; @Injectable() @@ -29,7 +29,7 @@ export class IsCommunity implements CanActivate, CanLoad { return this.check(route.queryParams['communityId']); } - canLoad(route: Route): Observable | Promise | boolean { + canLoad(route: Route, segments: UrlSegment[]): Observable | Promise | boolean { const path = '/' + route.path + document.location.search; return this.check(ConnectHelper.getCommunityFromPath(path)); } diff --git a/connect/contentProviders/searchDataproviders.service.ts b/connect/contentProviders/searchDataproviders.service.ts index acd2b9fa..f9bb279e 100644 --- a/connect/contentProviders/searchDataproviders.service.ts +++ b/connect/contentProviders/searchDataproviders.service.ts @@ -1,15 +1,16 @@ import {Injectable} from '@angular/core'; import {Http} from '@angular/http'; +import {HttpClient} from "@angular/common/http"; import{EnvProperties} from '../../utils/properties/env-properties'; @Injectable() export class SearchCommunityDataprovidersService { - constructor(private http: Http ) {} + 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()) + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); + //.map(res => res.json()) } } diff --git a/connect/curators/curator.service.ts b/connect/curators/curator.service.ts index 58155e40..8efa8441 100644 --- a/connect/curators/curator.service.ts +++ b/connect/curators/curator.service.ts @@ -1,9 +1,9 @@ import {Injectable} from '@angular/core'; -import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {HttpClient} from '@angular/common/http'; import {BehaviorSubject, Observable} from 'rxjs'; import {Curator} from '../../utils/entities/CuratorInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; -import {COOKIE} from '../../login/utils/helper.class'; +import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; @Injectable() export class CuratorService { @@ -34,20 +34,11 @@ export class CuratorService { } public updateCurator(url: string, curator: Curator) { - return this.http.post(url, curator, this.getAuthOptions()); + return this.http.post(url, curator, CustomOptions.getAuthOptions()); } public getCurator(properties: EnvProperties, url: string): Observable { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url); } - // TODO remove and use CustomOptions.getAuthOptions() - private getAuthOptions(): any { - const httpOptions = { - headers: new HttpHeaders({ - 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id), - }), withCredentials: true - }; - return httpOptions; - } } diff --git a/connect/projects/searchProjects.service.ts b/connect/projects/searchProjects.service.ts index ae5255ca..62ff1aa3 100644 --- a/connect/projects/searchProjects.service.ts +++ b/connect/projects/searchProjects.service.ts @@ -1,15 +1,16 @@ import {Injectable} from '@angular/core'; import {Http} from '@angular/http'; +import {HttpClient} from "@angular/common/http"; import{EnvProperties} from '../../utils/properties/env-properties'; @Injectable() export class SearchCommunityProjectsService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchProjects (properties:EnvProperties, communityId: string):any { let url = properties.communityAPI+communityId+"/projects"; - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); + //.map(res => res.json()) } } diff --git a/connect/userEmailPreferences/mailPrefs.component.ts b/connect/userEmailPreferences/mailPrefs.component.ts index db7ae031..6c3653f3 100644 --- a/connect/userEmailPreferences/mailPrefs.component.ts +++ b/connect/userEmailPreferences/mailPrefs.component.ts @@ -1,6 +1,6 @@ import {Component, ViewChild, Input} from '@angular/core'; import {Location} from '@angular/common'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {ActivatedRoute, Router} from '@angular/router'; import {ModalLoading} from '../../utils/modal/loading.component'; import {AlertModal} from '../../utils/modal/alert'; diff --git a/connect/userEmailPreferences/mailPrefs.service.ts b/connect/userEmailPreferences/mailPrefs.service.ts index cf8644e5..30da8a8b 100644 --- a/connect/userEmailPreferences/mailPrefs.service.ts +++ b/connect/userEmailPreferences/mailPrefs.service.ts @@ -1,6 +1,7 @@ import {Injectable} from '@angular/core'; import {Http, RequestOptions, Headers, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; //import { HttpErrorResponse } from '@angular/common/http'; import {EnvProperties} from '../../utils/properties/env-properties'; @@ -8,13 +9,13 @@ import { CustomOptions } from '../../services/servicesUtils/customOptions.class' @Injectable() export class MailPrefsService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getUserEmailPreferencesForCommunity (communityId:string, apiUrl:string):any { let url = apiUrl +"users/notification"+"?communityId="+communityId; return this.http.get(url, CustomOptions.getAuthOptions()) - .map(request => request.json()) + //.map(request => request.json()) //.do(request => console.info("Get user email preferences for communityId= "+communityId )); //.catch(this.handleError); } @@ -23,13 +24,13 @@ export class MailPrefsService { let url = apiUrl +"users/notification"; //var error: HttpErrorResponse = new HttpErrorResponse({"error": {"code": 204}, "status" : 204}); // doesn't work - var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null}); + //var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null}); return this.http.get(url, CustomOptions.getAuthOptions()) //.timeoutWith(100, Observable.throw(response)) // goes to error //.timeoutWith(100, Observable.of(response)) // goes to //.do(request => console.info(request)) - .map(request => request.json()) + //.map(request => request.json()) //.do(request => console.info("Get user email preferences for OpenAIRE" )); //.catch(this.handleError); } @@ -39,18 +40,18 @@ export class MailPrefsService { let body = JSON.stringify( notification ); //console.warn('Json body: : '+body); - let headers = new Headers({ 'Content-Type': 'application/json' }); - let options = new RequestOptions({ headers: headers }); + //let headers = new Headers({ 'Content-Type': 'application/json' }); + //let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) + //.map(res => res.json()) //.do(request => console.info("Insert Response:"+request.status) ); //.catch(this.handleError); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } } diff --git a/connect/zenodoCommunities/searchZenodoCommunities.service.ts b/connect/zenodoCommunities/searchZenodoCommunities.service.ts index 099522c5..a70641ab 100644 --- a/connect/zenodoCommunities/searchZenodoCommunities.service.ts +++ b/connect/zenodoCommunities/searchZenodoCommunities.service.ts @@ -1,15 +1,16 @@ import {Injectable} from '@angular/core'; import {Http} from '@angular/http'; +import {HttpClient} from "@angular/common/http"; import{EnvProperties} from '../../utils/properties/env-properties'; @Injectable() export class SearchZenodoCommunitiesService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchZCommunities (properties:EnvProperties, communityId: string):any { let url = properties.communityAPI+communityId+"/zenodocommunities"; - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); + //.map(res => res.json()) } } diff --git a/connect/zenodoCommunities/zenodo-communities.service.ts b/connect/zenodoCommunities/zenodo-communities.service.ts index 2388730f..6b89828d 100644 --- a/connect/zenodoCommunities/zenodo-communities.service.ts +++ b/connect/zenodoCommunities/zenodo-communities.service.ts @@ -1,28 +1,32 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Headers, RequestOptions} from '@angular/http'; -import {Observable} from 'rxjs/Rx'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; import {ZenodoCommunityInfo} from './zenodoCommunityInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class ZenodoCommunitiesService { - constructor(private http:Http) { + constructor(private http:HttpClient) { } getZenodoCommunities(properties:EnvProperties, url: string) { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) - .map(res => res.json()).map(res => [this.parseZenodoCommunities(res.hits.hits),res.hits.total]); + //.map(res => res.json()) + .pipe(map(res => [this.parseZenodoCommunities(res['hits'].hits),res['hits'].total])); } getZenodoCommunityById(properties:EnvProperties, url: string, openaireId:string) { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) - .map(res => res.json()).map(res => { + //.map(res => res.json()) + .pipe(map(res => { var community = this.parseZenodoCommunity(res); community["openaireId"]=openaireId; return community; - }); + })); } parseZenodoCommunities(data: any): ZenodoCommunityInfo[] { @@ -53,6 +57,7 @@ export class ZenodoCommunitiesService { getTotalZenodoCommunities(properties:EnvProperties, url: string) { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) - .map(res => res.json()).map(res => res.hits.total); + //.map(res => res.json()) + .pipe(map(res => res['hits'].total)); } } diff --git a/deposit/datasets/depositBySubject.component.ts b/deposit/datasets/depositBySubject.component.ts index dd5dfa6a..12b6317a 100644 --- a/deposit/datasets/depositBySubject.component.ts +++ b/deposit/datasets/depositBySubject.component.ts @@ -2,7 +2,7 @@ import {Component, Input} from '@angular/core'; import {Router, ActivatedRoute} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/deposit/datasets/depositBySubjectResult.component.ts b/deposit/datasets/depositBySubjectResult.component.ts index 422e2cac..055c8ac6 100644 --- a/deposit/datasets/depositBySubjectResult.component.ts +++ b/deposit/datasets/depositBySubjectResult.component.ts @@ -3,7 +3,7 @@ import {Router} from '@angular/router'; import {ActivatedRoute} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/deposit/deposit.component.ts b/deposit/deposit.component.ts index d3348c85..f097d03b 100644 --- a/deposit/deposit.component.ts +++ b/deposit/deposit.component.ts @@ -2,7 +2,7 @@ import {Component, Input} from '@angular/core'; import {Router, ActivatedRoute} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../utils/properties/env-properties'; diff --git a/deposit/depositResult.component.ts b/deposit/depositResult.component.ts index aacd0215..38f9de1c 100644 --- a/deposit/depositResult.component.ts +++ b/deposit/depositResult.component.ts @@ -2,7 +2,7 @@ import {Component, Input} from '@angular/core'; import {Router, ActivatedRoute} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {ErrorCodes} from '../utils/properties/errorCodes'; import{EnvProperties} from '../utils/properties/env-properties'; diff --git a/error/isRouteEnabled.guard.ts b/error/isRouteEnabled.guard.ts index 7e3fc80c..3a59488c 100644 --- a/error/isRouteEnabled.guard.ts +++ b/error/isRouteEnabled.guard.ts @@ -1,3 +1,7 @@ + +import {of as observableOf, Observable} from 'rxjs'; + +import {map, filter, mergeMap} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Router, @@ -7,14 +11,13 @@ import { RouterStateSnapshot, Route, Data } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/filter'; + import { ConfigurationService } from '../utils/configuration/configuration.service'; import { EnvironmentSpecificService} from '../utils/properties/environment-specific.service'; import {ConnectHelper} from '../connect/connectHelper'; @Injectable() -export class IsRouteEnabled implements CanActivate, CanLoad { +export class IsRouteEnabled implements CanActivate { constructor(private router: Router, private config: ConfigurationService, @@ -26,18 +29,18 @@ export class IsRouteEnabled implements CanActivate, CanLoad { community = data['community']; } const redirect = customRedirect ? customRedirect : '/error'; - const obs = this.propertiesService.subscribeEnvironment().map(res => { + const obs = this.propertiesService.subscribeEnvironment().pipe(map(res => { if (!community) { community = ConnectHelper.getCommunityFromDomain(res.domain); } return res['adminToolsAPIURL']; - }).mergeMap(url => { + }),mergeMap(url => { if (!community) { // no community to check - return true - return Observable.of(true); + return observableOf(true); } return this.config.isPageEnabled(url, community, '/' + path.split('?')[0].substring(1)); - }); - obs.filter(enabled => !enabled) + }),); + obs.pipe(filter(enabled => !enabled)) .subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}})); return obs; } @@ -45,8 +48,4 @@ export class IsRouteEnabled implements CanActivate, CanLoad { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { return this.check(route.data, route.queryParams['communityId'], state.url); } - canLoad(route: Route): Observable | Promise | boolean { - const path = '/' + route.path + document.location.search; - return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path); - } } diff --git a/landingPages/dataProvider/dataProvider.component.ts b/landingPages/dataProvider/dataProvider.component.ts index ab0f0c66..d5f56e32 100644 --- a/landingPages/dataProvider/dataProvider.component.ts +++ b/landingPages/dataProvider/dataProvider.component.ts @@ -1,12 +1,12 @@ + +import {merge as observableMerge, Observable} from 'rxjs'; import {Component, ViewChild} from '@angular/core'; import {Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/switch'; -import 'rxjs/add/operator/switchMap'; + import {EnvProperties} from '../../utils/properties/env-properties'; @@ -419,7 +419,7 @@ export class DataProviderComponent { && ( this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.LOADING || this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE )) { - this.relatedDatasourcesSub = Observable.merge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete) + this.relatedDatasourcesSub = observableMerge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete) .subscribe( data => {}, err => {}, diff --git a/landingPages/dataProvider/dataProvider.service.ts b/landingPages/dataProvider/dataProvider.service.ts index cc8dc189..d14c8e1d 100644 --- a/landingPages/dataProvider/dataProvider.service.ts +++ b/landingPages/dataProvider/dataProvider.service.ts @@ -1,17 +1,19 @@ import {Injectable} from '@angular/core'; import {Http, Response,Headers, RequestOptions} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {DataProviderInfo} from '../../utils/entities/dataProviderInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import{EnvProperties} from '../../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class DataProviderService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} dataProviderInfo: DataProviderInfo; @@ -20,37 +22,43 @@ export class DataProviderService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']) - .map(res => [res['oaf:datasource'], + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity'])) + .pipe(map(res => [res['oaf:datasource'], res['oaf:datasource']['datasourcetype'], res['oaf:datasource']['openairecompatibility'], res['oaf:datasource']['collectedfrom'], res['oaf:datasource']['accessinfopackage'], res['oaf:datasource']['rels']['rel'], res['oaf:datasource']['journal'] //6 - ]) - .map(res => this.parseDataProviderInfo(res)); + ])) + .pipe(map(res => this.parseDataProviderInfo(res))); } getDataproviderAggregationStatus(original_id: string, properties:EnvProperties):any { - let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'}); - let options = new RequestOptions({headers: headers}); + //let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'}); + //let options = new RequestOptions({headers: headers}); - let page: number = 0; + const options = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'accept': 'application/json'}) + }; + + let page: number = 0; let size: number = 1; return this.http.post(properties.datasourcesAPI+page+"/"+size+"?requestSortBy=id&order=ASCENDING", JSON.stringify({ "id": original_id }), options) - .map(res => res.json()) - .map(res => res['datasourceInfo']) - .map(res => this.parseDataproviderAggregationStatus(res)); + //.map(res => res.json()) + .pipe(map(res => res['datasourceInfo'])) + .pipe(map(res => this.parseDataproviderAggregationStatus(res))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseDataproviderAggregationStatus(data: any): any { diff --git a/landingPages/dataProvider/relatedDatasourcesTab.component.ts b/landingPages/dataProvider/relatedDatasourcesTab.component.ts index 08fb6b58..75ef6444 100644 --- a/landingPages/dataProvider/relatedDatasourcesTab.component.ts +++ b/landingPages/dataProvider/relatedDatasourcesTab.component.ts @@ -7,7 +7,7 @@ import { FetchOrps } from '../../utils/fetchEntitiesClasses/fetchOrps.class'; import { ErrorCodes} from '../../utils/properties/errorCodes'; import {RouterHelper} from '../../utils/routerHelper.class'; -import { Observable } from 'rxjs/Observable'; +import { Observable } from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; @Component({ diff --git a/landingPages/dataset/dataset.component.ts b/landingPages/dataset/dataset.component.ts index 418d497c..ed4d998f 100644 --- a/landingPages/dataset/dataset.component.ts +++ b/landingPages/dataset/dataset.component.ts @@ -3,7 +3,7 @@ import {Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {DatasetInfo} from '../../utils/entities/datasetInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/landingPages/dataset/dataset.service.ts b/landingPages/dataset/dataset.service.ts index ac19454e..564e1b74 100644 --- a/landingPages/dataset/dataset.service.ts +++ b/landingPages/dataset/dataset.service.ts @@ -1,18 +1,20 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {DatasetInfo} from '../../utils/entities/datasetInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import{EnvProperties} from '../../utils/properties/env-properties'; import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class DatasetService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -26,9 +28,9 @@ export class DatasetService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res]) - .map(res => [res[1], //0 + //.map(res => res.json()) + .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res])) + .pipe(map(res => [res[1], //0 res[1]['title'], //1 res[1]['rels']['rel'], //2 res[1]['children'], //3 @@ -45,14 +47,15 @@ export class DatasetService { res[2], //13 (res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, //14 res[1]['journal'] //15 - ]).map(res => this.parseDatasetInfo(res, properties)); + ])) + .pipe(map(res => this.parseDatasetInfo(res, properties))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseDatasetInfo (data: any, properties: EnvProperties):any { diff --git a/landingPages/htmlProjectReport/htmlProjectReport.component.ts b/landingPages/htmlProjectReport/htmlProjectReport.component.ts index 7f284fce..43bf7531 100644 --- a/landingPages/htmlProjectReport/htmlProjectReport.component.ts +++ b/landingPages/htmlProjectReport/htmlProjectReport.component.ts @@ -2,7 +2,7 @@ import {Component, Input} from '@angular/core'; import {ActivatedRoute, Params, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/landingPages/htmlProjectReport/htmlProjectReport.service.ts b/landingPages/htmlProjectReport/htmlProjectReport.service.ts index f63a3477..a50e6f1f 100644 --- a/landingPages/htmlProjectReport/htmlProjectReport.service.ts +++ b/landingPages/htmlProjectReport/htmlProjectReport.service.ts @@ -1,12 +1,14 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/do'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + +import {map} from "rxjs/operators"; @Injectable() export class HtmlProjectReportService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getHTML(id: string, size: number, type:string, csvAPIURL: string ):any { @@ -32,6 +34,9 @@ export class HtmlProjectReportService { let key = url; return this.http.get(url) - .map(res => res.text()); + .pipe(map(res => { + let resText:any = res; + return resText.text(); + })); } } diff --git a/landingPages/landing-utils/deletedByInference/deletedByInference.component.ts b/landingPages/landing-utils/deletedByInference/deletedByInference.component.ts index 1df36739..c14fa727 100644 --- a/landingPages/landing-utils/deletedByInference/deletedByInference.component.ts +++ b/landingPages/landing-utils/deletedByInference/deletedByInference.component.ts @@ -2,7 +2,7 @@ import {Component, ViewChild} from '@angular/core'; import {ElementRef, Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../../utils/properties/env-properties'; import {DeletedByInferenceResult} from '../../../utils/entities/deletedByInferenceResult'; @@ -11,8 +11,8 @@ import {ErrorCodes} from '../../../utils/properties/errorCodes import {DeletedByInferenceService} from './deletedByInference.service'; -//import {zip} from 'rxjs'; -import 'rxjs/add/observable/zip'; +import {zip} from 'rxjs'; + @Component({ selector: 'deletedByInference', @@ -152,7 +152,7 @@ export class DeletedByInferenceComponent { allRequests.push(this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties)); } - Observable.zip.apply(null, allRequests).subscribe( + zip.apply(null, allRequests).subscribe( // this._deletedByInferenceService.getDeletedByInferencePublications(id, this.properties).subscribe( data => { this.results = data; diff --git a/landingPages/landing-utils/deletedByInference/deletedByInference.service.ts b/landingPages/landing-utils/deletedByInference/deletedByInference.service.ts index 734c35b1..92823ef5 100644 --- a/landingPages/landing-utils/deletedByInference/deletedByInference.service.ts +++ b/landingPages/landing-utils/deletedByInference/deletedByInference.service.ts @@ -1,21 +1,15 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient} from "@angular/common/http"; import {DeletedByInferenceResult} from '../../../utils/entities/deletedByInferenceResult'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; -import 'rxjs/add/operator/map'; -import{EnvProperties} from '../../../utils/properties/env-properties'; - - -import { ParsingFunctions } from '../parsingFunctions.class'; +import {EnvProperties} from '../../../utils/properties/env-properties'; +import {ParsingFunctions} from '../parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class DeletedByInferenceService { private sizeOfDescription: number = 270; - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -26,9 +20,9 @@ export class DeletedByInferenceService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']) - .map(res => this.parseDeletedByInferencePublications(res, properties)); + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity'])) + .pipe(map(res => this.parseDeletedByInferencePublications(res, properties))); } parseDeletedByInferencePublications (result: any, properties: EnvProperties): DeletedByInferenceResult { diff --git a/landingPages/landing-utils/metrics.component.ts b/landingPages/landing-utils/metrics.component.ts index 9d98731f..f554cfbb 100644 --- a/landingPages/landing-utils/metrics.component.ts +++ b/landingPages/landing-utils/metrics.component.ts @@ -3,7 +3,7 @@ import {Metrics} from '../../utils/entities/metrics'; import {MetricsService } from '../../services/metrics.service'; import {ErrorCodes} from '../../utils/properties/errorCodes'; -import { Subscription } from 'rxjs/Subscription'; +import { Subscription } from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; @Component({ diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts index 4235b1f9..281fed76 100644 --- a/landingPages/organization/organization.component.ts +++ b/landingPages/organization/organization.component.ts @@ -3,8 +3,7 @@ import {ElementRef, Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; -import {Subject} from 'rxjs/Subject'; +import {Observable, Subject} from 'rxjs'; import {OrganizationService} from '../../services/organization.service'; import {OrganizationInfo} from '../../utils/entities/organizationInfo'; diff --git a/landingPages/orp/orp.component.ts b/landingPages/orp/orp.component.ts index 1f4fa1e3..8c2dc96f 100644 --- a/landingPages/orp/orp.component.ts +++ b/landingPages/orp/orp.component.ts @@ -3,7 +3,7 @@ import {Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {OrpInfo} from '../../utils/entities/orpInfo'; import {EnvProperties} from '../../utils/properties/env-properties'; diff --git a/landingPages/orp/orp.service.ts b/landingPages/orp/orp.service.ts index 61434cca..ebbd6ec1 100644 --- a/landingPages/orp/orp.service.ts +++ b/landingPages/orp/orp.service.ts @@ -1,18 +1,15 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {throwError} from 'rxjs'; import {OrpInfo} from '../../utils/entities/orpInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; -import{EnvProperties} from '../../utils/properties/env-properties'; - -import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {ParsingFunctions} from '../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class OrpService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -25,9 +22,9 @@ export class OrpService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'],res]) - .map(res => [res[1]['oaf:result'], //0 + //.map(res => res.json()) + .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'],res])) + .pipe(map(res => [res[1]['oaf:result'], //0 res[1]['oaf:result']['title'], //1 res[1]['oaf:result']['rels']['rel'], //2 res[1]['oaf:result']['children'], //3 @@ -43,14 +40,15 @@ export class OrpService { res[2], //13 (res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, //14 res[1]['oaf:result']['journal'] //15 - ]).map(res => this.parseOrpInfo(res, properties)); + ])) + .pipe(map(res => this.parseOrpInfo(res, properties))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseOrpInfo (data: any, properties: EnvProperties):any { diff --git a/landingPages/project/project.component.ts b/landingPages/project/project.component.ts index e3f2834c..7d308361 100644 --- a/landingPages/project/project.component.ts +++ b/landingPages/project/project.component.ts @@ -4,7 +4,7 @@ import {ActivatedRoute, Router} from '@angular/router'; import {Params} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {ProjectService} from './project.service'; import {ProjectInfo} from '../../utils/entities/projectInfo'; diff --git a/landingPages/project/project.service.ts b/landingPages/project/project.service.ts index abf6235a..32ebcaa5 100644 --- a/landingPages/project/project.service.ts +++ b/landingPages/project/project.service.ts @@ -1,18 +1,20 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {ProjectInfo} from '../../utils/entities/projectInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import{EnvProperties} from '../../utils/properties/env-properties'; import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class ProjectService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -25,12 +27,12 @@ export class ProjectService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']['oaf:project']) - .map(res => [res, + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project'])) + .pipe(map(res => [res, res['fundingtree'], - res['rels']['rel']]) - .map(res => this.parseProjectInfo(res, properties)); + res['rels']['rel']])) + .pipe(map(res => this.parseProjectInfo(res, properties))); } @@ -43,13 +45,13 @@ export class ProjectService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['results'][0]) - .map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],res['result']['header']['dri:objIdentifier']]) - .map(res => [res[0], + //.map(res => res.json()) + .pipe(map(res => res['results'][0])) + .pipe(map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],res['result']['header']['dri:objIdentifier']])) + .pipe(map(res => [res[0], res[0]['fundingtree'], - res[0]['rels']['rel'],res[1]]) - .map(res => this.parseProjectInfo(res, properties)); + res[0]['rels']['rel'],res[1]])) + .pipe(map(res => this.parseProjectInfo(res, properties))); } /* @@ -61,12 +63,12 @@ export class ProjectService { let key = url+'_projectDates'; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']['oaf:project']) - .map(res => [res, + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project'])) + .pipe(map(res => [res, res['fundingtree'], - res['rels']['rel']]) - .map(res => this.parseProjectDates(id,res)) + res['rels']['rel']])) + .pipe(map(res => this.parseProjectDates(id,res))) } @@ -75,14 +77,14 @@ export class ProjectService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']['oaf:project']) - .map(res => this.parseHTMLInfo(res)); + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project'])) + .pipe(map(res => this.parseHTMLInfo(res))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseHTMLInfo (data: any):any { diff --git a/landingPages/publication/publication.component.ts b/landingPages/publication/publication.component.ts index 011960ec..60b7e081 100644 --- a/landingPages/publication/publication.component.ts +++ b/landingPages/publication/publication.component.ts @@ -3,7 +3,7 @@ import {Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {EnvProperties} from '../../utils/properties/env-properties'; import {PublicationInfo} from '../../utils/entities/publicationInfo'; diff --git a/landingPages/publication/publication.service.ts b/landingPages/publication/publication.service.ts index e080fa07..f4836b84 100644 --- a/landingPages/publication/publication.service.ts +++ b/landingPages/publication/publication.service.ts @@ -1,22 +1,15 @@ - import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {throwError} from 'rxjs'; import {PublicationInfo} from '../../utils/entities/publicationInfo'; -import {DeletedByInferenceResult} from '../../utils/entities/deletedByInferenceResult'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; -import 'rxjs/add/operator/map'; -import{EnvProperties} from '../../utils/properties/env-properties'; - - -import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {ParsingFunctions} from '../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class PublicationService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -28,9 +21,9 @@ export class PublicationService { let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res]) - .map(res => [ res[1]['oaf:result'], //0 + //.map(res => res.json()) + .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res])) + .pipe(map(res => [ res[1]['oaf:result'], //0 res[1]['oaf:result']['title'], //1 res[1]['oaf:result']['rels']['rel'], //2 res[1]['oaf:result']['children'], //3 @@ -46,15 +39,15 @@ export class PublicationService { res[1]['oaf:result']['creator'], //13 res[2], //14 res[1]['oaf:result']['country'] //15 - ]) - .map(res => this.parsePublicationInfo(res, properties)); + ])) + .pipe(map(res => this.parsePublicationInfo(res, properties))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parsePublicationInfo (data: any, properties: EnvProperties):any { @@ -378,8 +371,8 @@ export class PublicationService { //return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) return this.http.get(url) - .map(res => res.json()) - .map(res => [res['total'], this.parseOpenCitations(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['total'], this.parseOpenCitations(res['results'])])); } parseOpenCitations(openCitations: any): {"url": string, "title": string, "year": string, "doi": string, "authors": string[]}[] { diff --git a/landingPages/software/software.component.ts b/landingPages/software/software.component.ts index 06b040bd..b3406195 100644 --- a/landingPages/software/software.component.ts +++ b/landingPages/software/software.component.ts @@ -3,7 +3,7 @@ import {Input} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {SoftwareService} from './software.service'; import {SoftwareInfo} from '../../utils/entities/softwareInfo'; diff --git a/landingPages/software/software.service.ts b/landingPages/software/software.service.ts index 36e8f7b1..d2eed2ea 100644 --- a/landingPages/software/software.service.ts +++ b/landingPages/software/software.service.ts @@ -1,18 +1,15 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {throwError} from 'rxjs'; import {SoftwareInfo} from '../../utils/entities/softwareInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; -import{EnvProperties} from '../../utils/properties/env-properties'; - -import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../../utils/properties/env-properties'; +import {ParsingFunctions} from '../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; @Injectable() export class SoftwareService { - constructor(private http: Http ) { + constructor(private http: HttpClient ) { this.parsingFunctions = new ParsingFunctions(); } @@ -26,9 +23,9 @@ export class SoftwareService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'], res]) - .map(res => [res[1], + //.map(res => res.json()) + .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'], res])) + .pipe(map(res => [res[1], res[1]['title'], res[1]['rels']['rel'], res[1]['children'], @@ -45,14 +42,15 @@ export class SoftwareService { res[1]['programmingLanguage'], res[2], res[1]['journal'] //15 - ]).map(res => this.parseSoftwareInfo(res, properties)); + ])) + .pipe(map(res => this.parseSoftwareInfo(res, properties))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseSoftwareInfo (data: any, properties: EnvProperties):any { diff --git a/login/adminLoginGuard.guard.ts b/login/adminLoginGuard.guard.ts index d3f5728a..7d3eb219 100644 --- a/login/adminLoginGuard.guard.ts +++ b/login/adminLoginGuard.guard.ts @@ -1,11 +1,19 @@ -import { Injectable } from '@angular/core'; -import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Injectable} from '@angular/core'; +import { + Router, + CanActivate, + ActivatedRouteSnapshot, + RouterStateSnapshot, + CanLoad, + Route, + UrlSegment +} from '@angular/router'; +import {Observable} from 'rxjs'; import {Session} from './utils/helper.class'; import {LoginErrorCodes} from './utils/guardHelper.class'; @Injectable() -export class AdminLoginGuard implements CanActivate, CanLoad { +export class AdminLoginGuard implements CanActivate{ constructor(private router: Router) { } @@ -22,7 +30,12 @@ export class AdminLoginGuard implements CanActivate, CanLoad { } } if (!loggedIn || !isAdmin) { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}}); + this.router.navigate(['/user-info'], { + queryParams: { + 'errorCode': errorCode, + 'redirectUrl': path + } + }); } return loggedIn && isAdmin; } @@ -31,7 +44,4 @@ export class AdminLoginGuard implements CanActivate, CanLoad { return this.check(state.url); } - canLoad(route: Route): Observable | Promise | boolean { - return this.check('/' + route.path); - } } diff --git a/login/claimsCuratorGuard.guard.ts b/login/claimsCuratorGuard.guard.ts index f4d2a457..e4574cfe 100644 --- a/login/claimsCuratorGuard.guard.ts +++ b/login/claimsCuratorGuard.guard.ts @@ -1,11 +1,19 @@ -import { Injectable } from '@angular/core'; -import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Injectable} from '@angular/core'; +import { + Router, + CanActivate, + ActivatedRouteSnapshot, + RouterStateSnapshot, + CanLoad, + Route, + UrlSegment +} from '@angular/router'; +import {Observable} from 'rxjs'; import {Session} from './utils/helper.class'; import {LoginErrorCodes} from './utils/guardHelper.class'; @Injectable() -export class ClaimsCuratorGuard implements CanActivate, CanLoad { +export class ClaimsCuratorGuard implements CanActivate { constructor(private router: Router) { } @@ -24,7 +32,12 @@ export class ClaimsCuratorGuard implements CanActivate, CanLoad { } } if (!loggedIn || !isAuthorized) { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}}); + this.router.navigate(['/user-info'], { + queryParams: { + 'errorCode': errorCode, + 'redirectUrl': path + } + }); } return loggedIn && isAuthorized; } @@ -33,7 +46,4 @@ export class ClaimsCuratorGuard implements CanActivate, CanLoad { return this.check(state.url); } - canLoad(route: Route): Observable | Promise | boolean { - return this.check('/' + route.path); - } } diff --git a/login/freeGuard.guard.ts b/login/freeGuard.guard.ts index da71fc42..d90dc0ad 100644 --- a/login/freeGuard.guard.ts +++ b/login/freeGuard.guard.ts @@ -7,11 +7,11 @@ import { Route, CanLoad } from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {LoginErrorCodes} from './utils/guardHelper.class'; @Injectable() -export class FreeGuard implements CanActivate, CanLoad { +export class FreeGuard implements CanActivate { constructor(private router: Router) { } @@ -28,7 +28,4 @@ export class FreeGuard implements CanActivate, CanLoad { return this.check(state.url); } - canLoad(route: Route): Observable | Promise | boolean { - return this.check('/' + route.path); - } } diff --git a/login/loginGuard.guard.ts b/login/loginGuard.guard.ts index a95ac9f3..0a9d59fa 100644 --- a/login/loginGuard.guard.ts +++ b/login/loginGuard.guard.ts @@ -1,11 +1,19 @@ -import { Injectable } from '@angular/core'; -import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Injectable} from '@angular/core'; +import { + Router, + CanActivate, + ActivatedRouteSnapshot, + RouterStateSnapshot, + Route, + CanLoad, + UrlSegment +} from '@angular/router'; +import {Observable} from 'rxjs'; import {Session} from './utils/helper.class'; import {LoginErrorCodes} from './utils/guardHelper.class'; @Injectable() -export class LoginGuard implements CanActivate, CanLoad { +export class LoginGuard implements CanActivate { constructor(private router: Router) { } @@ -16,7 +24,12 @@ export class LoginGuard implements CanActivate, CanLoad { loggedIn = true; } if (!loggedIn) { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}}); + this.router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_LOGIN, + 'redirectUrl': path + } + }); } return loggedIn; } @@ -24,8 +37,4 @@ export class LoginGuard implements CanActivate, CanLoad { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { return this.check(state.url); } - - canLoad(route: Route): Observable | Promise | boolean { - return this.check('/' + route.path); - } } diff --git a/searchPages/advanced/advancedSearchDataProviders.component.ts b/searchPages/advanced/advancedSearchDataProviders.component.ts index ac51e2ea..490d1668 100644 --- a/searchPages/advanced/advancedSearchDataProviders.component.ts +++ b/searchPages/advanced/advancedSearchDataProviders.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchDataprovidersService} from '../../services/searchDataproviders.service'; diff --git a/searchPages/advanced/advancedSearchDatasets.component.ts b/searchPages/advanced/advancedSearchDatasets.component.ts index e23ecc3b..fcd33d76 100644 --- a/searchPages/advanced/advancedSearchDatasets.component.ts +++ b/searchPages/advanced/advancedSearchDatasets.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchDatasetsService} from '../../services/searchDatasets.service'; diff --git a/searchPages/advanced/advancedSearchOrganizations.component.ts b/searchPages/advanced/advancedSearchOrganizations.component.ts index 00b57756..3e5dc5a7 100644 --- a/searchPages/advanced/advancedSearchOrganizations.component.ts +++ b/searchPages/advanced/advancedSearchOrganizations.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchOrganizationsService} from '../../services/searchOrganizations.service'; diff --git a/searchPages/advanced/advancedSearchOrps.component.ts b/searchPages/advanced/advancedSearchOrps.component.ts index a78251c1..fdc70bb2 100644 --- a/searchPages/advanced/advancedSearchOrps.component.ts +++ b/searchPages/advanced/advancedSearchOrps.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchOrpsService} from '../../services/searchOrps.service'; diff --git a/searchPages/advanced/advancedSearchProjects.component.ts b/searchPages/advanced/advancedSearchProjects.component.ts index fd676f4c..7bb76c8c 100644 --- a/searchPages/advanced/advancedSearchProjects.component.ts +++ b/searchPages/advanced/advancedSearchProjects.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchProjectsService} from '../../services/searchProjects.service'; diff --git a/searchPages/advanced/advancedSearchPublications.component.ts b/searchPages/advanced/advancedSearchPublications.component.ts index 44d381c5..f3f3fae5 100644 --- a/searchPages/advanced/advancedSearchPublications.component.ts +++ b/searchPages/advanced/advancedSearchPublications.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchPublicationsService} from '../../services/searchPublications.service'; diff --git a/searchPages/advanced/advancedSearchSoftware.component.ts b/searchPages/advanced/advancedSearchSoftware.component.ts index 4b424e4f..059cb19d 100644 --- a/searchPages/advanced/advancedSearchSoftware.component.ts +++ b/searchPages/advanced/advancedSearchSoftware.component.ts @@ -1,5 +1,5 @@ import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Router, ActivatedRoute} from '@angular/router'; import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchSoftwareService} from '../../services/searchSoftware.service'; diff --git a/searchPages/find/search.component.ts b/searchPages/find/search.component.ts index d2e398b2..2161466d 100644 --- a/searchPages/find/search.component.ts +++ b/searchPages/find/search.component.ts @@ -6,7 +6,7 @@ import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {FetchPublications} from '../../utils/fetchEntitiesClasses/fetchPublications.class'; import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class'; @@ -155,9 +155,9 @@ 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 => { var showEntity = {}; - for(var i=0; i< data.entities.length; i++){ + for(var i=0; i< data['entities'].length; i++){ - showEntity[""+data.entities[i]["pid"]+""] = data.entities[i]["isEnabled"]; + showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"]; } this.showPublications = showEntity["publication"]; this.showDatasets = showEntity["dataset"]; diff --git a/searchPages/searchUtils/advancedSearchForm.component.ts b/searchPages/searchUtils/advancedSearchForm.component.ts index 18841a90..8a87e997 100644 --- a/searchPages/searchUtils/advancedSearchForm.component.ts +++ b/searchPages/searchUtils/advancedSearchForm.component.ts @@ -1,12 +1,10 @@ -import {Component, Input, Output, EventEmitter, ElementRef} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; -import { Subject } from 'rxjs/Subject'; +import {Component, EventEmitter, Input, Output} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import {AdvancedField, OPERATOR} from '../searchUtils/searchHelperClasses.class'; -import {SearchFields, FieldDetails} from '../../utils/properties/searchFields'; +import {AdvancedField} from '../searchUtils/searchHelperClasses.class'; +import {SearchFields} from '../../utils/properties/searchFields'; import {Dates} from '../../utils/string-utils.class'; -import{EnvProperties} from '../../utils/properties/env-properties'; +import {EnvProperties} from '../../utils/properties/env-properties'; @Component({ selector: 'advanced-search-form', @@ -30,7 +28,7 @@ export class AdvancedSearchFormComponent { fieldList:{[id:string]:any[]} = {}; public searchFields:SearchFields = new SearchFields(); properties:EnvProperties; - public operators: {name:string, id:string}[] = this.searchFields.ADVANCED_SEARCH_OPERATORS; + public operators: {name:string, id:string}[] = this.searchFields.ADVANCED_SEARCH_OPERATORS; constructor (private route: ActivatedRoute) { } diff --git a/searchPages/searchUtils/advancedSearchPage.component.ts b/searchPages/searchUtils/advancedSearchPage.component.ts index 1ed4fab8..d49a7af2 100644 --- a/searchPages/searchUtils/advancedSearchPage.component.ts +++ b/searchPages/searchUtils/advancedSearchPage.component.ts @@ -4,7 +4,7 @@ import {Location} from '@angular/common'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Filter, Value, AdvancedField} from '../searchUtils/searchHelperClasses.class'; import {SearchResult} from '../../utils/entities/searchResult'; diff --git a/searchPages/searchUtils/dateFilter.component.ts b/searchPages/searchUtils/dateFilter.component.ts index 99331985..a4822e42 100644 --- a/searchPages/searchUtils/dateFilter.component.ts +++ b/searchPages/searchUtils/dateFilter.component.ts @@ -1,33 +1,68 @@ import {Component, Input, Output, EventEmitter} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Filter, Value, DateValue} from './searchHelperClasses.class'; import {IMyOptions, IMyDateModel} from '../../utils/my-date-picker/interfaces/index'; // import {IMyDateModel} from '../../../utils/my-date-picker/interfaces/my-date-model.interface'; import {Dates} from '../../utils/string-utils.class'; +import {FormControl} from "@angular/forms"; +import {MatDatepickerInputEvent} from "@angular/material"; @Component({ selector: 'date-filter', template: ` - -
- +
- - + + + + + + +
- - From - - To
+ + + From + + + + + + + + To + + + + + + +
-
+
+ + + + + + + + + + + + + + + ` }) @@ -52,19 +87,30 @@ export class DateFilterComponent { // Initialized to specific date (09.10.2018). public from;//: Object = { date: { year: 2018, month: 10, day: 9 } }; public to;//: Object = { date: { year: 2018, month: 10, day: 9 } }; + public fromDate; + public toDate; constructor() { + //this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to); +} + +ngOnInit() { this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to); } updateDefaultRangeDates(df:Date,dt:Date){ - this.from = { date: { year: df.getFullYear(), month: (df.getMonth()+1), day: df.getDate() } }; - this.to = { date: { year: dt.getFullYear(), month: (dt.getMonth()+1), day: dt.getDate() } }; + df.setMonth(df.getMonth()-1); + this.fromDate = new FormControl(df); + this.toDate = new FormControl(dt); + + //this.from = { date: { year: df.getFullYear(), month: (df.getMonth()+1), day: df.getDate() } }; + //this.to = { date: { year: dt.getFullYear(), month: (dt.getMonth()+1), day: dt.getDate() } }; } typeChanged(type:string){ this.dateValue.setDatesByType(type); this.updateDefaultRangeDates(this.dateValue.from, this.dateValue.to); } +/* onFromDateChanged(event: IMyDateModel) { this.dateValue.from = Dates.getDateFromString(event.formatted); this.validDateFrom = true; @@ -72,4 +118,16 @@ onFromDateChanged(event: IMyDateModel) { onToDateChanged(event: IMyDateModel) { this.dateValue.to = Dates.getDateFromString(event.formatted); this.validDateTo = true; -}} +} +*/ + +fromDateChanged(event: MatDatepickerInputEvent) { + this.dateValue.from = event.value; + //console.info("FROM: "+Dates.getDateToString(this.dateValue.from)); +} + +toDateChanged(event: MatDatepickerInputEvent) { + this.dateValue.to = event.value; + //console.info("TO: "+Dates.getDateToString(this.dateValue.to)); +} +} diff --git a/searchPages/searchUtils/dateFilter.module.ts b/searchPages/searchUtils/dateFilter.module.ts index 0c5dca82..86c1c25b 100644 --- a/searchPages/searchUtils/dateFilter.module.ts +++ b/searchPages/searchUtils/dateFilter.module.ts @@ -1,11 +1,16 @@ import { NgModule} from '@angular/core'; import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MyDatePickerModule } from '../../utils/my-date-picker/my-date-picker.module'; import {DateFilterComponent} from './dateFilter.component'; +import {MatNativeDateModule} from '@angular/material'; +import {MatDatepickerModule} from '@angular/material/datepicker'; +import {MatFormFieldModule} from '@angular/material'; +import {MatInputModule} from '@angular/material'; @NgModule({ imports: [ - CommonModule, FormsModule, MyDatePickerModule + CommonModule, FormsModule, ReactiveFormsModule, MyDatePickerModule, + MatNativeDateModule, MatDatepickerModule, MatFormFieldModule, MatInputModule ], declarations: [ DateFilterComponent diff --git a/searchPages/searchUtils/searchDownload.component.ts b/searchPages/searchUtils/searchDownload.component.ts index 6a4c460d..b0866e0f 100644 --- a/searchPages/searchUtils/searchDownload.component.ts +++ b/searchPages/searchUtils/searchDownload.component.ts @@ -1,5 +1,5 @@ import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { ActivatedRoute} from '@angular/router'; import {AlertModal} from '../../utils/modal/alert'; import {ReportsService} from '../../services/reports.service'; @@ -8,7 +8,7 @@ import {PiwikService} from '../../utils/piwik/piwik.service'; import{EnvProperties} from '../../utils/properties/env-properties'; import {ErrorCodes} from '../../utils/properties/errorCodes'; -import 'rxjs/Rx' ; +import 'rxjs' ; @Component({ selector: 'search-download', diff --git a/searchPages/searchUtils/searchFilter.component.ts b/searchPages/searchUtils/searchFilter.component.ts index a998e186..928fc765 100644 --- a/searchPages/searchUtils/searchFilter.component.ts +++ b/searchPages/searchUtils/searchFilter.component.ts @@ -1,5 +1,5 @@ import {Component, Input, Output, EventEmitter} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import { Filter, Value} from './searchHelperClasses.class'; import {Open} from '../../utils/modal/open.component'; diff --git a/searchPages/searchUtils/searchPageTableView.component.ts b/searchPages/searchUtils/searchPageTableView.component.ts index ece87eba..7fd46340 100644 --- a/searchPages/searchUtils/searchPageTableView.component.ts +++ b/searchPages/searchUtils/searchPageTableView.component.ts @@ -6,8 +6,7 @@ import {Location} from '@angular/common'; import {ActivatedRoute, Router} from '@angular/router'; import {Title, Meta} from '@angular/platform-browser'; -import {Observable} from 'rxjs/Observable'; -import {Subject} from 'rxjs/Subject'; +import {Observable, Subject} from 'rxjs'; import {DataTableDirective } from 'angular-datatables'; diff --git a/searchPages/searchUtils/searchPaging.component.ts b/searchPages/searchUtils/searchPaging.component.ts index 2c85f86a..17283340 100644 --- a/searchPages/searchUtils/searchPaging.component.ts +++ b/searchPages/searchUtils/searchPaging.component.ts @@ -1,5 +1,5 @@ import {Component, Input, Output, EventEmitter} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {ErrorCodes} from '../../utils/properties/errorCodes'; @Component({ diff --git a/services/curatorPhoto.service.ts b/services/curatorPhoto.service.ts index fa32cec6..6197dc82 100644 --- a/services/curatorPhoto.service.ts +++ b/services/curatorPhoto.service.ts @@ -1,8 +1,7 @@ import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {CustomOptions} from './servicesUtils/customOptions.class'; -import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {COOKIE} from '../login/utils/helper.class'; +import {HttpClient} from '@angular/common/http'; @Injectable() export class CuratorPhotoService { @@ -12,20 +11,11 @@ export class CuratorPhotoService { uploadPhoto(url: string, photo: File): Observable { const formData = new FormData(); formData.append('photo', photo); - return this.http.post(url, formData, this.getAuthOptions()); + return this.http.post(url, formData, CustomOptions.getAuthOptions()); } deletePhoto(url: string) { - return this.http.delete(url, this.getAuthOptions()); + return this.http.delete(url, CustomOptions.getAuthOptions()); } - // TODO remove and use CustomOptions.getAuthOptions(false) - private getAuthOptions(): any { - const httpOptions = { - headers: new HttpHeaders({ - 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id), - }) - }; - return httpOptions; - } } diff --git a/services/layout.service.ts b/services/layout.service.ts index d7a96eb1..70656db5 100644 --- a/services/layout.service.ts +++ b/services/layout.service.ts @@ -1,11 +1,13 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {CustomOptions} from './servicesUtils/customOptions.class'; +import {catchError} from "rxjs/operators"; @Injectable() export class LayoutService { - constructor(private http: Http) { + constructor(private http: HttpClient) { } static removeNulls(obj) { @@ -22,26 +24,26 @@ export class LayoutService { saveLayout(pid: string, url: string, layout: any) { LayoutService.removeNulls(layout); return this.http.post(url + 'community/' + pid + '/updateLayout', JSON.stringify(layout), CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) - .catch(this.handleError); + //.map(res => res.json()) + .pipe(catchError(this.handleError)); } getLayout(pid: string, url: string) { return this.http.get(url + 'community/' + pid + '/layout') - .map(res => res.json()) - .catch(this.handleError); + //.map(res => res.json()) + .pipe(catchError(this.handleError)); } loadDefaultLayout(pid: string, url: string) { return this.http.post(url + 'community/' + pid + '/resetLayout', null, CustomOptions.getAuthOptionsWithBody()) - .map(res => res.json()) - .catch(this.handleError); + //.map(res => res.json()) + .pipe(catchError(this.handleError)); } - private handleError(error: Response) { + private handleError(error: HttpErrorResponse) { // 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); - return Observable.throw(error.json().error || 'Server error'); + return throwError(error.error || 'Server error'); } } diff --git a/services/metrics.service.ts b/services/metrics.service.ts index 9e5c0701..0760b579 100644 --- a/services/metrics.service.ts +++ b/services/metrics.service.ts @@ -1,24 +1,26 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; import {Metrics} from '../utils/entities/metrics'; -import 'rxjs/add/operator/do'; + import{EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class MetricsService { metrics: Metrics; - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getMetrics (id: string, entityType: string, properties:EnvProperties):any { let url = properties.metricsAPIURL+entityType+"/"+id+"/clicks"; let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseMetrics(res["downloads"], res["views"], res["total_downloads"], res["total_views"], - res["total_openaire_views"], res["total_openaire_downloads"], res["pageviews"], properties)); + //.map(res => res.json()) + .pipe(map(res => this.parseMetrics(res["downloads"], res["views"], res["total_downloads"], res["total_views"], + res["total_openaire_views"], res["total_openaire_downloads"], res["pageviews"], properties))); } diff --git a/services/organization.service.ts b/services/organization.service.ts index 87791d76..f236638f 100644 --- a/services/organization.service.ts +++ b/services/organization.service.ts @@ -1,16 +1,18 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {OrganizationInfo} from '../utils/entities/organizationInfo'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import{EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class OrganizationService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} organizationInfo: OrganizationInfo; @@ -18,11 +20,11 @@ export class OrganizationService { let url = properties.searchAPIURLLAst+'resources?format=json&query=( (oaftype exact organization) and (reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native)) and ( objIdentifier ='+id+')'; return this.http.get((properties.useCache)? (properties.cacheUrl +encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['results'][0]) + //.map(res => res.json()) + .pipe(map(res => res['results'][0])) //.map(res => res[0]['result']['metadata']['oaf:entity']['oaf:organization']) //.map(res => [res, res['rels']['rel']]) - .map(res => this.parseOrganizationInfo(res)); + .pipe(map(res => this.parseOrganizationInfo(res))); } @@ -31,16 +33,16 @@ export class OrganizationService { let url = properties.searchAPIURLLAst+"organizations/"+id+"?format=json"; return this.http.get((properties.useCache) ? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['result']['metadata']['oaf:entity']['oaf:organization']) - .map(res => this.parseOrganizationNameAndUrl(res)); + //.map(res => res.json()) + .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:organization'])) + .pipe(map(res => this.parseOrganizationNameAndUrl(res))); } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } parseOrganizationInfo (data: any):any { diff --git a/services/refineFieldResults.service.ts b/services/refineFieldResults.service.ts index 598d8282..3590b643 100644 --- a/services/refineFieldResults.service.ts +++ b/services/refineFieldResults.service.ts @@ -1,16 +1,18 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import {RefineResultsUtils} from './servicesUtils/refineResults.class'; import{EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class RefineFieldResultsService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getRefineFieldsResultsByEntityName(fields:string[], entityName:string, properties:EnvProperties, communityQuery=null):any{ let url = properties.searchAPIURLLAst + this.getSearchAPIURLForEntity(entityName)+"?format=json&refine=true&page=1&size=0"; for(var i=0; i < fields.length; i++){ @@ -21,9 +23,9 @@ export class RefineFieldResultsService { } return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) - .map(res => [res['meta'].total, RefineResultsUtils.parse(res['refineResults'],fields, entityName)]); + .pipe(map(res => [res['meta'].total, RefineResultsUtils.parse(res['refineResults'],fields, entityName)])); } getRefineFieldResultsByFieldName(fieldName:string, entityName:string, properties:EnvProperties):any{ @@ -36,9 +38,9 @@ export class RefineFieldResultsService { let url = link+"&refine=true&page=1&size=0"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['refineResults']) - .map(res => this.parse(res,fieldName)); + //.map(res => res.json()) + .pipe(map(res => res['refineResults'])) + .pipe(map(res => this.parse(res,fieldName))); } parse(data: any,fieldName:string):any { @@ -78,10 +80,10 @@ export class RefineFieldResultsService { } return suffix; } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } } diff --git a/services/reports.service.ts b/services/reports.service.ts index 9ec08bd5..c32fdfca 100644 --- a/services/reports.service.ts +++ b/services/reports.service.ts @@ -1,35 +1,37 @@ import {Injectable} from '@angular/core'; import {Http, Response, Headers} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; + + + +import {map, tap} from "rxjs/operators"; @Injectable() export class ReportsService { // url:string = "http://beta.services.openaire.eu:8480/search/rest/v2/api/publications?format=csv&page=0&size=3&q=(%22test%22)&fq=instancetypename%20exact%20%22Dataset%22"; - constructor(private http: Http) {} + constructor(private http: HttpClient) {} //text/html //On the service: downloadCSVFile(url: string){ - var headers = new Headers(); - headers.append('responseType', 'arraybuffer'); + //var headers = new Headers(); + //headers.append('responseType', 'arraybuffer'); return this.http.get(url) - .map(res => new Blob([res['_body']], { type: 'text/csv' })); + .pipe(map(res => new Blob([res['_body']], { type: 'text/csv' }))); } getCSVResponse(url: string){ - var headers = new Headers(); - headers.append('responseType', 'arraybuffer'); + //var headers = new Headers(); + //headers.append('responseType', 'arraybuffer'); return this.http.get(url) - .map(res => res['_body']); + .pipe(map(res => res['_body'])); } downloadHTMLFile(url: string, info: string){ - var headers = new Headers(); - headers.append('responseType', 'arraybuffer'); + //var headers = new Headers(); + //headers.append('responseType', 'arraybuffer'); return this.http.get(url) - .map(res => this.addInfo(res, info)) - .map(res => new Blob([res['_body']], { type: 'text/html' })) - .do(res => console.log(res)) + .pipe(map(res => this.addInfo(res, info))) + .pipe(map(res => new Blob([res['_body']], { type: 'text/html' }))) + .pipe(tap(res => console.log(res))) } addInfo(res:any, info:string) { @@ -43,11 +45,11 @@ export class ReportsService { return res; } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } diff --git a/services/searchDataproviders.service.ts b/services/searchDataproviders.service.ts index 992c7578..54ab6b97 100644 --- a/services/searchDataproviders.service.ts +++ b/services/searchDataproviders.service.ts @@ -1,17 +1,19 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import {StringUtils} from '../utils/string-utils.class'; import{EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class SearchDataprovidersService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchDataproviders (params: string, refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -28,9 +30,9 @@ export class SearchDataprovidersService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")])); } //((oaftype exact datasource) and(collectedfromdatasourceid exact "openaire____::47ce9e9f4fad46e732cff06419ecaabb")) advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties ):any { @@ -47,9 +49,9 @@ export class SearchDataprovidersService { url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'])]) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])) } searchCompatibleDataprovidersTable ( properties:EnvProperties):any { @@ -60,9 +62,9 @@ export class SearchDataprovidersService { - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).map(res => res.json()) - - .map(res => res['meta'].total); + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + .pipe(map(res => res['meta'].total)); } searchCompatibleDataproviders (params: string,refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -77,9 +79,9 @@ export class SearchDataprovidersService { url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")])); } searchEntityRegistriesTable (properties:EnvProperties):any { @@ -90,8 +92,9 @@ export class SearchDataprovidersService { - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).map(res => res.json()) - .map(res => res['meta'].total); + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + .pipe(map(res => res['meta'].total)); } searchEntityRegistries (params: string,refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -106,9 +109,9 @@ export class SearchDataprovidersService { url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")])); } searchJournalsTable ( properties:EnvProperties):any { @@ -117,8 +120,8 @@ export class SearchDataprovidersService { url += '?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) and (datasourcetypeuiid exact "pubsrepository::journal" or datasourcetypeuiid exact "aggregator::pubsrepository::journals" ))'; url += "&page=0&size=0&format=json"; - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).map(res => res.json()) - .map(res => res['meta'].total); + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)//.map(res => res.json()) + .pipe(map(res => res['meta'].total)); } searchJournals (params: string,refineParams:string, page: number, size: number, refineFields:string[] , properties:EnvProperties):any { @@ -135,9 +138,9 @@ export class SearchDataprovidersService { url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")])); } searchDataprovidersForDeposit (id: string,type:string, page: number, size: number, properties:EnvProperties):any { @@ -155,8 +158,8 @@ export class SearchDataprovidersService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } searchDataProvidersBySubjects(keyword:string, type:string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchResourcesAPIURL; @@ -173,8 +176,8 @@ export class SearchDataprovidersService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } @@ -191,16 +194,16 @@ export class SearchDataprovidersService { url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } searchDataprovidersForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; let url = link+params+"/datasources?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } /* searchDataprovidersCSV (params: string, refineParams:string, page: number, size: number):any { @@ -411,8 +414,8 @@ export class SearchDataprovidersService { //let url = OpenaireProperties. getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityDataproviders(id: string, entity: string, properties:EnvProperties):any { @@ -454,8 +457,8 @@ getDataprovidersTableResults (queryType:string, properties:EnvProperties):any { - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).map(res => res.json()) - - .map(res => res['meta'].total); + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) + //.map(res => res.json()) + .pipe(map(res => res['meta'].total)); } } diff --git a/services/searchDatasets.service.ts b/services/searchDatasets.service.ts index 85b3724f..b6d22d55 100644 --- a/services/searchDatasets.service.ts +++ b/services/searchDatasets.service.ts @@ -1,21 +1,20 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import {SearchResult} from '../utils/entities/searchResult'; +import {HttpClient} from "@angular/common/http"; +import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + import {DOI, StringUtils} from '../utils/string-utils.class'; -import { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; -import{EnvProperties} from '../utils/properties/env-properties'; +import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class SearchDatasetsService { private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchDatasets (params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[], properties:EnvProperties ):any { @@ -35,16 +34,17 @@ export class SearchDatasetsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")])); + } searchDatasetById (id: string , properties:EnvProperties):any { let url = properties.searchAPIURLLAst+"datasets/"+id+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseResults(res, properties)); + //.map(res => res.json()) + .pipe(map(res => this.parseResults(res, properties))); } searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { @@ -63,8 +63,8 @@ export class SearchDatasetsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseRefineResults(id, res['refineResults'])) + //.map(res => res.json()) + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))) } searchDatasetsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -86,10 +86,10 @@ export class SearchDatasetsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")])); - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")]); } advancedSearchDatasets (params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -110,25 +110,27 @@ export class SearchDatasetsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } searchDatasetsForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; let url = link+params+"/datasets"+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); + } searchDatasetsForDataproviders(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) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); + } parseResults(data: any, properties: EnvProperties): SearchResult[] { @@ -347,8 +349,8 @@ export class SearchDatasetsService { numOfDatasets(url: string, properties:EnvProperties):any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityDatasets(id: string, entity: string, properties:EnvProperties):any { diff --git a/services/searchOrganizations.service.ts b/services/searchOrganizations.service.ts index 9b60812d..7af671d2 100644 --- a/services/searchOrganizations.service.ts +++ b/services/searchOrganizations.service.ts @@ -1,18 +1,20 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + + + import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; import{EnvProperties} from '../utils/properties/env-properties'; import {StringUtils} from '../utils/string-utils.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchOrganizationsService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} parseResultsForDeposit(data: any): {"name": string, "id": string}[] { let results: {"name": string, "id": string}[] = []; @@ -51,8 +53,8 @@ export class SearchOrganizationsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")])); } advancedSearchOrganizations (params: string, page: number, size: number, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -72,9 +74,9 @@ export class SearchOrganizationsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } parseResults(data: any): SearchResult[] { let results: SearchResult[] = []; @@ -165,8 +167,8 @@ export class SearchOrganizationsService { numOfOrganizations(url: string, properties:EnvProperties ): any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityOrganizations(id: string, entity: string, properties:EnvProperties ):any { diff --git a/services/searchOrps.service.ts b/services/searchOrps.service.ts index 54c27408..fe2108b7 100644 --- a/services/searchOrps.service.ts +++ b/services/searchOrps.service.ts @@ -1,21 +1,18 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import {SearchResult} from '../utils/entities/searchResult'; +import {HttpClient} from "@angular/common/http"; +import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; import {DOI, StringUtils} from '../utils/string-utils.class'; -import { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; -import{EnvProperties} from '../utils/properties/env-properties'; +import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() export class SearchOrpsService { private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchOrps (params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[], properties:EnvProperties ):any { @@ -35,17 +32,17 @@ export class SearchOrpsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "other")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "other")])); } searchOrpById (id: string , properties:EnvProperties):any { let url = properties.searchAPIURLLAst+"other/"+id+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseResults(res, properties)); + //.map(res => res.json()) + .pipe(map(res => this.parseResults(res, properties))); } searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { @@ -64,8 +61,8 @@ export class SearchOrpsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseRefineResults(id, res['refineResults'])) + //.map(res => res.json()) + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))) } searchOrpsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -88,10 +85,9 @@ export class SearchOrpsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "other")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "other")])); } advancedSearchOrps (params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -113,9 +109,9 @@ export class SearchOrpsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } searchOrpsForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; @@ -123,8 +119,8 @@ export class SearchOrpsService { let url = link+params+"/other"+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } searchOrpsForDataproviders(params: string, page: number, size: number, properties:EnvProperties):any { @@ -132,8 +128,8 @@ export class SearchOrpsService { let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } parseResults(data: any, properties: EnvProperties): SearchResult[] { @@ -351,8 +347,8 @@ export class SearchOrpsService { numOfOrps(url: string, properties:EnvProperties):any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityOrps(id: string, entity: string, properties:EnvProperties):any { diff --git a/services/searchProjects.service.ts b/services/searchProjects.service.ts index b4216f26..f3446595 100644 --- a/services/searchProjects.service.ts +++ b/services/searchProjects.service.ts @@ -1,18 +1,20 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + + + import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; import{EnvProperties} from '../utils/properties/env-properties'; import {StringUtils} from '../utils/string-utils.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchProjectsService { private sizeOfDescription: number = 270; - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchProjects (params: string, refineParams:string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any { @@ -29,8 +31,8 @@ export class SearchProjectsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")])); } getProjectsforDataProvider (datasourceId: string, page: number, size: number, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -46,8 +48,8 @@ export class SearchProjectsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -62,8 +64,8 @@ export class SearchProjectsService { url += "&page="+(page-1)+"&size="+size; url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'])]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'])])); } getProjectsForOrganizations (organizationId: string, filterquery: string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -84,15 +86,15 @@ export class SearchProjectsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")])); } getFunders(properties:EnvProperties ):any { let url = properties.searchAPIURLLAst+"projects?refine=true&fields=funder&size=0"+ "&format=json";; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, res['refineResults']['funder']]); + //.map(res => res.json()) + .pipe(map(res => [res['meta'].total, res['refineResults']['funder']])); } @@ -103,9 +105,10 @@ export class SearchProjectsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() .then(request =>{ - return (request.json().response.results)?request.json().response.results.result:request.json().response.result; + //return (request.json().response.results)?request.json().response.results.result:request.json().response.result; + return (request['response'].results)?request['response'].results.result:request['response'].result; - }) ; + }) ; } parseResults(data: any): SearchResult[] { let results: SearchResult[] = []; @@ -219,8 +222,8 @@ export class SearchProjectsService { numOfProjects(url: string, properties:EnvProperties ):any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityProjects(id: string, entity: string, properties:EnvProperties ):any { diff --git a/services/searchPublications.service.ts b/services/searchPublications.service.ts index 0a297a71..4df5592b 100644 --- a/services/searchPublications.service.ts +++ b/services/searchPublications.service.ts @@ -1,15 +1,11 @@ import {Injectable} from '@angular/core'; -import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; - -import {SearchResult} from '../utils/entities/searchResult'; +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 {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class'; +import {EnvProperties} from '../utils/properties/env-properties'; +import {map} from "rxjs/operators"; @Injectable() @@ -17,7 +13,7 @@ export class SearchPublicationsService { private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchPublications (params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[] , properties:EnvProperties):any { let link = properties.searchAPIURLLAst+"publications"; @@ -36,17 +32,14 @@ export class SearchPublicationsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - // .do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")])); } searchPublicationById (id: string, properties:EnvProperties ):any { let url = properties.searchAPIURLLAst+"publications/"+id+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseResults(res, properties)); + .pipe(map(res => this.parseResults(res, properties))); } searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { @@ -65,8 +58,8 @@ export class SearchPublicationsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseRefineResults(id, res['refineResults'])); + //.map(res => res.json()) + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))); } searchPublicationsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -89,9 +82,9 @@ export class SearchPublicationsService { url += "&page="+(page-1)+"&size="+size; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "publication")])); } advancedSearchPublications (params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { @@ -113,10 +106,9 @@ export class SearchPublicationsService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) + //.map(res => res.json()) //.do(res => console.info(res)) - - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } searchPublicationsForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; @@ -126,16 +118,14 @@ export class SearchPublicationsService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } searchPublicationsForDataproviders(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) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } /* searchPublicationsCSV (params: string, refineParams:string, page: number, size: number):any { @@ -463,8 +453,8 @@ export class SearchPublicationsService { numOfPublications(url: string, properties:EnvProperties): any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntityPublications(id: string, entity: string, properties:EnvProperties):any { diff --git a/services/searchSoftware.service.ts b/services/searchSoftware.service.ts index 92c0e455..d958b33e 100644 --- a/services/searchSoftware.service.ts +++ b/services/searchSoftware.service.ts @@ -1,20 +1,22 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; import{EnvProperties} from '../utils/properties/env-properties'; import {DOI, StringUtils} from '../utils/string-utils.class'; +import {map} from "rxjs/operators"; @Injectable() export class SearchSoftwareService { private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchSoftware (params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[], properties:EnvProperties ):any { @@ -34,9 +36,9 @@ export class SearchSoftwareService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")])); + } searchSoftwareById (id: string, properties:EnvProperties ):any { @@ -44,8 +46,7 @@ export class SearchSoftwareService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseResults(res, properties)); + .pipe(map(res => this.parseResults(res, properties))); } searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { @@ -63,8 +64,8 @@ export class SearchSoftwareService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => this.parseRefineResults(id, res['refineResults'])) + //.map(res => res.json()) + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))); } searchSoftwareByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { @@ -86,9 +87,8 @@ export class SearchSoftwareService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")])); } advancedSearchSoftware (params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; @@ -109,17 +109,16 @@ export class SearchSoftwareService { url += "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - //.do(res => console.info(res)) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); + } searchSoftwareForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; let url = link+params+"/software"+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); + } searchSoftwareForDataproviders(params: string, page: number, size: number, properties:EnvProperties):any { @@ -127,8 +126,7 @@ export class SearchSoftwareService { let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); + .pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); } parseResults(data: any, properties: EnvProperties): SearchResult[] { @@ -360,8 +358,8 @@ export class SearchSoftwareService { numOfSoftware(url: string, properties:EnvProperties):any { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res.total); + //.map(res => res.json()) + .pipe(map(res => res['total'])); } numOfEntitySoftware(id: string, entity: string, properties:EnvProperties):any { diff --git a/services/servicesUtils/customOptions.class.ts b/services/servicesUtils/customOptions.class.ts index d4e13e03..3f1b8ee0 100644 --- a/services/servicesUtils/customOptions.class.ts +++ b/services/servicesUtils/customOptions.class.ts @@ -1,9 +1,10 @@ -import { RequestOptions, Headers} from '@angular/http'; -import { COOKIE } from '../../login/utils/helper.class'; +import {COOKIE} from '../../login/utils/helper.class'; +import {HttpHeaders} from "@angular/common/http"; export class CustomOptions { + /* public static getAuthOptionsWithBody(): RequestOptions { const headers = new Headers(); headers.append('Content-Type', 'application/json'); @@ -11,12 +12,33 @@ export class CustomOptions { const options = new RequestOptions({ headers: headers, withCredentials: true }); return options; } + */ + public static getAuthOptionsWithBody():{} { + return { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id) + }), withCredentials: true + }; + } + + /* public static getAuthOptions(): RequestOptions { const headers = new Headers(); headers.append('X-XSRF-TOKEN', COOKIE.getCookie(COOKIE.cookieName_id)); const options = new RequestOptions({ headers: headers, withCredentials: true }); return options; } + */ + + public static getAuthOptions():any { + const httpOptions = { + headers: new HttpHeaders({ + 'X-XSRF-TOKEN': COOKIE.getCookie(COOKIE.cookieName_id), + }), withCredentials: true + }; + return httpOptions; + } } diff --git a/sharedComponents/bottom.component.ts b/sharedComponents/bottom.component.ts index 9faeea17..04d5cf10 100644 --- a/sharedComponents/bottom.component.ts +++ b/sharedComponents/bottom.component.ts @@ -1,6 +1,6 @@ import { Component, Input } from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import 'rxjs/Rx'; +import 'rxjs'; import{MenuItem} from './menu'; import { ConfigurationService } from '../utils/configuration/configuration.service'; @@ -34,8 +34,8 @@ constructor(private config: ConfigurationService, private route: ActivatedRoute if(this.showMenuItems){ if( this.APIUrl && this.communityId ){ this.config.getCommunityInformation(this.APIUrl, this.communityId ).subscribe(data => { - for(var i=0; i< data.pages.length; i++){ - this.showPage[data.pages[i]["route"]] = data.pages[i]["isEnabled"]; + for(var i=0; i< data['pages'].length; i++){ + this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"]; } // console.log(this.showPage) diff --git a/sharedComponents/cookie-law/cookie-law.component.ts b/sharedComponents/cookie-law/cookie-law.component.ts index 3a72e7d0..ebde6383 100644 --- a/sharedComponents/cookie-law/cookie-law.component.ts +++ b/sharedComponents/cookie-law/cookie-law.component.ts @@ -14,14 +14,14 @@ import { Input, Output, EventEmitter, - animate, +} from '@angular/core'; +import { animate, state, trigger, style, transition, - AnimationTransitionEvent, -} from '@angular/core'; - + AnimationEvent +} from '@angular/animations'; import { DomSanitizer, SafeHtml, @@ -129,7 +129,7 @@ export class CookieLawComponent implements OnInit { } } - afterDismissAnimation(evt: AnimationTransitionEvent) { + afterDismissAnimation(evt: AnimationEvent) { if (evt.toState === 'topOut' || evt.toState === 'bottomOut') { this.isSeen = true; diff --git a/sharedComponents/navigationBar.component.ts b/sharedComponents/navigationBar.component.ts index 87f48aaa..28d86613 100644 --- a/sharedComponents/navigationBar.component.ts +++ b/sharedComponents/navigationBar.component.ts @@ -1,7 +1,7 @@ import { Component, Input } from '@angular/core'; // import 'rxjs/Rx'; import {ActivatedRoute, Router} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; import {Session} from '../login/utils/helper.class'; import { ConfigurationService } from '../utils/configuration/configuration.service'; @@ -63,12 +63,12 @@ export class NavigationBarComponent { if( this.APIUrl && this.communityId ){ this.config.getCommunityInformation(this.APIUrl, this.communityId ).subscribe(data => { - for(var i=0; i< data.entities.length; i++){ + for(var i=0; i< data['entities'].length; i++){ - this.showEntity[""+data.entities[i]["pid"]+""] = data.entities[i]["isEnabled"]; + this.showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"]; } - for(var i=0; i< data.pages.length; i++){ - this.showPage[data.pages[i]["route"]] = data.pages[i]["isEnabled"]; + for(var i=0; i< data['pages'].length; i++){ + this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"]; } diff --git a/test/test.component.ts b/test/test.component.ts index 669320f0..ef3ca11d 100644 --- a/test/test.component.ts +++ b/test/test.component.ts @@ -1,6 +1,5 @@ import {Component, ElementRef} from '@angular/core'; -import { Subject } from 'rxjs/Subject'; -import {Observable} from 'rxjs/Observable'; +import { Subject , Observable} from 'rxjs'; import {SearchFields, FieldDetails} from '../utils/properties/searchFields'; diff --git a/utils/configuration/configuration.service.ts b/utils/configuration/configuration.service.ts index 601879a3..2e9d5120 100644 --- a/utils/configuration/configuration.service.ts +++ b/utils/configuration/configuration.service.ts @@ -1,20 +1,21 @@ import {Injectable} from '@angular/core'; import {Http, Response, Headers} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/mapTo'; -import 'rxjs/add/observable/of'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + + // import 'rxjs/add/operator/do'; // import 'rxjs/add/operator/share'; -import { mapTo } from 'rxjs/operators'; +import {map, mapTo} from 'rxjs/operators'; @Injectable() export class ConfigurationService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getCommunityInformation(APIUrl:string, community:string){ - return this.http.get(APIUrl + "/communityFull/" + community) - .map(res => res.json()); + return this.http.get(APIUrl + "/communityFull/" + community); + //.map(res => res.json()); } isEntityEnabled(APIUrl:string, community:string,entity: string){ @@ -26,32 +27,33 @@ export class ConfigurationService { // } // return Observable.of(new Object()).mapTo(true); return this.http.get(APIUrl + "/page") - .map(res => true); + .pipe(map(res => true)); } isPageEnabled(APIUrl:string, community:string,router: string){ return this.http.get(APIUrl + "/community/" + community+"/pages?page_route="+router) - .map(res => res.json()).map(res => { + //.map(res => res.json()) + .pipe(map(res => { let result = false; - if(res.length >0 && res[0].route == router){ + if(res['length'] >0 && res[0].route == router){ result = res[0].isEnabled; } return result; - });//.do(res => {console.log("Route "+router +" is "+res)}); + }));//.do(res => {console.log("Route "+router +" is "+res)}); } getMainPageContent(APIUrl:string, community:string,){ return this.http.get(APIUrl + "/page") - .map(res => true); + .pipe(map(res => true)); } getSpecialAnouncementContent(APIUrl:string, community:string,){ return this.http.get(APIUrl + "/page") - .map(res => ""); + .pipe(map(res => "")); } getHelpPageContent(APIUrl:string, community:string, router:string){ return this.http.get(APIUrl + "/page") - .map(res => true); + .pipe(map(res => true)); } // private handleError (error: Response) { // // in a real world app, we may send the error to some remote logging infrastructure diff --git a/utils/email/email.service.ts b/utils/email/email.service.ts index 873f8347..4e8a5468 100644 --- a/utils/email/email.service.ts +++ b/utils/email/email.service.ts @@ -1,5 +1,6 @@ import {Injectable} from '@angular/core'; import {Http, Response, Headers, RequestOptions} from '@angular/http'; +import {HttpClient} from "@angular/common/http"; import {Email} from './email'; import {CustomOptions} from '../../services/servicesUtils/customOptions.class'; import {EmailRecaptcha} from "../entities/EmailRecaptcha"; @@ -7,22 +8,22 @@ import {EmailRecaptcha} from "../entities/EmailRecaptcha"; @Injectable() export class EmailService { - constructor(private http:Http) { + constructor(private http:HttpClient) { } sendEmail(url: string, email: Email) { let body = JSON.stringify(email); - return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - .map(request => request.json()); + return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()); + //.map(request => request.json()); } contact(url: string, email: Email, recaptcha: string) { const data: EmailRecaptcha = new EmailRecaptcha(); data.email = email; data.recaptcha = recaptcha; - return this.http.post(url, data) - .map(request => request.json()); + return this.http.post(url, data); + //.map(request => request.json()); } } diff --git a/utils/entitiesAutoComplete/entitiesAutoComplete.component.ts b/utils/entitiesAutoComplete/entitiesAutoComplete.component.ts index 00a845d1..157d6ed3 100644 --- a/utils/entitiesAutoComplete/entitiesAutoComplete.component.ts +++ b/utils/entitiesAutoComplete/entitiesAutoComplete.component.ts @@ -1,11 +1,12 @@ + +import {switchMap, distinctUntilChanged, debounceTime} from 'rxjs/operators'; import {Component, ElementRef, Input, Output, EventEmitter, OnChanges, SimpleChange} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; -import {Subject} from 'rxjs/Subject'; +import {Observable, Subject} from 'rxjs'; import {Value} from '../../searchPages/searchUtils/searchHelperClasses.class'; import {EntitiesSearchService} from './entitySearch.service'; import{EnvProperties} from '../properties/env-properties'; -import 'rxjs/add/operator/debounceTime'; -import 'rxjs/add/operator/distinctUntilChanged'; + + //Usage example // @@ -100,36 +101,36 @@ export class EntitiesAutocompleteComponent { this.showInput = true; if(this.entityType == "project" && this.funderId ){ - this.filtered = this.searchTermStream - .debounceTime(300).distinctUntilChanged() - .switchMap((term: string) => { + this.filtered = this.searchTermStream.pipe( + debounceTime(300),distinctUntilChanged(), + switchMap((term: string) => { //console.log("funder"+this.funderId); var results = this._search.searchProjectsByFunder(term, (this.funderId == "0"?"":encodeURIComponent(this.funderId)), this.properties); this.showLoading = false; this.results = results.length; return results; - }); + }),); }else if(this.entityType == "organization" && this.depositType ){ - this.filtered = this.searchTermStream - .debounceTime(300).distinctUntilChanged() - .switchMap((term: string) => { + this.filtered = this.searchTermStream.pipe( + debounceTime(300),distinctUntilChanged(), + switchMap((term: string) => { var results = this._search.searchByDepositType(term, this.depositType, this.properties); this.showLoading = false; this.results = results.length; return results; - }); + }),); }else{ - this.filtered = this.searchTermStream - .debounceTime(300) - .distinctUntilChanged() - .switchMap((term: string) => { + this.filtered = this.searchTermStream.pipe( + debounceTime(300), + distinctUntilChanged(), + switchMap((term: string) => { var results = this._search.searchByType(term, this.entityType, this.properties); this.showLoading = false; this.results = results.length; return results; - }); + }),); this.getSelectedNameFromGivenId(); } diff --git a/utils/entitiesAutoComplete/entitySearch.service.ts b/utils/entitiesAutoComplete/entitySearch.service.ts index 4d64901d..6dfc139b 100644 --- a/utils/entitiesAutoComplete/entitySearch.service.ts +++ b/utils/entitiesAutoComplete/entitySearch.service.ts @@ -1,17 +1,19 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError} from 'rxjs'; import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; + + + import{EnvProperties} from '../properties/env-properties'; import {StringUtils} from '../string-utils.class'; +import {catchError, map} from "rxjs/operators"; @Injectable() export class EntitiesSearchService { public ready:boolean = false; - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} searchProjectsByFunder(keyword:string, funderId:string, properties:EnvProperties ):any { this.ready = false; @@ -30,7 +32,8 @@ export class EntitiesSearchService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() .then(request => { - request = request.json().results; + //request = request.json().results; + request = request['results']; this.ready = true; return this.parse(request,"oaf:project","project"); }).catch((ex) => { @@ -71,7 +74,8 @@ export class EntitiesSearchService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() .then(request => { - request = request.json().results; + //request = request.json().results; + request = request['results']; //console.log(request); this.ready = true; return this.parse(request,"oaf:organization","organization"); @@ -124,15 +128,16 @@ private fetch (link,id,oafEntityType,type, properties:EnvProperties ){ this.ready = false; let url = link+"/"+id+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(request => request.json()) + //.map(request => request.json()) // .do(res => console.info(res)) - .map(request => { + .pipe(map(request => { this.ready = true; return this.parse(request,oafEntityType,type); - }).catch((ex) => { + })) + .pipe(catchError((ex) => { console.error('An error occured', ex); return [{id:'-2',label:'Error'}];; - }); + })); } private search (link,keyword,oafEntityType,type, properties:EnvProperties ){ @@ -154,7 +159,8 @@ private fetch (link,id,oafEntityType,type, properties:EnvProperties ){ return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() .then(request => { - request = request.json().results; + //request = request.json().results; + request = request['results']; this.ready = true; return this.parse(request,oafEntityType,type); }).catch((ex) => { @@ -266,10 +272,10 @@ private fetch (link,id,oafEntityType,type, properties:EnvProperties ){ return array; } - private handleError (error: Response) { + private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } } diff --git a/utils/fetchEntitiesClasses/fetchDatasets.class.ts b/utils/fetchEntitiesClasses/fetchDatasets.class.ts index f18f77dc..672f3cff 100644 --- a/utils/fetchEntitiesClasses/fetchDatasets.class.ts +++ b/utils/fetchEntitiesClasses/fetchDatasets.class.ts @@ -3,7 +3,7 @@ import { ErrorCodes} from '../../utils/properties/errorCodes'; import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class'; import {DOI} from '../../utils/string-utils.class'; -import {Subject} from 'rxjs/Subject'; +import {Subject} from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; import {StringUtils} from '../../utils/string-utils.class'; export class FetchDatasets{ diff --git a/utils/fetchEntitiesClasses/fetchOrps.class.ts b/utils/fetchEntitiesClasses/fetchOrps.class.ts index 3198f9c0..568e67c5 100644 --- a/utils/fetchEntitiesClasses/fetchOrps.class.ts +++ b/utils/fetchEntitiesClasses/fetchOrps.class.ts @@ -3,7 +3,7 @@ import { ErrorCodes} from '../../utils/properties/errorCodes'; import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class'; import {DOI} from '../../utils/string-utils.class'; -import {Subject} from 'rxjs/Subject'; +import {Subject} from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; import {StringUtils} from '../../utils/string-utils.class'; diff --git a/utils/fetchEntitiesClasses/fetchPublications.class.ts b/utils/fetchEntitiesClasses/fetchPublications.class.ts index 7f862913..bed673f6 100644 --- a/utils/fetchEntitiesClasses/fetchPublications.class.ts +++ b/utils/fetchEntitiesClasses/fetchPublications.class.ts @@ -5,7 +5,7 @@ import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {SearchFields, FieldDetails} from '../../utils/properties/searchFields'; import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class'; import {DOI} from '../../utils/string-utils.class'; -import {Subject} from 'rxjs/Subject'; +import {Subject} from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; import {StringUtils} from '../../utils/string-utils.class'; export class FetchPublications { diff --git a/utils/fetchEntitiesClasses/fetchSoftware.class.ts b/utils/fetchEntitiesClasses/fetchSoftware.class.ts index 1face028..a6158112 100644 --- a/utils/fetchEntitiesClasses/fetchSoftware.class.ts +++ b/utils/fetchEntitiesClasses/fetchSoftware.class.ts @@ -3,7 +3,7 @@ import { ErrorCodes} from '../../utils/properties/errorCodes'; import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class'; import {DOI} from '../../utils/string-utils.class'; -import {Subject} from 'rxjs/Subject'; +import {Subject} from 'rxjs'; import{EnvProperties} from '../../utils/properties/env-properties'; import {StringUtils} from '../../utils/string-utils.class'; diff --git a/utils/helper/helper.component.ts b/utils/helper/helper.component.ts index b0e5767f..a06cf912 100644 --- a/utils/helper/helper.component.ts +++ b/utils/helper/helper.component.ts @@ -1,6 +1,6 @@ import { Component, Input } from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import 'rxjs/Rx'; +import 'rxjs'; import {HelperService} from './helper.service'; import{EnvProperties} from '../properties/env-properties'; import {ConnectHelper} from '../../connect/connectHelper'; diff --git a/utils/helper/helper.service.ts b/utils/helper/helper.service.ts index 781db651..bfd8833c 100644 --- a/utils/helper/helper.service.ts +++ b/utils/helper/helper.service.ts @@ -1,14 +1,15 @@ import {Injectable, Inject} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + + + import{EnvProperties} from '../properties/env-properties'; @Injectable() export class HelperService { - constructor(private http: Http) {} + constructor(private http: HttpClient) {} getHelper (router: string, position: string, before: boolean, div: string, properties:EnvProperties,communityId:string ):any { //console.info("get router helpText for : "+router+" - position="+position+" - before="+before + " - div="+div); @@ -23,8 +24,8 @@ export class HelperService { } } - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()); + return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url); + //.map(res => res.json()); } diff --git a/utils/my-date-picker/directives/my-date-picker.focus.directive.ts b/utils/my-date-picker/directives/my-date-picker.focus.directive.ts index 5508ea6c..631ae76e 100644 --- a/utils/my-date-picker/directives/my-date-picker.focus.directive.ts +++ b/utils/my-date-picker/directives/my-date-picker.focus.directive.ts @@ -15,6 +15,10 @@ export class FocusDirective implements AfterViewInit { return; } + console.info("focus"); + /*if (typeof document !== 'undefined') { + this.el.nativeElement.focus(); + }*/ this.renderer.invokeElementMethod(this.el.nativeElement, "focus", []); // Set cursor position at the end of text if input element diff --git a/utils/my-date-picker/directives/my-date-picker.input.auto.fill.directive.ts b/utils/my-date-picker/directives/my-date-picker.input.auto.fill.directive.ts index ef1a1501..89673395 100644 --- a/utils/my-date-picker/directives/my-date-picker.input.auto.fill.directive.ts +++ b/utils/my-date-picker/directives/my-date-picker.input.auto.fill.directive.ts @@ -64,6 +64,8 @@ export class InputAutoFillDirective { } private setInputValue(val: string): void { + console.info(val); this.rndr.setElementProperty(this.el.nativeElement, "value", val); + //this.rndr.setProperty(this.el.nativeElement, "value", val); } } \ No newline at end of file diff --git a/utils/my-date-picker/my-date-picker.component.ts b/utils/my-date-picker/my-date-picker.component.ts index 389a5be3..8107d938 100644 --- a/utils/my-date-picker/my-date-picker.component.ts +++ b/utils/my-date-picker/my-date-picker.component.ts @@ -118,7 +118,9 @@ export class MyDatePicker implements OnChanges, ControlValueAccessor { constructor(public elem: ElementRef, private renderer: Renderer, private cdr: ChangeDetectorRef, private localeService: LocaleService, private utilService: UtilService) { this.setLocaleOptions(); renderer.listenGlobal("document", "click", (event: any) => { - if (this.showSelector && event.target && this.elem.nativeElement !== event.target && !this.elem.nativeElement.contains(event.target)) { + //renderer.listen("document", "click", (event: any) => { +console.info("listen global"); + if (this.showSelector && event.target && this.elem.nativeElement !== event.target && !this.elem.nativeElement.contains(event.target)) { this.showSelector = false; this.calendarToggle.emit(4); } diff --git a/utils/piwik/piwik.service.ts b/utils/piwik/piwik.service.ts index 09bf36cc..aebc8682 100644 --- a/utils/piwik/piwik.service.ts +++ b/utils/piwik/piwik.service.ts @@ -1,9 +1,10 @@ import {Injectable} from '@angular/core'; import {Http, Response, Headers, RequestOptions, URLSearchParams} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from 'rxjs'; + + + import {Location} from '@angular/common'; import {StringUtils} from '../string-utils.class'; @@ -13,7 +14,7 @@ import {EnvProperties} from '../properties/env-properties'; @Injectable() export class PiwikService { private piwikbaseUrl:string = ""; - constructor(private http: Http, private location: Location ) {} + constructor(private http: HttpClient, private location: Location ) {} trackView (properties:EnvProperties, title, siteId = null):any { diff --git a/utils/piwik/previousRouteRecorder.guard.ts b/utils/piwik/previousRouteRecorder.guard.ts index 26092fd9..d10b7407 100644 --- a/utils/piwik/previousRouteRecorder.guard.ts +++ b/utils/piwik/previousRouteRecorder.guard.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { CanDeactivate, Router} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; +import {Observable} from 'rxjs'; @Injectable() // do not forget to register this class as a provider export class PreviousRouteRecorder implements CanDeactivate { diff --git a/utils/properties/environment-specific.service.ts b/utils/properties/environment-specific.service.ts index 06dc48dd..fe850b86 100644 --- a/utils/properties/environment-specific.service.ts +++ b/utils/properties/environment-specific.service.ts @@ -1,12 +1,18 @@ -import { Injectable, OnInit, PLATFORM_ID, Inject,InjectionToken , Optional, Injector } from '@angular/core'; +import {Injectable, OnInit, PLATFORM_ID, Inject, InjectionToken, Optional, Injector, inject} from '@angular/core'; import { isPlatformBrowser} from '@angular/common'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; -import { Observable, Subscription, BehaviorSubject } from 'rxjs/Rx'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/operator/toPromise'; +import {HttpClient} from "@angular/common/http"; +import { Observable, Subscription, BehaviorSubject , of } from 'rxjs'; + +import {Request} from 'express'; +import {REQUEST} from '@nguniversal/express-engine/tokens'; import { EnvProperties } from './env-properties'; -import { DOCUMENT } from '@angular/platform-browser'; +import { DOCUMENT } from '@angular/common'; +import {map} from "rxjs/operators"; +import {Type} from "@angular/compiler"; + +//export const REQUEST_TOKEN = new InjectionToken('request'); @Injectable() export class EnvironmentSpecificService { @@ -18,12 +24,14 @@ export class EnvironmentSpecificService { private envSpecificSubject: BehaviorSubject = new BehaviorSubject(null); private propertiesUrl = "/assets/env-properties.json"; - constructor(private http: Http, @Inject(PLATFORM_ID) private platformId: string, private injector: Injector) { + constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId: string, /*private injector: Injector,*/ + @Optional() @Inject(REQUEST) private request: Request) { this.testBrowser = isPlatformBrowser(platformId); if (this.testBrowser) { //this is only executed on the browser } } + public loadEnvironment() { // Only want to do this once - if root page is revisited, it calls this again. @@ -31,13 +39,13 @@ export class EnvironmentSpecificService { var domain = this.getDomain(); var location = this.getFullUrl(); // console.log('loadEnvironment: Loading '+ location); - return this.http.get(location) - .map((data) => { - var properties:EnvProperties=data.json(); + return this.http.get(location) + .pipe(map((data) => { + var properties:EnvProperties=data;//.json(); properties.domain = domain; this.envSpecific = properties; return properties; - }) + })) .toPromise(); } // console.log('loadEnvironment: already loaded '); @@ -50,38 +58,40 @@ export class EnvironmentSpecificService { var domain = this.getDomain(); var location = this.getFullUrl(); // console.log('subscribeEnvironment: Loading '+ location); - return this.http.get(location) - .map((data) => { - var properties:EnvProperties=data.json(); + return this.http.get(location) + .pipe(map((data) => { + var properties:EnvProperties=data;//.json(); properties.domain = domain; this.envSpecific = properties; return properties; - }) + })) } // console.log('subscribeEnvironment: already loaded '); - return Observable.of(this.envSpecific); + return of(this.envSpecific); } getFullUrl(){ var location =""; var domain = ""; if (typeof document == 'undefined') { - let req = this.injector.get('request'); - domain = req.get('host').split(":")[0]; - location = (domain.indexOf(".openaire.eu")!=-1?"https://":"http://")+ req.get('host') + this.propertiesUrl; + //let req = this.injector.get('request'); + //let req: Request = this.injector.get(REQUEST_TOKEN); + domain = this.request.get('host').split(":")[0]; + location = (domain.indexOf(".openaire.eu")!=-1?"https://":"http://")+ this.request.get('host') + this.propertiesUrl; }else{ - location = document.location.protocol +"//" + document.location.host+this.propertiesUrl; - domain = document.location.hostname; + location = document.location.protocol +"//" + document.location.host+this.propertiesUrl; + domain = document.location.hostname; } return location; } getDomain(){ var domain = ""; if (typeof document == 'undefined') { - let req = this.injector.get('request'); - domain = req.get('host').split(":")[0]; - }else{ - domain = document.location.hostname; + //let req = this.injector.get('request'); + //let req: Request = this.injector.get(REQUEST_TOKEN); + domain = this.request.get('host').split(":")[0]; + }else{ + domain = document.location.hostname; } return domain; } diff --git a/utils/staticAutoComplete/ISVocabularies.service.ts b/utils/staticAutoComplete/ISVocabularies.service.ts index 4d542007..05fd6a96 100644 --- a/utils/staticAutoComplete/ISVocabularies.service.ts +++ b/utils/staticAutoComplete/ISVocabularies.service.ts @@ -1,16 +1,15 @@ import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {Observable, throwError, of } from 'rxjs'; import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/do'; -import 'rxjs/add/operator/share'; import{EnvProperties} from '../properties/env-properties'; +import {catchError, map} from "rxjs/operators"; @Injectable() export class ISVocabulariesService { - constructor(private http: Http ) {} + constructor(private http: HttpClient ) {} getVocabularyByType(field:string,entity:string, properties:EnvProperties):any{ //console.log("getVocabulary field: "+ field + " for entity: "+ entity); @@ -34,7 +33,7 @@ export class ISVocabulariesService { return this.getVocabularyFromService(vocabulary, properties); }else if ( field == "type" && (entity == "software" || entity == "other")){ - return Observable.of([]); + return of([]); }else if( field == "access" && (entity == "publication" || entity == "dataset" || entity == "software" || entity == "other")){ // file= "accessMode.json"; @@ -81,10 +80,10 @@ export class ISVocabulariesService { // return results; // }); return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - .map(res => res.json()) - .map(res => res['terms']) - .map(res => this.parse(res)) - .catch(this.handleError); + //.map(res => res.json()) + .pipe(map(res => res['terms'])) + .pipe(map(res => this.parse(res))) + .pipe(catchError(this.handleError)); } @@ -100,10 +99,10 @@ export class ISVocabulariesService { return array; } -private handleError (error: Response) { +private handleError (error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return Observable.throw(error || 'Server error'); + return throwError(error || 'Server error'); } } diff --git a/utils/subscribe/subscribe.service.ts b/utils/subscribe/subscribe.service.ts index 2eaff5b7..b6b1ce40 100644 --- a/utils/subscribe/subscribe.service.ts +++ b/utils/subscribe/subscribe.service.ts @@ -1,54 +1,58 @@ import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; -import { Observable } from 'rxjs/Rx'; +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 {CustomOptions} from "../../services/servicesUtils/customOptions.class"; @Injectable() export class SubscribeService { - constructor(private http:Http) { + constructor(private http:HttpClient) { } getCommunitySubscribers(pid:string, url:string){ - return this.http.get(url+"/community/"+pid+"/subscribers") - .map(res => res.json()); + return this.http.get(url+"/community/"+pid+"/subscribers"); + //.map(res => res.json()); } isSubscribedToCommunity(pid:string, email:string, url:string){ return this.http.get(url+"/community/"+pid+"/subscribers") - .map(res => ((res =="")?{}: res.json())) + //.map(res => ((res =="")?{}: res.json())) - .map(res => { - if(res.status && res.status != 200) { + .pipe(map(res => { + if(res['status'] && res['status'] != 200) { return null; } - if(res.subscribers && res.subscribers != null){ + 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){ + for(var i =0; i< res['subscribers'].length; i++ ){ + if(res['subscribers'][i]!=null && res['subscribers'][i].email == email){ return true; } } } return false; - }); + })); } subscribeToCommunity(pid:string, email:string, url:string){ var subscriber = {"email":email}; - return this.http.post(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), this.getAuthOptionsWithBody()) - .map(res => res.json()); + 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]), this.getAuthOptionsWithBody()) - .map(res => res.json()); + 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()); + return this.http.get(url+"/subscriber/communities?email="+email); + //.map(res => res.json()); } + /* public getAuthOptionsWithBody():RequestOptions{ let headers = new Headers(); headers.append('Content-Type', 'application/json'); @@ -56,5 +60,14 @@ export class SubscribeService { 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 + }; + } }