diff --git a/connect/community/community.service.ts b/connect/community/community.service.ts index 6a819634..213b6bab 100644 --- a/connect/community/community.service.ts +++ b/connect/community/community.service.ts @@ -1,8 +1,5 @@ import { Injectable } from '@angular/core'; -import { Http, Response, Headers, RequestOptions } from '@angular/http'; -import { Observable } from 'rxjs/Rx'; - -import { ResultInfo } from '../results/resultInfo'; +import { Http, Headers, RequestOptions } from '@angular/http'; import { CommunityInfo } from './communityInfo'; import{EnvProperties} from '../../utils/properties/env-properties'; @@ -32,10 +29,12 @@ export class CommunityService { return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) .map(res => res.json()).map(res => this.parseCommunity(res)).map(community => community.managers.indexOf(manager)!=-1); } + iscommunityRI(properties:EnvProperties, url: string){ return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url) .map(res => res.json()).map(res => this.parseCommunity(res)).map(community => (community && community.type && community.type !="community")); } + isSubscribedToCommunity(pid:string, email:string, url:string){ return this.http.get(url+"/community/"+pid+"/subscribers") .map(res => ((res =="")?{}: res.json())) @@ -53,118 +52,60 @@ export class CommunityService { }); } - parseCommunity(data:any): CommunityInfo { - let length = Array.isArray(data) ? data.length :1; + private parseCommunity(data:any): CommunityInfo { - for (let i=0; i(); - } - - let managers = resData[0].managers; - let length = Array.isArray(managers) ? managers.length : 1; - - for(let i=0; i(); - } - - let subjects = resData[0].subjects; - let length = Array.isArray(subjects) ? subjects.length : 1; - - for(let i=0; i(); - } - - let managers = resData.managers; - let length = Array.isArray(managers) ? managers.length : 1; - - for(let i=0; i(); - } - - let subjects = resData.subjects; - let length = Array.isArray(subjects) ? subjects.length : 1; - - for(let i=0; i(); + } + + let managers = resData.managers; + let length = Array.isArray(managers) ? managers.length : 1; + + for(let i=0; i(); + } + + let subjects = resData.subjects; + let length = Array.isArray(subjects) ? subjects.length : 1; + + for(let i=0; i | boolean { - //console.log(state.url); - var user; - var loggedIn = false; - var isAdmin = false; - var errorCode = LoginErrorCodes.NOT_LOGIN; - + let errorCode = LoginErrorCodes.NOT_LOGIN; let community = (route.queryParams["communityId"]); if(Session.isLoggedIn()){ - loggedIn = true; - if(!Session.isLoggedIn()){ - loggedIn = false; - errorCode = LoginErrorCodes.NOT_VALID; - this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); - - return false; - }else if(Session.isPortalAdministrator() || Session.isCommunityCurator()) { - //console.log("is Admin"); - isAdmin = true; + if(Session.isPortalAdministrator() || Session.isCommunityCurator()) { return true; - }else { + } else { let obs = this.propertiesService.subscribeEnvironment().map(res=>res).mergeMap(properties => { return this.communityService.iscommunityManager(properties, properties["communityAPI"]+community,Session.getUserEmail())}); obs.filter(enabled => !enabled) .subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } })); return obs; } - }else{ + } else{ errorCode =LoginErrorCodes.NOT_LOGIN; this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); @@ -47,26 +33,4 @@ export class ConnectAdminLoginGuard implements CanActivate { } - /* - constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { - - let customRedirect = route.data['redirect']; - let api = route.data['api']; - let community = route.data['community'] - if(!community){ - community = (route.queryParams["communityId"])?route.queryParams["communityId"]:route.queryParams["community"]; - } - if(community){ - let isEnabled = this.config.isPageEnabled(api, community,"/"+state.url.split("?")[0].substring(1)); - let redirect = !!customRedirect ? customRedirect : '/error'; - - isEnabled.filter(enabled => !enabled) - .subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } })); - return isEnabled; - } - return true; - } - */ } diff --git a/connect/communityGuard/connectRIGuard.guard.ts b/connect/communityGuard/connectRIGuard.guard.ts index c9fb3e31..9044f1d7 100644 --- a/connect/communityGuard/connectRIGuard.guard.ts +++ b/connect/communityGuard/connectRIGuard.guard.ts @@ -12,34 +12,20 @@ export class ConnectRIGuard implements CanActivate { constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {} canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { - //console.log(state.url); - var user; - var loggedIn = false; - var isAdmin = false; - var errorCode = LoginErrorCodes.NOT_LOGIN; - + let errorCode = LoginErrorCodes.NOT_LOGIN; let community = (route.queryParams["communityId"]); if(Session.isLoggedIn()){ - loggedIn = true; - if(!Session.isLoggedIn()){ - loggedIn = false; - errorCode = LoginErrorCodes.NOT_VALID; - this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); - - return false; - }else if(Session.isPortalAdministrator()) { - isAdmin = true; + if(Session.isPortalAdministrator()) { return true; - }else { - + } else { let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => { return this.communityService.iscommunityRI(properties, properties["communityAPI"]+community)}); obs.filter(enabled => !enabled) .subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } })); return obs; } - }else{ - errorCode =LoginErrorCodes.NOT_LOGIN; + } else{ + errorCode = LoginErrorCodes.NOT_LOGIN; this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); return false; @@ -47,26 +33,4 @@ export class ConnectRIGuard implements CanActivate { } - /* - constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { - - let customRedirect = route.data['redirect']; - let api = route.data['api']; - let community = route.data['community'] - if(!community){ - community = (route.queryParams["communityId"])?route.queryParams["communityId"]:route.queryParams["community"]; - } - if(community){ - let isEnabled = this.config.isPageEnabled(api, community,"/"+state.url.split("?")[0].substring(1)); - let redirect = !!customRedirect ? customRedirect : '/error'; - - isEnabled.filter(enabled => !enabled) - .subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } })); - return isEnabled; - } - return true; - } - */ } diff --git a/landingPages/dataProvider/dataProvider-routing.module.ts b/landingPages/dataProvider/dataProvider-routing.module.ts deleted file mode 100644 index 8fb2f38f..00000000 --- a/landingPages/dataProvider/dataProvider-routing.module.ts +++ /dev/null @@ -1,18 +0,0 @@ -// import { NgModule } from '@angular/core'; -// import { RouterModule } from '@angular/router'; -// -// import { DataProviderComponent } from './dataProvider.component'; -// import {FreeGuard} from'../../login/freeGuard.guard'; -// import {PreviousRouteRecorder} from'../../utils/piwik/previousRouteRecorder.guard'; -// import {IsRouteEnabled} from '../../error/isRouteEnabled.guard'; -// -// @NgModule({ -// imports: [ -// RouterModule.forChild([ -// { path: '', component: DataProviderComponent, canActivate: [FreeGuard, IsRouteEnabled], data: { -// redirect: '/error' -// },canDeactivate: [PreviousRouteRecorder] } -// ]) -// ] -// }) -// export class DataProviderRoutingModule { } diff --git a/landingPages/dataProvider/dataProvider.service.ts b/landingPages/dataProvider/dataProvider.service.ts index dc1b38b7..77439cb9 100644 --- a/landingPages/dataProvider/dataProvider.service.ts +++ b/landingPages/dataProvider/dataProvider.service.ts @@ -164,14 +164,8 @@ export class DataProviderService { } if(data[4] != null) { - let oaiPmhURL: string; - if(Array.isArray(data[4])) { - oaiPmhURL = data[4][0]; - } - else { - oaiPmhURL = data[4]; - } - + let oaiPmhURL:string; + oaiPmhURL = Array.isArray(data[4]) ? data[4][0]:data[4]; if(oaiPmhURL != '' && oaiPmhURL != 'unknown') { this.dataProviderInfo.oaiPmhURL = oaiPmhURL; } diff --git a/landingPages/project/project-routing.module.ts b/landingPages/project/project-routing.module.ts deleted file mode 100644 index 2eff3b40..00000000 --- a/landingPages/project/project-routing.module.ts +++ /dev/null @@ -1,18 +0,0 @@ -// import { NgModule } from '@angular/core'; -// import { RouterModule } from '@angular/router'; -// -// import { ProjectComponent } from './project.component'; -// import {FreeGuard} from'../../login/freeGuard.guard'; -// import {PreviousRouteRecorder} from'../../utils/piwik/previousRouteRecorder.guard'; -// import {IsRouteEnabled} from '../../error/isRouteEnabled.guard'; -// -// @NgModule({ -// imports: [ -// RouterModule.forChild([ -// { path: '', component: ProjectComponent, canActivate: [FreeGuard, IsRouteEnabled], data: { -// redirect: '/error' -// },canDeactivate: [PreviousRouteRecorder] } -// ]) -// ] -// }) -// export class ProjectRoutingModule { } diff --git a/landingPages/project/project.service.ts b/landingPages/project/project.service.ts index 15bd2d80..abf6235a 100644 --- a/landingPages/project/project.service.ts +++ b/landingPages/project/project.service.ts @@ -33,6 +33,7 @@ export class ProjectService { .map(res => this.parseProjectInfo(res, properties)); } + getProjectInfoByGrantId (grant: string, funder:string, properties:EnvProperties):any { let url =properties.searchAPIURLLAst+ 'resources?query=(oaftype exact project)'+ @@ -80,8 +81,6 @@ export class ProjectService { } 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'); } @@ -98,15 +97,11 @@ export class ProjectService { parseProjectInfo (data: any, properties:EnvProperties):any { this.projectInfo = new ProjectInfo(); if(data[3] != null) { - this.projectInfo.id =data[3]; + this.projectInfo.id = data[3]; } if(data[0] != null) { this.projectInfo.acronym = data[0].acronym; - if(Array.isArray(data[0]['title'])) { - this.projectInfo.title = data[0].title[0]; - } else { - this.projectInfo.title = data[0].title; - } + this.projectInfo.title = Array.isArray(data[0]['title']) ? data[0].title[0] : data[0].title; this.projectInfo.callIdentifier = data[0].callidentifier; this.projectInfo.contractNum = data[0].code; this.projectInfo.startDate = data[0].startdate; @@ -116,39 +111,8 @@ export class ProjectService { this.projectInfo.openAccessMandateDatasets = data[0].ecarticle29_3; } if(data[1] != null) { - /* - if(data[1]['funder'] != null) { - this.projectInfo.funder = data[1]['funder'].shortname; - } - - let funding; - this.projectInfo.funding = ""; - - if(data[1]['funding_level_2'] != null) { - funding = data[1]['funding_level_2'].id; - } else if(data[1]['funding_level_1'] != null) { - funding = data[1]['funding_level_1'].id; - } else if(data[1]['funding_level_0'] != null) { - funding = data[1]['funding_level_0'].id; - } - - if(funding != undefined) { - funding = funding.split("::"); - for(let i=1; i0){ diff --git a/login/user.module.ts b/login/user.module.ts index 7addeb79..1f94750a 100644 --- a/login/user.module.ts +++ b/login/user.module.ts @@ -10,7 +10,6 @@ import {UserComponent} from './user.component'; import {PreviousRouteRecorder} from '../utils/piwik/previousRouteRecorder.guard'; import {FreeGuard} from './freeGuard.guard'; import {LoginGuard} from './loginGuard.guard'; -// import {LoginService} from './login.service'; @NgModule({ imports: [ diff --git a/login/userMini.component.ts b/login/userMini.component.ts index 67b372e6..06246939 100644 --- a/login/userMini.component.ts +++ b/login/userMini.component.ts @@ -1,8 +1,6 @@ import {Component, ElementRef, Input} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; import {ActivatedRoute, Router} from '@angular/router'; import {Location} from '@angular/common'; -// import {LoginService} from './login.service'; import {User,Session} from './utils/helper.class'; import {RouterHelper} from '../utils/routerHelper.class'; import {StringUtils} from '../utils/string-utils.class'; @@ -82,9 +80,7 @@ export class UserMiniComponent { @Input() logOutUrl; @Input() cookieDomain; public redirectUrl: string = ""; - private baseUrl = "user-info"; sub:any; - // public properties:EnvProperties; constructor( private router: Router, private route: ActivatedRoute, private location: Location) {} @@ -103,53 +99,44 @@ export class UserMiniComponent { ngOnDestroy(){ this.sub.unsubscribe(); } + initialize(){ this.redirectUrl = this.location.path(); if(Session.isLoggedIn()){ - this.loggedIn = Session.isLoggedIn(); + this.loggedIn = true; this.user = Session.getUser(); if(Session.isClaimsCurator() || Session.isPortalAdministrator()){ - this.isAuthorized = true; - }else { - this.isAuthorized = false; + this.isAuthorized = true; + } else { + this.isAuthorized = false; } }else { - this.loggedIn = false; - this.isAuthorized = false; - this.user = null; + this.loggedIn = false; + this.isAuthorized = false; + this.user = null; } } - // gotoUserPage(){ - // this.redirectUrl = this.location.path(); - // if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != "" && this.redirectUrl !="user-info"){ - // this.router.navigate([this.baseUrl], { queryParams: this.routerHelper.createQueryParam("redirectUrl",this.redirectUrl )}); - // }else{ - // this.router.navigate([this.baseUrl]); - // } - // } + logOut(){ if(Session.isLoggedIn()){ Session.removeUser(); - //console.log("Try to Logout!"); - // console.log("Redirect to "+location.href); window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href); } this.loggedIn = false; - this.isAuthorized = false; + this.isAuthorized = false; this.user = new User(); } logIn(){ - // console.log("LOgin is clicked " + this.logInUrl); Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search); window.location.href = this.logInUrl } onClick(id: string) { - var el: HTMLElement = document.getElementById(id); + let el: HTMLElement = document.getElementById(id); el.classList.remove('uk-open'); } diff --git a/services/searchSoftware.service.ts b/services/searchSoftware.service.ts index d8a6a2cc..979018f3 100644 --- a/services/searchSoftware.service.ts +++ b/services/searchSoftware.service.ts @@ -251,11 +251,7 @@ export class SearchSoftwareService { var date:string = (resData.dateofacceptance)+""; // transform to string in case it is an integer result.year = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date; - if(!Array.isArray(resData.description)) { - result.description = resData.description; - } else { - result.description = resData.description[0]; - } + result.description = Array.isArray(resData.description) ? resData.description[0] : resData.description; if(result.description && result.description.length > this.sizeOfDescription) { result.description = result.description.substring(0, this.sizeOfDescription)+"..."; }