From 21ac8fd2f092f7ff88480641f9c6178a6ede76e2 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 1 Nov 2018 17:21:10 +0000 Subject: [PATCH] 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-services-library/trunk/ng-openaire-library/src/app@53613 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../mailPrefs.component.html | 36 ++--- .../mailPrefs.component.ts | 134 ++++++++++++------ 2 files changed, 107 insertions(+), 63 deletions(-) diff --git a/connect/userEmailPreferences/mailPrefs.component.html b/connect/userEmailPreferences/mailPrefs.component.html index 3dfdb834..9536a988 100644 --- a/connect/userEmailPreferences/mailPrefs.component.html +++ b/connect/userEmailPreferences/mailPrefs.component.html @@ -1,13 +1,16 @@ -
+
User Email Preferences for Claims Notifications
-
- User session is not valid. Please login again. + + @@ -20,7 +23,7 @@
-
Do you want to receive e-mail notifications?
+
Notify for claims:
-
How often?
+
Frequency:
- + + +
@@ -67,6 +71,6 @@
-
+ diff --git a/connect/userEmailPreferences/mailPrefs.component.ts b/connect/userEmailPreferences/mailPrefs.component.ts index c971d241..1a824845 100644 --- a/connect/userEmailPreferences/mailPrefs.component.ts +++ b/connect/userEmailPreferences/mailPrefs.component.ts @@ -9,6 +9,7 @@ import {EnvProperties} from '../../utils/properties/env-properties'; import {MailPrefsService} from './mailPrefs.service'; import {ConnectHelper} from '../connectHelper'; import {ErrorCodes} from '../../utils/properties/errorCodes'; +import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; declare var UIkit: any; @@ -27,10 +28,11 @@ export class MailPrefsComponent { public notifications = []; public initialNotifications = []; + public prefsChanged = {}; - public showErrorMessage:boolean = false; //public showForbiddenMessage:boolean = false; public userValidMessage:string = ""; + public savedMessage: string = ""; public fetchId:string; @@ -68,8 +70,12 @@ export class MailPrefsComponent { getEmailPreferences() { 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"; @@ -116,58 +122,90 @@ export class MailPrefsComponent { } } - changeNotify(notification: any, checked: boolean) { + changeNotify(notification: any, checked: boolean, index: number) { + this.savedMessage = ""; + this.status = this.errorCodes.DONE; notification.notify = checked; + this.prefsChanged[index] = true; + } + + changeFrequency(value: number, index: number) { + this.savedMessage = ""; + this.status = this.errorCodes.DONE; + if(this.initialNotifications[index].frequency != value) { + this.prefsChanged[index] = true; + } } saveNotification(index: number) { - if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { - if(!Session.isLoggedIn()){ - this.userValidMessage = "User session has expired. Please login again."; - - }else{ - this.status = this.errorCodes.LOADING; - - console.info("Send notification to db: ", this.notifications[index]); - - this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe( - data => { - console.info("Notification saved successfully"); - this.initialNotifications[index] = JSON.parse(JSON.stringify( this.notifications[index] )); - - this.status = this.errorCodes.DONE; - - UIkit.notification({ - message : 'Your email preferences for '+this.notifications[index].openaireName+' have been successfully changed', - status : 'success', - timeout : 3000, - pos : 'top-center' - }); - }, - err => { - console.log(err); - this.status = this.errorCodes.NOT_SAVED; + if(this.notifications.length > 0 && this.initialNotifications.length > 0) { + if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { + 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 = ""; + console.info("Send notification to db: ", this.notifications[index]); + + this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe( + data => { + console.info("Notification saved successfully"); + this.initialNotifications[index] = JSON.parse(JSON.stringify( this.notifications[index] )); + + this.status = this.errorCodes.DONE; + + /*UIkit.notification({ + message : 'Your email preferences for '+this.notifications[index].openaireName+' have been successfully changed', + status : 'success', + timeout : 3000, + pos : 'top-center' + });*/ + this.savedMessage = "Notification settings for claims saved!"; + }, + err => { + console.log(err); + this.status = this.errorCodes.NOT_SAVED; + } + ); + } + } else { + console.info("Notification not changed: ", this.notifications[index]); + /*UIkit.notification({ + message : 'No changes selected for '+this.notifications[index].openaireName+' email preferences', + status : 'primary', + timeout : 3000, + pos : 'top-center' + });*/ + this.savedMessage = "Notification settings for claims saved!"; } - } else { - console.info("Notification not changed: ", this.notifications[index]); - UIkit.notification({ - message : 'No changes selected for '+this.notifications[index].openaireName+' email preferences', - status : 'primary', - timeout : 3000, - pos : 'top-center' - }); } } restoreNotification(index: number) { - console.info("Restore Notification"); - console.info(this.notifications[index]); - this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] )); - console.info(this.initialNotifications[index]); + if(this.notifications.length > 0 && this.initialNotifications.length > 0) { + this.status = this.errorCodes.LOADING; + this.savedMessage = ""; + console.info("Restore Notification"); + console.info(this.notifications[index]); + this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] )); + console.info(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) { + if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { + return true; + } + } + return false; + } +*/ ngOnDestroy() { if(this.sub) { this.sub.unsubscribe(); @@ -177,11 +215,13 @@ export class MailPrefsComponent { handleErrors(err){ //this.showErrorMessage = true; //try{ - var error = err.json() - //var code = error.code; - - console.info(err); - var code = error.code; + var code = ""; + if(!err.status) { + var error = err.json(); + code = error.code; + } else { + code = err.status; + } console.info(code); if(code == "403") { this.status = this.errorCodes.FORBIDDEN;