Skip to content

Commit

Permalink
Merge pull request #306 from NREL/issue-287
Browse files Browse the repository at this point in the history
Add disabled button option to toast notification
  • Loading branch information
RLiNREL authored Nov 4, 2024
2 parents a7b1538 + 2d60800 commit 63a4b0e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.toast-footer{
text-align: right;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<div class="toast-body">
<span [innerHTML]="toastNotification.body"></span>
</div>
<div class="toast-footer ps-2 pe-2 pb-2" *ngIf="toastNotification?.showDisable">
<button class="btn btn-sm btn-secondary" (click)="disableNotification()">Disable Notification</button>
</div>
</ng-template>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ToastNotificationsComponent } from './toast-notifications.component';
import { LocalStorageDataService } from 'src/app/shared/shared-services/local-storage-data.service';

describe('ToastNotificationsComponent', () => {
let component: ToastNotificationsComponent;
let fixture: ComponentFixture<ToastNotificationsComponent>;

let localStorageDataService: Partial<LocalStorageDataService> = {}
beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [
{ provide: LocalStorageDataService, useValue: localStorageDataService }
],
declarations: [ToastNotificationsComponent]
})
.compileComponents();
.compileComponents();

fixture = TestBed.createComponent(ToastNotificationsComponent);
component = fixture.componentInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export class ToastNotificationsComponent {
}
}



closeToast() {
this.toast.hide();
this.toastNotificationService.disableNotification.next(false);
this.toastNotificationService.toastNotification.next(undefined);
}

disableNotification() {
this.toast.hide();
this.toastNotificationService.disableNotification.next(true);
this.toastNotificationService.toastNotification.next(undefined);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { TestBed } from '@angular/core/testing';

import { ToastNotificationsService } from './toast-notifications.service';
import { LocalStorageDataService } from 'src/app/shared/shared-services/local-storage-data.service';

describe('ToastNotificationsService', () => {
let service: ToastNotificationsService;

let localStorageDataService: Partial<LocalStorageDataService> = {}
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
providers: [
{ provide: LocalStorageDataService, useValue: localStorageDataService }
]
});
service = TestBed.inject(ToastNotificationsService);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Subscription } from 'rxjs';
import { LocalStorageDataService } from 'src/app/shared/shared-services/local-storage-data.service';

@Injectable({
providedIn: 'root'
})
export class ToastNotificationsService {

toastNotification: BehaviorSubject<ToastNotification>;

constructor() {
disableNotification: BehaviorSubject<boolean>;
disableNotificaitonSub: Subscription;
constructor(private localStorageDataService: LocalStorageDataService) {
this.toastNotification = new BehaviorSubject<ToastNotification>(undefined);
this.disableNotification = new BehaviorSubject<boolean>(false);
}

showToast(title: string, body: string, toastClass: ToastClass, autoHide: boolean) {
showToast(title: string, body: string, toastClass: ToastClass, autoHide: boolean, showDisable: boolean) {
this.toastNotification.next({
autoHide: autoHide,
title: title,
body: body,
toastClass: toastClass
toastClass: toastClass,
showDisable: showDisable
})
}

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);
if (!this.localStorageDataService.disableDataDisclaimer) {
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, true);
let initDisable: boolean = true;
this.disableNotificaitonSub = this.disableNotification.subscribe(val => {
if (val == true) {
this.localStorageDataService.setDisableDataDisclaimer(true)
};
if (!initDisable) {
this.disableNotificaitonSub.unsubscribe();
} else {
initDisable = false;
}
});
}
}
}

export interface ToastNotification {
autoHide: boolean,
title: string,
body: string,
toastClass: ToastClass
toastClass: ToastClass,
showDisable: boolean
}

export type ToastClass = 'bg-success' | 'bg-info' | 'bg-danger' | 'bg-primary' | 'bg-secondary' | 'bg-warning' | 'bg-light' | 'bg-dark';
7 changes: 7 additions & 0 deletions src/app/shared/shared-services/local-storage-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class LocalStorageDataService {
processEquipmentAccordionGuid: string;
assessmentAccordionGuid: string;
disableAlphaDisclaimer: boolean;
disableDataDisclaimer: boolean;
constructor(private localStorageService: LocalStorageService) {
this.setupHelpPanelCollapsed = this.localStorageService.retrieve("setupHelpPanelCollapsed");
if (this.setupHelpPanelCollapsed == undefined) {
Expand All @@ -32,6 +33,7 @@ export class LocalStorageDataService {
this.processEquipmentAccordionGuid = this.localStorageService.retrieve("processEquipmentAccordionGuid");
this.assessmentAccordionGuid = this.localStorageService.retrieve("assessmentAccordionGuid");
this.disableAlphaDisclaimer = this.localStorageService.retrieve("disableAlphaDisclaimer");
this.disableDataDisclaimer = this.localStorageService.retrieve("disableDataDisclaimer");
}

setSetupPanelCollapsed(val: boolean) {
Expand Down Expand Up @@ -73,4 +75,9 @@ export class LocalStorageDataService {
this.disableAlphaDisclaimer = disableAlphaDisclaimer;
this.localStorageService.store('disableAlphaDisclaimer', this.disableAlphaDisclaimer);
}

setDisableDataDisclaimer(disableDataDisclaimer: boolean) {
this.disableDataDisclaimer = disableDataDisclaimer;
this.localStorageService.store('disableDataDisclaimer', this.disableDataDisclaimer);
}
}

0 comments on commit 63a4b0e

Please sign in to comment.