fix(frontend): unify custom metadata fetch dialog flow (#1088)
Co-authored-by: Alex <25013571+alexhb1@users.noreply.github.com>
This commit is contained in:
+16
-2
@@ -19,6 +19,12 @@ import {AddPhysicalBookDialogComponent} from '../add-physical-book-dialog/add-ph
|
||||
import {BulkIsbnImportDialogComponent} from '../bulk-isbn-import-dialog/bulk-isbn-import-dialog.component';
|
||||
import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component';
|
||||
|
||||
interface MetadataRefreshDialogContext {
|
||||
metadataRefreshType: MetadataRefreshType;
|
||||
bookIds?: number[];
|
||||
libraryId?: number;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BookDialogHelperService {
|
||||
|
||||
@@ -75,12 +81,20 @@ export class BookDialogHelperService {
|
||||
}
|
||||
|
||||
openMetadataRefreshDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
||||
return this.openMetadataRefreshDialogWithContext({
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: Array.from(bookIds)
|
||||
});
|
||||
}
|
||||
|
||||
openMetadataRefreshDialogWithContext(context: MetadataRefreshDialogContext): DynamicDialogRef | null {
|
||||
return this.openDialog(MultiBookMetadataFetchComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||
data: {
|
||||
bookIds: Array.from(bookIds),
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: context.bookIds ?? [],
|
||||
libraryId: context.libraryId,
|
||||
metadataRefreshType: context.metadataRefreshType,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ describe('LibraryShelfMenuService', () => {
|
||||
};
|
||||
const dialogLauncherService = {
|
||||
openLibraryEditDialog: vi.fn(),
|
||||
openLibraryMetadataFetchDialog: vi.fn(),
|
||||
openShelfEditDialog: vi.fn(),
|
||||
openMagicShelfEditDialog: vi.fn(),
|
||||
};
|
||||
@@ -103,6 +102,7 @@ describe('LibraryShelfMenuService', () => {
|
||||
openAddPhysicalBookDialog: vi.fn(),
|
||||
openBulkIsbnImportDialog: vi.fn(),
|
||||
openDuplicateMergerDialog: vi.fn(),
|
||||
openMetadataRefreshDialogWithContext: vi.fn(),
|
||||
};
|
||||
const translocoService = {
|
||||
translate: vi.fn((key: string) => key),
|
||||
@@ -143,7 +143,6 @@ describe('LibraryShelfMenuService', () => {
|
||||
userService.getCurrentUser.mockClear();
|
||||
router.navigate.mockClear();
|
||||
dialogLauncherService.openLibraryEditDialog.mockClear();
|
||||
dialogLauncherService.openLibraryMetadataFetchDialog.mockClear();
|
||||
dialogLauncherService.openShelfEditDialog.mockClear();
|
||||
dialogLauncherService.openMagicShelfEditDialog.mockClear();
|
||||
magicShelfService.deleteShelf.mockClear();
|
||||
@@ -152,6 +151,7 @@ describe('LibraryShelfMenuService', () => {
|
||||
bookDialogHelperService.openAddPhysicalBookDialog.mockClear();
|
||||
bookDialogHelperService.openBulkIsbnImportDialog.mockClear();
|
||||
bookDialogHelperService.openDuplicateMergerDialog.mockClear();
|
||||
bookDialogHelperService.openMetadataRefreshDialogWithContext.mockClear();
|
||||
translocoService.translate.mockClear();
|
||||
});
|
||||
|
||||
@@ -179,7 +179,7 @@ describe('LibraryShelfMenuService', () => {
|
||||
expect(bookDialogHelperService.openBulkIsbnImportDialog).not.toHaveBeenCalled();
|
||||
expect(bookDialogHelperService.openDuplicateMergerDialog).not.toHaveBeenCalled();
|
||||
expect(dialogLauncherService.openLibraryEditDialog).not.toHaveBeenCalled();
|
||||
expect(dialogLauncherService.openLibraryMetadataFetchDialog).not.toHaveBeenCalled();
|
||||
expect(bookDialogHelperService.openMetadataRefreshDialogWithContext).not.toHaveBeenCalled();
|
||||
expect(taskHelperService.refreshMetadataTask).not.toHaveBeenCalled();
|
||||
expect(confirmationService.confirm).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -199,7 +199,10 @@ describe('LibraryShelfMenuService', () => {
|
||||
expect(bookDialogHelperService.openAddPhysicalBookDialog).toHaveBeenCalledWith(42);
|
||||
expect(bookDialogHelperService.openBulkIsbnImportDialog).toHaveBeenCalledWith(42);
|
||||
expect(dialogLauncherService.openLibraryEditDialog).toHaveBeenCalledWith(42);
|
||||
expect(dialogLauncherService.openLibraryMetadataFetchDialog).toHaveBeenCalledWith(42);
|
||||
expect(bookDialogHelperService.openMetadataRefreshDialogWithContext).toHaveBeenCalledWith({
|
||||
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
||||
libraryId: 42
|
||||
});
|
||||
expect(taskHelperService.refreshMetadataTask).toHaveBeenCalledWith({
|
||||
refreshType: MetadataRefreshType.LIBRARY,
|
||||
libraryId: 42,
|
||||
|
||||
@@ -36,177 +36,176 @@ export class LibraryShelfMenuService {
|
||||
|
||||
initializeLibraryMenuItems(entity: Library | null): MenuItem[] {
|
||||
const libraryId = entity?.id;
|
||||
const disableLibraryActions = libraryId == null;
|
||||
|
||||
return [
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'),
|
||||
icon: 'pi pi-book',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.bulkIsbnImport'),
|
||||
icon: 'pi pi-barcode',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.editLibrary'),
|
||||
icon: 'pi pi-pen-to-square',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dialogLauncherService.openLibraryEditDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.rescanLibrary'),
|
||||
icon: 'pi pi-refresh',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.shelfMenuService.confirm.rescanLibraryMessage', {name: entity?.name}),
|
||||
header: this.t.translate('book.shelfMenuService.confirm.header'),
|
||||
icon: undefined,
|
||||
acceptLabel: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptIcon: undefined,
|
||||
rejectIcon: undefined,
|
||||
acceptButtonStyleClass: undefined,
|
||||
rejectButtonStyleClass: undefined,
|
||||
rejectButtonProps: {
|
||||
label: this.t.translate('common.cancel'),
|
||||
severity: 'secondary',
|
||||
},
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||
severity: 'success',
|
||||
},
|
||||
accept: () => {
|
||||
this.libraryService.refreshLibrary(libraryId).subscribe({
|
||||
complete: () => {
|
||||
this.messageService.add({severity: 'info', summary: this.t.translate('common.success'), detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshSuccessDetail')});
|
||||
label: this.t.translate('book.shelfMenuService.library.optionsLabel'),
|
||||
items: [
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'),
|
||||
icon: 'pi pi-book',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.bulkIsbnImport'),
|
||||
icon: 'pi pi-barcode',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.editLibrary'),
|
||||
icon: 'pi pi-pen-to-square',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.dialogLauncherService.openLibraryEditDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.rescanLibrary'),
|
||||
icon: 'pi pi-refresh',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('book.shelfMenuService.confirm.rescanLibraryMessage', {name: entity?.name}),
|
||||
header: this.t.translate('book.shelfMenuService.confirm.header'),
|
||||
icon: undefined,
|
||||
acceptLabel: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||
rejectLabel: this.t.translate('common.cancel'),
|
||||
acceptIcon: undefined,
|
||||
rejectIcon: undefined,
|
||||
acceptButtonStyleClass: undefined,
|
||||
rejectButtonStyleClass: undefined,
|
||||
rejectButtonProps: {
|
||||
label: this.t.translate('common.cancel'),
|
||||
severity: 'secondary',
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
|
||||
detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshFailedDetail'),
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||
severity: 'success',
|
||||
},
|
||||
accept: () => {
|
||||
this.libraryService.refreshLibrary(libraryId).subscribe({
|
||||
complete: () => {
|
||||
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: this.t.translate('book.shelfMenuService.toast.failedSummary'),
|
||||
detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.customFetchMetadata'),
|
||||
icon: 'pi pi-sync',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dialogLauncherService.openLibraryMetadataFetchDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.autoFetchMetadata'),
|
||||
icon: 'pi pi-bolt',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.taskHelperService.refreshMetadataTask({
|
||||
refreshType: MetadataRefreshType.LIBRARY,
|
||||
libraryId
|
||||
}).subscribe();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.findDuplicates'),
|
||||
icon: 'pi pi-copy',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookDialogHelperService.openDuplicateMergerDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.deleteLibrary'),
|
||||
icon: 'pi pi-trash',
|
||||
disabled: disableLibraryActions,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.confirmationService.confirm({
|
||||
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: this.t.translate('common.cancel'),
|
||||
severity: 'secondary',
|
||||
},
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('common.yes'),
|
||||
severity: 'danger',
|
||||
},
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(this.t.translate('book.shelfMenuService.loading.deletingLibrary', {name: entity?.name}));
|
||||
|
||||
this.libraryService.deleteLibrary(libraryId)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe({
|
||||
complete: () => {
|
||||
this.router.navigate(['/']);
|
||||
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: this.t.translate('book.shelfMenuService.toast.failedSummary'),
|
||||
detail: this.t.translate('book.shelfMenuService.toast.libraryDeleteFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.customFetchMetadata'),
|
||||
icon: 'pi pi-sync',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.bookDialogHelperService.openMetadataRefreshDialogWithContext({
|
||||
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
||||
libraryId
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.autoFetchMetadata'),
|
||||
icon: 'pi pi-bolt',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.taskHelperService.refreshMetadataTask({
|
||||
refreshType: MetadataRefreshType.LIBRARY,
|
||||
libraryId
|
||||
}).subscribe();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.findDuplicates'),
|
||||
icon: 'pi pi-copy',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.bookDialogHelperService.openDuplicateMergerDialog(libraryId);
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: this.t.translate('book.shelfMenuService.library.deleteLibrary'),
|
||||
icon: 'pi pi-trash',
|
||||
disabled: libraryId == null,
|
||||
command: () => {
|
||||
if (libraryId == null) {
|
||||
return;
|
||||
}
|
||||
this.confirmationService.confirm({
|
||||
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: this.t.translate('common.cancel'),
|
||||
severity: 'secondary',
|
||||
},
|
||||
acceptButtonProps: {
|
||||
label: this.t.translate('common.yes'),
|
||||
severity: 'danger',
|
||||
},
|
||||
accept: () => {
|
||||
const loader = this.loadingService.show(this.t.translate('book.shelfMenuService.loading.deletingLibrary', {name: entity?.name}));
|
||||
|
||||
this.libraryService.deleteLibrary(libraryId)
|
||||
.pipe(finalize(() => this.loadingService.hide(loader)))
|
||||
.subscribe({
|
||||
complete: () => {
|
||||
this.router.navigate(['/']);
|
||||
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: this.t.translate('book.shelfMenuService.toast.failedSummary'),
|
||||
detail: this.t.translate('book.shelfMenuService.toast.libraryDeleteFailedDetail'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user