Improve notifications

This commit is contained in:
aditya.chandel
2024-12-27 11:14:31 -07:00
parent ea716bfb69
commit 3f13917191
13 changed files with 93 additions and 30 deletions
@@ -1,6 +1,6 @@
<div class="library-header">
<div class="library-header-dial">
<h3 class="library-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h3>
<h4 class="library-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h4>
<p-speedDial
[model]="speedDialItems!"
direction="right"
@@ -1,10 +1,11 @@
.library-header {
display: flex;
justify-content: space-between;
padding: 15px 15px 10px 17px;
padding: 8px 16px 8px 16px;
background-color: var(--surface-card);
border-radius: 12px 12px 0 0;
margin-bottom: 15px;
align-items: center;
}
.library-header-dial {
@@ -21,13 +21,14 @@
(click)="toggleEventDisplay()"
(mouseenter)="onMouseEnter()"
(mouseleave)="onMouseLeave()"
[class.pi-spin]="eventHighlight"
[class.pulsating]="eventHighlight"
[class.highlight]="eventHighlight">
<i class="pi pi-sync"></i>
<i class="pi pi-wave-pulse"></i>
</button>
<div *ngIf="showEvents" class="live-event-container" (mouseleave)="onMouseLeave()">
{{ latestEvent }}
<p *ngIf="latestEvent.timestamp">{{ latestEvent.timestamp }}</p>
<p>{{ latestEvent.message }}</p>
</div>
<button class="p-link layout-menu-button layout-topbar-button" (click)="openLibraryCreatorDialog()" pTooltip="Create New Library" tooltipPosition="top">
<i class="pi pi-plus-circle"></i>
@@ -16,7 +16,7 @@
}
.highlight {
color: var(--yellow-400) !important;
color: red !important;
}
@keyframes pulsate {
@@ -12,6 +12,7 @@ import {SearchComponent} from '../search/search.component';
import {FileUploadComponent} from '../file-upload/file-upload.component';
import {NgClass, NgIf} from '@angular/common';
import {EventService} from '../../service/event.service';
import {LogNotification} from '../../model/log-notification.model';
@Component({
selector: 'app-topbar',
@@ -31,7 +32,7 @@ export class AppTopBarComponent implements OnDestroy {
items!: MenuItem[];
ref: DynamicDialogRef | undefined;
latestEvent: string = 'No recent events...';
latestEvent: LogNotification = { message: 'No recent notifications...' };
eventHighlight: boolean = false;
showEvents: boolean = false;
eventTimeout: any;
@@ -0,0 +1,14 @@
export interface LogNotification {
timestamp?: string;
message: string;
}
export function parseLogNotification(messageBody: string): LogNotification {
const raw = JSON.parse(messageBody);
const localTime = new Date(raw.timestamp).toLocaleTimeString();
return {
timestamp: localTime,
message: raw.message,
};
}
@@ -1,11 +1,12 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {LogNotification} from '../model/log-notification.model';
@Injectable({
providedIn: 'root',
})
export class EventService {
private latestEventSubject = new BehaviorSubject<string>('No recent events...');
private latestEventSubject = new BehaviorSubject<LogNotification>({message: 'No recent notifications...'});
latestEvent$ = this.latestEventSubject.asObservable();
private eventHighlightSubject = new BehaviorSubject<boolean>(false);
@@ -13,10 +14,11 @@ export class EventService {
private eventTimeout: any;
constructor() {}
constructor() {
}
handleIncomingEvent(event: string): void {
this.latestEventSubject.next(event);
handleIncomingLog(logNotification: LogNotification): void {
this.latestEventSubject.next(logNotification);
this.eventHighlightSubject.next(true);
if (this.eventTimeout) {
@@ -25,12 +27,12 @@ export class EventService {
this.eventTimeout = setTimeout(() => {
this.eventHighlightSubject.next(false);
}, 1000);
}, 2500);
setTimeout(() => {
if (!this.eventHighlightSubject.value) {
this.latestEventSubject.next('No recent events...');
this.latestEventSubject.next({message: 'No recent notifications...'});
}
}, 2500);
}, 7500);
}
}