1. library.css: Add class 'inherit-color' (used in user notifications: uk-form-label).

2. mailPrefs.component: make functionality of buttons like manage-user-notifications.component of admin portal (when preferences change, save button remains clickable unless 'reset' is clicked).
3. manage-user-notifications.component: Change html (stop using table for proper layout - use form instead).
4. When Session expires, redirect to '/user-info'.


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-admin-portal/trunk@53613 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2018-11-01 17:21:10 +00:00
parent 3ff95d06c0
commit f4c2cccbf2
2 changed files with 105 additions and 29 deletions

View File

@ -1,13 +1,45 @@
<div id="manage-user-notifications" class=" uk-card uk-card-default uk-padding">
<div class="uk-text-large uk-text-center uk-width-5-6@l uk-width">Manage User Notifications</div>
</div>
<div *ngIf="communityId != null && userNotifications && !showLoading && !errorMessage">
<div id="manage-user-notifications" class=" uk-card uk-card-default uk-padding">
<div class="uk-text-large uk-text-center uk-width-5-6@l uk-width">Manage User Notifications</div>
</div>
<div class="uk-container uk-margin-top">
<div *ngIf="updateErrorMessage" class="uk-alert uk-alert-danger" role="alert">{{updateErrorMessage}}</div>
<div *ngIf="errorMessage" class="uk-alert uk-alert-danger" role="alert">{{errorMessage}}</div>
<div *ngIf="successfulSaveMessage" class="uk-alert uk-alert-success" role="alert">{{successfulSaveMessage}}</div>
<div *ngIf="successfulResetMessage" class="uk-alert uk-alert-warning" role="alert">{{successfulResetMessage}}</div>
<div *ngIf="showLoading" class="uk-animation-fade uk-width-1-1" role="alert"><img class="uk-align-center loading-gif"></div>
<table class="uk-table uk-width-1-2 uk-align-center">
<div *ngIf="communityId != null && userNotifications && !showLoading && !errorMessage" class="uk-first-column uk-align-center uk-width-2-3">
<form class="uk-form-horizontal">
<div class="uk-margin">
<div class="uk-form-label inherit-color">Notify for new managers:</div>
<div class="uk-form-controls uk-form-controls-text" data-uk-button-group>
<button *ngIf="userNotifications.notifyForNewManagers" class="uk-button uk-button-primary uk-button-small"
data-uk-button>ON</button>
<button *ngIf="!userNotifications.notifyForNewManagers" class="uk-button uk-button-default uk-button-small"
(click)="changeValueForNewManagers(userNotifications.notifyForNewManagers)" data-uk-button>ON</button>
<button *ngIf="!userNotifications.notifyForNewManagers" class="uk-button uk-button-danger uk-button-small"
data-uk-button>OFF</button>
<button *ngIf="userNotifications.notifyForNewManagers" class="uk-button uk-button-default uk-button-small"
(click)="changeValueForNewManagers(userNotifications.notifyForNewManagers)" data-uk-button>OFF</button>
</div>
</div>
<div class="uk-margin">
<div class="uk-form-label inherit-color">Notify for new subscribers:</div>
<div class="uk-form-controls uk-form-controls-text" data-uk-button-group>
<button *ngIf="userNotifications.notifyForNewSubscribers" class="uk-button uk-button-primary uk-button-small"
data-uk-button>ON</button>
<button *ngIf="!userNotifications.notifyForNewSubscribers" class="uk-button uk-button-default uk-button-small"
(click)="changeValueForNewSubscribers(userNotifications.notifyForNewSubscribers)" data-uk-button>ON</button>
<button *ngIf="!userNotifications.notifyForNewSubscribers" class="uk-button uk-button-danger uk-button-small"
data-uk-button>OFF</button>
<button *ngIf="userNotifications.notifyForNewSubscribers" class="uk-button uk-button-default uk-button-small"
(click)="changeValueForNewSubscribers(userNotifications.notifyForNewSubscribers)" data-uk-button>OFF</button>
</div>
</div>
</form>
</div>
</div>
<!-- <table class="uk-table uk-width-1-2 uk-align-center">
<tbody>
<div>
<tr>
@ -46,11 +78,17 @@
</tr>
</div>
</tbody>
</table>
<div class = "uk-grid-margin uk-first-column uk-align-center uk-width-1-3">
</table> -->
<!-- <div class = "uk-grid-margin uk-first-column uk-align-center uk-width-1-3">
<button *ngIf="hasChanged" class="uk-button uk-button-primary" (click)="updateUserNotifications()">Save</button>
<button *ngIf="!hasChanged" class="uk-button uk-button-default" disabled>Save</button>
<button class="uk-button" (click)="resetForm(communityId)">Reset</button>
</div>
</div>
<mailPrefs></mailPrefs>
</div> -->
<mailPrefs id="mailPrefs" [showSaveResetButtons]="false"></mailPrefs>
<div class = "uk-first-column uk-align-center uk-width-1-3">
<button *ngIf="hasChanged || mailPrefsChanged()" class="uk-button uk-button-primary" (click)="updateUserNotifications()">Save</button>
<button *ngIf="!hasChanged && !mailPrefsChanged()" class="uk-button uk-button-default" disabled>Save</button>
<button class="uk-button" (click)="resetForm(communityId)">Reset</button>
</div>

View File

@ -1,4 +1,4 @@
import {Component, OnInit, Input} from '@angular/core';
import {Component, OnInit, Input, ViewChild} from '@angular/core';
import {FormGroup, FormBuilder} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router';
import {CommonModule} from "@angular/common";
@ -11,6 +11,9 @@ import {ManageUserNotificationsService} from './manage-user-notifications.servic
import {UserNotificationsRights} from './userNotificationsRights';
import {MailPrefsComponent} from '../../openaireLibrary/connect/userEmailPreferences/mailPrefs.component';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
@Component({
selector: 'manage-user-notifications',
templateUrl: './manage-user-notifications.component.html',
@ -24,6 +27,7 @@ export class ManageUserNotificationsComponent implements OnInit {
public properties: EnvProperties = null;
public communityId = null;
public userNotifications = null;
public initialUserNotifications = null;
public userEmail = null;
public showLoading: boolean = true;
@ -35,6 +39,8 @@ export class ManageUserNotificationsComponent implements OnInit {
public hasChanged: boolean = false;
@ViewChild (MailPrefsComponent) mailPrefs : MailPrefsComponent;
constructor (private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder,
private _manageUserNotificationsService: ManageUserNotificationsService) {
}
@ -49,32 +55,36 @@ export class ManageUserNotificationsComponent implements OnInit {
this.showLoading = true;
this.updateErrorMessage = "";
this.errorMessage = "";
this.successfulSaveMessage = "";
if (Session.getUser()) {
this.userEmail = Session.getUserEmail();
this._manageUserNotificationsService.getUserNotifications(this.properties.adminToolsAPIURL + "community/" + this.communityId + "/notifications", this.userEmail).subscribe(
userNotifications => {
this.userNotifications = userNotifications;
this.initialUserNotifications = userNotifications;
if (this.userNotifications['notifyForNewManagers'] == null || this.userNotifications['notifyForNewSubscribers'] == null) {
this.userNotifications = this.initiateUserNotifications();
if (this.initialUserNotifications['notifyForNewManagers'] == null || this.initialUserNotifications['notifyForNewSubscribers'] == null) {
this.initialUserNotifications = this.initiateUserNotifications();
}
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications ));
//TODO remove after final testing
console.log("Before: ", userNotifications);
console.log("After: ", this.userNotifications);
console.log("After: ", this.initialUserNotifications);
this.showLoading = false;
},
error => {
console.log(error.status);
if (error.status == '404') {
this.userNotifications = this.initiateUserNotifications();
console.log(this.userNotifications);
this.showLoading = false;
this.initialUserNotifications = this.initiateUserNotifications();
console.log(this.initialUserNotifications);
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications ));
} else {
this.handleError('System error retrieving user notifications', error)
}
this.showLoading = false;
}
);
}
@ -95,19 +105,28 @@ export class ManageUserNotificationsComponent implements OnInit {
}
public updateUserNotifications() {
if (this.communityId != null && this.communityId != '') {
this.showLoading = true;
var userNotifications = this.parseUpdatedUserNotifications();
console.log(userNotifications);
if(!Session.isLoggedIn()){
console.info(this._router.url);
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._manageUserNotificationsService.updateUserNotifications(this.properties.adminToolsAPIURL + "community/" + this.communityId + "/notifications", userNotifications).subscribe(
userNotifications => {
this.handleSuccessfulSave('Notification settings saved!')
},
error => this.handleUpdateError('System error updating user notifications', error)
);
this.successfulSaveMessage = "";
this.showLoading = true;
var userNotifications = this.parseUpdatedUserNotifications();
console.log(userNotifications);
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();
}
this.resetChange();
}
private parseUpdatedUserNotifications() : {} {
@ -127,11 +146,14 @@ export class ManageUserNotificationsComponent implements OnInit {
}
public resetForm(communityId:string) {
/*
if (communityId != null && communityId != '') {
this.showLoading = true;
this.updateErrorMessage = "";
this.errorMessage = "";
this.mailPrefs.restoreNotification(0);
this._manageUserNotificationsService.getUserNotifications(this.properties.adminToolsAPIURL + "community/" + this.communityId + "/notifications", this.userEmail).subscribe(
userNotifications => {
this.userNotifications = userNotifications;
@ -141,6 +163,18 @@ export class ManageUserNotificationsComponent implements OnInit {
error => this.handleError('System error retrieving user notifications', error)
);
}
*/
this.mailPrefs.restoreNotification(0);
if(this.userNotifications && this.initialUserNotifications) {
this.successfulSaveMessage = "";
this.showLoading = true;
this.userNotifications = JSON.parse(JSON.stringify( this.initialUserNotifications ));
this.showLoading = false;
}
this.resetChange();
}
@ -168,6 +202,10 @@ export class ManageUserNotificationsComponent implements OnInit {
console.log('I have changed: I AM FALSE');
}
public mailPrefsChanged(): boolean {
return this.mailPrefs.prefsChanged["0"];//(0);
}
handleUpdateError(message: string, error) {
this.updateErrorMessage = message;
console.log('Server responded: ' +error);