From 9b5607fbd0204b44fb2c650df77fcb88f613fc2e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 28 Jun 2022 21:13:40 +0300 Subject: [PATCH] Notify form: Open dropdown on empty. Delele unsused mailPrefsComponent. Finish UI of subscribers and invite subscriber. Fix an input bug in case of adding chip with enter key --- .../mailPrefs.component.html | 55 ---- .../mailPrefs.component.ts | 259 ------------------ .../userEmailPreferences/mailPrefs.service.ts | 39 +-- .../userEmailPreferences/mailsPrefs.module.ts | 23 -- .../role-users/role-users.component.html | 73 ++--- .../subscribers/subscribers.component.html | 111 ++++---- .../subscribers/subscribers.component.ts | 16 +- .../users/subscribers/subscribers.module.ts | 3 +- .../notify-form/notify-form.component.ts | 2 +- sharedComponents/input/input.component.ts | 6 +- .../subscriber-invite.component.ts | 25 +- utils/email/composer.ts | 7 +- 12 files changed, 117 insertions(+), 502 deletions(-) delete mode 100644 connect/userEmailPreferences/mailPrefs.component.html delete mode 100644 connect/userEmailPreferences/mailPrefs.component.ts delete mode 100644 connect/userEmailPreferences/mailsPrefs.module.ts diff --git a/connect/userEmailPreferences/mailPrefs.component.html b/connect/userEmailPreferences/mailPrefs.component.html deleted file mode 100644 index 4bbe55a2..00000000 --- a/connect/userEmailPreferences/mailPrefs.component.html +++ /dev/null @@ -1,55 +0,0 @@ - -
-
- User Email Preferences for Claims Notifications -
- - - - - - -
- - -
- -
-
Notify - for new user links:
- - -
- -
-
Frequency:
-
- -
-
- -
- - -
- -
- -
- - - -
- diff --git a/connect/userEmailPreferences/mailPrefs.component.ts b/connect/userEmailPreferences/mailPrefs.component.ts deleted file mode 100644 index 6243387f..00000000 --- a/connect/userEmailPreferences/mailPrefs.component.ts +++ /dev/null @@ -1,259 +0,0 @@ -import {Component, Input} from '@angular/core'; -import {Location} from '@angular/common'; -import {ActivatedRoute, Router} from '@angular/router'; -import {Session} from '../../login/utils/helper.class'; -import {EnvProperties} from '../../utils/properties/env-properties'; -import {MailPrefsService} from './mailPrefs.service'; -import {ConnectHelper} from '../connectHelper'; -import {ErrorCodes} from '../../utils/properties/errorCodes'; -import {ErrorMessagesComponent} from '../../utils/errorMessages.component'; -import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; -import {properties} from "../../../../environments/environment"; -import {Subscriber} from "rxjs"; - -declare var UIkit: any; - -@Component({ - selector: 'mailPrefs', - templateUrl: 'mailPrefs.component.html', - providers:[MailPrefsService] - -}) -export class MailPrefsComponent { - properties:EnvProperties; - subscriptions = []; - @Input() communityId: string; - public preferencesFor: string = "community"; - public status: number; - - public notifications = []; - public initialNotifications = []; - public prefsChanged = {}; - public hidden: boolean = true; - - //public showForbiddenMessage:boolean = false; - public userValidMessage:string = ""; - public savedMessage: string = ""; - - private errorCodes: ErrorCodes; - private errorMessages: ErrorMessagesComponent; - - @Input() showSaveResetButtons: boolean = true; - - constructor (private _mailPrefsService: MailPrefsService, private route: ActivatedRoute, private _router:Router, private location: Location) { - this.errorCodes = new ErrorCodes(); - this.errorMessages = new ErrorMessagesComponent(); - this.status = this.errorCodes.LOADING; - } - - ngOnInit() { - this.properties = properties; - this.subscriptions.push(this.route.params.subscribe(params => { - this.hidden = true; - console.debug(this.communityId); - if(!this.communityId){ - this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); - } - if(!this.communityId) { - this.communityId = params['community']; - } - console.debug(this.communityId, params) - this.getEmailPreferences(); - })); - - - } - - 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"; - this.subscriptions.push(this._mailPrefsService.getUserEmailPreferencesForCommunity(this.communityId, this.properties.claimsAPIURL).subscribe( - data => { - if(data.code == "204") { - this.status = this.errorCodes.NONE; - this.initialNotifications = [{notify: true, frequency:24, openaireId: this.communityId}]; - } else { - this.initialNotifications = data.data; - } - this.notifications = JSON.parse(JSON.stringify( this.initialNotifications )); - - this.status = this.errorCodes.DONE; - this.hidden = false; - - }, - err => { - this.hidden = false; - this.handleErrors(err); - this.handleError("Error getting user email preferences for community with id: "+this.communityId, err); - } - )); - } else { - this.preferencesFor = "project"; - this.subscriptions.push(this._mailPrefsService.getUserEmailPreferencesForOpenaire(this.properties.claimsAPIURL).subscribe( - data => { - - if(data.code == "204") { - this.status = this.errorCodes.NONE; - } else { - - this.initialNotifications = data.data; - this.notifications = JSON.parse(JSON.stringify( this.initialNotifications )); - //this.notifications = this.initialNotifications.map(x => Object.assign({}, x)); - //this.notifications = this.initialNotifications; - - this.status = this.errorCodes.DONE; - } - }, - err => { - //console.info(err); - this.handleErrors(err); - this.handleError("Error getting user email preferences for openaire", err); - } - )); - } - } - } - - changeNotify(notification: any, checked: boolean, index: number) { - if(!Session.isLoggedIn()){ - //this.userValidMessage = "User session has expired. Please login again."; - if(this.showSaveResetButtons) { - this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); - } - } else { - this.savedMessage = ""; - this.status = this.errorCodes.DONE; - notification.notify = checked; - this.prefsChanged[index] = true; - } - } - - changeFrequency(index: number) { - if(!Session.isLoggedIn()){ - //this.userValidMessage = "User session has expired. Please login again."; - if(this.showSaveResetButtons) { - this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); - } - } else { - this.savedMessage = ""; - this.status = this.errorCodes.DONE; - if(this.initialNotifications[index].frequency != this.notifications[index].frequency) { - this.prefsChanged[index] = true; - } - } - } - - saveNotification(index: number) { - if(this.notifications.length > 0 && this.initialNotifications.length > 0) { - if(!Session.isLoggedIn()){ - //this.userValidMessage = "User session has expired. Please login again."; - if(this.showSaveResetButtons) { - this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); - } - } else { - if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { - - this.status = this.errorCodes.LOADING; - this.savedMessage = ""; - - this.subscriptions.push(this._mailPrefsService.saveUserEmailPreferences(this.notifications[index], this.properties.claimsAPIURL).subscribe( - data => { - this.initialNotifications[index] = JSON.parse(JSON.stringify( this.notifications[index] )); - - this.status = this.errorCodes.DONE; - - /*UIkit.notification({ - message : '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.handleError("Error saving user email preferences: "+JSON.stringify(this.notifications[index]), err); - this.status = this.errorCodes.NOT_SAVED; - } - )); - } - else { - /*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!"; - } - } - } - } - - restoreNotification(index: number) { - if(!Session.isLoggedIn()){ - //this.userValidMessage = "User session has expired. Please login again."; - if(this.showSaveResetButtons) { - this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); - } - } else { - if(this.notifications.length > 0 && this.initialNotifications.length > 0) { - this.status = this.errorCodes.LOADING; - this.savedMessage = ""; - this.notifications[index] = JSON.parse(JSON.stringify( this.initialNotifications[index] )); - this.status = this.errorCodes.DONE; - this.prefsChanged[index] = false; - } - } - } - /* - prefsChanged(index: number) : boolean { - if(this.notifications.length > 0 && this.initialNotifications.length > 0) { - if(JSON.stringify(this.notifications[index]) != JSON.stringify(this.initialNotifications[index])) { - return true; - } - } - return false; - } - */ - ngOnDestroy() { - this.subscriptions.forEach(subscription => { - if (subscription instanceof Subscriber) { - subscription.unsubscribe(); - } - }); - } - - - handleErrors(err){ - //this.showErrorMessage = true; - //try{ - var code = ""; - if(!err.status) { - var error = err.json(); - code = error.code; - } else { - code = err.status; - } - this.status = this.errorMessages.getErrorCode(code); - } - - private handleError(message: string, error) { - console.error("User mail notification preferences Page (for claims): "+message, error); - } - - - //}catch (e) { - //console.log("Couldn't parse answer as json") - //this.showErrorMessage = true; - //} -} diff --git a/connect/userEmailPreferences/mailPrefs.service.ts b/connect/userEmailPreferences/mailPrefs.service.ts index 5170f76d..5a72febc 100644 --- a/connect/userEmailPreferences/mailPrefs.service.ts +++ b/connect/userEmailPreferences/mailPrefs.service.ts @@ -8,46 +8,15 @@ export class MailPrefsService { constructor(private http: HttpClient ) {} getUserEmailPreferencesForCommunity (communityId:string, apiUrl:string):any { - let url = apiUrl +"users/notification"+"?communityId="+communityId; - - return this.http.get(url, CustomOptions.getAuthOptions()) - //.map(request => request.json()) - //.do(request => console.info("Get user email preferences for communityId= "+communityId )); - //.catch(this.handleError); + return this.http.get(apiUrl +"users/notification"+"?communityId="+communityId, CustomOptions.getAuthOptions()) } getUserEmailPreferencesForOpenaire (apiUrl:string):any { - let url = apiUrl +"users/notification"; - - //var error: HttpErrorResponse = new HttpErrorResponse({"error": {"code": 204}, "status" : 204}); // doesn't work - //var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null}); - - return this.http.get(url, CustomOptions.getAuthOptions()) - //.timeoutWith(100, Observable.throw(response)) // goes to error - //.timeoutWith(100, Observable.of(response)) // goes to - //.do(request => console.info(request)) - //.map(request => request.json()) - //.do(request => console.info("Get user email preferences for OpenAIRE" )); - //.catch(this.handleError); + return this.http.get(apiUrl +"users/notification", CustomOptions.getAuthOptions()); } saveUserEmailPreferences (notification: any, apiUrl: string) { - let url = apiUrl +"users/notification/save"; - - let body = JSON.stringify( notification ); - //console.warn('Json body: : '+body); - //let headers = new Headers({ 'Content-Type': 'application/json' }); - //let options = new RequestOptions({ headers: headers }); - return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - //.do(request => console.info("Insert Response:"+request.status) ); - //.catch(this.handleError); - } - - private handleError (error: HttpErrorResponse) { - // in a real world app, we may send the error to some remote logging infrastructure - // instead of just logging it to the console - console.log(error); - return throwError(error || 'Server error'); + let body = JSON.stringify(notification); + return this.http.post(apiUrl +"users/notification/save", body, CustomOptions.getAuthOptionsWithBody()); } } diff --git a/connect/userEmailPreferences/mailsPrefs.module.ts b/connect/userEmailPreferences/mailsPrefs.module.ts deleted file mode 100644 index f670212e..00000000 --- a/connect/userEmailPreferences/mailsPrefs.module.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { NgModule} from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { RouterModule } from '@angular/router'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; - -import { MailPrefsComponent } from './mailPrefs.component'; -import { MailPrefsService } from './mailPrefs.service'; -import {ErrorMessagesModule} from '../../utils/errorMessages.module'; -import { MatSlideToggleModule } from '@angular/material/slide-toggle'; - -@NgModule({ - imports: [ - CommonModule, RouterModule, FormsModule, ReactiveFormsModule, ErrorMessagesModule, MatSlideToggleModule - ], - declarations: [ - MailPrefsComponent - ], - providers:[MailPrefsService], - exports: [ - MailPrefsComponent - ] -}) -export class MailPrefsModule { } diff --git a/dashboard/users/role-users/role-users.component.html b/dashboard/users/role-users/role-users.component.html index aebb6336..8facaed8 100644 --- a/dashboard/users/role-users/role-users.component.html +++ b/dashboard/users/role-users/role-users.component.html @@ -3,10 +3,7 @@
-
- -
-
+
  • @@ -25,7 +22,8 @@ [searchControl]="filterForm.get('pending')" [expandable]="true" [placeholder]="'Search invitations'" searchInputClass="outer">
-
-
-
-
No {{role}}s found
-
No pending {{role}} invitations found
-
-
- - - - -
-
-
-
- {{(showCurrent) ? item.email : item}} -
-
diff --git a/dashboard/users/subscribers/subscribers.component.html b/dashboard/users/subscribers/subscribers.component.html index b5534eb6..c939b4e0 100644 --- a/dashboard/users/subscribers/subscribers.component.html +++ b/dashboard/users/subscribers/subscribers.component.html @@ -1,78 +1,64 @@ -
+
+
+
+
+
+ + +
+
-
+
-
No subscribers found
+
No members found
- -
-
-
-
-
- Email: - {{item.email}} -
+
+
+
+
+ {{item.email}}
-
-
-
- -
-
+
- - +
+ + +
@@ -83,20 +69,17 @@
- Are you sure you want to remove {{selectedUser}} from subscribers? + Are you sure you want to remove {{selectedUser}} from members?
-
+
-
-
+
+
diff --git a/dashboard/users/subscribers/subscribers.component.ts b/dashboard/users/subscribers/subscribers.component.ts index bd9fee67..6729709c 100644 --- a/dashboard/users/subscribers/subscribers.component.ts +++ b/dashboard/users/subscribers/subscribers.component.ts @@ -1,10 +1,10 @@ import { ChangeDetectorRef, - Component, + Component, EventEmitter, Input, OnChanges, OnDestroy, - OnInit, + OnInit, Output, SimpleChanges, ViewChild } from '@angular/core'; @@ -39,6 +39,8 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges { public message: string = null; @Input() public inviteDisableMessage: string; + @Output() + public stickyEmitter: EventEmitter = new EventEmitter(); public user: User = null; public subscribers: any[]; public showSubscribers: any[]; @@ -50,7 +52,7 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges { public roleFb: FormGroup; /** Paging */ page: number = 1; - pageSize: number = 5; + pageSize: number = 10; /** Search */ filterForm: FormGroup; @ViewChild('inviteModal') inviteModal: AlertModal; @@ -70,7 +72,9 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges { keyword: this.fb.control('') }); this.subs.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { - this.filterBySearch(value); + if(this.subscribers) { + this.filterBySearch(value); + } })); this.updateList(); this.userManagementService.getUserInfo().subscribe(user => { @@ -120,13 +124,13 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges { openDeleteModal(item: any) { this.selectedUser = item.email; - this.deleteModal.alertTitle = 'Delete subscriber'; + this.deleteModal.alertTitle = 'Delete member'; this.deleteModal.open(); } openInviteModal() { if(this.subscriberInvite && !this.subscriberInvite.loading) { - this.inviteModal.alertTitle = 'Invite users to subscribe'; + this.inviteModal.alertTitle = 'Invite users to join ' + this.name; this.inviteModal.okButtonLeft = false; this.inviteModal.okButtonText = 'Send'; this.subscriberInvite.reset(); diff --git a/dashboard/users/subscribers/subscribers.module.ts b/dashboard/users/subscribers/subscribers.module.ts index db17bb57..7095fff5 100644 --- a/dashboard/users/subscribers/subscribers.module.ts +++ b/dashboard/users/subscribers/subscribers.module.ts @@ -11,9 +11,10 @@ import {SafeHtmlPipeModule} from "../../../utils/pipes/safeHTMLPipe.module"; import {NoLoadPaging} from "../../../searchPages/searchUtils/no-load-paging.module"; import {SearchInputModule} from "../../../sharedComponents/search-input/search-input.module"; import {SubscriberInviteModule} from "../../../sharedComponents/subscriber-invite/subscriber-invite.module"; +import {PagingModule} from "../../../utils/paging.module"; @NgModule({ - imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule, NoLoadPaging, SearchInputModule, SubscriberInviteModule], + imports: [CommonModule, AlertModalModule, ReactiveFormsModule, LoadingModule, IconsModule, InputModule, PageContentModule, SafeHtmlPipeModule, NoLoadPaging, SearchInputModule, SubscriberInviteModule, PagingModule], declarations: [SubscribersComponent], exports: [SubscribersComponent] }) diff --git a/notifications/notify-form/notify-form.component.ts b/notifications/notify-form/notify-form.component.ts index be9e88dd..bdc5aeb6 100644 --- a/notifications/notify-form/notify-form.component.ts +++ b/notifications/notify-form/notify-form.component.ts @@ -23,7 +23,7 @@ declare var UIkit;
-
diff --git a/sharedComponents/input/input.component.ts b/sharedComponents/input/input.component.ts index 6f3ea1fd..fcaa0014 100644 --- a/sharedComponents/input/input.component.ts +++ b/sharedComponents/input/input.component.ts @@ -100,7 +100,7 @@ declare var UIkit;
{{getLabel(chip.value)}} -
@@ -309,7 +309,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang @HostListener('window:keydown.enter', ['$event']) enter(event: KeyboardEvent) { - if (this.opened) { + if (this.opened && this.optionBox) { event.preventDefault(); if (this.filteredOptions[this.selectedIndex]) { this.selectOption(this.filteredOptions[this.selectedIndex], event); @@ -483,7 +483,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang add(event) { if (this.addExtraChips && this.searchControl.value && this.searchControl.valid) { - if (event) { + if (event && event.stopPropagation) { event.stopPropagation(); } this.formAsArray.push(new FormControl(this.searchControl.value, this.validators)); diff --git a/sharedComponents/subscriber-invite/subscriber-invite.component.ts b/sharedComponents/subscriber-invite/subscriber-invite.component.ts index 0266184b..9a391afd 100644 --- a/sharedComponents/subscriber-invite/subscriber-invite.component.ts +++ b/sharedComponents/subscriber-invite/subscriber-invite.component.ts @@ -17,24 +17,17 @@ declare var UIkit; selector: 'subscriber-invite', template: `
-
-
- From: -
+
+
-
-
- To *: -
-
-
-
- Message *: -
-
+
+ +
' + let defaultMainBody = '

You are invited to join ' + communityTitle + ' dashboard.
'; if(communityId !== 'covid-19') { defaultMainBody += 'The purpose of this dashboard is to gather, link & monitor the research results related to your community.

' @@ -209,13 +208,13 @@ export class Composer { '

The community dashboard is part of the OpenAIRE-Connect project.

' } - return body = {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""}; + return {fromMessage: ", on behalf of ", fromName: fullname, paragraphs: defaultMainBody, signature: this.closing, note: ""}; } public static initializeInvitationsEmail(communityTitle: string) { let email: Email = new Email(); - return email = {body: "", subject: this.subjectPrefix + communityTitle, recipients: []}; + return {body: "", subject: this.subjectPrefix + communityTitle, recipients: []}; } public static composeEmailForMonitorDashboard(name: string, recipient: string, role: "manager" | "member") {