Refactor confirmation dialogs to standardize button labels and styles across components (#2562)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+2
-2
@@ -391,7 +391,7 @@
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (hasBulkReadActionsItems) {
|
||||
@if (hasMoreActionsItems) {
|
||||
<div class="more-actions-wrapper">
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
@@ -401,7 +401,7 @@
|
||||
severity="info"
|
||||
icon="pi pi-ellipsis-v">
|
||||
</p-button>
|
||||
<p-tieredMenu #menu [model]="bulkReadActionsMenuItems" [popup]="true" appendTo="body"/>
|
||||
<p-tieredMenu #menu [model]="moreActionsMenuItems" [popup]="true" appendTo="body"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
+18
-11
@@ -4,7 +4,7 @@ import {ConfirmationService, MenuItem, MessageService, PrimeTemplate} from 'prim
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {debounceTime, filter, map, switchMap, takeUntil} from 'rxjs/operators';
|
||||
import {BehaviorSubject, combineLatest, finalize, Observable, of, Subject} from 'rxjs';
|
||||
import {BehaviorSubject, combineLatest, finalize, Observable, of, Subject, Subscription} from 'rxjs';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {Shelf} from '../../model/shelf.model';
|
||||
@@ -153,7 +153,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private settingFiltersFromUrl = false;
|
||||
private destroy$ = new Subject<void>();
|
||||
protected metadataMenuItems: MenuItem[] | undefined;
|
||||
protected bulkReadActionsMenuItems: MenuItem[] | undefined;
|
||||
protected moreActionsMenuItems: MenuItem[] | undefined;
|
||||
|
||||
private sideBarFilter = new SideBarFilter(this.selectedFilter, this.selectedFilterMode);
|
||||
private headerFilter = new HeaderFilter(this.searchTerm$);
|
||||
@@ -161,6 +161,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
selectedSort => this.onManualSortChange(selectedSort)
|
||||
);
|
||||
|
||||
private bookStateSubscription: Subscription | undefined;
|
||||
|
||||
@ViewChild(BookTableComponent)
|
||||
bookTableComponent!: BookTableComponent;
|
||||
@ViewChild(BookFilterComponent, {static: false})
|
||||
@@ -262,8 +264,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return this.metadataMenuItems!.length > 0;
|
||||
}
|
||||
|
||||
get hasBulkReadActionsItems(): boolean {
|
||||
return this.bulkReadActionsMenuItems!.length > 0;
|
||||
get hasMoreActionsItems(): boolean {
|
||||
return this.moreActionsMenuItems!.length > 0;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -375,7 +377,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
);
|
||||
});
|
||||
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
private setupQueryParamSubscription(): void {
|
||||
@@ -501,19 +503,19 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
onCheckboxClicked(event: CheckboxClickEvent): void {
|
||||
this.bookSelectionService.handleCheckboxClick(event);
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
handleBookSelect(book: Book, selected: boolean): void {
|
||||
this.bookSelectionService.handleBookSelection(book, selected);
|
||||
this.isDrawerVisible = this.bookSelectionService.hasSelection();
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
onSelectedBooksChange(selectedBookIds: Set<number>): void {
|
||||
this.bookSelectionService.setSelectedBooks(selectedBookIds);
|
||||
this.isDrawerVisible = this.bookSelectionService.hasSelection();
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
selectAllBooks(): void {
|
||||
@@ -521,7 +523,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
if (this.bookTableComponent) {
|
||||
this.bookTableComponent.selectAllBooks();
|
||||
}
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
@@ -530,7 +532,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
if (this.bookTableComponent) {
|
||||
this.bookTableComponent.clearSelectedBooks();
|
||||
}
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
confirmDeleteBooks(): void {
|
||||
@@ -585,9 +587,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
this.bookState$
|
||||
if (this.bookStateSubscription) {
|
||||
this.bookStateSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
this.bookStateSubscription = this.bookState$
|
||||
.pipe(
|
||||
filter(state => state.loaded && !state.error),
|
||||
takeUntil(this.destroy$),
|
||||
map(state => state.books || [])
|
||||
)
|
||||
.subscribe(books => {
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
}
|
||||
@if (hasBulkReadActionsItems) {
|
||||
@if (hasMoreActionsItems) {
|
||||
<div class="more-actions-wrapper">
|
||||
<p-button
|
||||
(click)="menu.toggle($event)"
|
||||
@@ -183,7 +183,7 @@
|
||||
severity="info"
|
||||
icon="pi pi-ellipsis-v">
|
||||
</p-button>
|
||||
<p-tieredMenu #menu [model]="bulkReadActionsMenuItems" [popup]="true" appendTo="body"/>
|
||||
<p-tieredMenu #menu [model]="moreActionsMenuItems" [popup]="true" appendTo="body"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -94,7 +94,7 @@ export class SeriesPageComponent implements OnDestroy {
|
||||
|
||||
// Menu items
|
||||
protected metadataMenuItems: MenuItem[] | undefined;
|
||||
protected bulkReadActionsMenuItems: MenuItem[] | undefined;
|
||||
protected moreActionsMenuItems: MenuItem[] | undefined;
|
||||
|
||||
seriesParam$: Observable<string> = this.route.paramMap.pipe(
|
||||
map((params) => params.get("seriesName") || ""),
|
||||
@@ -208,7 +208,7 @@ export class SeriesPageComponent implements OnDestroy {
|
||||
() => this.generateCustomCoversForSelected(),
|
||||
userState.user
|
||||
);
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -351,12 +351,12 @@ export class SeriesPageComponent implements OnDestroy {
|
||||
this.handleBookSelection(book, !isUnselectingRange);
|
||||
}
|
||||
}
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
handleBookSelect(book: Book, selected: boolean): void {
|
||||
this.handleBookSelection(book, selected);
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
selectAllBooks(): void {
|
||||
@@ -364,12 +364,12 @@ export class SeriesPageComponent implements OnDestroy {
|
||||
for (const book of this.currentBooks) {
|
||||
this.selectedBooks.add(book.id);
|
||||
}
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
this.selectedBooks.clear();
|
||||
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
|
||||
this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user());
|
||||
}
|
||||
|
||||
confirmDeleteBooks(): void {
|
||||
@@ -525,7 +525,7 @@ export class SeriesPageComponent implements OnDestroy {
|
||||
return (this.metadataMenuItems?.length ?? 0) > 0;
|
||||
}
|
||||
|
||||
get hasBulkReadActionsItems(): boolean {
|
||||
return (this.bulkReadActionsMenuItems?.length ?? 0) > 0;
|
||||
get hasMoreActionsItems(): boolean {
|
||||
return (this.moreActionsMenuItems?.length ?? 0) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class BookMenuService {
|
||||
return items;
|
||||
}
|
||||
|
||||
getBulkReadActionsMenu(selectedBooks: Set<number>, user: User | null): MenuItem[] {
|
||||
getMoreActionsMenu(selectedBooks: Set<number>, user: User | null): MenuItem[] {
|
||||
const count = selectedBooks.size;
|
||||
const permissions = user?.permissions;
|
||||
const items: MenuItem[] = [];
|
||||
@@ -134,6 +134,48 @@ export class BookMenuService {
|
||||
});
|
||||
}
|
||||
|
||||
// Shelf Actions
|
||||
if (permissions?.canManageLibrary || permissions?.admin) { // Assuming these permissions cover shelf management for books
|
||||
items.push({
|
||||
label: 'Remove from all shelves',
|
||||
icon: 'pi pi-bookmark-fill', // Or bookmark-slash
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to remove ${count} book(s) from ALL their shelves?`,
|
||||
header: 'Confirm Unshelve',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptLabel: 'Yes',
|
||||
rejectLabel: 'No',
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(`Removing ${count} book(s) from shelves...`);
|
||||
const books = this.bookService.getBooksByIdsFromState(Array.from(selectedBooks));
|
||||
const allShelfIds = new Set<number>();
|
||||
books.forEach(b => b.shelves?.forEach(s => {
|
||||
if (s.id) allShelfIds.add(s.id);
|
||||
}));
|
||||
|
||||
if (allShelfIds.size === 0) {
|
||||
this.loadingService.hide(loader);
|
||||
this.messageService.add({ severity: 'info', summary: 'Info', detail: 'Selected books are not on any shelves.' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookService.updateBookShelves(selectedBooks, new Set(), allShelfIds)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Books removed from all shelves'});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (permissions?.canBulkResetBookloreReadProgress) {
|
||||
items.push({
|
||||
label: 'Reset Booklore Progress',
|
||||
|
||||
Reference in New Issue
Block a user