-
Notifications
You must be signed in to change notification settings - Fork 2
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 #298 from NREL/issue-28
Initial Toast System and Data Privacy Disclaimer
- Loading branch information
Showing
9 changed files
with
158 additions
and
2 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
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
Empty file.
14 changes: 14 additions & 0 deletions
14
src/app/core-components/toast-notifications/toast-notifications.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,14 @@ | ||
<div class="toast-container position-fixed bottom-0 end-0 p-3 hide-print"> | ||
<div #toastItem role="alert" aria-live="assertive" aria-atomic="true" class="toast" | ||
[attr.data-bs-autohide]="toastNotification?.autoHide" [ngClass]="toastNotification?.toastClass"> | ||
<ng-template [ngIf]="toastNotification"> | ||
<div class="toast-header"> | ||
<strong class="me-auto">{{toastNotification.title}}</strong> | ||
<button type="button" class="btn-close" (click)="closeToast()" aria-label="Close"></button> | ||
</div> | ||
<div class="toast-body"> | ||
<span [innerHTML]="toastNotification.body"></span> | ||
</div> | ||
</ng-template> | ||
</div> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
src/app/core-components/toast-notifications/toast-notifications.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,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ToastNotificationsComponent } from './toast-notifications.component'; | ||
|
||
describe('ToastNotificationsComponent', () => { | ||
let component: ToastNotificationsComponent; | ||
let fixture: ComponentFixture<ToastNotificationsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ToastNotificationsComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ToastNotificationsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
src/app/core-components/toast-notifications/toast-notifications.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,57 @@ | ||
import { Component, ElementRef, ViewChild } from '@angular/core'; | ||
import * as bootstrap from 'bootstrap'; | ||
import { ToastNotification, ToastNotificationsService } from './toast-notifications.service'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-toast-notifications', | ||
templateUrl: './toast-notifications.component.html', | ||
styleUrl: './toast-notifications.component.css' | ||
}) | ||
export class ToastNotificationsComponent { | ||
|
||
|
||
@ViewChild('toastItem', { static: false }) toastItem: ElementRef; | ||
toast: any; | ||
|
||
toastNotification: ToastNotification; | ||
toastNotificationSub: Subscription; | ||
constructor(private toastNotificationService: ToastNotificationsService) { | ||
} | ||
|
||
ngOnInit(): void { | ||
this.toastNotificationSub = this.toastNotificationService.toastNotification.subscribe(notification => { | ||
this.toastNotification = notification; | ||
this.showToast(); | ||
}) | ||
} | ||
|
||
ngAfterViewInit() { | ||
//Bootstrap toast initialization | ||
if (bootstrap) { | ||
this.toast = new bootstrap.Toast(this.toastItem.nativeElement); | ||
this.showToast(); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.toastNotificationSub.unsubscribe(); | ||
if (this.toast) { | ||
this.toast.dispose(); | ||
} | ||
} | ||
|
||
showToast() { | ||
if (this.toastNotification && this.toast) { | ||
this.toast.show(); | ||
} | ||
} | ||
|
||
|
||
|
||
closeToast() { | ||
this.toast.hide(); | ||
this.toastNotificationService.toastNotification.next(undefined); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/app/core-components/toast-notifications/toast-notifications.service.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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ToastNotificationsService } from './toast-notifications.service'; | ||
|
||
describe('ToastNotificationsService', () => { | ||
let service: ToastNotificationsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ToastNotificationsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/app/core-components/toast-notifications/toast-notifications.service.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,40 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ToastNotificationsService { | ||
|
||
toastNotification: BehaviorSubject<ToastNotification>; | ||
|
||
constructor() { | ||
this.toastNotification = new BehaviorSubject<ToastNotification>(undefined); | ||
} | ||
|
||
showToast(title: string, body: string, toastClass: ToastClass, autoHide: boolean) { | ||
this.toastNotification.next({ | ||
autoHide: autoHide, | ||
title: title, | ||
body: body, | ||
toastClass: toastClass | ||
}) | ||
} | ||
|
||
showWebDisclaimer() { | ||
let title: string = "JUSTIFI Web"; | ||
let body: string = `You are running JUSTIFI in a web browser. All application data is saved within this browser (The DOE does not have access to your data). | ||
It is encouraged that you download backup files of your data frequently. Backups can be uploaded to restore lost or corrupted data. Additionally, sharing backups with the development team can help in their effort to make this tool. <br> <hr> | ||
You can download data backups using the "Download Data" button in the upper right hand corner of your screen.` | ||
this.showToast(title, body, "bg-info", false); | ||
} | ||
} | ||
|
||
export interface ToastNotification { | ||
autoHide: boolean, | ||
title: string, | ||
body: string, | ||
toastClass: ToastClass | ||
} | ||
|
||
export type ToastClass = 'bg-success' | 'bg-info' | 'bg-danger' | 'bg-primary' | 'bg-secondary' | 'bg-warning' | 'bg-light' | 'bg-dark'; |