better toast/notifications.

- configurable autohide
- success style
- notifications on sync ocomplete.
This commit is contained in:
Jason Kulatunga 2022-10-12 08:53:24 -07:00
parent b8112947cd
commit 6af72266f6
7 changed files with 45 additions and 5 deletions

View File

@ -6,7 +6,7 @@ go mod vendor
go run backend/cmd/fasten/fasten.go start --config ./config.example.yaml --debug go run backend/cmd/fasten/fasten.go start --config ./config.example.yaml --debug
docker build -t fasten-couchdb -f docker/couchdb/Dockerfile . docker build -t fasten-couchdb -f docker/couchdb/Dockerfile .
docker run --rm -it -p 5984:5984 -v `pwd`/.couchdb/data:/opt/couchdb/data fasten-couchdb docker run --rm -it -p 5984:5984 -v `pwd`/.couchdb/data:/opt/couchdb/data -v `pwd`/.couchdb/config:/opt/couchdb/etc/local.d fasten-couchdb
``` ```
# Docker # Docker

View File

@ -1,8 +1,8 @@
<div class="pos-absolute t-10 r-10"> <div class="toast-container">
<ngb-toast <ngb-toast
*ngFor="let toast of toastService.toasts" *ngFor="let toast of toastService.toasts"
[class]="toast.displayClass" [class]="toast.displayClass"
[autohide]="true" [autohide]="toast.autohide"
[delay]="toast.delay || 5000" [delay]="toast.delay || 5000"
(hidden)="toastService.remove(toast)" (hidden)="toastService.remove(toast)"
> >

View File

@ -1,5 +1,6 @@
export enum ToastType { export enum ToastType {
Error = "error", Error = "error",
Success = "success",
Info = "info" Info = "info"
} }
@ -8,4 +9,5 @@ export class ToastNotification {
message: string message: string
type: ToastType = ToastType.Info type: ToastType = ToastType.Info
displayClass: string = 'demo-static-toast' displayClass: string = 'demo-static-toast'
autohide: boolean = true
} }

View File

@ -12,6 +12,8 @@ import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common'; import {Location} from '@angular/common';
import {SourceType} from '../../../lib/models/database/source_types'; import {SourceType} from '../../../lib/models/database/source_types';
import {QueueService} from '../../workers/queue.service'; import {QueueService} from '../../workers/queue.service';
import {ToastService} from '../../services/toast.service';
import {ToastNotification, ToastType} from '../../models/fasten/toast';
// If you dont import this angular will import the wrong "Location" // If you dont import this angular will import the wrong "Location"
export const sourceConnectWindowTimeout = 24*5000 //wait 2 minutes (5 * 24 = 120) export const sourceConnectWindowTimeout = 24*5000 //wait 2 minutes (5 * 24 = 120)
@ -38,6 +40,7 @@ export class MedicalSourcesComponent implements OnInit {
private router: Router, private router: Router,
private location: Location, private location: Location,
private queueService: QueueService, private queueService: QueueService,
private toastService: ToastService
) { } ) { }
status: { [name: string]: string } = {} status: { [name: string]: string } = {}
@ -250,11 +253,21 @@ export class MedicalSourcesComponent implements OnInit {
//remove item from available sources list, add to connected sources. //remove item from available sources list, add to connected sources.
this.availableSourceList.splice(this.availableSourceList.findIndex((item) => item.metadata.source_type == sourceType), 1); this.availableSourceList.splice(this.availableSourceList.findIndex((item) => item.metadata.source_type == sourceType), 1);
this.connectedSourceList.push({source: sourceSyncMessage.source, metadata: this.metadataSources[sourceType]}) this.connectedSourceList.push({source: sourceSyncMessage.source, metadata: this.metadataSources[sourceType]})
const toastNotificaiton = new ToastNotification()
toastNotificaiton.type = ToastType.Success
toastNotificaiton.message = `Successfully connected ${sourceType}`
this.toastService.show(toastNotificaiton)
}, },
(err) => { (err) => {
delete this.status[sourceType] delete this.status[sourceType]
// window.location.reload(); // window.location.reload();
const toastNotificaiton = new ToastNotification()
toastNotificaiton.type = ToastType.Error
toastNotificaiton.message = `An error occurred while accessing ${sourceType}: ${err}`
toastNotificaiton.autohide = false
this.toastService.show(toastNotificaiton)
console.error(err) console.error(err)
}); });
} }

View File

@ -11,11 +11,19 @@ export class ToastService {
show(toastNotification: ToastNotification) { show(toastNotification: ToastNotification) {
if(!toastNotification.title){ if(!toastNotification.title){
toastNotification.title = toastNotification.type == ToastType.Error ? "Error" : "Notification" if(toastNotification.type == ToastType.Error){
toastNotification.title = "Error"
}else if(toastNotification.type == ToastType.Success){
toastNotification.title = "Success"
}else{
toastNotification.title = "Notification"
}
} }
if(toastNotification.type == ToastType.Error){ if(toastNotification.type == ToastType.Error){
toastNotification.displayClass += ' bg-danger text-light' toastNotification.displayClass += ' bg-danger text-light'
} else if(toastNotification.type == ToastType.Success){
toastNotification.displayClass += ' bg-indigo text-light'
} }
this.toasts.push(toastNotification); this.toasts.push(toastNotification);

View File

@ -3,13 +3,15 @@ import {Observable, of} from 'rxjs';
import {fromWorker} from 'observable-webworker'; import {fromWorker} from 'observable-webworker';
import {Source} from '../../lib/models/database/source'; import {Source} from '../../lib/models/database/source';
import {SourceSyncMessage} from '../models/queue/source-sync-message'; import {SourceSyncMessage} from '../models/queue/source-sync-message';
import {ToastService} from '../services/toast.service';
import {ToastNotification, ToastType} from '../models/fasten/toast';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class QueueService { export class QueueService {
constructor() { } constructor(private toastService: ToastService) { }
runSourceSyncWorker(source: Source):Observable<string> { runSourceSyncWorker(source: Source):Observable<string> {
if (typeof Worker !== 'undefined') { if (typeof Worker !== 'undefined') {
@ -26,6 +28,12 @@ export class QueueService {
// Web workers are not supported in this environment. // Web workers are not supported in this environment.
// You should add a fallback so that your program still executes correctly. // You should add a fallback so that your program still executes correctly.
console.error("WORKERS ARE NOT SUPPORTED") console.error("WORKERS ARE NOT SUPPORTED")
const toastNotificaiton = new ToastNotification()
toastNotificaiton.type = ToastType.Error
toastNotificaiton.message = "Your browser does not support web-workers. Cannot continue."
toastNotificaiton.autohide = false
this.toastService.show(toastNotificaiton)
} }
} }

View File

@ -22,6 +22,15 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
// toast notifications container
// sticky-top float-right pt-3 pr-3
.toast-container {
position: fixed;
right: 20px;
top: 20px;
z-index: 1000;
}
/* You can add global styles to this file, and also import other style files */ /* You can add global styles to this file, and also import other style files */
/* /*
* Azia v1.0.0 (https://www.bootstrapdash.com/demo/azia/v1.0/) * Azia v1.0.0 (https://www.bootstrapdash.com/demo/azia/v1.0/)