Fix manage user notifications buttons status

This commit is contained in:
Konstantinos Triantafyllou 2022-07-08 21:59:17 +03:00
parent 803dc0a2d9
commit 264f5ca30b
7 changed files with 48 additions and 108 deletions

@ -1 +1 @@
Subproject commit f08c63d3849e966bcfe916f0ca48788e0b401306 Subproject commit 02bf9abee4f2b514f2f02c510fab47da6bf3431b

View File

@ -10,8 +10,7 @@ import {UserManagementService} from "../../../../openaireLibrary/services/user-m
import {StringUtils} from "../../../../openaireLibrary/utils/string-utils.class"; import {StringUtils} from "../../../../openaireLibrary/utils/string-utils.class";
import {Subscription} from "rxjs"; import {Subscription} from "rxjs";
import {Option} from "../../../../openaireLibrary/sharedComponents/input/input.component"; import {Option} from "../../../../openaireLibrary/sharedComponents/input/input.component";
import {NotificationHandler} from "../../../../openaireLibrary/utils/notification-handler";
declare var UIkit;
@Component({ @Component({
selector: 'edit-community', selector: 'edit-community',
@ -56,7 +55,8 @@ declare var UIkit;
</div> </div>
</div> </div>
</div> </div>
<div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'" [formInput]="communityFb.get('logoUrl')"></div> <div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'"
[formInput]="communityFb.get('logoUrl')"></div>
</div> </div>
<div *ngIf="communityFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle"> <div *ngIf="communityFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
<div class="uk-card uk-card-default uk-text-center uk-border-circle"> <div class="uk-card uk-card-default uk-text-center uk-border-circle">
@ -77,7 +77,7 @@ declare var UIkit;
<div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div> <div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div>
</div> </div>
<div class="uk-width-1-2@m"> <div class="uk-width-1-2@m">
<div input [formInput]="communityFb.get('status')" <div input [formInput]="communityFb.get('status')"
placeholder="Visibility status for your community's profile." placeholder="Visibility status for your community's profile."
[options]="statuses" type="select"></div> [options]="statuses" type="select"></div>
</div> </div>
@ -212,19 +212,11 @@ export class EditCommunityComponent {
this.subscriptions.push(this.communityService.updateCommunity( this.subscriptions.push(this.communityService.updateCommunity(
this.properties.communityAPI + this.community.communityId, this.communityFb.getRawValue()).subscribe(() => { this.properties.communityAPI + this.community.communityId, this.communityFb.getRawValue()).subscribe(() => {
this.communityService.getCommunity(this.community.communityId, true).subscribe(community => { this.communityService.getCommunity(this.community.communityId, true).subscribe(community => {
UIkit.notification(community.shortTitle + ' has been <b>successfully created</b>', { NotificationHandler.rise(community.shortTitle + ' has been <b>successfully created</b>');
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
callback(community); callback(community);
}); });
}, error => { }, error => {
UIkit.notification('An error has occurred. Please try again later', { NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
if (errorCallback) { if (errorCallback) {
errorCallback(error) errorCallback(error)
} }
@ -232,19 +224,11 @@ export class EditCommunityComponent {
} else { } else {
this.subscriptions.push(this.communityService.updateCommunity(this.properties.communityAPI + this.community.communityId, this.communityFb.getRawValue()).subscribe(() => { this.subscriptions.push(this.communityService.updateCommunity(this.properties.communityAPI + this.community.communityId, this.communityFb.getRawValue()).subscribe(() => {
this.communityService.getCommunity(this.community.communityId, true).subscribe(community => { this.communityService.getCommunity(this.community.communityId, true).subscribe(community => {
UIkit.notification(community.shortTitle + ' has been <b>successfully saved</b>', { NotificationHandler.rise(community.shortTitle + ' has been <b>successfully saved</b>');
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
callback(community); callback(community);
}); });
}, error => { }, error => {
UIkit.notification('An error has occurred. Please try again later', { NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
})); }));
} }
} }

View File

@ -59,7 +59,7 @@
<div class="uk-flex uk-flex-between"> <div class="uk-flex uk-flex-between">
<label *ngFor="let option of frequencyOptions"> <label *ngFor="let option of frequencyOptions">
<input class="uk-radio" type="radio" [checked]="notification.frequency === option.value" <input class="uk-radio" type="radio" [checked]="notification.frequency === option.value"
(click)="notification.frequency = option.value"> (click)="notification.frequency = option.value; change()">
<span class="uk-margin-small-left">{{option.label}}</span> <span class="uk-margin-small-left">{{option.label}}</span>
</label> </label>
</div> </div>

View File

@ -6,7 +6,6 @@ import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
import {ManageUserNotificationsService} from './manage-user-notifications.service'; import {ManageUserNotificationsService} from './manage-user-notifications.service';
import {UserNotificationsRights} from './userNotificationsRights'; import {UserNotificationsRights} from './userNotificationsRights';
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {HelperFunctions} from '../../openaireLibrary/utils/HelperFunctions.class';
import {UserManagementService} from '../../openaireLibrary/services/user-management.service'; import {UserManagementService} from '../../openaireLibrary/services/user-management.service';
import {Title} from '@angular/platform-browser'; import {Title} from '@angular/platform-browser';
import {CommunityService} from '../../openaireLibrary/connect/community/community.service'; import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
@ -15,8 +14,7 @@ import {Subscriber} from 'rxjs';
import {MailPrefsService} from '../../openaireLibrary/connect/userEmailPreferences/mailPrefs.service'; import {MailPrefsService} from '../../openaireLibrary/connect/userEmailPreferences/mailPrefs.service';
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo"; import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
import {Option} from "../../openaireLibrary/sharedComponents/input/input.component"; import {Option} from "../../openaireLibrary/sharedComponents/input/input.component";
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
declare var UIkit;
@Component({ @Component({
selector: 'manage-user-notifications', selector: 'manage-user-notifications',
@ -137,41 +135,34 @@ export class ManageUserNotificationsComponent implements OnInit {
public updateUserNotifications() { public updateUserNotifications() {
if (!Session.isLoggedIn()) { if (this.community.communityId != null && this.community.communityId !== '') {
this._router.navigate(['/user-info'], this.showLoading = true;
{queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}}); const userNotifications = this.parseUpdatedUserNotifications();
} else { this.subscriptions.push(this.manageUserNotificationsService.updateUserNotifications(this.properties, this.community.communityId, userNotifications).subscribe(
if (this.community.communityId != null && this.community.communityId !== '') { userNotifications => {
this.showLoading = true; this.initialUserNotifications = JSON.parse(JSON.stringify(this.userNotifications));
const userNotifications = this.parseUpdatedUserNotifications(); this.handleSuccessfulSave('Notification settings saved!');
this.subscriptions.push(this.manageUserNotificationsService.updateUserNotifications(this.properties, this.community.communityId, userNotifications).subscribe( },
userNotifications => { error => this.handleUpdateError('System error updating user notifications', error)
this.initialUserNotifications = JSON.parse(JSON.stringify(this.userNotifications)); ));
this.handleSuccessfulSave('Notification settings saved!'); this.subscriptions.push(this.mailPrefsService.saveUserEmailPreferences(this.notifications[0], this.properties.claimsAPIURL).subscribe(
}, data => {
error => this.handleUpdateError('System error updating user notifications', error) this.initialNotifications[0] = JSON.parse(JSON.stringify(this.notifications[0]));
)); this.handleSuccessfulSave('Claims notification settings saved!');
this.subscriptions.push(this.mailPrefsService.saveUserEmailPreferences(this.notifications[0], this.properties.claimsAPIURL).subscribe( },
data => { err => {
this.initialNotifications[0] = JSON.parse(JSON.stringify(this.notifications[0])); //console.log(err);
this.handleSuccessfulSave('Claims notification settings saved!'); this.handleError("Error saving user email preferences: " + JSON.stringify(this.notifications[0]), err);
}, }
err => { ));
//console.log(err);
this.handleError("Error saving user email preferences: " + JSON.stringify(this.notifications[0]), err);
}
));
}
this.resetChange();
} }
this.resetChange();
} }
private parseUpdatedUserNotifications(): {} { private parseUpdatedUserNotifications(): {} {
const userNotifications = {}; const userNotifications = {};
userNotifications['notifyForNewManagers'] = this.userNotifications.notifyForNewManagers; userNotifications['notifyForNewManagers'] = this.userNotifications.notifyForNewManagers;
userNotifications['notifyForNewSubscribers'] = this.userNotifications.notifyForNewSubscribers; userNotifications['notifyForNewSubscribers'] = this.userNotifications.notifyForNewSubscribers;
if (this.userNotifications.managerEmail) { if (this.userNotifications.managerEmail) {
userNotifications['managerEmail'] = this.userNotifications.managerEmail; userNotifications['managerEmail'] = this.userNotifications.managerEmail;
} }
@ -179,50 +170,27 @@ export class ManageUserNotificationsComponent implements OnInit {
} }
public resetForm() { public resetForm() {
if (!Session.isLoggedIn()) { this.notifications[0] = JSON.parse(JSON.stringify(this.initialNotifications[0]));
this._router.navigate(['/user-info'], { if (this.userNotifications && this.initialUserNotifications) {
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url} this.showLoading = true;
}); this.userNotifications = JSON.parse(JSON.stringify(this.initialUserNotifications));
} else { this.showLoading = false;
// this.mailPrefs.restoreNotification(0);
this.notifications[0] = JSON.parse(JSON.stringify(this.initialNotifications[0]));
if (this.userNotifications && this.initialUserNotifications) {
// this.successfulSaveMessage = '';
this.showLoading = true;
this.userNotifications = JSON.parse(JSON.stringify(this.initialUserNotifications));
this.showLoading = false;
}
this.resetChange();
} }
this.resetChange();
} }
public changeValueForNewManagers(notifyForManagers: any) { public changeValueForNewManagers(notifyForManagers: any) {
if (!Session.isLoggedIn()) { this.userNotifications.notifyForNewManagers = !notifyForManagers;
this._router.navigate(['/user-info'], { this.change();
queryParams: {' "errorCode"': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.userNotifications.notifyForNewManagers = !notifyForManagers;
this.change();
}
} }
public changeValueForNewSubscribers(notifyForSubscribers: any) { public changeValueForNewSubscribers(notifyForSubscribers: any) {
if (!Session.isLoggedIn()) { this.userNotifications.notifyForNewSubscribers = !notifyForSubscribers;
this._router.navigate(['/user-info'], { this.change();
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
});
} else {
this.userNotifications.notifyForNewSubscribers = !notifyForSubscribers;
this.change();
}
} }
private change() { public change() {
this.hasChanged = true; this.hasChanged = true;
// this.successfulSaveMessage = '';
// this.successfulResetMessage = '';
} }
private resetChange() { private resetChange() {
@ -230,31 +198,19 @@ export class ManageUserNotificationsComponent implements OnInit {
} }
handleUpdateError(message: string, error) { handleUpdateError(message: string, error) {
// this.updateErrorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
this.showLoading = false; this.showLoading = false;
} }
handleError(message: string, error) { handleError(message: string, error) {
// this.errorMessage = message;
console.log('Server responded: ' + error); console.log('Server responded: ' + error);
UIkit.notification(message, { NotificationHandler.rise(message, 'danger');
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false; this.showLoading = false;
} }
handleSuccessfulSave(message) { handleSuccessfulSave(message) {
this.showLoading = false; this.showLoading = false;
// this.successfulSaveMessage = message; NotificationHandler.rise(message);
UIkit.notification(message, {
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
} }
changeNotify(notification: any, checked: boolean, index: number) { changeNotify(notification: any, checked: boolean, index: number) {

@ -1 +1 @@
Subproject commit 052d94e27ce698a119755973e0b7285d2b64370b Subproject commit d577c6d69a55901e319cf0cf5b93f900f1cdeaab

@ -1 +1 @@
Subproject commit 319eff1cc355ffc4148cf20c4ba23e15fbc6a6f6 Subproject commit 141c71c3104bab1382e6008697043ea87e03ea44

@ -1 +1 @@
Subproject commit 3c6d5cab3a9e3a1e3be42e231424a5c1350749ad Subproject commit 32040ce807ad4945e7682b39a3fbc6faecf2f619