feat: add i18n translations for book components, services, and readers (en/es) (#2738)

This commit is contained in:
ACX
2026-02-13 16:20:02 -07:00
committed by GitHub
parent 3e44ee7d92
commit 5076522f35
108 changed files with 3406 additions and 1102 deletions
@@ -9,6 +9,7 @@ import {LoadingService} from '../../../core/services/loading.service';
import {User} from '../../settings/user-management/user.service';
import {APIException} from '../../../shared/models/api-exception.model';
import {HttpErrorResponse} from '@angular/common/http';
import {TranslocoService} from '@jsverse/transloco';
@Injectable({
providedIn: 'root'
@@ -19,6 +20,7 @@ export class BookMenuService {
messageService = inject(MessageService);
bookService = inject(BookService);
loadingService = inject(LoadingService);
private readonly t = inject(TranslocoService);
getMetadataMenuItems(
autoFetchMetadata: () => void,
@@ -34,7 +36,7 @@ export class BookMenuService {
if (permissions?.canBulkAutoFetchMetadata) {
items.push({
label: 'Auto Fetch Metadata',
label: this.t.translate('book.menuService.menu.autoFetchMetadata'),
icon: 'pi pi-bolt',
command: autoFetchMetadata
});
@@ -42,7 +44,7 @@ export class BookMenuService {
if (permissions?.canBulkCustomFetchMetadata) {
items.push({
label: 'Custom Fetch Metadata',
label: this.t.translate('book.menuService.menu.customFetchMetadata'),
icon: 'pi pi-sync',
command: fetchMetadata
});
@@ -50,12 +52,12 @@ export class BookMenuService {
if (permissions?.canBulkEditMetadata) {
items.push({
label: 'Bulk Metadata Editor',
label: this.t.translate('book.menuService.menu.bulkMetadataEditor'),
icon: 'pi pi-table',
command: bulkEditMetadata
});
items.push({
label: 'Multi-Book Metadata Editor',
label: this.t.translate('book.menuService.menu.multiBookMetadataEditor'),
icon: 'pi pi-clone',
command: multiBookEditMetadata
});
@@ -63,12 +65,12 @@ export class BookMenuService {
if (permissions?.canBulkRegenerateCover) {
items.push({
label: 'Regenerate Covers',
label: this.t.translate('book.menuService.menu.regenerateCovers'),
icon: 'pi pi-image',
command: regenerateCovers
});
items.push({
label: 'Generate Custom Covers',
label: this.t.translate('book.menuService.menu.generateCustomCovers'),
icon: 'pi pi-palette',
command: generateCustomCovers
});
@@ -84,27 +86,27 @@ export class BookMenuService {
if (permissions?.canBulkResetBookReadStatus) {
items.push({
label: 'Update Read Status',
label: this.t.translate('book.menuService.menu.updateReadStatus'),
icon: 'pi pi-book',
items: Object.entries(readStatusLabels).map(([status, label]) => ({
label,
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to mark ${count} book(s) as "${label}"?`,
header: 'Confirm Read Status Update',
message: this.t.translate('book.menuService.confirm.readStatusMessage', {count, label}),
header: this.t.translate('book.menuService.confirm.readStatusHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
acceptButtonProps: {
label: 'Yes',
label: this.t.translate('common.yes'),
severity: 'success'
},
rejectButtonProps: {
label: 'No',
label: this.t.translate('common.no'),
severity: 'secondary'
},
accept: () => {
const loader = this.loadingService.show(`Updating read status for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.updatingReadStatus', {count}));
this.bookService.updateBookReadStatus(Array.from(selectedBooks), status as ReadStatus)
.pipe(finalize(() => this.loadingService.hide(loader)))
@@ -112,8 +114,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Read Status Updated',
detail: `Marked as "${label}"`,
summary: this.t.translate('book.menuService.toast.readStatusUpdatedSummary'),
detail: this.t.translate('book.menuService.toast.readStatusUpdatedDetail', {label}),
life: 2000
});
},
@@ -121,8 +123,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: apiError?.message || 'Could not update read status.',
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.readStatusFailedDetail'),
life: 3000
});
}
@@ -136,20 +138,20 @@ export class BookMenuService {
if (permissions?.canBulkEditMetadata) {
items.push({
label: 'Set Age Rating',
label: this.t.translate('book.menuService.menu.setAgeRating'),
icon: 'pi pi-user',
items: [
...AGE_RATING_OPTIONS.map(option => ({
label: option.label,
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to set the age rating to "${option.label}" for ${count} book(s)?`,
header: 'Confirm Age Rating Update',
message: this.t.translate('book.menuService.confirm.ageRatingMessage', {label: option.label, count}),
header: this.t.translate('book.menuService.confirm.ageRatingHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Setting age rating for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.settingAgeRating', {count}));
this.bookService.updateBooksMetadata({
bookIds: Array.from(selectedBooks),
ageRating: option.id
@@ -158,8 +160,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Age Rating Updated',
detail: `Set to "${option.label}"`,
summary: this.t.translate('book.menuService.toast.ageRatingUpdatedSummary'),
detail: this.t.translate('book.menuService.toast.ageRatingUpdatedDetail', {label: option.label}),
life: 2000
});
},
@@ -167,8 +169,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: apiError?.message || 'Could not update age rating.',
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.ageRatingFailedDetail'),
life: 3000
});
}
@@ -181,17 +183,17 @@ export class BookMenuService {
separator: true
},
{
label: 'Clear Age Rating',
label: this.t.translate('book.menuService.menu.clearAgeRating'),
icon: 'pi pi-times',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to clear the age rating for ${count} book(s)?`,
header: 'Confirm Clear Age Rating',
message: this.t.translate('book.menuService.confirm.clearAgeRatingMessage', {count}),
header: this.t.translate('book.menuService.confirm.clearAgeRatingHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Clearing age rating for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.clearingAgeRating', {count}));
this.bookService.updateBooksMetadata({
bookIds: Array.from(selectedBooks),
clearAgeRating: true
@@ -200,8 +202,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Age Rating Cleared',
detail: 'Age rating has been cleared.',
summary: this.t.translate('book.menuService.toast.ageRatingClearedSummary'),
detail: this.t.translate('book.menuService.toast.ageRatingClearedDetail'),
life: 2000
});
},
@@ -209,8 +211,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: apiError?.message || 'Could not clear age rating.',
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.clearAgeRatingFailedDetail'),
life: 3000
});
}
@@ -223,20 +225,20 @@ export class BookMenuService {
});
items.push({
label: 'Set Content Rating',
label: this.t.translate('book.menuService.menu.setContentRating'),
icon: 'pi pi-shield',
items: [
...Object.entries(CONTENT_RATING_LABELS).map(([value, label]) => ({
label: label,
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to set the content rating to "${label}" for ${count} book(s)?`,
header: 'Confirm Content Rating Update',
message: this.t.translate('book.menuService.confirm.contentRatingMessage', {label, count}),
header: this.t.translate('book.menuService.confirm.contentRatingHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Setting content rating for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.settingContentRating', {count}));
this.bookService.updateBooksMetadata({
bookIds: Array.from(selectedBooks),
contentRating: value
@@ -245,8 +247,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Content Rating Updated',
detail: `Set to "${label}"`,
summary: this.t.translate('book.menuService.toast.contentRatingUpdatedSummary'),
detail: this.t.translate('book.menuService.toast.contentRatingUpdatedDetail', {label}),
life: 2000
});
},
@@ -254,8 +256,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: apiError?.message || 'Could not update content rating.',
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.contentRatingFailedDetail'),
life: 3000
});
}
@@ -268,17 +270,17 @@ export class BookMenuService {
separator: true
},
{
label: 'Clear Content Rating',
label: this.t.translate('book.menuService.menu.clearContentRating'),
icon: 'pi pi-times',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to clear the content rating for ${count} book(s)?`,
header: 'Confirm Clear Content Rating',
message: this.t.translate('book.menuService.confirm.clearContentRatingMessage', {count}),
header: this.t.translate('book.menuService.confirm.clearContentRatingHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Clearing content rating for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.clearingContentRating', {count}));
this.bookService.updateBooksMetadata({
bookIds: Array.from(selectedBooks),
clearContentRating: true
@@ -287,8 +289,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Content Rating Cleared',
detail: 'Content rating has been cleared.',
summary: this.t.translate('book.menuService.toast.contentRatingClearedSummary'),
detail: this.t.translate('book.menuService.toast.contentRatingClearedDetail'),
life: 2000
});
},
@@ -296,8 +298,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: apiError?.message || 'Could not clear content rating.',
summary: this.t.translate('book.menuService.toast.updateFailedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.clearContentRatingFailedDetail'),
life: 3000
});
}
@@ -313,17 +315,17 @@ 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',
label: this.t.translate('book.menuService.menu.removeFromAllShelves'),
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',
message: this.t.translate('book.menuService.confirm.unshelveMessage', {count}),
header: this.t.translate('book.menuService.confirm.unshelveHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Removing ${count} book(s) from shelves...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.removingFromShelves', {count}));
const books = this.bookService.getBooksByIdsFromState(Array.from(selectedBooks));
const allShelfIds = new Set<number>();
books.forEach(b => b.shelves?.forEach(s => {
@@ -332,7 +334,7 @@ export class BookMenuService {
if (allShelfIds.size === 0) {
this.loadingService.hide(loader);
this.messageService.add({ severity: 'info', summary: 'Info', detail: 'Selected books are not on any shelves.' });
this.messageService.add({ severity: 'info', summary: 'Info', detail: this.t.translate('book.menuService.toast.noBooksOnShelvesDetail') });
return;
}
@@ -340,10 +342,10 @@ export class BookMenuService {
.pipe(finalize(() => this.loadingService.hide(loader)))
.subscribe({
next: () => {
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Books removed from all shelves'});
this.messageService.add({severity: 'success', summary: this.t.translate('common.success'), detail: this.t.translate('book.menuService.toast.unshelveSuccessDetail')});
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'});
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('book.menuService.toast.unshelveFailedDetail')});
}
});
}
@@ -354,17 +356,17 @@ export class BookMenuService {
if (permissions?.canBulkResetBookloreReadProgress) {
items.push({
label: 'Reset Booklore Progress',
label: this.t.translate('book.menuService.menu.resetBookloreProgress'),
icon: 'pi pi-undo',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to reset Booklore reading progress for ${count} book(s)?`,
header: 'Confirm Reset',
message: this.t.translate('book.menuService.confirm.resetBookloreMessage', {count}),
header: this.t.translate('book.menuService.confirm.resetHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Resetting Booklore progress for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.resettingBookloreProgress', {count}));
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.BOOKLORE)
.pipe(finalize(() => this.loadingService.hide(loader)))
@@ -372,8 +374,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'Booklore reading progress has been reset.',
summary: this.t.translate('book.menuService.toast.progressResetSummary'),
detail: this.t.translate('book.menuService.toast.bookloreProgressResetDetail'),
life: 1500
});
},
@@ -381,8 +383,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: apiError?.message || 'Could not reset progress.',
summary: this.t.translate('book.menuService.toast.failedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.progressResetFailedDetail'),
life: 3000
});
}
@@ -395,17 +397,17 @@ export class BookMenuService {
if (permissions?.canBulkResetKoReaderReadProgress) {
items.push({
label: 'Reset KOReader Progress',
label: this.t.translate('book.menuService.menu.resetKOReaderProgress'),
icon: 'pi pi-undo',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to reset KOReader reading progress for ${count} book(s)?`,
header: 'Confirm Reset',
message: this.t.translate('book.menuService.confirm.resetKOReaderMessage', {count}),
header: this.t.translate('book.menuService.confirm.resetHeader'),
icon: 'pi pi-exclamation-triangle',
acceptLabel: 'Yes',
rejectLabel: 'No',
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.no'),
accept: () => {
const loader = this.loadingService.show(`Resetting KOReader progress for ${count} book(s)...`);
const loader = this.loadingService.show(this.t.translate('book.menuService.loading.resettingKOReaderProgress', {count}));
this.bookService.resetProgress(Array.from(selectedBooks), ResetProgressTypes.KOREADER)
.pipe(finalize(() => this.loadingService.hide(loader)))
@@ -413,8 +415,8 @@ export class BookMenuService {
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'KOReader reading progress has been reset.',
summary: this.t.translate('book.menuService.toast.progressResetSummary'),
detail: this.t.translate('book.menuService.toast.koreaderProgressResetDetail'),
life: 1500
});
},
@@ -422,8 +424,8 @@ export class BookMenuService {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: apiError?.message || 'Could not reset progress.',
summary: this.t.translate('book.menuService.toast.failedSummary'),
detail: apiError?.message || this.t.translate('book.menuService.toast.progressResetFailedDetail'),
life: 3000
});
}
@@ -13,6 +13,7 @@ import {Router} from '@angular/router';
import {BookStateService} from './book-state.service';
import {BookSocketService} from './book-socket.service';
import {BookPatchService} from './book-patch.service';
import {TranslocoService} from '@jsverse/transloco';
export interface BookStatusUpdateResponse {
bookId: number;
@@ -41,6 +42,7 @@ export class BookService {
private bookStateService = inject(BookStateService);
private bookSocketService = inject(BookSocketService);
private bookPatchService = inject(BookPatchService);
private readonly t = inject(TranslocoService);
private loading$: Observable<Book[]> | null = null;
@@ -210,22 +212,22 @@ export class BookService {
if (response.failedFileDeletions?.length > 0) {
this.messageService.add({
severity: 'warn',
summary: 'Some files could not be deleted',
detail: `Books: ${response.failedFileDeletions.join(', ')}`,
summary: this.t.translate('book.bookService.toast.someFilesNotDeletedSummary'),
detail: this.t.translate('book.bookService.toast.someFilesNotDeletedDetail', {fileNames: response.failedFileDeletions.join(', ')}),
});
} else {
this.messageService.add({
severity: 'success',
summary: 'Books Deleted',
detail: `${idList.length} book(s) deleted successfully.`,
summary: this.t.translate('book.bookService.toast.booksDeletedSummary'),
detail: this.t.translate('book.bookService.toast.booksDeletedDetail', {count: idList.length}),
});
}
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Delete Failed',
detail: error?.error?.message || error?.message || 'An error occurred while deleting books.',
summary: this.t.translate('book.bookService.toast.deleteFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.deleteFailedDetail'),
});
return throwError(() => error);
})
@@ -253,15 +255,15 @@ export class BookService {
});
this.messageService.add({
severity: 'success',
summary: 'Physical Book Created',
detail: `"${newBook.metadata?.title || 'Book'}" has been added to your library.`
summary: this.t.translate('book.bookService.toast.physicalBookCreatedSummary'),
detail: this.t.translate('book.bookService.toast.physicalBookCreatedDetail', {title: newBook.metadata?.title || 'Book'})
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Creation Failed',
detail: error?.error?.message || error?.message || 'An error occurred while creating the physical book.'
summary: this.t.translate('book.bookService.toast.creationFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.creationFailedDetail')
});
return throwError(() => error);
})
@@ -384,15 +386,15 @@ export class BookService {
this.messageService.add({
severity: 'success',
summary: 'File Deleted',
detail: 'Additional file deleted successfully.'
summary: this.t.translate('book.bookService.toast.fileDeletedSummary'),
detail: this.t.translate('book.bookService.toast.additionalFileDeletedDetail')
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Delete Failed',
detail: error?.error?.message || error?.message || 'An error occurred while deleting the file.'
summary: this.t.translate('book.bookService.toast.fileDeleteFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.fileDeleteFailedDetail')
});
return throwError(() => error);
})
@@ -441,15 +443,15 @@ export class BookService {
this.messageService.add({
severity: 'success',
summary: 'File Deleted',
detail: 'Book file deleted successfully.'
summary: this.t.translate('book.bookService.toast.fileDeletedSummary'),
detail: this.t.translate('book.bookService.toast.bookFileDeletedDetail')
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Delete Failed',
detail: error?.error?.message || error?.message || 'An error occurred while deleting the file.'
summary: this.t.translate('book.bookService.toast.fileDeleteFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.fileDeleteFailedDetail')
});
return throwError(() => error);
})
@@ -507,15 +509,15 @@ export class BookService {
this.messageService.add({
severity: 'success',
summary: 'File Uploaded',
detail: 'Additional file uploaded successfully.'
summary: this.t.translate('book.bookService.toast.fileUploadedSummary'),
detail: this.t.translate('book.bookService.toast.fileUploadedDetail')
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Upload Failed',
detail: error?.error?.message || error?.message || 'An error occurred while uploading the file.'
summary: this.t.translate('book.bookService.toast.uploadFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.uploadFailedDetail')
});
return throwError(() => error);
})
@@ -644,8 +646,8 @@ export class BookService {
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Field Lock Update Failed',
detail: 'Failed to update metadata field locks. Please try again.',
summary: this.t.translate('book.bookService.toast.fieldLockFailedSummary'),
detail: this.t.translate('book.bookService.toast.fieldLockFailedDetail'),
});
throw error;
})
@@ -789,15 +791,15 @@ export class BookService {
const fileCount = sourceBookIds.length;
this.messageService.add({
severity: 'success',
summary: 'Files Attached',
detail: `${fileCount} book file${fileCount > 1 ? 's have' : ' has'} been attached successfully.`
summary: this.t.translate('book.bookService.toast.filesAttachedSummary'),
detail: this.t.translate('book.bookService.toast.filesAttachedDetail', {count: fileCount})
});
}),
catchError(error => {
this.messageService.add({
severity: 'error',
summary: 'Attachment Failed',
detail: error?.error?.message || error?.message || 'An error occurred while attaching the files.'
summary: this.t.translate('book.bookService.toast.attachmentFailedSummary'),
detail: error?.error?.message || error?.message || this.t.translate('book.bookService.toast.attachmentFailedDetail')
});
return throwError(() => error);
})
@@ -13,6 +13,7 @@ import {LoadingService} from '../../../core/services/loading.service';
import {finalize} from 'rxjs';
import {DialogLauncherService} from '../../../shared/services/dialog-launcher.service';
import {BookDialogHelperService} from '../components/book-browser/book-dialog-helper.service';
import {TranslocoService} from '@jsverse/transloco';
@Injectable({
providedIn: 'root',
@@ -30,14 +31,15 @@ export class LibraryShelfMenuService {
private userService = inject(UserService);
private loadingService = inject(LoadingService);
private bookDialogHelperService = inject(BookDialogHelperService);
private readonly t = inject(TranslocoService);
initializeLibraryMenuItems(entity: Library | Shelf | MagicShelf | null): MenuItem[] {
return [
{
label: 'Options',
label: this.t.translate('book.shelfMenuService.library.optionsLabel'),
items: [
{
label: 'Add Physical Book',
label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'),
icon: 'pi pi-book',
command: () => {
this.bookDialogHelperService.openAddPhysicalBookDialog(entity?.id as number);
@@ -47,44 +49,44 @@ export class LibraryShelfMenuService {
separator: true
},
{
label: 'Edit Library',
label: this.t.translate('book.shelfMenuService.library.editLibrary'),
icon: 'pi pi-pen-to-square',
command: () => {
this.dialogLauncherService.openLibraryEditDialog((entity?.id as number));
}
},
{
label: 'Re-scan Library',
label: this.t.translate('book.shelfMenuService.library.rescanLibrary'),
icon: 'pi pi-refresh',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to refresh library: ${entity?.name}?`,
header: 'Confirmation',
message: this.t.translate('book.shelfMenuService.confirm.rescanLibraryMessage', {name: entity?.name}),
header: this.t.translate('book.shelfMenuService.confirm.header'),
icon: undefined,
acceptLabel: 'Rescan',
rejectLabel: 'Cancel',
acceptLabel: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
rejectLabel: this.t.translate('common.cancel'),
acceptIcon: undefined,
rejectIcon: undefined,
acceptButtonStyleClass: undefined,
rejectButtonStyleClass: undefined,
rejectButtonProps: {
label: 'Cancel',
label: this.t.translate('common.cancel'),
severity: 'secondary',
},
acceptButtonProps: {
label: 'Rescan',
label: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
severity: 'success',
},
accept: () => {
this.libraryService.refreshLibrary(entity?.id!).subscribe({
complete: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Library refresh scheduled'});
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshSuccessDetail')});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to refresh library',
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshFailedDetail'),
});
}
});
@@ -93,14 +95,14 @@ export class LibraryShelfMenuService {
}
},
{
label: 'Custom Fetch Metadata',
label: this.t.translate('book.shelfMenuService.library.customFetchMetadata'),
icon: 'pi pi-sync',
command: () => {
this.dialogLauncherService.openLibraryMetadataFetchDialog((entity?.id as number));
}
},
{
label: 'Auto Fetch Metadata',
label: this.t.translate('book.shelfMenuService.library.autoFetchMetadata'),
icon: 'pi pi-bolt',
command: () => {
this.taskHelperService.refreshMetadataTask({
@@ -113,37 +115,37 @@ export class LibraryShelfMenuService {
separator: true
},
{
label: 'Delete Library',
label: this.t.translate('book.shelfMenuService.library.deleteLibrary'),
icon: 'pi pi-trash',
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to delete library: ${entity?.name}?`,
header: 'Confirmation',
acceptLabel: 'Yes',
rejectLabel: 'Cancel',
message: this.t.translate('book.shelfMenuService.confirm.deleteLibraryMessage', {name: entity?.name}),
header: this.t.translate('book.shelfMenuService.confirm.header'),
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.cancel'),
rejectButtonProps: {
label: 'Cancel',
label: this.t.translate('common.cancel'),
severity: 'secondary',
},
acceptButtonProps: {
label: 'Yes',
label: this.t.translate('common.yes'),
severity: 'danger',
},
accept: () => {
const loader = this.loadingService.show(`Deleting library '${entity?.name}'...`);
const loader = this.loadingService.show(this.t.translate('book.shelfMenuService.loading.deletingLibrary', {name: entity?.name}));
this.libraryService.deleteLibrary(entity?.id!)
.pipe(finalize(() => this.loadingService.hide(loader)))
.subscribe({
complete: () => {
this.router.navigate(['/']);
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Library was deleted'});
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfMenuService.toast.libraryDeletedDetail')});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to delete library',
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
detail: this.t.translate('book.shelfMenuService.toast.libraryDeleteFailedDetail'),
});
}
});
@@ -164,10 +166,10 @@ export class LibraryShelfMenuService {
return [
{
label: (isPublicShelf ? 'Public Shelf - ' : '') + (disableOptions ? 'Read only' : 'Options'),
label: (isPublicShelf ? this.t.translate('book.shelfMenuService.shelf.publicShelfPrefix') : '') + (disableOptions ? this.t.translate('book.shelfMenuService.shelf.readOnly') : this.t.translate('book.shelfMenuService.shelf.optionsLabel')),
items: [
{
label: 'Edit Shelf',
label: this.t.translate('book.shelfMenuService.shelf.editShelf'),
icon: 'pi pi-pen-to-square',
disabled: disableOptions,
command: () => {
@@ -178,34 +180,34 @@ export class LibraryShelfMenuService {
separator: true
},
{
label: 'Delete Shelf',
label: this.t.translate('book.shelfMenuService.shelf.deleteShelf'),
icon: 'pi pi-trash',
disabled: disableOptions,
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to delete shelf: ${entity?.name}?`,
header: 'Confirmation',
acceptLabel: 'Yes',
rejectLabel: 'Cancel',
message: this.t.translate('book.shelfMenuService.confirm.deleteShelfMessage', {name: entity?.name}),
header: this.t.translate('book.shelfMenuService.confirm.header'),
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.cancel'),
acceptButtonProps: {
label: 'Yes',
label: this.t.translate('common.yes'),
severity: 'danger'
},
rejectButtonProps: {
label: 'Cancel',
label: this.t.translate('common.cancel'),
severity: 'secondary'
},
accept: () => {
this.shelfService.deleteShelf(entity?.id!).subscribe({
complete: () => {
this.router.navigate(['/']);
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Shelf was deleted'});
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfMenuService.toast.shelfDeletedDetail')});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to delete shelf',
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
detail: this.t.translate('book.shelfMenuService.toast.shelfDeleteFailedDetail'),
});
}
});
@@ -225,10 +227,10 @@ export class LibraryShelfMenuService {
return [
{
label: 'Options',
label: this.t.translate('book.shelfMenuService.magicShelf.optionsLabel'),
items: [
{
label: 'Edit Magic Shelf',
label: this.t.translate('book.shelfMenuService.magicShelf.editMagicShelf'),
icon: 'pi pi-pen-to-square',
disabled: disableOptions,
command: () => {
@@ -239,34 +241,34 @@ export class LibraryShelfMenuService {
separator: true
},
{
label: 'Delete Magic Shelf',
label: this.t.translate('book.shelfMenuService.magicShelf.deleteMagicShelf'),
icon: 'pi pi-trash',
disabled: disableOptions,
command: () => {
this.confirmationService.confirm({
message: `Are you sure you want to delete magic shelf: ${entity?.name}?`,
header: 'Confirmation',
acceptLabel: 'Yes',
rejectLabel: 'Cancel',
message: this.t.translate('book.shelfMenuService.confirm.deleteMagicShelfMessage', {name: entity?.name}),
header: this.t.translate('book.shelfMenuService.confirm.header'),
acceptLabel: this.t.translate('common.yes'),
rejectLabel: this.t.translate('common.cancel'),
acceptButtonProps: {
label: 'Yes',
label: this.t.translate('common.yes'),
severity: 'danger'
},
rejectButtonProps: {
label: 'Cancel',
label: this.t.translate('common.cancel'),
severity: 'secondary'
},
accept: () => {
this.magicShelfService.deleteShelf(entity?.id!).subscribe({
complete: () => {
this.router.navigate(['/']);
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Magic shelf was deleted'});
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfMenuService.toast.magicShelfDeletedDetail')});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Failed to delete shelf',
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
detail: this.t.translate('book.shelfMenuService.toast.magicShelfDeleteFailedDetail'),
});
}
});