Check is LoggedIn from Session

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57064 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-09-13 08:26:09 +00:00
parent 69c86456b8
commit 95ee0d8984
5 changed files with 688 additions and 808 deletions

View File

@ -1,11 +1,10 @@
import {Component, Input} from '@angular/core';
import {Router} from '@angular/router';
import {ContextsService} from './service/contexts.service';
import {ClaimEntity} from './claimHelper.class';
import {ClaimContext, ClaimEntity} from './claimHelper.class';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties';
import {UserManagementService} from "../../services/user-management.service";
declare var UIkit: any;
@ -15,7 +14,7 @@ declare var UIkit: any;
})
export class ClaimContextSearchFormComponent {
@Input() public results: ClaimEntity[];
@Input() public results:ClaimEntity[];
@Input() public sources;
@Input() public properties: EnvProperties;
@Input() communityId: string = null;
@ -45,9 +44,7 @@ export class ClaimContextSearchFormComponent {
this.getCommunities();
}
constructor(private _contextService: ContextsService,
private router: Router,
private userManagementService: UserManagementService) {
constructor(private _contextService: ContextsService, private router: Router) {
}
@ -98,7 +95,7 @@ export class ClaimContextSearchFormComponent {
// });
// return;
// }
const entity: ClaimEntity = new ClaimEntity();
const entity: ClaimEntity = new ClaimEntity() ;
entity.type = "community";
entity.context = {community: community, category: category, concept: concept};
@ -112,81 +109,77 @@ export class ClaimContextSearchFormComponent {
}
getCommunities() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin();
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
this.loading = true;
this._contextService.getPublicCommunities(this.properties.contextsAPI).subscribe(
data => {
this.communities = data;
if (this.communities.length > 0) {
this.communities.sort((n1, n2) => n1.label > n2.label);
}
this.loading = false;
if (this.communityId != null) {
//preselect community
this.selectedCommunityId = this.communityId;
for (let i = 0; i < this.communities.length; i++) {
if (this.communities[i].id == this.selectedCommunityId) {
this.selectedCommunityLabel = this.communities[i].label;
break;
}
}
this.addNewContext(this.selectedCommunityLabel, null, {
'id': this.selectedCommunityId,
'label': this.selectedCommunityLabel
}, false)
}
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting communities", err);
this.loading = false;
this.error = true;
} else {
this.loading = true;
this._contextService.getPublicCommunities(this.properties.contextsAPI).subscribe(
data => {
this.communities = data;
if (this.communities.length > 0) {
this.communities.sort((n1, n2) => n1.label > n2.label);
}
);
}
});
this.loading = false;
if (this.communityId != null) {
//preselect community
this.selectedCommunityId = this.communityId;
for (let i = 0; i < this.communities.length; i++) {
if (this.communities[i].id == this.selectedCommunityId) {
this.selectedCommunityLabel = this.communities[i].label;
break;
}
}
this.addNewContext(this.selectedCommunityLabel, null, {
'id': this.selectedCommunityId,
'label': this.selectedCommunityLabel
}, false)
}
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting communities", err);
this.loading = false;
this.error = true;
}
);
}
}
getCategories() {
this.loading = true;
// this.categories=[];
if (this.selectedCommunityId != '0') {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin();
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
if (this.categories[this.selectedCommunityId]) {
this.loading = false;
return;
}
this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe(
data => {
this.categories[this.selectedCommunityId] = data;
this.concepts = [];
if (this.query !== "") {
const event = {value: ""};
event.value = this.query;
}
this.loading = false;
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err);
this.loading = false;
}
);
} else {
if (this.categories[this.selectedCommunityId]) {
this.loading = false;
return;
}
});
this._contextService.getCategories(this.selectedCommunityId, this.properties.contextsAPI).subscribe(
data => {
this.categories[this.selectedCommunityId] = data;
this.concepts = [];
if (this.query !== "") {
const event = {value: ""};
event.value = this.query;
}
this.loading = false;
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting categories for community with id: " + this.selectedCommunityId, err);
this.loading = false;
}
);
}
}
}
/*
getConcepts() {
this.loading = true;
@ -225,7 +218,6 @@ export class ClaimContextSearchFormComponent {
this.loading = false;
}
}*/
/*
getSubConcepts(conceptId) {
this.loading = true;
@ -269,40 +261,38 @@ export class ClaimContextSearchFormComponent {
}
browseConcepts(categoryId) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this.saveStateAndRedirectLogin();
if (!Session.isLoggedIn()) {
this.saveStateAndRedirectLogin();
} else {
if (this.conceptsClass[categoryId] != null) {
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
return;
} else {
if (this.conceptsClass[categoryId] != null) {
this.conceptsClassDisplay[categoryId] = !this.conceptsClassDisplay[categoryId];
return;
} else {
this.conceptsClassDisplay[categoryId] = true;
}
this.conceptsClass[categoryId] = [];
this.conceptsCategoryLoading[categoryId] = true;
this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe(
data => {
// var concepts = data;
this.conceptsClass[categoryId] = [];
for (let i = 0; i < data.length; i++) {
if (data[i].hasSubConcept == true) {
this.browseSubConcepts(categoryId, data[i].id);
} else {
this.conceptsClass[categoryId].push(data[i]);
}
}
this.conceptsCategoryLoading[categoryId] = false;
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err);
this.conceptsCategoryLoading[categoryId] = false;
}
);
this.conceptsClassDisplay[categoryId] = true;
}
});
this.conceptsClass[categoryId] = [];
this.conceptsCategoryLoading[categoryId] = true;
this._contextService.getConcepts(categoryId, "", false, this.properties.contextsAPI).subscribe(
data => {
// var concepts = data;
this.conceptsClass[categoryId] = [];
for (let i = 0; i < data.length; i++) {
if (data[i].hasSubConcept == true) {
this.browseSubConcepts(categoryId, data[i].id);
} else {
this.conceptsClass[categoryId].push(data[i]);
}
}
this.conceptsCategoryLoading[categoryId] = false;
},
err => {
//console.log(err);
ClaimContextSearchFormComponent.handleError("Error getting concepts for category with id: " + this.selectedCategoryId, err);
this.conceptsCategoryLoading[categoryId] = false;
}
);
}
}
browseSubConcepts(categoryId, conceptId) {

View File

@ -1,32 +1,34 @@
import {Component, QueryList, ViewChild, ViewChildren, ViewEncapsulation} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Meta, Title} from '@angular/platform-browser';
import {Component, ViewChild, ViewChildren, QueryList, Input, ViewEncapsulation} from '@angular/core';
import {Location} from '@angular/common';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {DataTableDirective} from 'angular-datatables';
import {Subject} from 'rxjs';
import {DataTableDirective} from 'angular-datatables';
import {Observable, Subject } from 'rxjs';
import {EnvProperties} from '../../utils/properties/env-properties';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import{EnvProperties} from '../../utils/properties/env-properties';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {RouterHelper} from '../../utils/routerHelper.class';
import {ClaimsDatatablePipe} from '../../utils/pipes/claimsDatatable.pipe';
import {ModalSelect} from '../../utils/modal/selectModal.component';
import {ModalLoading} from '../../utils/modal/loading.component';
import {RouterHelper} from '../../utils/routerHelper.class';
import {ClaimsByTokenService} from './claimsByToken.service';
import {ModalSelect} from '../../utils/modal/selectModal.component';
import {ModalLoading} from '../../utils/modal/loading.component';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {UserManagementService} from "../../services/user-management.service";
import {ClaimsByTokenService} from './claimsByToken.service';
import {Session} from '../../login/utils/helper.class';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
@Component({
selector: 'claims-project-manager',
templateUrl: 'claimsByToken.component.html',
styles: [`
#table1_info, #table1_paginate, #table1_length, #table1_filter,
#table2_info, #table2_paginate, #table2_length, #table2_filter {
#table1_info, #table1_paginate, #table1_length, #table1_filter,
#table2_info, #table2_paginate, #table2_length, #table2_filter{
display: none;
}
@ -38,7 +40,7 @@ export class ClaimsByTokenComponent {
public openaireId: string = "";
public sub: any;
public project: any;
private claims: any = [];
private claims:any = [];
public pending_claims: any = [];
public curated_claims: any = [];
public selectedRight_PendingMode: Set<string>;
@ -60,13 +62,13 @@ export class ClaimsByTokenComponent {
public showTables: boolean = true;
public rowsOnPage = 5;
public sortOrder = "asc";
public keyword1: string = "";
public keyword2: string = "";
public keyword1:string = "";
public keyword2:string = "";
public activePendingPage: any = {page: 1};
public totalPendingResults: any = {count: 0};
public activeCuratedPage: any = {page: 1};
public totalCuratedResults: any = {count: 0};
public activePendingPage:any = {page: 1};
public totalPendingResults:any = {count: 0};
public activeCuratedPage:any = {page: 1};
public totalCuratedResults:any = {count: 0};
dtTrigger: Subject<any>[] = [];
private triggered: boolean = false;
@ -77,31 +79,29 @@ export class ClaimsByTokenComponent {
//@ViewChild("table1") table1: DataTableDirective;
//@ViewChild("table2") table2: DataTableDirective;
@ViewChild(ModalSelect) selectModal: ModalSelect;
@ViewChild(ModalLoading) loading: ModalLoading;
@ViewChild (ModalSelect) selectModal : ModalSelect;
@ViewChild (ModalLoading) loading : ModalLoading ;
properties: EnvProperties;
properties:EnvProperties;
public routerHelper: RouterHelper = new RouterHelper();
public routerHelper:RouterHelper = new RouterHelper();
constructor(private route: ActivatedRoute,
private _router: Router,
private claimsByTokenService: ClaimsByTokenService,
private _meta: Meta, private _title: Title,
private userManagementService: UserManagementService) {
constructor (private route: ActivatedRoute,
private _router: Router,
private claimsByTokenService: ClaimsByTokenService,
private _meta: Meta, private _title: Title) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.pending_status = this.errorCodes.LOADING;
this.curated_status = this.errorCodes.LOADING;
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
});
this.sub = this.route.queryParams.subscribe(params => {
this.sub = this.route.queryParams.subscribe(params => {
this.mode = "pending";
this.openaireId = params['openaireId'];
this.selectedRight_PendingMode = new Set<string>();
@ -119,11 +119,11 @@ export class ClaimsByTokenComponent {
//"searching": false,
//"lengthChange": false,
"pageLength": this.rowsOnPage,
"columnDefs": [{
"columnDefs": [ {
"type": "date",
"targets": 2
}],
"order": [[2, 'desc']]
} ],
"order": [[ 2, 'desc' ]]
//"pagingType": 'full_numbers',
/*"language": {
"search": "",
@ -133,11 +133,11 @@ export class ClaimsByTokenComponent {
this.dtOptions[1] = {
"pageLength": this.rowsOnPage,
"columnDefs": [{
"columnDefs": [ {
"type": "date",
"targets": [2, 4]
}],
"order": [[4, 'desc']]
"targets": [2,4]
} ],
"order": [[ 4, 'desc' ]]
};
@ -146,24 +146,17 @@ export class ClaimsByTokenComponent {
}
ngAfterViewInit(): void {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (isLoggedIn) {
$.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
if (settings.sTableId == 'table1') {
return !!this.filterData(data, this.keyword1);
} else if (settings.sTableId == 'table2') {
return !!this.filterData(data, this.keyword2);
}
});
} else {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
$.fn['dataTable'].ext.search.push((settings, data, dataIndex) => {
if(settings.sTableId == 'table1') {
if (this.filterData(data, this.keyword1)) {
return true;
}
return false;
} else if(settings.sTableId == 'table2') {
if (this.filterData(data, this.keyword2)) {
return true;
}
return false;
}
});
}
@ -178,10 +171,10 @@ export class ClaimsByTokenComponent {
/*
Trigger a table draw in order to get the initial filtering
*/
triggerInitialLoad() {
triggerInitialLoad(){
this.triggered = true;
//console.info("triggerInitialLoad");
setTimeout(function () {
setTimeout(function(){
/*var table1 = <any>$('#table1').DataTable();
table1.page( 0 ).draw( false );
@ -208,249 +201,226 @@ export class ClaimsByTokenComponent {
});
}
filterData(row: any, query: string): boolean {
let returnValue: boolean = false;
if (query) {
for (var i = 0; i < 3; i++) {
var r = this.filterQuery(row[i], query);
if (r) {
returnValue = true;
break;
filterData(row: any, query: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
let returnValue: boolean = false;
if(query) {
for(var i=0; i <3; i++){
var r= this.filterQuery(row[i], query);
if(r) {
returnValue = true;
break;
}
}
if(!returnValue) {
return false;
}
}
if (!returnValue) {
return false;
}
return true;
}
return true;
}
filterQuery(data, query) {
if (data.toLowerCase().indexOf(query.toLowerCase()) > -1) {
filterQuery(data, query){
if(data.toLowerCase().indexOf(query.toLowerCase()) > -1){
return true;
} else {
}else{
return false;
}
}
refreshTable(page: number, whichTable: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
if (whichTable == "pending") {
var table = $('#table1').DataTable();
table.page(page - 1).draw(false);
refreshTable(page:number, whichTable: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if(whichTable == "pending") {
var table = $('#table1').DataTable();
table.page( page - 1 ).draw( false );
var info = table.page.info();
var info = table.page.info();
this.activePendingPage.page = page;//$event.value;
this.totalPendingResults.count = info.recordsDisplay;
} else if (whichTable == 'curated') {
var table = $('#table2').DataTable();
table.page(page - 1).draw(false);
this.activePendingPage.page = page;//$event.value;
this.totalPendingResults.count = info.recordsDisplay;
} else if(whichTable == 'curated') {
var table = $('#table2').DataTable();
table.page( page - 1 ).draw( false );
var info = table.page.info();
var info = table.page.info();
this.activeCuratedPage.page = page;//$event.value;
this.totalCuratedResults.count = info.recordsDisplay;
}
this.activeCuratedPage.page = page;//$event.value;
this.totalCuratedResults.count = info.recordsDisplay;
}
});
}
//table.mfActivePage=$event.value;
//table.setPage(table.mfActivePage, this.rowsOnPage);
}
validateJWTandToken() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
if (this.openaireId) {
this.pending_status = this.errorCodes.LOADING;
this.curated_status = this.errorCodes.LOADING;
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if(this.openaireId) {
this.pending_status = this.errorCodes.LOADING;
this.curated_status = this.errorCodes.LOADING;
this.showTables = false;
this.pending_claims = [];
this.curated_claims = [];
this.showTables = false;
this.pending_claims = [];
this.curated_claims = [];
this.activePendingPage.page = 1;
this.totalPendingResults.count = 0;
this.activeCuratedPage.page = 1;
this.totalCuratedResults.count = 0;
this.activePendingPage.page = 1;
this.totalPendingResults.count = 0;
this.activeCuratedPage.page = 1;
this.totalCuratedResults.count = 0;
this.claimsByTokenService.getClaims(this.openaireId, this.properties.claimsAPIURL).subscribe(
data => {
//this.closeLoading();
this.accessStatus = "valid";
this.claims = data.data;
for (let claim of this.claims) {
if (claim.targetType == "project") {
this.project = claim.target;
} else {
this.project = claim.source;
}
if (claim.curatedBy) {
this.curated_claims.push(claim);
} else {
this.pending_claims.push(claim);
}
}
this.totalPendingResults.count = this.pending_claims.length;
this.totalCuratedResults.count = this.curated_claims.length;
if (this.project) {
this.updateTitle("Claims For Project Managers - " + this.project.name);
}
this.showTables = true;
if (!this.triggered) {
//console.info("initial load");
this.triggerInitialLoad();
this.claimsByTokenService.getClaims(this.openaireId, this.properties.claimsAPIURL).subscribe(
data => {
//this.closeLoading();
this.accessStatus = "valid";
this.claims = data.data;
for(let claim of this.claims) {
if(claim.targetType == "project") {
this.project = claim.target;
} else {
//console.info("rerender");
var table1 = $('#table1').DataTable();
table1.clear();
var table2 = $('#table2').DataTable();
table2.clear();
this.rerender();
this.project = claim.source;
}
this.pending_status = this.errorCodes.DONE;
this.curated_status = this.errorCodes.DONE;
},
err => {
this.handleError("Error getting claims for openaire id: " + this.openaireId, err);
this.pending_status = this.errorMessages.getErrorCode(err.status);
this.curated_status = this.pending_status;
/*if(err.status == '404') {
this.pending_status = this.errorCodes.NOT_FOUND;
this.curated_status = this.errorCodes.NOT_FOUND;
} else if(err.status == '500') {
this.pending_status = this.errorCodes.ERROR;
this.curated_status = this.errorCodes.ERROR;
if(claim.curatedBy) {
this.curated_claims.push(claim);
} else {
this.pending_status = this.errorCodes.NOT_AVAILABLE;
this.curated_status = this.errorCodes.NOT_AVAILABLE;
}*/
this.showTables = true;
if (!this.triggered) {
this.triggerInitialLoad();
} else {
var table1 = $('#table1').DataTable();
table1.clear();
var table2 = $('#table2').DataTable();
table2.clear();
this.rerender();
this.pending_claims.push(claim);
}
this.accessStatus = "invalid";
//console.log(err);
}
);
} else {
this.accessStatus = "invalid";
}
}
});
}
selectApprove(id: string, event, mode: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
this.totalPendingResults.count = this.pending_claims.length;
this.totalCuratedResults.count = this.curated_claims.length;
if(this.project) {
this.updateTitle("Claims For Project Managers - "+this.project.name);
}
this.showTables = true;
if(!this.triggered) {
//console.info("initial load");
this.triggerInitialLoad();
} else {
//console.info("rerender");
var table1 = $('#table1').DataTable();
table1.clear();
var table2 = $('#table2').DataTable();
table2.clear();
this.rerender();
}
this.pending_status = this.errorCodes.DONE;
this.curated_status = this.errorCodes.DONE;
},
err => {
this.handleError("Error getting claims for openaire id: "+this.openaireId, err);
this.pending_status = this.errorMessages.getErrorCode(err.status);
this.curated_status = this.pending_status;
/*if(err.status == '404') {
this.pending_status = this.errorCodes.NOT_FOUND;
this.curated_status = this.errorCodes.NOT_FOUND;
} else if(err.status == '500') {
this.pending_status = this.errorCodes.ERROR;
this.curated_status = this.errorCodes.ERROR;
} else {
this.pending_status = this.errorCodes.NOT_AVAILABLE;
this.curated_status = this.errorCodes.NOT_AVAILABLE;
}*/
this.showTables = true;
if(!this.triggered) {
this.triggerInitialLoad();
} else {
var table1 = $('#table1').DataTable();
table1.clear();
var table2 = $('#table2').DataTable();
table2.clear();
this.rerender();
}
this.accessStatus = "invalid";
//console.log(err);
}
});
);
} else {
var value = event.currentTarget.checked;
if (value) {
if (mode == "pending") {
this.selectedRight_PendingMode.add(id);
this.selectedWrong_PendingMode.delete(id);
} else {
this.selectedRight_CuratedMode.add(id);
this.selectedWrong_CuratedMode.delete(id);
}
} else {
if (mode == "pending") {
this.selectedRight_PendingMode.delete(id);
}
// } else {
// this.selectedRight_CuratedMode.delete(id);
// this.selectedWrong_CuratedMode.add(id);
// }
}
this.accessStatus = "invalid";
}
});
}
}
selectDisapprove(id: string, event, mode: string) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
var value = event.currentTarget.checked;
if (value) {
if (mode == "pending") {
this.selectedWrong_PendingMode.add(id);
this.selectedRight_PendingMode.delete(id);
} else {
this.selectedWrong_CuratedMode.add(id);
this.selectedRight_CuratedMode.delete(id);
}
selectApprove(id:string, event, mode: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
var value = event.currentTarget.checked;
if(value){
if(mode == "pending") {
this.selectedRight_PendingMode.add(id);
this.selectedWrong_PendingMode.delete(id);
} else {
if (mode == "pending") {
this.selectedWrong_PendingMode.delete(id);
}
// } else {
// this.selectedWrong_CuratedMode.delete(id);
// this.selectedRight_CuratedMode.add(id);
// }
this.selectedRight_CuratedMode.add(id);
this.selectedWrong_CuratedMode.delete(id);
}
}else{
if(mode == "pending") {
this.selectedRight_PendingMode.delete(id);
}
// } else {
// this.selectedRight_CuratedMode.delete(id);
// this.selectedWrong_CuratedMode.add(id);
// }
}
});
}
}
isSelected(id: string, set: Set<string>) {
selectDisapprove(id:string, event, mode: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
var value = event.currentTarget.checked;
if(value){
if(mode == "pending") {
this.selectedWrong_PendingMode.add(id);
this.selectedRight_PendingMode.delete(id);
} else {
this.selectedWrong_CuratedMode.add(id);
this.selectedRight_CuratedMode.delete(id);
}
}else{
if(mode == "pending") {
this.selectedWrong_PendingMode.delete(id);
}
// } else {
// this.selectedWrong_CuratedMode.delete(id);
// this.selectedRight_CuratedMode.add(id);
// }
}
}
}
isSelected(id:string, set:Set<string>) {
return set.has(id);
}
/*
isSelectedWrong(id:string) {
return this.selectedWrong.has(id);
}
*/
isRight_CuratedMode(claim: any) {
if (this.isSelected(claim.id, this.selectedRight_CuratedMode)) {
if(this.isSelected(claim.id, this.selectedRight_CuratedMode)) {
return true;
} else if (claim.approved == true && !this.isSelected(claim.id, this.selectedWrong_CuratedMode)) {
} else if(claim.approved == true && !this.isSelected(claim.id, this.selectedWrong_CuratedMode)) {
return true;
}
@ -458,9 +428,9 @@ export class ClaimsByTokenComponent {
}
isWrong_CuratedMode(claim: any) {
if (this.isSelected(claim.id, this.selectedWrong_CuratedMode)) {
if(this.isSelected(claim.id, this.selectedWrong_CuratedMode)) {
return true;
} else if (claim.approved == false && !this.isSelected(claim.id, this.selectedRight_CuratedMode)) {
} else if(claim.approved == false && !this.isSelected(claim.id, this.selectedRight_CuratedMode)) {
return true;
}
@ -468,125 +438,96 @@ export class ClaimsByTokenComponent {
}
cancelEditOfCuration(claim: any) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if(claim.approved) {
//this.selectedRight_CuratedMode.add(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
} else {
if (claim.approved) {
//this.selectedRight_CuratedMode.add(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
} else {
this.selectedRight_CuratedMode.delete(claim.id);
//this.selectedWrong_CuratedMode.add(claim.id);
}
this.selectedRight_CuratedMode.delete(claim.id);
//this.selectedWrong_CuratedMode.add(claim.id);
}
});
}
saveEdited(claim: any, editable_index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.curated_status = this.errorCodes.LOADING;
let approved: boolean = this.isRight_CuratedMode(claim);
if (approved == claim.approved) {
this.selectedRight_CuratedMode.delete(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
this.editable.delete(editable_index);
this.curated_status = this.errorCodes.DONE;
} else {
let claimCurationInfo: { "id": string, "approved": boolean } = {"id": claim.id, "approved": approved};
this.claimsByTokenService.updateClaimCuration(claimCurationInfo, this.properties.claimsAPIURL).subscribe(
data => {
this.selectedRight_CuratedMode.delete(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
this.editable.delete(editable_index);
this.validateJWTandToken();
},
err => {
//console.log(err);
this.handleError("Error updating claim curation: " + JSON.stringify(claimCurationInfo), err);
this.curated_status = this.errorCodes.NOT_SAVED;
}
);
}
}
});
}
saveChanges() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.pending_status = this.errorCodes.LOADING;
//this.openLoading();
//console.info("Changes Saved!, right-wrong", this.selectedRight_PendingMode, this.selectedWrong_PendingMode);
this.claimsByTokenService.updateClaimsCuration(this.selectedRight_PendingMode, this.selectedWrong_PendingMode, this.properties.claimsAPIURL).subscribe(
data => {
//this.closeLoading();
this.mode = "curated";
this.clearCheckboxes();
this.validateJWTandToken();
},
err => {
//this.closeLoading();
//console.log(err);
this.handleError("Error updating claims: right: " + JSON.stringify(this.selectedRight_PendingMode) + " and wrong: " + JSON.stringify(this.selectedWrong_PendingMode), err);
this.pending_status = this.errorCodes.NOT_SAVED;
}
);
}
});
}
clearCheckboxes() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.pending_status = this.errorCodes.LOADING;
this.selectedRight_PendingMode.clear();
this.selectedWrong_PendingMode.clear();
this.pending_status = this.errorCodes.DONE;
}
});
}
public openLoading() {
if (this.loading) {
this.loading.open();
}
}
public closeLoading() {
if (this.loading) {
saveEdited(claim: any, editable_index: number) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.curated_status = this.errorCodes.LOADING;
let approved: boolean = this.isRight_CuratedMode(claim);
if(approved == claim.approved) {
this.selectedRight_CuratedMode.delete(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
this.editable.delete(editable_index);
this.curated_status = this.errorCodes.DONE;
} else {
let claimCurationInfo: {"id": string, "approved": boolean} = {"id": claim.id, "approved": approved};
this.claimsByTokenService.updateClaimCuration(claimCurationInfo, this.properties.claimsAPIURL).subscribe(
data => {
this.selectedRight_CuratedMode.delete(claim.id);
this.selectedWrong_CuratedMode.delete(claim.id);
this.editable.delete(editable_index);
this.validateJWTandToken();
},
err => {
//console.log(err);
this.handleError("Error updating claim curation: "+JSON.stringify(claimCurationInfo), err);
this.curated_status = this.errorCodes.NOT_SAVED;
}
);
}
}
}
saveChanges() {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.pending_status = this.errorCodes.LOADING;
//this.openLoading();
//console.info("Changes Saved!, right-wrong", this.selectedRight_PendingMode, this.selectedWrong_PendingMode);
this.claimsByTokenService.updateClaimsCuration(this.selectedRight_PendingMode, this.selectedWrong_PendingMode, this.properties.claimsAPIURL).subscribe(
data => {
//this.closeLoading();
this.mode = "curated";
this.clearCheckboxes();
this.validateJWTandToken();
},
err => {
//this.closeLoading();
//console.log(err);
this.handleError("Error updating claims: right: "+JSON.stringify(this.selectedRight_PendingMode)+" and wrong: "+JSON.stringify(this.selectedWrong_PendingMode), err);
this.pending_status = this.errorCodes.NOT_SAVED;
}
);
}
}
clearCheckboxes() {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.pending_status = this.errorCodes.LOADING;
this.selectedRight_PendingMode.clear();
this.selectedWrong_PendingMode.clear();
this.pending_status = this.errorCodes.DONE;
}
}
public openLoading(){
if(this.loading){
this.loading.open();
}
}
public closeLoading(){
if(this.loading){
this.loading.close();
}
}
@ -595,41 +536,41 @@ export class ClaimsByTokenComponent {
//console.info("selected curator: "+selected);
}
public openSelect() {
if (this.selectModal) {
public openSelect(){
if(this.selectModal){
this.selectModal.open();
}
}
public setMessageSelect(message: string) {
if (this.selectModal) {
public setMessageSelect(message: string){
if(this.selectModal){
this.selectModal.message = message;
}
}
public setOptionsSelect(options: string[]) {
if (this.selectModal) {
public setOptionsSelect(options: string[]){
if(this.selectModal){
this.selectModal.options = options;
}
}
totalPages(totalResults: number): number {
let totalPages: any = totalResults / (this.rowsOnPage);
if (!(Number.isInteger(totalPages))) {
let totalPages:any = totalResults/(this.rowsOnPage);
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1);
}
return totalPages;
}
updateTitle(title: string) {
var _prefix = "OpenAIRE | ";
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
this._meta.updateTag({content: _title}, "property='og:title'");
updateTitle(title:string){
var _prefix ="OpenAIRE | ";
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
this._meta.updateTag({content:_title},"property='og:title'");
this._title.setTitle(_title);
}
private handleError(message: string, error) {
console.error("Claims Project Manager Page: " + message, error);
console.error("Claims Project Manager Page: "+message, error);
}
}

View File

@ -1,25 +1,27 @@
import {Component, Input} from '@angular/core';
import {Component, ViewChild, 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';
import {ConnectHelper} from '../connectHelper';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {UserManagementService} from "../../services/user-management.service";
declare var UIkit: any;
@Component({
selector: 'mailPrefs',
templateUrl: 'mailPrefs.component.html',
providers: [MailPrefsService]
providers:[MailPrefsService]
})
export class MailPrefsComponent {
properties: EnvProperties;
properties:EnvProperties;
sub: any;
public communityId: string;
public preferencesFor: string = "community";
@ -30,19 +32,17 @@ export class MailPrefsComponent {
public prefsChanged = {};
//public showForbiddenMessage:boolean = false;
public userValidMessage: string = "";
public userValidMessage:string = "";
public savedMessage: string = "";
public fetchId: string;
public fetchId:string;
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
@Input() showSaveResetButtons: boolean = true;
constructor(private _mailPrefsService: MailPrefsService,
private route: ActivatedRoute, private _router: Router,
private location: Location,
private userManagementService: UserManagementService) {
constructor (private _mailPrefsService: MailPrefsService, private route: ActivatedRoute, private _router:Router, private location: Location) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.status = this.errorCodes.LOADING;
@ -53,201 +53,167 @@ export class MailPrefsComponent {
.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 = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(!this.communityId) {
this.communityId = params['communityId'];
}
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.fetchId = user.email;
this.getEmailPreferences();
});
this.fetchId = Session.getUserEmail();
this.getEmailPreferences();
});
});
}
getEmailPreferences() {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again.";
if (this.showSaveResetButtons) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} else {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
if (this.communityId && this.communityId != "openaire") {
this.preferencesFor = "community";
this._mailPrefsService.getUserEmailPreferencesForCommunity(this.communityId, this.properties.claimsAPIURL).subscribe(
data => {
if (data.code == "204") {
this.status = this.errorCodes.NONE;
} else {
this.initialNotifications = data.data;
this.notifications = JSON.parse(JSON.stringify(this.initialNotifications));
this.status = this.errorCodes.DONE;
}
},
err => {
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(
data => {
if (data.code == "204") {
this.status = this.errorCodes.NONE;
} else {
this.initialNotifications = data.data;
this.notifications = JSON.parse(JSON.stringify(this.initialNotifications));
//this.notifications = this.initialNotifications.map(x => Object.assign({}, x));
//this.notifications = this.initialNotifications;
this.status = this.errorCodes.DONE;
}
},
err => {
//console.info(err);
this.handleErrors(err);
this.handleError("Error getting user email preferences for openaire", err);
}
);
}
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
}
});
} else {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
if(this.communityId && this.communityId != "openaire") {
this.preferencesFor = "community";
this._mailPrefsService.getUserEmailPreferencesForCommunity(this.communityId, this.properties.claimsAPIURL).subscribe(
data => {
if(data.code == "204") {
this.status = this.errorCodes.NONE;
} else {
this.initialNotifications = data.data;
this.notifications = JSON.parse(JSON.stringify( this.initialNotifications ));
this.status = this.errorCodes.DONE;
}
},
err => {
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(
data => {
if(data.code == "204") {
this.status = this.errorCodes.NONE;
} else {
this.initialNotifications = data.data;
this.notifications = JSON.parse(JSON.stringify( this.initialNotifications ));
//this.notifications = this.initialNotifications.map(x => Object.assign({}, x));
//this.notifications = this.initialNotifications;
this.status = this.errorCodes.DONE;
}
},
err => {
//console.info(err);
this.handleErrors(err);
this.handleError("Error getting user email preferences for openaire", err);
}
);
}
}
}
changeNotify(notification: any, checked: boolean, index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again.";
if (this.showSaveResetButtons) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} else {
this.savedMessage = "";
this.status = this.errorCodes.DONE;
notification.notify = checked;
this.prefsChanged[index] = true;
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
}
});
} else {
this.savedMessage = "";
this.status = this.errorCodes.DONE;
notification.notify = checked;
this.prefsChanged[index] = true;
}
}
changeFrequency(index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again.";
if (this.showSaveResetButtons) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} else {
this.savedMessage = "";
this.status = this.errorCodes.DONE;
if (this.initialNotifications[index].frequency != this.notifications[index].frequency) {
this.prefsChanged[index] = true;
}
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
}
});
} else {
this.savedMessage = "";
this.status = this.errorCodes.DONE;
if(this.initialNotifications[index].frequency != this.notifications[index].frequency) {
this.prefsChanged[index] = true;
}
}
}
saveNotification(index: number) {
if (this.notifications.length > 0 && this.initialNotifications.length > 0) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again.";
if (this.showSaveResetButtons) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} else {
if (JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe(
data => {
this.initialNotifications[index] = JSON.parse(JSON.stringify(this.notifications[index]));
this.status = this.errorCodes.DONE;
/*UIkit.notification({
message : '<strong>Your email preferences for '+this.notifications[index].openaireName+' have been successfully changed<strong>',
status : 'success',
timeout : 3000,
pos : 'top-center'
});*/
this.savedMessage = "Notification settings for claims saved!";
},
err => {
//console.log(err);
this.handleError("Error saving user email preferences: " + JSON.stringify(this.notifications[index]), err);
this.status = this.errorCodes.NOT_SAVED;
}
);
} else {
/*UIkit.notification({
message : '<strong>No changes selected for '+this.notifications[index].openaireName+' email preferences<strong>',
status : 'primary',
timeout : 3000,
pos : 'top-center'
});*/
this.savedMessage = "Notification settings for claims saved!";
}
if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
}
});
} else {
if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe(
data => {
this.initialNotifications[index] = JSON.parse(JSON.stringify( this.notifications[index] ));
this.status = this.errorCodes.DONE;
/*UIkit.notification({
message : '<strong>Your email preferences for '+this.notifications[index].openaireName+' have been successfully changed<strong>',
status : 'success',
timeout : 3000,
pos : 'top-center'
});*/
this.savedMessage = "Notification settings for claims saved!";
},
err => {
//console.log(err);
this.handleError("Error saving user email preferences: "+JSON.stringify(this.notifications[index]), err);
this.status = this.errorCodes.NOT_SAVED;
}
);
}
else {
/*UIkit.notification({
message : '<strong>No changes selected for '+this.notifications[index].openaireName+' email preferences<strong>',
status : 'primary',
timeout : 3000,
pos : 'top-center'
});*/
this.savedMessage = "Notification settings for claims saved!";
}
}
}
}
restoreNotification(index: number) {
this.userManagementService.isLoggedIn(this.properties.userInfoUrl).subscribe(isLoggedIn => {
if (!isLoggedIn) {
//this.userValidMessage = "User session has expired. Please login again.";
if (this.showSaveResetButtons) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
}
} else {
if (this.notifications.length > 0 && this.initialNotifications.length > 0) {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
this.notifications[index] = JSON.parse(JSON.stringify(this.initialNotifications[index]));
this.status = this.errorCodes.DONE;
this.prefsChanged[index] = false;
}
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
if(this.showSaveResetButtons) {
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
}
});
} else {
if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
this.status = this.errorCodes.LOADING;
this.savedMessage = "";
this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] ));
this.status = this.errorCodes.DONE;
this.prefsChanged[index] = false;
}
}
}
/*
prefsChanged(index: number) : boolean {
if(this.notifications.length > 0 && this.initialNotifications.length > 0) {
@ -259,17 +225,17 @@ export class MailPrefsComponent {
}
*/
ngOnDestroy() {
if (this.sub) {
if(this.sub) {
this.sub.unsubscribe();
}
}
handleErrors(err) {
handleErrors(err){
//this.showErrorMessage = true;
//try{
var code = "";
if (!err.status) {
var error = err.json();
if(!err.status) {
var error = err.json();
code = error.code;
} else {
code = err.status;
@ -278,7 +244,7 @@ export class MailPrefsComponent {
}
private handleError(message: string, error) {
console.error("User mail notification preferences Page (for claims): " + message, error);
console.error("User mail notification preferences Page (for claims): "+message, error);
}

View File

@ -1,47 +1,31 @@
import {Injectable} from '@angular/core';
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Route,
CanLoad,
UrlSegment
} from '@angular/router';
import {Observable} from 'rxjs';
import { Injectable } from '@angular/core';
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {Session} from './utils/helper.class';
import {LoginErrorCodes} from './utils/guardHelper.class';
import {filter, map, mergeMap} from "rxjs/operators";
import {CommunityService} from "../connect/community/community.service";
import {UserManagementService} from "../services/user-management.service";
import {EnvironmentSpecificService} from "../utils/properties/environment-specific.service";
@Injectable()
export class LoginGuard implements CanActivate {
export class LoginGuard implements CanActivate, CanLoad {
constructor(private router: Router,
private userManagementService: UserManagementService,
private propertiesService: EnvironmentSpecificService) {
constructor(private router: Router) {
}
check(path: string): Observable<boolean> |boolean {
const loggedIn = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return this.userManagementService.isLoggedIn(properties['userInfoUrl']).pipe(map( isLoggedIn => {
return isLoggedIn;
}));
}));
loggedIn.pipe(filter( isLoggedIn => !isLoggedIn)).subscribe( () => {
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': LoginErrorCodes.NOT_LOGIN,
'redirectUrl': path
}
});
});
check(path: string): boolean {
let loggedIn = false;
if (Session.isLoggedIn()) {
loggedIn = true;
}
if (!loggedIn) {
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
}
return loggedIn;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.check(state.url);
}
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
return this.check('/' + route.path);
}
}

View File

@ -1,137 +1,136 @@
import {Component, Input} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {Component, Input} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Title, Meta} from '@angular/platform-browser';
import {User,Session} from './utils/helper.class';
import {RouterHelper} from '../utils/routerHelper.class';
import {User, Session} from './utils/helper.class';
import {RouterHelper} from '../utils/routerHelper.class';
import {EnvProperties} from '../utils/properties/env-properties';
import {EnvProperties} from '../utils/properties/env-properties';
import {UserManagementService} from "../services/user-management.service";
@Component({
selector: 'user',
templateUrl: 'user.component.html'
})
selector: 'user',
templateUrl: 'user.component.html'
})
export class UserComponent {
public user: User;
public loggedIn: boolean = false;
public server: boolean = true;
public errorMessage: string = "";
public password: string = "";
private sub:any;
private sublogin:any;
public errorCode: string = "";
public redirectUrl: string = "";
public routerHelper:RouterHelper = new RouterHelper();
public loginUrl;
properties:EnvProperties;
@Input() mainComponent = true;
public user: User;
public loggedIn: boolean = false;
public server: boolean = true;
public errorMessage: string = "";
public password: string = "";
private sub: any;
private sublogin: any;
public errorCode: string = "";
public redirectUrl: string = "";
public routerHelper: RouterHelper = new RouterHelper();
public loginUrl;
properties: EnvProperties;
@Input() mainComponent = true;
constructor( private router: Router,
private route: ActivatedRoute,
private _meta: Meta,
private _title: Title,
private userManagementsService: UserManagementService) {
constructor(private router: Router,
private route: ActivatedRoute,
private _meta: Meta,
private _title: Title,
private userManagementsService: UserManagementService) {
var title = "OpenAIRE | Login";
this._title.setTitle(title);
}
var title = "OpenAIRE | Login";
this._title.setTitle(title);
}
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.loginUrl = this.properties.loginUrl;
ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.loginUrl = this.properties.loginUrl;
});
if( typeof document !== 'undefined') {
this.server = false;
}
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loggedIn = !!this.user;
});
if (typeof document !== 'undefined') {
this.server = false;
}
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.loggedIn = !!this.user;
this.errorMessage = "";
this.sub = this.route.queryParams.subscribe(params => {
this.sub = this.route.queryParams.subscribe(params => {
this.errorCode = params["errorCode"];
this.redirectUrl = params["redirectUrl"];
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loggedIn = !!this.user;
});
this.errorMessage = "";
if(this.loggedIn && this.errorCode == '1'){
if (this.loggedIn && this.errorCode == '1') {
this.redirect();
}
});
});
}
ngOnDestroy() {
this.sub.unsubscribe();
if (this.sublogin) {
this.sublogin.unsubscribe();
}
ngOnDestroy(){
this.sub.unsubscribe();
if(this.sublogin){
this.sublogin.unsubscribe();
}
redirect() {
if (this.redirectUrl && this.redirectUrl != "") {
this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl;
var queryParams = "";
var paramsArray = [];
var valuesArray = [];
if (this.redirectUrl.indexOf('?') != -1) {
baseUrl = this.redirectUrl.split('?')[0];
queryParams = this.redirectUrl.split('?')[1];
}
if (queryParams != "") {
var queryParamsArray = queryParams.split('&');
for (var i = 0; i < queryParamsArray.length; i++) {
paramsArray.push(queryParamsArray[i].split("=")[0]);
valuesArray.push(queryParamsArray[i].split("=")[1]);
}
this.router.navigate([baseUrl], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
} else {
this.router.navigate([baseUrl]);
}
}
// else{
// this.router.navigate(['/']);
// }
}
redirect(){
if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != ""){
this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl;
var queryParams = "";
var paramsArray =[];
var valuesArray =[];
if(this.redirectUrl.indexOf('?') != -1){
baseUrl = this.redirectUrl.split('?')[0];
queryParams = this.redirectUrl.split('?')[1];
logIn() {
if (this.redirectUrl && this.redirectUrl != "") {
this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl;
var queryParams = "";
if (this.redirectUrl.indexOf('?') != -1) {
var splits = this.redirectUrl.split('?');
if (splits.length > 0) {
baseUrl = splits[0];
}
if(queryParams != ""){
var queryParamsArray = queryParams.split('&');
for(var i = 0; i < queryParamsArray.length; i++){
paramsArray.push(queryParamsArray[i].split("=")[0]);
valuesArray.push(queryParamsArray[i].split("=")[1]);
}
this.router.navigate([baseUrl], { queryParams: this.routerHelper.createQueryParams(paramsArray,valuesArray)});
}else{
this.router.navigate([baseUrl]);
if (splits.length > 1) {
queryParams = splits[1];
}
}
// else{
// this.router.navigate(['/']);
// }
Session.setReloadUrl(location.protocol + "//" + location.host, baseUrl, queryParams);
}
logIn(){
if(this.redirectUrl && this.redirectUrl != null && this.redirectUrl != ""){
this.redirectUrl = decodeURIComponent(this.redirectUrl);
var baseUrl = this.redirectUrl;
var queryParams = "";
if(this.redirectUrl.indexOf('?') != -1){
var splits =this.redirectUrl.split('?');
if(splits.length>0){
baseUrl = splits[0];
}
if(splits.length >1){
queryParams = splits[1];
}
}
Session.setReloadUrl(location.protocol +"//"+location.host, baseUrl, queryParams);
}
window.location.href = this.properties.loginUrl;
}
window.location.href = this.properties.loginUrl;
}
getTheRolesFormatted(roles:string[]){
let formattedRoles = [];
for(let role of roles ){
let formattedRole = role.split("urn:geant:openaire.eu:group:")[1];
formattedRole=formattedRole.split("#aai.openaire.eu")[0]
formattedRole = formattedRole.replace("+"," ");
formattedRole = formattedRole.split("+").join(" ");
formattedRoles.push(formattedRole);
}
return formattedRoles.join(", ");
}
isUserManager(){
return Session.isUserManager(this.user);
getTheRolesFormatted(roles: string[]) {
let formattedRoles = [];
for (let role of roles) {
let formattedRole = role.split("urn:geant:openaire.eu:group:")[1];
formattedRole = formattedRole.split("#aai.openaire.eu")[0]
formattedRole = formattedRole.replace("+", " ");
formattedRole = formattedRole.split("+").join(" ");
formattedRoles.push(formattedRole);
}
return formattedRoles.join(", ");
}
isUserManager() {
return Session.isUserManager(this.user);
}
}