Make left menu work
This commit is contained in:
@@ -50,43 +50,46 @@ public class LibraryService {
|
||||
Set<String> deletedPaths = currentPaths.stream().filter(path -> !updatedPaths.contains(path)).collect(Collectors.toSet());
|
||||
Set<String> newPaths = updatedPaths.stream().filter(path -> !currentPaths.contains(path)).collect(Collectors.toSet());
|
||||
|
||||
if (!deletedPaths.isEmpty()) {
|
||||
Set<LibraryPathEntity> pathsToRemove = library.getLibraryPaths().stream()
|
||||
.filter(pathEntity -> deletedPaths.contains(pathEntity.getPath()))
|
||||
.collect(Collectors.toSet());
|
||||
library.getLibraryPaths().removeAll(pathsToRemove);
|
||||
if(newPaths.isEmpty() && deletedPaths.isEmpty()) {
|
||||
return libraryMapper.toLibrary(libraryRepository.save(library));
|
||||
} else {
|
||||
if (!deletedPaths.isEmpty()) {
|
||||
Set<LibraryPathEntity> pathsToRemove = library.getLibraryPaths().stream()
|
||||
.filter(pathEntity -> deletedPaths.contains(pathEntity.getPath()))
|
||||
.collect(Collectors.toSet());
|
||||
library.getLibraryPaths().removeAll(pathsToRemove);
|
||||
|
||||
List<Long> books = bookRepository.findAllBookIdsByLibraryPathIdIn(pathsToRemove.stream().map(LibraryPathEntity::getId).collect(Collectors.toSet()));
|
||||
if (!books.isEmpty()) {
|
||||
notificationService.sendMessage(Topic.BOOKS_REMOVE, books);
|
||||
List<Long> books = bookRepository.findAllBookIdsByLibraryPathIdIn(pathsToRemove.stream().map(LibraryPathEntity::getId).collect(Collectors.toSet()));
|
||||
if (!books.isEmpty()) {
|
||||
notificationService.sendMessage(Topic.BOOKS_REMOVE, books);
|
||||
}
|
||||
|
||||
libraryPathRepository.deleteAll(pathsToRemove);
|
||||
libraryPathRepository.saveAll(library.getLibraryPaths());
|
||||
libraryRepository.save(library);
|
||||
}
|
||||
|
||||
libraryPathRepository.deleteAll(pathsToRemove);
|
||||
libraryPathRepository.saveAll(library.getLibraryPaths());
|
||||
libraryRepository.save(library);
|
||||
if (!newPaths.isEmpty()) {
|
||||
Set<LibraryPathEntity> newPathEntities = newPaths.stream()
|
||||
.map(path -> LibraryPathEntity.builder().path(path).library(library).build())
|
||||
.collect(Collectors.toSet());
|
||||
library.getLibraryPaths().addAll(newPathEntities);
|
||||
libraryPathRepository.saveAll(library.getLibraryPaths());
|
||||
libraryRepository.save(library);
|
||||
|
||||
Thread.startVirtualThread(() -> {
|
||||
try {
|
||||
libraryProcessingService.processLibrary(libraryId);
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
log.warn("InvalidDataAccessApiUsageException - Library id: {}", libraryId);
|
||||
} catch (IOException e) {
|
||||
log.error("Error while parsing library books", e);
|
||||
}
|
||||
log.info("Parsing task completed!");
|
||||
});
|
||||
}
|
||||
return libraryMapper.toLibrary(libraryRepository.save(library));
|
||||
}
|
||||
|
||||
if (!newPaths.isEmpty()) {
|
||||
Set<LibraryPathEntity> newPathEntities = newPaths.stream()
|
||||
.map(path -> LibraryPathEntity.builder().path(path).library(library).build())
|
||||
.collect(Collectors.toSet());
|
||||
library.getLibraryPaths().addAll(newPathEntities);
|
||||
libraryPathRepository.saveAll(library.getLibraryPaths());
|
||||
libraryRepository.save(library);
|
||||
|
||||
Thread.startVirtualThread(() -> {
|
||||
try {
|
||||
libraryProcessingService.processLibrary(libraryId);
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
log.warn("InvalidDataAccessApiUsageException - Library id: {}", libraryId);
|
||||
} catch (IOException e) {
|
||||
log.error("Error while parsing library books", e);
|
||||
}
|
||||
log.info("Parsing task completed!");
|
||||
});
|
||||
}
|
||||
|
||||
return libraryMapper.toLibrary(library);
|
||||
}
|
||||
|
||||
public Library createLibrary(CreateLibraryRequest request) {
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
</i>
|
||||
</a>
|
||||
|
||||
<a class="topbar-items topbar-item">
|
||||
<i
|
||||
class="pi pi-sort"
|
||||
pTooltip="Select sorting"
|
||||
tooltipPosition="top">
|
||||
</i>
|
||||
</a>
|
||||
|
||||
<a class="topbar-items topbar-item" (click)="toggleTableGrid()">
|
||||
<i
|
||||
[ngClass]="viewIcon"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||
import {AsyncPipe, NgForOf, NgIf} from '@angular/common';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
@@ -7,6 +7,7 @@ import {Observable, of} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {ShelfService} from '../../../book/service/shelf.service';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {LibraryShelfMenuService} from '../../../book/service/library-shelf-menu.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu',
|
||||
@@ -18,8 +19,11 @@ export class AppMenuComponent implements OnInit {
|
||||
shelfMenu$: Observable<any> | undefined;
|
||||
homeMenu$: Observable<any> | undefined;
|
||||
|
||||
constructor(private libraryService: LibraryService, private shelfService: ShelfService, private bookService: BookService) {
|
||||
}
|
||||
private libraryService = inject(LibraryService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private bookService = inject(BookService);
|
||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
|
||||
@@ -28,7 +32,9 @@ export class AppMenuComponent implements OnInit {
|
||||
label: 'Library',
|
||||
separator: false,
|
||||
items: state.libraries?.map((library) => ({
|
||||
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library),
|
||||
label: library.name,
|
||||
type: 'Library',
|
||||
icon: 'pi pi-' + library.icon,
|
||||
routerLink: [`/library/${library.id}/books`],
|
||||
bookCount$: this.libraryService.getBookCount(library.id ?? 0),
|
||||
@@ -43,7 +49,9 @@ export class AppMenuComponent implements OnInit {
|
||||
label: 'Shelves',
|
||||
separator: false,
|
||||
items: state.shelves?.map((shelf) => ({
|
||||
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(shelf),
|
||||
label: shelf.name,
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||
@@ -66,6 +74,7 @@ export class AppMenuComponent implements OnInit {
|
||||
},
|
||||
{
|
||||
label: 'All Books',
|
||||
type: 'All Books',
|
||||
icon: 'pi pi-fw pi-book',
|
||||
routerLink: ['/all-books'],
|
||||
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
||||
|
||||
@@ -28,19 +28,30 @@
|
||||
</span>
|
||||
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||
</a>
|
||||
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false" class="book-count">
|
||||
<p-button
|
||||
(mouseover)="hovered = true"
|
||||
(mouseleave)="hovered = false"
|
||||
[text]="true"
|
||||
[outlined]="false"
|
||||
[rounded]="true"
|
||||
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
|
||||
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
||||
[style.width]="'30px'"
|
||||
[style.height]="'30px'"
|
||||
[style.display]="'flex'">
|
||||
</p-button>
|
||||
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false">
|
||||
<ng-container *ngIf="item.type === 'Library' || item.type === 'Shelf'">
|
||||
<p-button
|
||||
(click)="entitymenu.toggle($event)"
|
||||
(mouseover)="hovered = true"
|
||||
(mouseleave)="hovered = false"
|
||||
[text]="true"
|
||||
[outlined]="false"
|
||||
[rounded]="true"
|
||||
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
|
||||
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
||||
[style.width]="'30px'"
|
||||
[style.height]="'30px'"
|
||||
[style.display]="'flex'">
|
||||
</p-button>
|
||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="item.type === 'All Books'">
|
||||
<p
|
||||
class="text-[var(--primary-color)] pr-1">
|
||||
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
||||
</p>
|
||||
</ng-container>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,119 +7,122 @@ import {MenuService} from './service/app.menu.service';
|
||||
import {AsyncPipe, NgClass, NgForOf, NgIf} from '@angular/common';
|
||||
import {Ripple} from 'primeng/ripple';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
|
||||
@Component({
|
||||
selector: '[app-menuitem]',
|
||||
templateUrl: './app.menuitem.component.html',
|
||||
styleUrl: './app.menuitem.component.scss',
|
||||
imports: [
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
NgClass,
|
||||
NgForOf,
|
||||
Ripple,
|
||||
NgIf,
|
||||
AsyncPipe,
|
||||
Button
|
||||
],
|
||||
animations: [
|
||||
trigger('children', [
|
||||
state('collapsed', style({
|
||||
height: '0'
|
||||
})),
|
||||
state('expanded', style({
|
||||
height: '*'
|
||||
})),
|
||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||
])
|
||||
]
|
||||
selector: '[app-menuitem]',
|
||||
templateUrl: './app.menuitem.component.html',
|
||||
styleUrl: './app.menuitem.component.scss',
|
||||
imports: [
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
NgClass,
|
||||
NgForOf,
|
||||
Ripple,
|
||||
NgIf,
|
||||
AsyncPipe,
|
||||
Button,
|
||||
Menu
|
||||
],
|
||||
animations: [
|
||||
trigger('children', [
|
||||
state('collapsed', style({
|
||||
height: '0'
|
||||
})),
|
||||
state('expanded', style({
|
||||
height: '*'
|
||||
})),
|
||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||
])
|
||||
]
|
||||
})
|
||||
export class AppMenuitemComponent implements OnInit, OnDestroy {
|
||||
@Input() item: any;
|
||||
@Input() index!: number;
|
||||
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||
@Input() parentKey!: string;
|
||||
@Input() item: any;
|
||||
@Input() index!: number;
|
||||
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||
@Input() parentKey!: string;
|
||||
|
||||
hovered = false;
|
||||
hovered = false;
|
||||
|
||||
active = false;
|
||||
menuSourceSubscription: Subscription;
|
||||
menuResetSubscription: Subscription;
|
||||
key: string = "";
|
||||
active = false;
|
||||
menuSourceSubscription: Subscription;
|
||||
menuResetSubscription: Subscription;
|
||||
key: string = "";
|
||||
|
||||
constructor(public router: Router, private menuService: MenuService) {
|
||||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||
Promise.resolve(null).then(() => {
|
||||
if (value.routeEvent) {
|
||||
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
|
||||
} else {
|
||||
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
|
||||
constructor(public router: Router, private menuService: MenuService) {
|
||||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||
Promise.resolve(null).then(() => {
|
||||
if (value.routeEvent) {
|
||||
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
|
||||
} else {
|
||||
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
|
||||
this.active = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
});
|
||||
}
|
||||
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
|
||||
this.active = false;
|
||||
});
|
||||
|
||||
ngOnInit() {
|
||||
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateActiveStateFromRoute() {
|
||||
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
||||
paths: 'exact',
|
||||
queryParams: 'ignored',
|
||||
matrixParams: 'ignored',
|
||||
fragment: 'ignored'
|
||||
});
|
||||
if (activeRoute) {
|
||||
this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
|
||||
}
|
||||
ngOnInit() {
|
||||
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
}
|
||||
|
||||
itemClick(event: Event) {
|
||||
if (this.item.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (this.item.command) {
|
||||
this.item.command({originalEvent: event, item: this.item});
|
||||
}
|
||||
if (this.item.items) {
|
||||
this.active = !this.active;
|
||||
}
|
||||
this.menuService.onMenuStateChange({key: this.key});
|
||||
updateActiveStateFromRoute() {
|
||||
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
||||
paths: 'exact',
|
||||
queryParams: 'ignored',
|
||||
matrixParams: 'ignored',
|
||||
fragment: 'ignored'
|
||||
});
|
||||
if (activeRoute) {
|
||||
this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
|
||||
}
|
||||
}
|
||||
|
||||
get submenuAnimation() {
|
||||
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
||||
itemClick(event: Event) {
|
||||
if (this.item.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (this.item.command) {
|
||||
this.item.command({originalEvent: event, item: this.item});
|
||||
}
|
||||
if (this.item.items) {
|
||||
this.active = !this.active;
|
||||
}
|
||||
this.menuService.onMenuStateChange({key: this.key});
|
||||
}
|
||||
|
||||
@HostBinding('class.active-menuitem')
|
||||
get activeClass() {
|
||||
return this.active && !this.root;
|
||||
}
|
||||
get submenuAnimation() {
|
||||
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.menuSourceSubscription) {
|
||||
this.menuSourceSubscription.unsubscribe();
|
||||
}
|
||||
if (this.menuResetSubscription) {
|
||||
this.menuResetSubscription.unsubscribe();
|
||||
}
|
||||
@HostBinding('class.active-menuitem')
|
||||
get activeClass() {
|
||||
return this.active && !this.root;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.menuSourceSubscription) {
|
||||
this.menuSourceSubscription.unsubscribe();
|
||||
}
|
||||
if (this.menuResetSubscription) {
|
||||
this.menuResetSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<div class="topbar-right-items">
|
||||
<app-book-searcher></app-book-searcher>
|
||||
<ul class="topbar-items">
|
||||
<ul class="topbar-items pl-6">
|
||||
<div class="flex gap-6">
|
||||
<li>
|
||||
<a class="topbar-item">
|
||||
|
||||
Reference in New Issue
Block a user