[Admin]: Change check of user info from user management.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@57073 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-09-13 09:39:18 +00:00
parent 07b827f6e9
commit 0b46787551
9 changed files with 637 additions and 600 deletions

View File

@ -1,10 +1,10 @@
<navbar *ngIf= "properties && showMenu" portal="connect-admin" logoPath="assets/imgs/" [onlyTop]=false [userMenu]=true <navbar *ngIf= "properties && showMenu && checkLogin" portal="connect-admin" logoPath="assets/imgs/" [onlyTop]=false [userMenu]=true
[homeurl] = false [userMenuItems]=userMenuItems [menuItems]=menuItems [properties]=properties [homeurl] = false [user]="user" [userMenuItems]=userMenuItems [menuItems]=menuItems [properties]=properties
[community]=community class="adminMenu"></navbar> [community]=community class="adminMenu"></navbar>
<div id="wrapper" class="uk-section uk-padding-remove"> <div id="wrapper" class="uk-section uk-padding-remove">
<div class="uk-grid-collapse" uk-height-viewport="expand: true" uk-grid> <div class="uk-grid-collapse" uk-height-viewport="expand: true" uk-grid>
<sidebar *ngIf="showSidebar" [menuItems]="sideMenuItems" class="uk-width-1-5 uk-light sidebar "></sidebar> <sidebar *ngIf="showSidebar && checkLogin" [menuItems]="sideMenuItems" class="uk-width-1-5 uk-light sidebar "></sidebar>
<div class="uk-width-expand uk-overflow-auto" [ngClass]="(!wellcome)?'uk-container uk-container-large uk-padding':''" <div class="uk-width-expand uk-overflow-auto" [ngClass]="(!wellcome)?'uk-container uk-container-large uk-padding':''"
[ngStyle]="{height: (!wellcome)?'85vh':'90vh'}"> [ngStyle]="{height: (!wellcome)?'85vh':'90vh'}">

View File

@ -4,12 +4,13 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu'; import {MenuItem, RootMenuItem, SideMenuItem} from './openaireLibrary/sharedComponents/menu';
import {ActivatedRoute, NavigationStart, Router, RoutesRecognized} from '@angular/router'; import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from './openaireLibrary/connect/communities/communities.service'; import {CommunitiesService} from './openaireLibrary/connect/communities/communities.service';
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {Session} from './openaireLibrary/login/utils/helper.class'; import {Session, User} from './openaireLibrary/login/utils/helper.class';
import {HelperFunctions} from './openaireLibrary/utils/HelperFunctions.class'; import {HelperFunctions} from './openaireLibrary/utils/HelperFunctions.class';
import {UserManagementService} from './openaireLibrary/services/user-management.service';
declare var UIkit: any; declare var UIkit: any;
@ -18,7 +19,7 @@ declare var UIkit: any;
templateUrl: './app.component.html', templateUrl: './app.component.html',
}) })
export class AppComponent implements OnInit{ export class AppComponent implements OnInit {
title = 'Metadata Registry Service'; title = 'Metadata Registry Service';
userMenuItems: MenuItem[] = []; userMenuItems: MenuItem[] = [];
@ -33,16 +34,19 @@ export class AppComponent implements OnInit{
isPortalAdministrator = false; isPortalAdministrator = false;
showSidebar: boolean; showSidebar: boolean;
wellcome = false; wellcome = false;
showMenu:boolean = false; showMenu: boolean = false;
user: User;
checkLogin: boolean = false;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private propertiesService: EnvironmentSpecificService, private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService, private _communitiesService: CommunitiesService,
private router: Router) { private router: Router,
private userManagementService: UserManagementService) {
this.router.events.forEach((event) => { this.router.events.forEach((event) => {
if (event instanceof NavigationStart) { if (event instanceof NavigationStart) {
HelperFunctions.scroll(); HelperFunctions.scroll();
if(event.url === '/') { if (event.url === '/') {
this.wellcome = true; this.wellcome = true;
} else { } else {
this.wellcome = false; this.wellcome = false;
@ -60,15 +64,18 @@ export class AppComponent implements OnInit{
this.logOutUrl = this.properties.logoutUrl; this.logOutUrl = this.properties.logoutUrl;
this.showSidebar = false; this.showSidebar = false;
this.showMenu = false; this.showMenu = false;
if (Session.getUser()) { this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
localStorage.setItem('user_id', Session.getUser().id); this.user = user;
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL); this.checkLogin = true;
localStorage.setItem('isCommunityManager', Session.isCommunityCurator() + ''); if (this.user) {
localStorage.setItem('user_id', this.user.id);
localStorage.setItem('mining_backend_address', this.properties.miningBackendURL);
localStorage.setItem('isCommunityManager', Session.isCommunityCurator(this.user) + '');
this.isPortalAdministrator = Session.isPortalAdministrator(); this.isPortalAdministrator = Session.isPortalAdministrator(this.user);
} }
this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities'); this._communitiesService.updateCommunities(this.properties, this.properties.communityAPI + 'communities');
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe(params => {
this.communityId = (params['communityId']) ? params['communityId'] : ''; this.communityId = (params['communityId']) ? params['communityId'] : '';
this.communityType = null; this.communityType = null;
@ -77,7 +84,7 @@ export class AppComponent implements OnInit{
this._communitiesService.getCommunitiesState().subscribe( this._communitiesService.getCommunitiesState().subscribe(
communities => { communities => {
// this.community = community; // this.community = community;
if(!communities || communities.length === 0) { if (!communities || communities.length === 0) {
return; return;
} }
this.userMenuItems = []; this.userMenuItems = [];
@ -85,11 +92,11 @@ export class AppComponent implements OnInit{
let index_managerOfCommunity = null; let index_managerOfCommunity = null;
for (let i = 0; i < communities.length; i++) { for (let i = 0; i < communities.length; i++) {
const com = communities[i]; const com = communities[i];
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) { if (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user)) {
this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId})); this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
} else { } else {
for (const manager of com.managers) { for (const manager of com.managers) {
if (manager == Session.getUserEmail()) { if (this.user && manager == this.user.email) {
countCommunities++; countCommunities++;
index_managerOfCommunity = i; index_managerOfCommunity = i;
this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId})); this.userMenuItems.push(new MenuItem('manage' + com.communityId, 'Manage ' + ((com.shortTitle) ? com.shortTitle : com.title), '', '/dashboard', false, [], [], {communityId: com.communityId}));
@ -130,7 +137,7 @@ export class AppComponent implements OnInit{
if (this.communityId) { if (this.communityId) {
this.userMenuItems.push(new MenuItem('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId})); this.userMenuItems.push(new MenuItem('manage-user-notifications', 'Manage notification settings', '', '/manage-user-notifications', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem('personal', 'Manage Personal Info', '', '/personal', false, [], [], {communityId: this.communityId})); this.userMenuItems.push(new MenuItem('personal', 'Manage Personal Info', '', '/personal', false, [], [], {communityId: this.communityId}));
this.userMenuItems.push(new MenuItem("","Support","https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611","",false,[],[],{})) this.userMenuItems.push(new MenuItem('', 'Support', 'https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611', '', false, [], [], {}));
} }
this.showMenu = true; this.showMenu = true;
this.buildSideBar(); this.buildSideBar();
@ -146,6 +153,7 @@ export class AppComponent implements OnInit{
} }
} }
); );
});
}); });
}); });
} }
@ -185,19 +193,19 @@ export class AppComponent implements OnInit{
} }
); );
this.sideMenuItems.push(adminTools); this.sideMenuItems.push(adminTools);
this.sideMenuItems.push( { this.sideMenuItems.push({
rootItem: new MenuItem('communities', 'Manage Communities', '/', rootItem: new MenuItem('communities', 'Manage Communities', '/',
'/', false, [], [], null), '/', false, [], [], null),
items: [], items: [],
ukIcon: 'cog' ukIcon: 'cog'
}); });
this.sideMenuItems.push( { this.sideMenuItems.push({
rootItem: new MenuItem('communities', 'Explore', '', rootItem: new MenuItem('communities', 'Explore', '',
'/dashboard', false, [], [], {communityId: 'openaire'}), '/dashboard', false, [], [], {communityId: 'openaire'}),
items: [], items: [],
ukIcon: 'cog' ukIcon: 'cog'
}); });
this.sideMenuItems.push( { this.sideMenuItems.push({
rootItem: new MenuItem('communities', 'Connect', '', rootItem: new MenuItem('communities', 'Connect', '',
'/dashboard', false, [], [], {communityId: 'connect'}), '/dashboard', false, [], [], {communityId: 'connect'}),
items: [], items: [],
@ -362,11 +370,11 @@ export class AppComponent implements OnInit{
'/manage-subscribers', false, [], [], {communityId: this.communityId}), '/manage-subscribers', false, [], [], {communityId: this.communityId}),
items: [] items: []
}); });
users.items.push( { users.items.push({
rootItem: new MenuItem('personalInfo', 'Personal Info', '/personal', rootItem: new MenuItem('personalInfo', 'Personal Info', '/personal',
'/personal', false, [], [], {communityId: this.communityId}), '/personal', false, [], [], {communityId: this.communityId}),
items: [] items: []
}) });
users.items.push({ users.items.push({
rootItem: new MenuItem('notifications', 'Notification settings', '/manage-user-notifications', rootItem: new MenuItem('notifications', 'Notification settings', '/manage-user-notifications',
'/manage-user-notifications', false, [], [], {communityId: this.communityId}), '/manage-user-notifications', false, [], [], {communityId: this.communityId}),

View File

@ -44,8 +44,7 @@ export class AffiliationsComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private _router: Router, private _router: Router,
private affiliationService: AffiliationService, private affiliationService: AffiliationService,
private _helpContentService: HelpContentService, private _helpContentService: HelpContentService) {
private utilitiesService: UtilitiesService) {
} }

View File

@ -3,7 +3,7 @@ import {ActivatedRoute, Router} from '@angular/router';
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {CuratorService} from '../../openaireLibrary/connect/curators/curator.service'; import {CuratorService} from '../../openaireLibrary/connect/curators/curator.service';
import {Curator} from '../../openaireLibrary/utils/entities/CuratorInfo'; import {Curator} from '../../openaireLibrary/utils/entities/CuratorInfo';
@ -11,6 +11,7 @@ import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class
import {UtilitiesService} from '../../openaireLibrary/services/utilities.service'; import {UtilitiesService} from '../../openaireLibrary/services/utilities.service';
import {HelpContentService} from '../../services/help-content.service'; import {HelpContentService} from '../../services/help-content.service';
import {AlertModal} from '../../openaireLibrary/utils/modal/alert'; import {AlertModal} from '../../openaireLibrary/utils/modal/alert';
import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
@Component({ @Component({
selector: 'curator', selector: 'curator',
@ -34,9 +35,10 @@ export class CuratorComponent implements OnInit {
public curator: Curator = null; public curator: Curator = null;
public photo: any = null; public photo: any = null;
public properties: EnvProperties = null; public properties: EnvProperties = null;
public user: User;
private file: File = null; private file: File = null;
private maxsize: number = 200*1024; private maxsize: number = 200 * 1024;
public enabled = true; public enabled = true;
private deletePhoto = false; private deletePhoto = false;
@ -47,7 +49,8 @@ export class CuratorComponent implements OnInit {
private _router: Router, private _router: Router,
private curatorService: CuratorService, private curatorService: CuratorService,
private utilitiesService: UtilitiesService, private utilitiesService: UtilitiesService,
private helpContentService: HelpContentService) { private helpContentService: HelpContentService,
private userManagementService: UserManagementService) {
} }
@ -63,39 +66,42 @@ export class CuratorComponent implements OnInit {
this.communityId = params['communityId']; this.communityId = params['communityId'];
this.showLoading = true; this.showLoading = true;
this.updateErrorMessage = ''; this.updateErrorMessage = '';
this.curatorId = Session.getUser().id; this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.curatorService.getCurator(this.properties, this.user = user;
this.properties.adminToolsAPIURL + 'curator/' + this.curatorId).subscribe( this.curatorId = this.user.id;
curator => { this.curatorService.getCurator(this.properties,
if (curator && Object.keys(curator).length > 0) { this.properties.adminToolsAPIURL + 'curator/' + this.curatorId).subscribe(
this.curator = curator; curator => {
this.curator.email = Session.getUserEmail(); if (curator && Object.keys(curator).length > 0) {
if (this.curator.photo && this.curator.photo !== '') { this.curator = curator;
this.photo = this.properties.utilsService + '/download/' + this.curator.photo; this.curator.email = this.user.email;
if (this.curator.photo && this.curator.photo !== '') {
this.photo = this.properties.utilsService + '/download/' + this.curator.photo;
} else {
this.photo = 'assets/common-assets/curator-default.png';
}
this.curatorsPageStatus();
this.showLoading = false;
HelperFunctions.scroll();
} else { } else {
this.newCurator = true;
this.curator = new Curator();
this.curator._id = this.curatorId;
this.curator.email = this.user.email;
this.curator.name = this.user.fullname;
this.curator.affiliations = [];
this.curator.bio = '';
this.curator.photo = null;
this.photo = 'assets/common-assets/curator-default.png'; this.photo = 'assets/common-assets/curator-default.png';
this.showLoading = false;
HelperFunctions.scroll();
} }
this.curatorsPageStatus(); },
this.showLoading = false; error => {
HelperFunctions.scroll();
} else {
this.newCurator = true;
this.curator = new Curator();
this.curator._id = this.curatorId;
this.curator.email = Session.getUserEmail();
this.curator.name = Session.getUserFullName();
this.curator.affiliations = [];
this.curator.bio = '';
this.curator.photo = null;
this.photo = 'assets/common-assets/curator-default.png';
this.showLoading = false;
HelperFunctions.scroll();
} }
}, );
error => { });
} });
);
})
} }
}); });
@ -116,7 +122,7 @@ export class CuratorComponent implements OnInit {
curator => { curator => {
if (curator) { if (curator) {
this.curator = curator; this.curator = curator;
this.curator.email = Session.getUserEmail(); this.curator.email = this.user.email;
if (this.curator.photo && this.curator.photo !== '') { if (this.curator.photo && this.curator.photo !== '') {
this.photo = this.properties.utilsService + '/download/' + this.curator.photo; this.photo = this.properties.utilsService + '/download/' + this.curator.photo;
} else { } else {
@ -129,8 +135,8 @@ export class CuratorComponent implements OnInit {
this.newCurator = true; this.newCurator = true;
this.curator = new Curator(); this.curator = new Curator();
this.curator._id = this.curatorId; this.curator._id = this.curatorId;
this.curator.email = Session.getUserEmail(); this.curator.email = this.user.email
this.curator.name = Session.getUserFullName(); this.curator.name = this.user.fullname;
this.curator.affiliations = []; this.curator.affiliations = [];
this.curator.bio = ''; this.curator.bio = '';
this.curator.photo = null; this.curator.photo = null;
@ -149,16 +155,16 @@ export class CuratorComponent implements OnInit {
private curatorsPageStatus() { private curatorsPageStatus() {
this.helpContentService.getCommunityFull(this.communityId, this.properties.adminToolsAPIURL).subscribe((community) => { this.helpContentService.getCommunityFull(this.communityId, this.properties.adminToolsAPIURL).subscribe((community) => {
for(let page of community.pages) { for (let page of community.pages) {
if(page['route'] === '/curators') { if (page['route'] === '/curators') {
this.curatorsEnabled = page['isEnabled']; this.curatorsEnabled = page['isEnabled'];
console.log(this.curatorsEnabled) console.log(this.curatorsEnabled);
return; return;
} }
} }
this.curatorsEnabled = false; this.curatorsEnabled = false;
console.log(this.curatorsEnabled) console.log(this.curatorsEnabled);
}) });
} }
private change() { private change() {
@ -199,7 +205,7 @@ export class CuratorComponent implements OnInit {
this.handleUpdateError('You must choose a file with type: image/png or image/jpeg!', null); this.handleUpdateError('You must choose a file with type: image/png or image/jpeg!', null);
this.file = null; this.file = null;
} else if (this.file.size > this.maxsize) { } else if (this.file.size > this.maxsize) {
this.handleUpdateError("File exceeds size's limit! Maximum resolution is 256x256 pixels.", null); this.handleUpdateError('File exceeds size\'s limit! Maximum resolution is 256x256 pixels.', null);
this.file = null; this.file = null;
} else { } else {
this.updateErrorMessage = ''; this.updateErrorMessage = '';
@ -247,7 +253,7 @@ export class CuratorComponent implements OnInit {
} }
); );
} else { } else {
if(this.deletePhoto) { if (this.deletePhoto) {
this.utilitiesService.deletePhoto(this.properties.utilsService + '/delete/' + this.curator.photo).subscribe(); this.utilitiesService.deletePhoto(this.properties.utilsService + '/delete/' + this.curator.photo).subscribe();
this.curator.photo = ''; this.curator.photo = '';
} }
@ -262,9 +268,9 @@ export class CuratorComponent implements OnInit {
this.handleUpdateError('An error has occurred. Try again later!', error); this.handleUpdateError('An error has occurred. Try again later!', error);
this.resetChange(); this.resetChange();
}); });
}
} }
} }
}
} }
onNameChange() { onNameChange() {
@ -285,7 +291,7 @@ export class CuratorComponent implements OnInit {
privacy() { privacy() {
this.privacyStatement.cancelButton = false; this.privacyStatement.cancelButton = false;
this.privacyStatement.okButtonText = 'Close'; this.privacyStatement.okButtonText = 'Close';
this.privacyStatement.alertTitle = 'Privacy policy statement' this.privacyStatement.alertTitle = 'Privacy policy statement';
this.privacyStatement.open(); this.privacyStatement.open();
} }
} }

View File

@ -9,6 +9,7 @@ import { EnvProperties } from '../../openaireLibrary/utils/properties/env-proper
import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {Session} from '../../openaireLibrary/login/utils/helper.class';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class"; import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
@Component({ @Component({
selector: 'entities', selector: 'entities',
@ -55,6 +56,11 @@ export class EntitiesComponent implements OnInit {
public modalErrorMessage = ''; public modalErrorMessage = '';
public isPortalAdministrator = null; public isPortalAdministrator = null;
constructor(private element: ElementRef, private route: ActivatedRoute,
private _router: Router,
private _helpContentService: HelpContentService,
private userManagementService: UserManagementService) {}
ngOnInit() { ngOnInit() {
this.formGroup = this.formComponent.form; this.formGroup = this.formComponent.form;
this.route.data this.route.data
@ -63,18 +69,16 @@ export class EntitiesComponent implements OnInit {
this.route.queryParams.subscribe(params => { this.route.queryParams.subscribe(params => {
HelperFunctions.scroll(); HelperFunctions.scroll();
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.selectedCommunityPid = params['communityId']; this.selectedCommunityPid = params['communityId'];
this.applyCommunityFilter(this.selectedCommunityPid); this.applyCommunityFilter(this.selectedCommunityPid);
this.isPortalAdministrator = Session.isPortalAdministrator() && !this.selectedCommunityPid; this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
});
}); });
}); });
} }
constructor(private element: ElementRef, private route: ActivatedRoute,
private _router: Router,
private _helpContentService: HelpContentService) {}
getEntities(community_pid: string) { getEntities(community_pid: string) {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], this._router.navigate(['/user-info'],

View File

@ -1,367 +1,372 @@
/** /**
* Created by stefania on 7/13/17. * Created by stefania on 7/13/17.
*/ */
import { Component, ViewChild, OnInit, ElementRef } from '@angular/core'; import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { ActivatedRoute, Router } from "@angular/router"; import {ActivatedRoute, Router} from '@angular/router';
import { HelpContentService } from "../../services/help-content.service"; import {HelpContentService} from '../../services/help-content.service';
import { FormGroup } from "@angular/forms"; import {FormGroup} from '@angular/forms';
import { PageFormComponent } from "./page-form.component"; import {PageFormComponent} from './page-form.component';
import { CheckPage, Page } from "../../domain/page"; import {CheckPage, Page} from '../../domain/page';
import { Community } from "../../domain/community"; import {Community} from '../../domain/community';
import { Entity } from "../../domain/entity"; import {Entity} from '../../domain/entity';
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {Session} from '../../openaireLibrary/login/utils/helper.class';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class"; import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class';
import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
@Component({ @Component({
selector: 'pages', selector: 'pages',
templateUrl: './pages.component.html', templateUrl: './pages.component.html',
}) })
export class PagesComponent implements OnInit { export class PagesComponent implements OnInit {
@ViewChild('AlertModalSavePage') alertModalSavePage; @ViewChild('AlertModalSavePage') alertModalSavePage;
@ViewChild('AlertModalUpdatePage') alertModalUpdatePage; @ViewChild('AlertModalUpdatePage') alertModalUpdatePage;
@ViewChild('AlertModalDeletePages') alertModalDeletePages; @ViewChild('AlertModalDeletePages') alertModalDeletePages;
private selectedPages: string[] = []; private selectedPages: string[] = [];
@ViewChild(PageFormComponent) @ViewChild(PageFormComponent)
public formComponent : PageFormComponent; public formComponent: PageFormComponent;
public checkboxes : CheckPage[] = []; public checkboxes: CheckPage[] = [];
public pages : Page[] = []; public pages: Page[] = [];
public pageWithDivIds: string[] = []; public pageWithDivIds: string[] = [];
//public errorMessage: string; //public errorMessage: string;
public formGroup : FormGroup; public formGroup: FormGroup;
private searchText : RegExp = new RegExp(''); private searchText: RegExp = new RegExp('');
public keyword: string = ""; public keyword: string = '';
public communities: Community[] = []; public communities: Community[] = [];
public selectedCommunityPid: string; public selectedCommunityPid: string;
public pagesType: string; public pagesType: string;
public properties:EnvProperties = null; public properties: EnvProperties = null;
public showLoading: boolean = true; public showLoading: boolean = true;
public errorMessage: string = ''; public errorMessage: string = '';
public updateErrorMessage: string = ''; public updateErrorMessage: string = '';
public modalErrorMessage: string = ''; public modalErrorMessage: string = '';
public isPortalAdministrator = null; public isPortalAdministrator = null;
ngOnInit() { constructor(private element: ElementRef, private route: ActivatedRoute,
this.formGroup = this.formComponent.form; private _router: Router, private _helpContentService: HelpContentService,
this.route.data private userManagementService: UserManagementService) {
.subscribe((data: { envSpecific: EnvProperties }) => { }
this.properties = data.envSpecific;
this.route.queryParams.subscribe(params => { ngOnInit() {
HelperFunctions.scroll(); this.formGroup = this.formComponent.form;
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.pagesType = ""; this.route.queryParams.subscribe(params => {
if(params['type']) { HelperFunctions.scroll();
this.pagesType = params['type'];
}
this.keyword = ""; this.pagesType = '';
if (params['type']) {
this.pagesType = params['type'];
}
this.selectedCommunityPid = params['communityId']; this.keyword = '';
this.applyCommunityFilter(this.selectedCommunityPid); this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.isPortalAdministrator = Session.isPortalAdministrator() && !this.selectedCommunityPid; this.selectedCommunityPid = params['communityId'];
this.applyCommunityFilter(this.selectedCommunityPid);
//this.getCommunities(); this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.selectedCommunityPid;
}); });
//this.getCommunities();
}); });
} });
}
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router, private _helpContentService: HelpContentService) {} getPages(community_pid: string) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this.errorMessage = '';
getPages(community_pid: string) { this.pageWithDivIds = [];
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.showLoading = true;
this.updateErrorMessage = "";
this.errorMessage = "";
this.pageWithDivIds = []; let parameters = '';
if (this.pagesType) {
let parameters = ""; parameters = '?page_type=' + this.pagesType;
if(this.pagesType) {
parameters = "?page_type="+this.pagesType;
}
if(community_pid) {
this._helpContentService.getCommunityPages(community_pid, parameters, this.properties.adminToolsAPIURL).subscribe(
pages => {
this.pagesReturned(pages);
//if(!this.pagesType || this.pagesType == "link") {
this.getPagesWithDivIds(community_pid);
//} else {
//this.showLoading = false;
//}
},
error => this.handleError('System error retrieving pages', error)
);
} else {
this._helpContentService.getPagesFull(this.properties.adminToolsAPIURL, null).subscribe(
pages => {
this.pagesReturned(pages);
this.showLoading = false;
},
error => this.handleError('System error retrieving pages', error)
);
}
} }
} if (community_pid) {
this._helpContentService.getCommunityPages(community_pid, parameters, this.properties.adminToolsAPIURL).subscribe(
getPagesWithDivIds(community_pid: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this._helpContentService.getPagesWithDivIds(community_pid, this.properties.adminToolsAPIURL).subscribe(
pages => { pages => {
this.pageWithDivIds = pages; this.pagesReturned(pages);
this.showLoading = false; //if(!this.pagesType || this.pagesType == "link") {
}, this.getPagesWithDivIds(community_pid);
error => this.handleError('System error retrieving information about pages\' classes', error)); //} else {
//this.showLoading = false;
//}
},
error => this.handleError('System error retrieving pages', error)
);
} else {
this._helpContentService.getPagesFull(this.properties.adminToolsAPIURL, null).subscribe(
pages => {
this.pagesReturned(pages);
this.showLoading = false;
},
error => this.handleError('System error retrieving pages', error)
);
} }
} }
}
pagesReturned(pages: Page[]) { getPagesWithDivIds(community_pid: string) {
this.pages = pages; if (!Session.isLoggedIn()) {
this.checkboxes = []; this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
if(pages) { this._helpContentService.getPagesWithDivIds(community_pid, this.properties.adminToolsAPIURL).subscribe(
pages.forEach(_ => { pages => {
this.checkboxes.push(<CheckPage>{page : _, checked : false}); this.pageWithDivIds = pages;
}); this.showLoading = false;
}
}
/*
getCommunities() {
this._helpContentService.getCommunities(this.properties.adminToolsAPIURL).subscribe(
communities => {
this.communities = communities;
this.selectedCommunityPid = this.communities[0].pid;
this.getPages(this.selectedCommunityPid);
this.getPagesWithDivIds(this.selectedCommunityPid);
}, },
error => this.handleError('System error retrieving communities', error)); error => this.handleError('System error retrieving information about pages\' classes', error));
} }
*/ }
public toggleCheckBoxes(event) { pagesReturned(pages: Page[]) {
this.checkboxes.forEach(_ => _.checked = event.target.checked); this.pages = pages;
this.checkboxes = [];
if (pages) {
pages.forEach(_ => {
this.checkboxes.push(<CheckPage>{page: _, checked: false});
});
}
}
/*
getCommunities() {
this._helpContentService.getCommunities(this.properties.adminToolsAPIURL).subscribe(
communities => {
this.communities = communities;
this.selectedCommunityPid = this.communities[0].pid;
this.getPages(this.selectedCommunityPid);
this.getPagesWithDivIds(this.selectedCommunityPid);
},
error => this.handleError('System error retrieving communities', error));
}
*/
public toggleCheckBoxes(event) {
this.checkboxes.forEach(_ => _.checked = event.target.checked);
}
public applyCheck(flag: boolean) {
this.checkboxes.forEach(_ => _.checked = flag);
}
public getSelectedPages(): string[] {
return this.checkboxes.filter(page => page.checked == true).map(checkedPage => checkedPage.page).map(res => res._id);
}
private deletePagesFromArray(ids: string[]): void {
for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.page._id == id);
this.checkboxes.splice(i, 1);
}
}
public confirmDeletePage(id: string) {
//this.deleteConfirmationModal.ids = [id];
//this.deleteConfirmationModal.showModal();
this.selectedPages = [id];
this.confirmModalOpen();
}
public confirmDeleteSelectedPages() {
//this.deleteConfirmationModal.ids = this.getSelectedPages();
//this.deleteConfirmationModal.showModal();
this.selectedPages = this.getSelectedPages();
this.confirmModalOpen();
}
private confirmModalOpen() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.alertModalDeletePages.cancelButton = true;
this.alertModalDeletePages.okButton = true;
this.alertModalDeletePages.alertTitle = 'Delete Confirmation';
this.alertModalDeletePages.message = 'Are you sure you want to delete the selected page(s)?';
this.alertModalDeletePages.okButtonText = 'Yes';
this.alertModalDeletePages.open();
}
}
public confirmedDeletePages(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.showLoading = true;
this.updateErrorMessage = '';
this._helpContentService.deletePages(this.selectedPages, this.properties.adminToolsAPIURL).subscribe(
_ => {
this.deletePagesFromArray(this.selectedPages);
this.showLoading = false;
},
error => this.handleUpdateError('System error deleting the selected pages', error)
);
}
}
public editPage(i: number) {
let page: Page = this.checkboxes[i].page;
this.formGroup.patchValue(page);
this.formComponent.setEntities(page.entities as Entity[]);
//console.info(this.formGroup.value);
//this.updateModal.showModal();
this.modalErrorMessage = '';
this.pagesModalOpen(this.alertModalUpdatePage, 'Update', 'Update Page');
}
public newPage() {
this.formComponent.reset();
this.modalErrorMessage = '';
this.pagesModalOpen(this.alertModalSavePage, 'Save', 'Add a new Page');
}
private pagesModalOpen(modal: any, title: string, yesBtn: string) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
modal.cancelButton = true;
modal.okButton = true;
modal.alertTitle = title;
modal.okButtonText = yesBtn;
modal.open();
}
}
public pageSaveConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
if (!this.formGroup.valid) {
this.pagesModalOpen(this.alertModalSavePage, 'Save', 'Add a new Page');
this.modalErrorMessage = 'Please fill in all required fields marked with *';
} else {
this.modalErrorMessage = '';
this._helpContentService.savePage(<Page>this.formGroup.value, this.properties.adminToolsAPIURL).subscribe(
page => {
this.pageSavedSuccessfully(page);
},
error => this.handleUpdateError('System error creating page', error)
);
}
}
}
public pageUpdateConfirmed(data: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
if (!this.formGroup.valid) {
this.pagesModalOpen(this.alertModalUpdatePage, 'Update', 'Update Page');
this.modalErrorMessage = 'Please fill in all required fields marked with *';
} else {
this._helpContentService.updatePage(<Page>this.formGroup.value, this.properties.adminToolsAPIURL).subscribe(
page => {
this.pageUpdatedSuccessfully(page);
},
error => this.handleUpdateError('System error updating page', error)
);
}
}
}
public pageSavedSuccessfully(page: Page) {
this.checkboxes.push(<CheckPage>{page: page, checked: false});
this.applyCheck(false);
}
public pageUpdatedSuccessfully(page: Page) {
this.checkboxes.find(checkItem => checkItem.page._id == page._id).page = page;
this.applyCheck(false);
}
public filterBySearch(text: string) {
this.searchText = new RegExp(text, 'i');
this.applyFilter();
}
public applyFilter() {
this.checkboxes = [];
this.pages.filter(item => this.filterPages(item)).forEach(
_ => this.checkboxes.push(<CheckPage>{page: _, checked: false})
);
}
public filterPages(page: Page): boolean {
let textFlag = this.searchText.toString() == '' || (page.route + ' ' + page.name).match(this.searchText) != null;
return textFlag;
}
handleError(message: string, error) {
// if(error == null) {
// this.formComponent.reset();
// } else {
this.errorMessage = message;// + ' (Server responded: ' + error + ')';
console.log('Server responded: ' + error);
//}
this.showLoading = false;
}
handleUpdateError(message: string, error) {
if (error == null) {
this.formComponent.reset();
} else {
this.updateErrorMessage = message;// + ' (Server responded: ' + error + ')';
console.log('Server responded: ' + error);
} }
public applyCheck(flag : boolean) { this.showLoading = false;
this.checkboxes.forEach(_ => _.checked = flag); }
}
public getSelectedPages() : string[] { // public filterByCommunity(event: any) {
return this.checkboxes.filter(page => page.checked == true).map(checkedPage => checkedPage.page).map(res => res._id); // this.selectedCommunityPid = event.target.value;
} // this.applyCommunityFilter(this.selectedCommunityPid);
// }
private deletePagesFromArray(ids : string[]) : void { public applyCommunityFilter(community_pid: string) {
for(let id of ids) { this.getPages(community_pid);
}
public togglePages(status: boolean, ids: string[]) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else {
this.updateErrorMessage = '';
this._helpContentService.togglePages(this.selectedCommunityPid, ids, status, this.properties.adminToolsAPIURL).subscribe(
() => {
for (let id of ids) {
let i = this.checkboxes.findIndex(_ => _.page._id == id); let i = this.checkboxes.findIndex(_ => _.page._id == id);
this.checkboxes.splice(i, 1); this.checkboxes[i].page.isEnabled = status;
} }
this.applyCheck(false);
},
error => this.handleUpdateError('System error changing the status of the selected page(s)', error)
);
} }
}
public confirmDeletePage(id : string) { public capitalizeFirstLetter(str: string) {
//this.deleteConfirmationModal.ids = [id]; return str.charAt(0).toUpperCase() + str.slice(1);
//this.deleteConfirmationModal.showModal(); }
this.selectedPages = [id];
this.confirmModalOpen();
}
public confirmDeleteSelectedPages() {
//this.deleteConfirmationModal.ids = this.getSelectedPages();
//this.deleteConfirmationModal.showModal();
this.selectedPages = this.getSelectedPages();
this.confirmModalOpen();
}
private confirmModalOpen() {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.alertModalDeletePages.cancelButton = true;
this.alertModalDeletePages.okButton = true;
this.alertModalDeletePages.alertTitle = "Delete Confirmation";
this.alertModalDeletePages.message = "Are you sure you want to delete the selected page(s)?";
this.alertModalDeletePages.okButtonText = "Yes";
this.alertModalDeletePages.open();
}
}
public confirmedDeletePages(data: any) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.showLoading = true;
this.updateErrorMessage = "";
this._helpContentService.deletePages(this.selectedPages, this.properties.adminToolsAPIURL).subscribe(
_ => {
this.deletePagesFromArray(this.selectedPages);
this.showLoading = false;
},
error => this.handleUpdateError('System error deleting the selected pages', error)
);
}
}
public editPage(i : number) {
let page : Page = this.checkboxes[i].page;
this.formGroup.patchValue(page);
this.formComponent.setEntities(page.entities as Entity[]);
//console.info(this.formGroup.value);
//this.updateModal.showModal();
this.modalErrorMessage = "";
this.pagesModalOpen(this.alertModalUpdatePage, "Update", "Update Page");
}
public newPage() {
this.formComponent.reset();
this.modalErrorMessage = "";
this.pagesModalOpen(this.alertModalSavePage, "Save", "Add a new Page");
}
private pagesModalOpen(modal: any, title: string, yesBtn: string) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
modal.cancelButton = true;
modal.okButton = true;
modal.alertTitle = title;
modal.okButtonText = yesBtn;
modal.open();
}
}
public pageSaveConfirmed(data: any) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if(!this.formGroup.valid) {
this.pagesModalOpen(this.alertModalSavePage, "Save", "Add a new Page");
this.modalErrorMessage = "Please fill in all required fields marked with *";
} else {
this.modalErrorMessage = "";
this._helpContentService.savePage(<Page> this.formGroup.value, this.properties.adminToolsAPIURL).subscribe(
page => {
this.pageSavedSuccessfully(page);
},
error => this.handleUpdateError("System error creating page", error)
);
}
}
}
public pageUpdateConfirmed(data: any) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if(!this.formGroup.valid) {
this.pagesModalOpen(this.alertModalUpdatePage, "Update", "Update Page");
this.modalErrorMessage = "Please fill in all required fields marked with *";
} else {
this._helpContentService.updatePage(<Page> this.formGroup.value, this.properties.adminToolsAPIURL).subscribe(
page => {
this.pageUpdatedSuccessfully(page);
},
error => this.handleUpdateError("System error updating page", error)
);
}
}
}
public pageSavedSuccessfully(page: Page) {
this.checkboxes.push(<CheckPage>{page : page, checked : false});
this.applyCheck(false);
}
public pageUpdatedSuccessfully(page : Page) {
this.checkboxes.find(checkItem => checkItem.page._id==page._id).page = page;
this.applyCheck(false);
}
public filterBySearch(text : string) {
this.searchText = new RegExp(text,'i');
this.applyFilter();
}
public applyFilter() {
this.checkboxes = [];
this.pages.filter(item => this.filterPages(item)).forEach(
_ => this.checkboxes.push(<CheckPage>{page: _, checked: false})
);
}
public filterPages(page : Page) : boolean {
let textFlag = this.searchText.toString() == '' || (page.route + ' ' +page.name).match(this.searchText) != null;
return textFlag;
}
handleError(message: string, error) {
// if(error == null) {
// this.formComponent.reset();
// } else {
this.errorMessage = message;// + ' (Server responded: ' + error + ')';
console.log('Server responded: ' +error);
//}
this.showLoading = false;
}
handleUpdateError(message: string, error) {
if(error == null) {
this.formComponent.reset();
} else {
this.updateErrorMessage = message;// + ' (Server responded: ' + error + ')';
console.log('Server responded: ' +error);
}
this.showLoading = false;
}
// public filterByCommunity(event: any) {
// this.selectedCommunityPid = event.target.value;
// this.applyCommunityFilter(this.selectedCommunityPid);
// }
public applyCommunityFilter(community_pid: string) {
this.getPages(community_pid);
}
public togglePages(status : boolean, ids : string[]) {
if(!Session.isLoggedIn()){
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
this.updateErrorMessage = "";
this._helpContentService.togglePages(this.selectedCommunityPid,ids,status, this.properties.adminToolsAPIURL).subscribe(
() => {
for(let id of ids) {
let i = this.checkboxes.findIndex(_ => _.page._id == id);
this.checkboxes[i].page.isEnabled=status;
}
this.applyCheck(false);
},
error => this.handleUpdateError('System error changing the status of the selected page(s)', error)
);
}
}
public capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
} }

View File

@ -4,7 +4,7 @@ import {ActivatedRoute, Router} from '@angular/router';
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
import {ManageUserNotificationsService} from './manage-user-notifications.service'; import {ManageUserNotificationsService} from './manage-user-notifications.service';
@ -12,214 +12,221 @@ import {UserNotificationsRights} from './userNotificationsRights';
import {MailPrefsComponent} from '../../openaireLibrary/connect/userEmailPreferences/mailPrefs.component'; import {MailPrefsComponent} from '../../openaireLibrary/connect/userEmailPreferences/mailPrefs.component';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class"; import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class';
import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
@Component({ @Component({
selector: 'manage-user-notifications', selector: 'manage-user-notifications',
templateUrl: './manage-user-notifications.component.html', templateUrl: './manage-user-notifications.component.html',
}) })
export class ManageUserNotificationsComponent implements OnInit { export class ManageUserNotificationsComponent implements OnInit {
@Input('group') @Input('group')
myForm: FormGroup; myForm: FormGroup;
public properties: EnvProperties = null; public properties: EnvProperties = null;
public communityId = null; public communityId = null;
public userNotifications = null; public userNotifications = null;
public initialUserNotifications = null; public initialUserNotifications = null;
public userEmail = null; public userEmail = null;
public showLoading = true; public showLoading = true;
public errorMessage = ''; public errorMessage = '';
public updateErrorMessage = ''; public updateErrorMessage = '';
public successfulSaveMessage = ''; public successfulSaveMessage = '';
public successfulResetMessage = ''; public successfulResetMessage = '';
public hasChanged = false; public hasChanged = false;
public user: User;
@ViewChild (MailPrefsComponent) mailPrefs: MailPrefsComponent; @ViewChild(MailPrefsComponent) mailPrefs: MailPrefsComponent;
constructor (private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder, constructor(private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder,
private _manageUserNotificationsService: ManageUserNotificationsService, private element: ElementRef) { private _manageUserNotificationsService: ManageUserNotificationsService,
} private element: ElementRef, private userManagementService: UserManagementService) {
}
ngOnInit() { ngOnInit() {
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific; this.properties = data.envSpecific;
this.route.queryParams.subscribe( this.route.queryParams.subscribe(
communityId => { communityId => {
HelperFunctions.scroll(); HelperFunctions.scroll();
this.communityId = communityId['communityId'];
if (this.communityId != null && this.communityId !== '') {
this.showLoading = true;
this.updateErrorMessage = '';
this.errorMessage = '';
this.successfulSaveMessage = '';
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
if (this.user) {
this.userEmail = this.user.email;
this._manageUserNotificationsService.getUserNotifications(
this.properties.adminToolsAPIURL + 'community/' + this.communityId + '/notifications', this.userEmail).subscribe(
userNotifications => {
this.initialUserNotifications = userNotifications;
if (this.initialUserNotifications['notifyForNewManagers'] == null ||
this.initialUserNotifications['notifyForNewSubscribers'] == null) {
this.initialUserNotifications = this.initiateUserNotifications();
}
this.communityId = communityId['communityId']; this.userNotifications = JSON.parse(JSON.stringify(this.initialUserNotifications));
if (this.communityId != null && this.communityId !== '') {
this.showLoading = true;
this.updateErrorMessage = '';
this.errorMessage = '';
this.successfulSaveMessage = '';
if (Session.getUser()) { // TODO remove after final testing
this.userEmail = Session.getUserEmail(); this.showLoading = false;
this._manageUserNotificationsService.getUserNotifications( },
this.properties.adminToolsAPIURL + 'community/' + this.communityId + '/notifications', this.userEmail). error => {
subscribe( if (error.status === 404) {
userNotifications => { this.initialUserNotifications = this.initiateUserNotifications();
this.initialUserNotifications = userNotifications; this.userNotifications = JSON.parse(JSON.stringify(this.initialUserNotifications));
if (this.initialUserNotifications['notifyForNewManagers'] == null || } else {
this.initialUserNotifications['notifyForNewSubscribers'] == null) { this.handleError('System error retrieving user notifications', error);
this.initialUserNotifications = this.initiateUserNotifications(); }
} this.showLoading = false;
}
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications )); );
// TODO remove after final testing
this.showLoading = false;
},
error => {
if (error.status === 404) {
this.initialUserNotifications = this.initiateUserNotifications();
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications ));
} else {
this.handleError('System error retrieving user notifications', error);
}
this.showLoading = false;
}
);
}
}
} }
); });
});
}
public initiateUserNotifications(): UserNotificationsRights {
const notificationRights: UserNotificationsRights = new UserNotificationsRights();
notificationRights['notifyForNewManagers'] = true;
notificationRights['notifyForNewSubscribers'] = true;
notificationRights['managerEmail'] = this.userEmail;
return notificationRights;
}
public updateUserNotifications() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'],
{ queryParams: { 'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} });
} else {
if (this.communityId != null && this.communityId !== '') {
this.mailPrefs.saveNotification(0);
this.successfulSaveMessage = '';
this.showLoading = true;
const userNotifications = this.parseUpdatedUserNotifications();
this._manageUserNotificationsService.updateUserNotifications(
this.properties.adminToolsAPIURL + 'community/' + this.communityId + '/notifications',
userNotifications).subscribe(
userNotifications => {
this.initialUserNotifications = JSON.parse(JSON.stringify( this.userNotifications ));
this.handleSuccessfulSave('Notification settings saved!');
},
error => this.handleUpdateError('System error updating user notifications', error)
);
} }
this.resetChange(); }
} );
} });
}
private parseUpdatedUserNotifications(): {} { public initiateUserNotifications(): UserNotificationsRights {
const userNotifications = {}; const notificationRights: UserNotificationsRights = new UserNotificationsRights();
userNotifications['notifyForNewManagers'] = this.userNotifications.notifyForNewManagers; notificationRights['notifyForNewManagers'] = true;
userNotifications['notifyForNewSubscribers'] = this.userNotifications.notifyForNewSubscribers; notificationRights['notifyForNewSubscribers'] = true;
notificationRights['managerEmail'] = this.userEmail;
if (this.userNotifications.managerEmail) { return notificationRights;
userNotifications['managerEmail'] = this.userNotifications.managerEmail; }
} else {
if (Session.getUser()) {
userNotifications['managerEmail'] = Session.getUserEmail();
}
}
return userNotifications;
}
public resetForm() { public updateUserNotifications() {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'],
queryParams: { 'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} }); {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
} else { } else {
this.mailPrefs.restoreNotification(0); if (this.communityId != null && this.communityId !== '') {
if (this.userNotifications && this.initialUserNotifications) { this.mailPrefs.saveNotification(0);
this.successfulSaveMessage = '';
this.showLoading = true;
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications ));
this.showLoading = false;
}
this.resetChange();
}
}
public changeValueForNewManagers(notifyForManagers: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {' "errorCode"': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} });
} else {
this.userNotifications.notifyForNewManagers = !notifyForManagers;
this.change();
}
}
public changeValueForNewSubscribers(notifyForSubscribers: any) {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: { 'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} });
} else {
this.userNotifications.notifyForNewSubscribers = !notifyForSubscribers;
this.change();
}
}
private change() {
this.hasChanged = true;
this.successfulSaveMessage = ''; this.successfulSaveMessage = '';
this.successfulResetMessage = ''; this.showLoading = true;
const userNotifications = this.parseUpdatedUserNotifications();
this._manageUserNotificationsService.updateUserNotifications(
this.properties.adminToolsAPIURL + 'community/' + this.communityId + '/notifications',
userNotifications).subscribe(
userNotifications => {
this.initialUserNotifications = JSON.parse(JSON.stringify(this.userNotifications));
this.handleSuccessfulSave('Notification settings saved!');
},
error => this.handleUpdateError('System error updating user notifications', error)
);
}
this.resetChange();
} }
}
private resetChange() { private parseUpdatedUserNotifications(): {} {
this.hasChanged = false; const userNotifications = {};
userNotifications['notifyForNewManagers'] = this.userNotifications.notifyForNewManagers;
userNotifications['notifyForNewSubscribers'] = this.userNotifications.notifyForNewSubscribers;
if (this.userNotifications.managerEmail) {
userNotifications['managerEmail'] = this.userNotifications.managerEmail;
} else {
if (this.user) {
userNotifications['managerEmail'] = this.user.email;
}
} }
return userNotifications;
}
public mailPrefsChanged(): boolean { public resetForm() {
if (!Session.isLoggedIn()) { if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], { this._router.navigate(['/user-info'], {
queryParams: { 'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} }); queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
} else { });
return this.mailPrefs.prefsChanged['0']; } else {
} this.mailPrefs.restoreNotification(0);
} if (this.userNotifications && this.initialUserNotifications) {
this.successfulSaveMessage = '';
handleUpdateError(message: string, error) { this.showLoading = true;
this.updateErrorMessage = message; this.userNotifications = JSON.parse(JSON.stringify(this.initialUserNotifications));
console.log('Server responded: ' + error);
this.showLoading = false; this.showLoading = false;
}
this.resetChange();
} }
}
handleError(message: string, error) { public changeValueForNewManagers(notifyForManagers: any) {
this.errorMessage = message; if (!Session.isLoggedIn()) {
console.log('Server responded: ' + error); this._router.navigate(['/user-info'], {
queryParams: {' "errorCode"': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
this.showLoading = false; });
} else {
this.userNotifications.notifyForNewManagers = !notifyForManagers;
this.change();
} }
}
handleSuccessfulSave(message) { public changeValueForNewSubscribers(notifyForSubscribers: any) {
this.showLoading = false; if (!Session.isLoggedIn()) {
this.successfulSaveMessage = message; this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.userNotifications.notifyForNewSubscribers = !notifyForSubscribers;
this.change();
} }
}
handleSuccessfulReset(message) { private change() {
this.showLoading = false; this.hasChanged = true;
this.successfulResetMessage = message; this.successfulSaveMessage = '';
this.successfulResetMessage = '';
}
private resetChange() {
this.hasChanged = false;
}
public mailPrefsChanged(): boolean {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
return this.mailPrefs.prefsChanged['0'];
} }
}
handleUpdateError(message: string, error) {
this.updateErrorMessage = message;
console.log('Server responded: ' + error);
this.showLoading = false;
}
handleError(message: string, error) {
this.errorMessage = message;
console.log('Server responded: ' + error);
this.showLoading = false;
}
handleSuccessfulSave(message) {
this.showLoading = false;
this.successfulSaveMessage = message;
}
handleSuccessfulReset(message) {
this.showLoading = false;
this.successfulResetMessage = message;
}
} }

View File

@ -1,11 +1,12 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {EnvironmentSpecificService} from '../../openaireLibrary/utils/properties/environment-specific.service'; import {EnvironmentSpecificService} from '../../openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from '../../openaireLibrary/connect/communities/communities.service'; import {CommunitiesService} from '../../openaireLibrary/connect/communities/communities.service';
import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo'; import {CommunityInfo} from '../../openaireLibrary/connect/community/communityInfo';
import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class'; import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class';
import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
@Component({ @Component({
selector: 'wellcome', selector: 'wellcome',
@ -88,8 +89,10 @@ export class WellcomeComponent implements OnInit {
properties: EnvProperties = null; properties: EnvProperties = null;
public communities: CommunityInfo[] = []; public communities: CommunityInfo[] = [];
showLoading: boolean; showLoading: boolean;
private user: User;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, private _communitiesService: CommunitiesService) { constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService, private _communitiesService: CommunitiesService,
private userManagementService: UserManagementService) {
} }
ngOnInit() { ngOnInit() {
@ -98,32 +101,35 @@ export class WellcomeComponent implements OnInit {
this.propertiesService.setEnvProperties(es); this.propertiesService.setEnvProperties(es);
this.properties = this.propertiesService.envSpecific; this.properties = this.propertiesService.envSpecific;
HelperFunctions.scroll(); HelperFunctions.scroll();
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
//this._communitiesService.getCommunities(this.properties, this.properties.communityAPI + 'communities').subscribe( //this._communitiesService.getCommunities(this.properties, this.properties.communityAPI + 'communities').subscribe(
this._communitiesService.getCommunitiesState().subscribe( this._communitiesService.getCommunitiesState().subscribe(
communities => { communities => {
if (!communities || communities.length === 0) { if (!communities || communities.length === 0) {
return; return;
} }
var countCommunities = 0; var countCommunities = 0;
var index_managerOfCommunity = null; var index_managerOfCommunity = null;
for (var i = 0; i < communities.length; i++) { for (var i = 0; i < communities.length; i++) {
var com = communities[i]; var com = communities[i];
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) { if (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user)) {
this.communities.push(communities[i]); this.communities.push(communities[i]);
} else { } else {
for (var manager of com.managers) { for (var manager of com.managers) {
if (manager == Session.getUserEmail()) { if (this.user && manager == this.user.email) {
countCommunities++; countCommunities++;
index_managerOfCommunity = i; index_managerOfCommunity = i;
this.communities.push(communities[i]); this.communities.push(communities[i]);
break; break;
}
} }
} }
} }
} this.showLoading = false;
this.showLoading = false; });
}); });
}); });
} }
} }

View File

@ -35,6 +35,8 @@
"piwikBaseUrl" :" https://analytics.openaire.eu/piwik.php?idsite=6", "piwikBaseUrl" :" https://analytics.openaire.eu/piwik.php?idsite=6",
"loginUrl" :"http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/openid_connect_login", "loginUrl" :"http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/openid_connect_login",
"userInfoUrl" : "http://rudie.di.uoa.gr:8280/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
"logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=", "logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
"cookieDomain" :".di.uoa.gr", "cookieDomain" :".di.uoa.gr",