Implement notification mechanism
This commit is contained in:
+1
@@ -69,6 +69,7 @@ public class LibraryProcessingService {
|
|||||||
if (bookDTO != null) {
|
if (bookDTO != null) {
|
||||||
BookNotification notification = BookNotification.builder().action(BOOK_ADDED).addedBook(bookDTO).build();
|
BookNotification notification = BookNotification.builder().action(BOOK_ADDED).addedBook(bookDTO).build();
|
||||||
notificationService.sendMessage("/topic/books", notification);
|
notificationService.sendMessage("/topic/books", notification);
|
||||||
|
notificationService.sendMessage("/topic/logs", "Book added: " + bookDTO.getFileName());
|
||||||
log.info("Processed file: {}", libraryFile.getFilePath());
|
log.info("Processed file: {}", libraryFile.getFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ spring:
|
|||||||
hibernate:
|
hibernate:
|
||||||
naming:
|
naming:
|
||||||
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
show-sql: true
|
show-sql: false
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
jdbc:
|
jdbc:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {RxStompService} from './book/service/rx-stomp.service';
|
|||||||
import {Message} from '@stomp/stompjs';
|
import {Message} from '@stomp/stompjs';
|
||||||
import {BookService} from './book/service/book.service';
|
import {BookService} from './book/service/book.service';
|
||||||
import {Action, parseBookNotification} from './book/model/book-notification.model';
|
import {Action, parseBookNotification} from './book/model/book-notification.model';
|
||||||
|
import {EventService} from './book/service/event.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -12,7 +13,7 @@ import {Action, parseBookNotification} from './book/model/book-notification.mode
|
|||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private bookService: BookService, private rxStompService: RxStompService) {
|
constructor(private bookService: BookService, private rxStompService: RxStompService, private eventService: EventService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -24,6 +25,10 @@ export class AppComponent implements OnInit {
|
|||||||
this.bookService.handleRemovedBookIds(notification.removedBookIds!);
|
this.bookService.handleRemovedBookIds(notification.removedBookIds!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.rxStompService.watch('/topic/logs').subscribe((message: Message) => {
|
||||||
|
this.eventService.handleIncomingEvent(message.body);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage() {
|
sendMessage() {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<div class="layout-topbar">
|
<div class="layout-topbar">
|
||||||
|
|
||||||
<a class="layout-topbar-logo" routerLink="">
|
<a class="layout-topbar-logo" routerLink="">
|
||||||
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
|
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg" alt="logo">
|
||||||
alt="logo">
|
|
||||||
<span>BookLore</span>
|
<span>BookLore</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -19,20 +17,25 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div #topbarmenu class="layout-topbar-menu">
|
<div #topbarmenu class="layout-topbar-menu">
|
||||||
<button
|
<button class="p-link layout-topbar-button"
|
||||||
class="p-link layout-menu-button layout-topbar-button"
|
(click)="toggleEventDisplay()"
|
||||||
(click)="openLibraryCreatorDialog()"
|
(mouseenter)="onMouseEnter()"
|
||||||
pTooltip="Create New Library"
|
(mouseleave)="onMouseLeave()"
|
||||||
tooltipPosition="top">
|
[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>
|
<i class="pi pi-plus-circle"></i>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button (click)="openFileUploadDialog()" class="p-link layout-topbar-button">
|
||||||
(click)="openFileUploadDialog()"
|
|
||||||
class="p-link layout-topbar-button">
|
|
||||||
<i class="pi pi-upload"></i>
|
<i class="pi pi-upload"></i>
|
||||||
<span>Profile</span>
|
<span>Profile</span>
|
||||||
</button>
|
</button>
|
||||||
<app-notification></app-notification>
|
|
||||||
<div class="top-bar-app-theme-switcher">
|
<div class="top-bar-app-theme-switcher">
|
||||||
<app-theme-switcher></app-theme-switcher>
|
<app-theme-switcher></app-theme-switcher>
|
||||||
</div>
|
</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 {FormsModule} from '@angular/forms';
|
||||||
import {InputTextModule} from 'primeng/inputtext';
|
import {InputTextModule} from 'primeng/inputtext';
|
||||||
import {SearchComponent} from '../search/search.component';
|
import {SearchComponent} from '../search/search.component';
|
||||||
import {NotificationComponent} from '../notification/notification.component';
|
|
||||||
import {FileUploadComponent} from '../file-upload/file-upload.component';
|
import {FileUploadComponent} from '../file-upload/file-upload.component';
|
||||||
|
import {NgClass, NgIf} from '@angular/common';
|
||||||
|
import {EventService} from '../../service/event.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-topbar',
|
selector: 'app-topbar',
|
||||||
|
templateUrl: './app.topbar.component.html',
|
||||||
|
styleUrls: ['./app.topbar.component.scss'],
|
||||||
imports: [
|
imports: [
|
||||||
RouterLink,
|
RouterLink,
|
||||||
TooltipModule,
|
TooltipModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
InputTextModule,
|
InputTextModule,
|
||||||
SearchComponent,
|
SearchComponent,
|
||||||
NotificationComponent,
|
ThemeSwitcherComponent,
|
||||||
ThemeSwitcherComponent
|
NgIf
|
||||||
],
|
],
|
||||||
templateUrl: './app.topbar.component.html',
|
|
||||||
})
|
})
|
||||||
export class AppTopBarComponent implements OnDestroy {
|
export class AppTopBarComponent implements OnDestroy {
|
||||||
items!: MenuItem[];
|
items!: MenuItem[];
|
||||||
ref: DynamicDialogRef | undefined;
|
ref: DynamicDialogRef | undefined;
|
||||||
|
|
||||||
|
latestEvent: string = 'No recent events...';
|
||||||
|
eventHighlight: boolean = false;
|
||||||
|
showEvents: boolean = false;
|
||||||
|
eventTimeout: any;
|
||||||
|
|
||||||
@ViewChild('menubutton') menuButton!: ElementRef;
|
@ViewChild('menubutton') menuButton!: ElementRef;
|
||||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||||
@ViewChild('topbarmenu') menu!: 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 {
|
openLibraryCreatorDialog(): void {
|
||||||
@@ -60,5 +85,6 @@ export class AppTopBarComponent implements OnDestroy {
|
|||||||
if (this.ref) {
|
if (this.ref) {
|
||||||
this.ref.close();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user