[Library|Trunk]
code clean up - Connect related: -remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc) -remove Freeguard from modules -unsubscribe all subscriptions - remove old properties json files git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59825 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
8569010477
commit
7ca179f3e8
|
@ -1,6 +1,6 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {BehaviorSubject, Observable, Subscriber} from 'rxjs';
|
||||
import {Affiliation} from '../../utils/entities/CuratorInfo';
|
||||
import {properties} from "../../../../environments/environment";
|
||||
|
||||
|
@ -8,13 +8,20 @@ import {properties} from "../../../../environments/environment";
|
|||
export class AffiliationService {
|
||||
|
||||
private affiliationsSubject: BehaviorSubject<Affiliation[]> = new BehaviorSubject([]);
|
||||
|
||||
sub;
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.clearSubscriptions();
|
||||
}
|
||||
clearSubscriptions(){
|
||||
if (this.sub instanceof Subscriber) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
public initAffiliations(communityId: string): void {
|
||||
let url = properties.communityAPI + communityId + "/organizations";
|
||||
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe((affiliations) => {
|
||||
this.sub = this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe((affiliations) => {
|
||||
this.affiliationsSubject.next(affiliations);
|
||||
},
|
||||
error => {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Component, Input } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import {HttpClient} from "@angular/common/http";
|
|||
|
||||
import {CommunityInfo} from '../community/communityInfo';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {BehaviorSubject} from "rxjs";
|
||||
import {BehaviorSubject, Subscriber} from "rxjs";
|
||||
import {map} from "rxjs/operators";
|
||||
|
||||
@Injectable()
|
||||
|
@ -14,9 +14,17 @@ export class CommunitiesService {
|
|||
constructor(private http: HttpClient) {
|
||||
this.communities = new BehaviorSubject([]);
|
||||
}
|
||||
|
||||
sub;
|
||||
ngOnDestroy() {
|
||||
this.clearSubscriptions();
|
||||
}
|
||||
clearSubscriptions(){
|
||||
if (this.sub instanceof Subscriber) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
updateCommunities(properties: EnvProperties, url: string) {
|
||||
this.getCommunities(properties, url).subscribe(res => {
|
||||
this.sub = this.getCommunities(properties, url).subscribe(res => {
|
||||
this.communities.next(res);
|
||||
}, error => {
|
||||
this.communities.error(error);
|
||||
|
|
|
@ -3,7 +3,7 @@ import {HttpClient, HttpHeaders} from "@angular/common/http";
|
|||
import { CommunityInfo } from './communityInfo';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {map} from "rxjs/operators";
|
||||
import {BehaviorSubject, from} from "rxjs";
|
||||
import {BehaviorSubject, from, Subscriber} from "rxjs";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
|
@ -15,10 +15,18 @@ export class CommunityService {
|
|||
constructor(private http: HttpClient) {
|
||||
this.community = new BehaviorSubject(null);
|
||||
}
|
||||
|
||||
sub;
|
||||
ngOnDestroy() {
|
||||
this.clearSubscriptions();
|
||||
}
|
||||
clearSubscriptions(){
|
||||
if (this.sub instanceof Subscriber) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
getCommunityByService(properties: EnvProperties, url: string) {
|
||||
this.promise = new Promise<any>(resolve => {
|
||||
this.getCommunity(properties, url).subscribe(res => {
|
||||
this.sub = this.getCommunity(properties, url).subscribe(res => {
|
||||
this.community.next(res);
|
||||
resolve();
|
||||
},
|
||||
|
@ -35,6 +43,7 @@ export class CommunityService {
|
|||
}
|
||||
|
||||
await this.promise;
|
||||
this.clearSubscriptions();
|
||||
return this.community.getValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +1,29 @@
|
|||
import {filter, map, mergeMap, take, tap} from 'rxjs/operators';
|
||||
import {take, tap} from 'rxjs/operators';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {CommunityService} from '../community/community.service';
|
||||
import {ConnectHelper} from '../connectHelper';
|
||||
import {UserManagementService} from "../../services/user-management.service";
|
||||
import {SubscribeService} from "../../utils/subscribe/subscribe.service";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
|
||||
@Injectable()
|
||||
export class ConnectSubscriberGuard implements CanActivate {
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private subscribeService: SubscribeService,
|
||||
private userManagementService: UserManagementService) {
|
||||
private subscribeService: SubscribeService) {
|
||||
}
|
||||
|
||||
check(community: string, path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let email = null;
|
||||
const subscribed = this.userManagementService.getUserInfo(false).pipe(take(1),map(user => {
|
||||
if (user) {
|
||||
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
email = user.email;
|
||||
let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||
if (communityDomain) {
|
||||
community = communityDomain;
|
||||
}
|
||||
if (Session.isSubscribedTo('community', community, user)) {
|
||||
return of(true);
|
||||
}
|
||||
return this.subscribeService.isSubscribedToCommunity(properties, community).pipe(take(1));
|
||||
} else {
|
||||
return of(false);
|
||||
|
||||
check(community: string, path: string): Observable<boolean> {
|
||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
return this.subscribeService.isSubscribedToCommunity(properties, community).pipe(take(1), tap(subscribed =>{
|
||||
if(!subscribed){
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
});
|
||||
}
|
||||
}), mergeMap(authorized => {
|
||||
return authorized;
|
||||
}));
|
||||
subscribed.pipe(filter(subscribed => !subscribed)).subscribe(() => {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
})
|
||||
});
|
||||
return subscribed;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {filter, map, mergeMap} from "rxjs/operators";
|
||||
import {filter, map, mergeMap, take} from "rxjs/operators";
|
||||
import {UserManagementService} from "../../services/user-management.service";
|
||||
import {EnvironmentSpecificService} from "../../utils/properties/environment-specific.service";
|
||||
import {Session} from "../../login/utils/helper.class";
|
||||
|
@ -13,7 +13,19 @@ export class IsCommunityOrAdmin implements CanActivate {
|
|||
private userManagementService: UserManagementService,
|
||||
private propertiesService: EnvironmentSpecificService) {
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO add login guard and simplify this method
|
||||
check(community: string): Observable<boolean> | boolean {
|
||||
return this.userManagementService.getUserInfo(false).pipe(take(1),map(user => {
|
||||
if (community && community !== 'undefined' || Session.isPortalAdministrator(user)) {
|
||||
return true;
|
||||
} else {
|
||||
this.router.navigate(['/errorCommunity']);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
}
|
||||
*/
|
||||
check(community: string): Observable<boolean> | boolean {
|
||||
if (community && community !== 'undefined') {
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Http} from '@angular/http';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import{EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {map} from "rxjs/operators";
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
export class ResultInfo {
|
||||
title: string;
|
||||
id: string;
|
||||
|
@ -7,3 +8,4 @@ export class ResultInfo {
|
|||
description: string;
|
||||
type: string;
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import {Component, ViewChild, Input} from '@angular/core';
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {Location} from '@angular/common';
|
||||
import {Observable} from 'rxjs';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {ModalLoading} from '../../utils/modal/loading.component';
|
||||
import {AlertModal} from '../../utils/modal/alert';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {MailPrefsService} from './mailPrefs.service';
|
||||
|
@ -11,6 +8,8 @@ import {ConnectHelper} from '../connectHelper';
|
|||
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
||||
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {Subscriber} from "rxjs";
|
||||
|
||||
declare var UIkit: any;
|
||||
|
||||
|
@ -22,7 +21,7 @@ declare var UIkit: any;
|
|||
})
|
||||
export class MailPrefsComponent {
|
||||
properties:EnvProperties;
|
||||
sub: any;
|
||||
subscriptions = [];
|
||||
public communityId: string;
|
||||
public preferencesFor: string = "community";
|
||||
public status: number;
|
||||
|
@ -47,19 +46,15 @@ export class MailPrefsComponent {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
this.properties = data.envSpecific;
|
||||
this.sub = this.route.queryParams.subscribe(params => {
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||
if(!this.communityId) {
|
||||
this.communityId = params['communityId'];
|
||||
}
|
||||
this.properties = properties;
|
||||
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
||||
if(!this.communityId) {
|
||||
this.communityId = params['communityId'];
|
||||
}
|
||||
this.getEmailPreferences();
|
||||
}));
|
||||
|
||||
this.getEmailPreferences();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -75,7 +70,7 @@ export class MailPrefsComponent {
|
|||
|
||||
if(this.communityId && this.communityId != "openaire") {
|
||||
this.preferencesFor = "community";
|
||||
this._mailPrefsService.getUserEmailPreferencesForCommunity(this.communityId, this.properties.claimsAPIURL).subscribe(
|
||||
this.subscriptions.push(this._mailPrefsService.getUserEmailPreferencesForCommunity(this.communityId, this.properties.claimsAPIURL).subscribe(
|
||||
data => {
|
||||
if(data.code == "204") {
|
||||
this.status = this.errorCodes.NONE;
|
||||
|
@ -90,10 +85,10 @@ export class MailPrefsComponent {
|
|||
this.handleErrors(err);
|
||||
this.handleError("Error getting user email preferences for community with id: "+this.communityId, err);
|
||||
}
|
||||
);
|
||||
));
|
||||
} else {
|
||||
this.preferencesFor = "project";
|
||||
this._mailPrefsService.getUserEmailPreferencesForOpenaire(this.properties.claimsAPIURL).subscribe(
|
||||
this.subscriptions.push(this._mailPrefsService.getUserEmailPreferencesForOpenaire(this.properties.claimsAPIURL).subscribe(
|
||||
data => {
|
||||
|
||||
if(data.code == "204") {
|
||||
|
@ -113,7 +108,7 @@ export class MailPrefsComponent {
|
|||
this.handleErrors(err);
|
||||
this.handleError("Error getting user email preferences for openaire", err);
|
||||
}
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +155,7 @@ export class MailPrefsComponent {
|
|||
this.status = this.errorCodes.LOADING;
|
||||
this.savedMessage = "";
|
||||
|
||||
this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe(
|
||||
this.subscriptions.push(this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe(
|
||||
data => {
|
||||
this.initialNotifications[index] = JSON.parse(JSON.stringify( this.notifications[index] ));
|
||||
|
||||
|
@ -179,7 +174,7 @@ export class MailPrefsComponent {
|
|||
this.handleError("Error saving user email preferences: "+JSON.stringify(this.notifications[index]), err);
|
||||
this.status = this.errorCodes.NOT_SAVED;
|
||||
}
|
||||
);
|
||||
));
|
||||
}
|
||||
else {
|
||||
/*UIkit.notification({
|
||||
|
@ -221,11 +216,14 @@ export class MailPrefsComponent {
|
|||
}
|
||||
*/
|
||||
ngOnDestroy() {
|
||||
if(this.sub) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if (subscription instanceof Subscriber) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
handleErrors(err){
|
||||
//this.showErrorMessage = true;
|
||||
//try{
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Http, RequestOptions, Headers, Response} from '@angular/http';
|
||||
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';
|
||||
import {throwError} from 'rxjs';
|
||||
import { CustomOptions } from '../../services/servicesUtils/customOptions.class';
|
||||
|
||||
@Injectable()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Http} from '@angular/http';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import{EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Http, Response} from '@angular/http';
|
||||
import {Headers, RequestOptions} from '@angular/http';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
import {ZenodoCommunityInfo} from './zenodoCommunityInfo';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
|
Loading…
Reference in New Issue