Implement notification mechanism

This commit is contained in:
aditya.chandel
2024-12-27 00:09:19 -07:00
parent e08cd4e8d3
commit ea716bfb69
10 changed files with 129 additions and 70 deletions
@@ -69,6 +69,7 @@ public class LibraryProcessingService {
if (bookDTO != null) {
BookNotification notification = BookNotification.builder().action(BOOK_ADDED).addedBook(bookDTO).build();
notificationService.sendMessage("/topic/books", notification);
notificationService.sendMessage("/topic/logs", "Book added: " + bookDTO.getFileName());
log.info("Processed file: {}", libraryFile.getFilePath());
}
}
@@ -22,7 +22,7 @@ spring:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
show-sql: true
show-sql: false
properties:
hibernate:
jdbc:
+6 -1
View File
@@ -3,6 +3,7 @@ import {RxStompService} from './book/service/rx-stomp.service';
import {Message} from '@stomp/stompjs';
import {BookService} from './book/service/book.service';
import {Action, parseBookNotification} from './book/model/book-notification.model';
import {EventService} from './book/service/event.service';
@Component({
selector: 'app-root',
@@ -12,7 +13,7 @@ import {Action, parseBookNotification} from './book/model/book-notification.mode
})
export class AppComponent implements OnInit {
constructor(private bookService: BookService, private rxStompService: RxStompService) {
constructor(private bookService: BookService, private rxStompService: RxStompService, private eventService: EventService) {
}
ngOnInit(): void {
@@ -24,6 +25,10 @@ export class AppComponent implements OnInit {
this.bookService.handleRemovedBookIds(notification.removedBookIds!);
}
});
this.rxStompService.watch('/topic/logs').subscribe((message: Message) => {
this.eventService.handleIncomingEvent(message.body);
});
}
sendMessage() {
@@ -1,8 +1,6 @@
<div class="layout-topbar">
<a class="layout-topbar-logo" routerLink="">
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
alt="logo">
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg" alt="logo">
<span>BookLore</span>
</a>
@@ -19,20 +17,25 @@
</button>
<div #topbarmenu class="layout-topbar-menu">
<button
class="p-link layout-menu-button layout-topbar-button"
(click)="openLibraryCreatorDialog()"
pTooltip="Create New Library"
tooltipPosition="top">
<button class="p-link layout-topbar-button"
(click)="toggleEventDisplay()"
(mouseenter)="onMouseEnter()"
(mouseleave)="onMouseLeave()"
[class.pi-spin]="eventHighlight"
[class.highlight]="eventHighlight">
<i class="pi pi-sync"></i>
</button>
<div *ngIf="showEvents" class="live-event-container" (mouseleave)="onMouseLeave()">
{{ latestEvent }}
</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>
</button>
<button
(click)="openFileUploadDialog()"
class="p-link layout-topbar-button">
<button (click)="openFileUploadDialog()" class="p-link layout-topbar-button">
<i class="pi pi-upload"></i>
<span>Profile</span>
</button>
<app-notification></app-notification>
<div class="top-bar-app-theme-switcher">
<app-theme-switcher></app-theme-switcher>
</div>
@@ -0,0 +1,39 @@
.live-event-container {
position: absolute;
top: 50px;
right: 0;
width: 500px;
background: var(--surface-border);
border: 1px solid var(--primary-800);
border-radius: 4px;
padding: 10px;
box-shadow: 0px 3px 5px rgba(0, 0, 0, .02), 0px 0px 2px rgba(0, 0, 0, .05), 0px 1px 4px rgba(0, 0, 0, .08);
color: var(--text-color);
overflow-x: hidden;
z-index: 1000;
word-wrap: break-word;
white-space: normal;
}
.highlight {
color: var(--yellow-400) !important;
}
@keyframes pulsate {
0% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.25);
opacity: 0.8;
}
100% {
transform: scale(1);
opacity: 1;
}
}
.pulsating {
animation: pulsate 1.5s infinite ease-in-out;
}
@@ -9,31 +9,56 @@ import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
import {SearchComponent} from '../search/search.component';
import {NotificationComponent} from '../notification/notification.component';
import {FileUploadComponent} from '../file-upload/file-upload.component';
import {NgClass, NgIf} from '@angular/common';
import {EventService} from '../../service/event.service';
@Component({
selector: 'app-topbar',
templateUrl: './app.topbar.component.html',
styleUrls: ['./app.topbar.component.scss'],
imports: [
RouterLink,
TooltipModule,
FormsModule,
InputTextModule,
SearchComponent,
NotificationComponent,
ThemeSwitcherComponent
ThemeSwitcherComponent,
NgIf
],
templateUrl: './app.topbar.component.html',
})
export class AppTopBarComponent implements OnDestroy {
items!: MenuItem[];
ref: DynamicDialogRef | undefined;
latestEvent: string = 'No recent events...';
eventHighlight: boolean = false;
showEvents: boolean = false;
eventTimeout: any;
@ViewChild('menubutton') menuButton!: ElementRef;
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
@ViewChild('topbarmenu') menu!: ElementRef;
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService) {
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService, private eventService: EventService) {
this.eventService.latestEvent$.subscribe(event => {
this.latestEvent = event;
});
this.eventService.eventHighlight$.subscribe(highlight => {
this.eventHighlight = highlight;
});
}
onMouseEnter() {
this.showEvents = true;
}
onMouseLeave() {
this.showEvents = false;
}
toggleEventDisplay(): void {
this.showEvents = !this.showEvents;
}
openLibraryCreatorDialog(): void {
@@ -60,5 +85,6 @@ export class AppTopBarComponent implements OnDestroy {
if (this.ref) {
this.ref.close();
}
clearTimeout(this.eventTimeout);
}
}
@@ -1,6 +0,0 @@
<button
class="p-link layout-topbar-button"
[ngClass]="{'glowing-icon': glowing}">
<i class="pi pi-bolt"></i>
<span>Progress</span>
</button>
@@ -1,3 +0,0 @@
.glowing-icon {
color: yellow;
}
@@ -1,42 +0,0 @@
import {Component, OnInit, OnDestroy} from '@angular/core';
import {Subscription} from 'rxjs';
import {NgClass} from '@angular/common';
import {BookUpdateEvent} from '../../model/book.model';
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
imports: [
NgClass
],
styleUrls: ['./notification.component.scss']
})
export class NotificationComponent implements OnInit, OnDestroy {
glowing: boolean = false;
private eventSubscription!: Subscription;
ngOnInit(): void {
/*this.eventSubscription = this.bookProgressService.connect(1).subscribe({
next: (event: BookUpdateEvent) => {
this.handleNewNotification(event);
},
error: (error) => {
console.error('Error receiving progress updates:', error);
}
});*/
}
handleNewNotification(event: BookUpdateEvent): void {
this.glowing = true;
setTimeout(() => {
this.glowing = false;
console.log("reset")
}, 200);
}
ngOnDestroy(): void {
if (this.eventSubscription) {
this.eventSubscription.unsubscribe();
}
}
}
@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class EventService {
private latestEventSubject = new BehaviorSubject<string>('No recent events...');
latestEvent$ = this.latestEventSubject.asObservable();
private eventHighlightSubject = new BehaviorSubject<boolean>(false);
eventHighlight$ = this.eventHighlightSubject.asObservable();
private eventTimeout: any;
constructor() {}
handleIncomingEvent(event: string): void {
this.latestEventSubject.next(event);
this.eventHighlightSubject.next(true);
if (this.eventTimeout) {
clearTimeout(this.eventTimeout);
}
this.eventTimeout = setTimeout(() => {
this.eventHighlightSubject.next(false);
}, 1000);
setTimeout(() => {
if (!this.eventHighlightSubject.value) {
this.latestEventSubject.next('No recent events...');
}
}, 2500);
}
}