-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1139 from ORCID/sendNotificationsDialog
send notifications dialog
- Loading branch information
Showing
17 changed files
with
299 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ui/src/app/affiliation/affiliation-import-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
ui/src/app/affiliation/send-notifications-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<form name="notificationForm" (ngSubmit)="send()"> | ||
<div class="modal-header"> | ||
<h4 class="modal-title" i18n="@@gatewayApp.assertionServiceAssertion.notifications.title.string">Send permission notifications</h4> | ||
<button type="button" class="close" (click)="close()" aria-hidden="true">×</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="alert alert-danger" *ngIf="requestAlreadyInProgress" i18n="@@gatewayApp.assertionServiceAssertion.notifications.alreadyInProgress.string"> | ||
A request to send notifications to your users is already in progress. Please try again later. | ||
</div> | ||
<p i18n="@@gatewayApp.assertionServiceAssertion.notifications.description.string">Are you sure that you would like ORCID to send permission links to your researchers for the affiliations that are pending?</p> | ||
<h6 class="mb-1 font-weight-bold" i18n="@@gatewayApp.assertionServiceAssertion.notifications.languageHeader.string">Notification language</h6> | ||
<p i18n="@@gatewayApp.assertionServiceAssertion.notifications.languageDescription.string">What language should the notification be sent in?</p> | ||
<select class="form-control w-66" id="langKey" name="langKey" [(ngModel)]="language"> | ||
<option *ngFor="let lang of languages | keyvalue" [ngValue]="lang.key">{{lang.value.name}}</option> | ||
</select> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-outline-primary" (click)="close()"> | ||
<fa-icon [icon]="'ban'"></fa-icon> <span i18n="@@entity.action.cancel.string">Cancel</span> | ||
</button> | ||
<button id="jhi-confirm-csv-upload" type="submit" class="btn btn-primary"> | ||
<fa-icon [icon]="faPaperPlane"></fa-icon> <span i18n="@@gatewayApp.assertionServiceAssertion.notifications.sendNotifications.string">Send notifications</span> | ||
</button> | ||
</div> | ||
</form> |
Empty file.
101 changes: 101 additions & 0 deletions
101
ui/src/app/affiliation/send-notifications-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
|
||
import { SendNotificationsDialogComponent } from './send-notifications-dialog.component' | ||
import { NotificationService } from './service/notification.service' | ||
import { EventService } from '../shared/service/event.service' | ||
import { AccountService } from '../account' | ||
import { MemberService } from '../member/service/member.service' | ||
import { AlertService } from '../shared/service/alert.service' | ||
import { LanguageService } from '../shared/service/language.service' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { FormBuilder } from '@angular/forms' | ||
import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' | ||
import { ErrorService } from '../error/service/error.service' | ||
import { FileUploadService } from '../shared/service/file-upload.service' | ||
import { UserService } from '../user/service/user.service' | ||
import { of } from 'rxjs' | ||
|
||
describe('SendNotificationsDialogComponent', () => { | ||
let component: SendNotificationsDialogComponent | ||
let fixture: ComponentFixture<SendNotificationsDialogComponent> | ||
|
||
let notificationServiceSpy: jasmine.SpyObj<NotificationService> | ||
let eventServiceSpy: jasmine.SpyObj<EventService> | ||
let alertServiceSpy: jasmine.SpyObj<AlertService> | ||
let languageServiceSpy: jasmine.SpyObj<LanguageService> | ||
let memberServiceSpy: jasmine.SpyObj<MemberService> | ||
let accountServiceSpy: jasmine.SpyObj<AccountService> | ||
|
||
beforeEach(() => { | ||
eventServiceSpy = jasmine.createSpyObj('EventService', ['broadcast', 'on']) | ||
alertServiceSpy = jasmine.createSpyObj('AlertService', ['broadcast', 'on']) | ||
memberServiceSpy = jasmine.createSpyObj('MemberService', ['find']) | ||
accountServiceSpy = jasmine.createSpyObj('AccountService', ['getAccountData']) | ||
notificationServiceSpy = jasmine.createSpyObj('NotificationService', ['updateStatuses', 'requestInProgress']) | ||
languageServiceSpy = jasmine.createSpyObj('LanguageService', [ | ||
'getAllLanguages', | ||
'getCurrentLanguage', | ||
'changeLanguage', | ||
]) | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [SendNotificationsDialogComponent], | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
FormBuilder, | ||
NgbModal, | ||
NgbActiveModal, | ||
{ provide: AccountService, useValue: accountServiceSpy }, | ||
{ provide: EventService, useValue: eventServiceSpy }, | ||
{ provide: AlertService, useValue: alertServiceSpy }, | ||
{ provide: MemberService, useValue: memberServiceSpy }, | ||
{ provide: LanguageService, useValue: languageServiceSpy }, | ||
{ provide: NotificationService, useValue: notificationServiceSpy }, | ||
{ provide: ErrorService, useValue: {} }, | ||
], | ||
}).compileComponents() | ||
|
||
fixture = TestBed.createComponent(SendNotificationsDialogComponent) | ||
component = fixture.componentInstance | ||
|
||
eventServiceSpy = TestBed.inject(EventService) as jasmine.SpyObj<EventService> | ||
accountServiceSpy = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService> | ||
alertServiceSpy = TestBed.inject(AlertService) as jasmine.SpyObj<AlertService> | ||
languageServiceSpy = TestBed.inject(LanguageService) as jasmine.SpyObj<LanguageService> | ||
memberServiceSpy = TestBed.inject(MemberService) as jasmine.SpyObj<MemberService> | ||
}) | ||
|
||
it('should create', () => { | ||
accountServiceSpy.getAccountData.and.returnValue( | ||
of({ | ||
activated: true, | ||
authorities: ['test', 'test'], | ||
email: '[email protected]', | ||
firstName: 'name', | ||
langKey: 'en', | ||
lastName: 'surname', | ||
imageUrl: 'url', | ||
salesforceId: 'sfid', | ||
loggedAs: false, | ||
loginAs: 'sfid', | ||
mainContact: false, | ||
mfaEnabled: true, | ||
}) | ||
) | ||
|
||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('send should call notification service', () => { | ||
notificationServiceSpy.requestInProgress.and.returnValue(of({ inProgress: false })) | ||
notificationServiceSpy.updateStatuses.and.returnValue(of({})) | ||
component.send() | ||
expect(notificationServiceSpy.updateStatuses).toHaveBeenCalled() | ||
}) | ||
|
||
it('send should not call notification service when request is already in progress', () => { | ||
notificationServiceSpy.requestInProgress.and.returnValue(of({ inProgress: true })) | ||
component.send() | ||
expect(notificationServiceSpy.updateStatuses).toHaveBeenCalledTimes(0) | ||
}) | ||
}) |
119 changes: 119 additions & 0 deletions
119
ui/src/app/affiliation/send-notifications-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { Component, OnDestroy, OnInit } from '@angular/core' | ||
import { NotificationService } from './service/notification.service' | ||
import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' | ||
import { EventService } from '../shared/service/event.service' | ||
import { AlertService } from '../shared/service/alert.service' | ||
import { IUser } from '../user/model/user.model' | ||
import { faPaperPlane } from '@fortawesome/free-solid-svg-icons' | ||
import { IMember } from '../member/model/member.model' | ||
import { MemberService } from '../member/service/member.service' | ||
import { LanguageService } from '../shared/service/language.service' | ||
import { AccountService } from '../account' | ||
import { IAccount } from '../account/model/account.model' | ||
import { AlertType, EventType } from '../app.constants' | ||
import { ActivatedRoute, Router } from '@angular/router' | ||
|
||
@Component({ | ||
selector: 'app-send-notifications-dialog', | ||
templateUrl: './send-notifications-dialog.component.html', | ||
styleUrls: ['./send-notifications-dialog.component.scss'], | ||
}) | ||
export class SendNotificationsDialogComponent implements OnInit { | ||
faPaperPlane = faPaperPlane | ||
requestAlreadyInProgress = false | ||
languages: { [langCode: string]: { name: string } } | undefined | ||
language = '' | ||
account: IUser | undefined | ||
|
||
constructor( | ||
protected notificationService: NotificationService, | ||
public activeModal: NgbActiveModal, | ||
protected eventService: EventService, | ||
protected alertService: AlertService, | ||
private languageService: LanguageService, | ||
private memberService: MemberService, | ||
private accountService: AccountService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.languages = this.languageService.getAllLanguages() | ||
|
||
this.accountService.getAccountData().subscribe((account) => { | ||
this.memberService.find(account!.salesforceId).subscribe((member) => { | ||
if (member) { | ||
this.language = member.defaultLanguage || 'en' | ||
} else { | ||
this.language = 'en' | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
clear() { | ||
this.activeModal.dismiss(true) | ||
window.history.back() | ||
} | ||
|
||
send() { | ||
console.log('this.language is ', this.language) | ||
|
||
this.notificationService.requestInProgress().subscribe((res: any) => { | ||
if (res.inProgress) { | ||
this.requestAlreadyInProgress = true | ||
} else { | ||
this.notificationService.updateStatuses(this.language).subscribe(() => { | ||
this.alertService.broadcast(AlertType.NOTIFICATION_IN_PROGRESS) | ||
this.close() | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
close() { | ||
this.eventService.broadcast({ | ||
type: EventType.SEND_NOTIFICATIONS, | ||
payload: 'Send notifications', | ||
}) | ||
this.activeModal.dismiss(true) | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'app-send-notifications-popup', | ||
template: '', | ||
}) | ||
export class SendNotificationsPopupComponent implements OnInit, OnDestroy { | ||
protected ngbModalRef: NgbModalRef | undefined | null | ||
|
||
constructor( | ||
protected activatedRoute: ActivatedRoute, | ||
protected router: Router, | ||
protected modalService: NgbModal | ||
) {} | ||
|
||
ngOnInit() { | ||
this.activatedRoute.data.subscribe(({ assertion }) => { | ||
setTimeout(() => { | ||
this.ngbModalRef = this.modalService.open(SendNotificationsDialogComponent as Component, { | ||
size: 'lg', | ||
backdrop: 'static', | ||
}) | ||
this.ngbModalRef.componentInstance.assertion = assertion | ||
this.ngbModalRef.result.then( | ||
(result) => { | ||
this.router.navigate(['/affiliations', { outlets: { popup: null } }]) | ||
this.ngbModalRef = null | ||
}, | ||
(reason) => { | ||
this.router.navigate(['/affiliations', { outlets: { popup: null } }]) | ||
this.ngbModalRef = null | ||
} | ||
) | ||
}, 0) | ||
}) | ||
} | ||
|
||
ngOnDestroy() { | ||
this.ngbModalRef = null | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Injectable } from '@angular/core' | ||
import { HttpClient, HttpResponse } from '@angular/common/http' | ||
import { Observable } from 'rxjs' | ||
import * as moment from 'moment' | ||
import { map } from 'rxjs/operators' | ||
import { AffiliationPage, IAffiliation, IAffiliationPage } from '../model/affiliation.model' | ||
import { createRequestOption } from 'src/app/shared/request-util' | ||
import { AffiliationService } from './affiliation.service' | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class NotificationService { | ||
resourceUrl: string | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private affiliationService: AffiliationService | ||
) { | ||
this.resourceUrl = this.affiliationService.resourceUrl + '/notification-request' | ||
} | ||
|
||
updateStatuses(language: string): Observable<any> { | ||
return this.http.post<any>(this.resourceUrl, { language }) | ||
} | ||
|
||
requestInProgress(): Observable<any> { | ||
return this.http.get<any>(this.resourceUrl) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.