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 {BulkIsbnImportDialogComponent} from '../bulk-isbn-import-dialog/bulk-isbn-import-dialog.component';
|
||||||
import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component';
|
import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component';
|
||||||
|
|
||||||
|
interface MetadataRefreshDialogContext {
|
||||||
|
metadataRefreshType: MetadataRefreshType;
|
||||||
|
bookIds?: number[];
|
||||||
|
libraryId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class BookDialogHelperService {
|
export class BookDialogHelperService {
|
||||||
|
|
||||||
@@ -75,12 +81,20 @@ export class BookDialogHelperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openMetadataRefreshDialog(bookIds: Set<number>): DynamicDialogRef | null {
|
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, {
|
return this.openDialog(MultiBookMetadataFetchComponent, {
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`,
|
||||||
data: {
|
data: {
|
||||||
bookIds: Array.from(bookIds),
|
bookIds: context.bookIds ?? [],
|
||||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
libraryId: context.libraryId,
|
||||||
|
metadataRefreshType: context.metadataRefreshType,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
};
|
};
|
||||||
const dialogLauncherService = {
|
const dialogLauncherService = {
|
||||||
openLibraryEditDialog: vi.fn(),
|
openLibraryEditDialog: vi.fn(),
|
||||||
openLibraryMetadataFetchDialog: vi.fn(),
|
|
||||||
openShelfEditDialog: vi.fn(),
|
openShelfEditDialog: vi.fn(),
|
||||||
openMagicShelfEditDialog: vi.fn(),
|
openMagicShelfEditDialog: vi.fn(),
|
||||||
};
|
};
|
||||||
@@ -103,6 +102,7 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
openAddPhysicalBookDialog: vi.fn(),
|
openAddPhysicalBookDialog: vi.fn(),
|
||||||
openBulkIsbnImportDialog: vi.fn(),
|
openBulkIsbnImportDialog: vi.fn(),
|
||||||
openDuplicateMergerDialog: vi.fn(),
|
openDuplicateMergerDialog: vi.fn(),
|
||||||
|
openMetadataRefreshDialogWithContext: vi.fn(),
|
||||||
};
|
};
|
||||||
const translocoService = {
|
const translocoService = {
|
||||||
translate: vi.fn((key: string) => key),
|
translate: vi.fn((key: string) => key),
|
||||||
@@ -143,7 +143,6 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
userService.getCurrentUser.mockClear();
|
userService.getCurrentUser.mockClear();
|
||||||
router.navigate.mockClear();
|
router.navigate.mockClear();
|
||||||
dialogLauncherService.openLibraryEditDialog.mockClear();
|
dialogLauncherService.openLibraryEditDialog.mockClear();
|
||||||
dialogLauncherService.openLibraryMetadataFetchDialog.mockClear();
|
|
||||||
dialogLauncherService.openShelfEditDialog.mockClear();
|
dialogLauncherService.openShelfEditDialog.mockClear();
|
||||||
dialogLauncherService.openMagicShelfEditDialog.mockClear();
|
dialogLauncherService.openMagicShelfEditDialog.mockClear();
|
||||||
magicShelfService.deleteShelf.mockClear();
|
magicShelfService.deleteShelf.mockClear();
|
||||||
@@ -152,6 +151,7 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
bookDialogHelperService.openAddPhysicalBookDialog.mockClear();
|
bookDialogHelperService.openAddPhysicalBookDialog.mockClear();
|
||||||
bookDialogHelperService.openBulkIsbnImportDialog.mockClear();
|
bookDialogHelperService.openBulkIsbnImportDialog.mockClear();
|
||||||
bookDialogHelperService.openDuplicateMergerDialog.mockClear();
|
bookDialogHelperService.openDuplicateMergerDialog.mockClear();
|
||||||
|
bookDialogHelperService.openMetadataRefreshDialogWithContext.mockClear();
|
||||||
translocoService.translate.mockClear();
|
translocoService.translate.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
expect(bookDialogHelperService.openBulkIsbnImportDialog).not.toHaveBeenCalled();
|
expect(bookDialogHelperService.openBulkIsbnImportDialog).not.toHaveBeenCalled();
|
||||||
expect(bookDialogHelperService.openDuplicateMergerDialog).not.toHaveBeenCalled();
|
expect(bookDialogHelperService.openDuplicateMergerDialog).not.toHaveBeenCalled();
|
||||||
expect(dialogLauncherService.openLibraryEditDialog).not.toHaveBeenCalled();
|
expect(dialogLauncherService.openLibraryEditDialog).not.toHaveBeenCalled();
|
||||||
expect(dialogLauncherService.openLibraryMetadataFetchDialog).not.toHaveBeenCalled();
|
expect(bookDialogHelperService.openMetadataRefreshDialogWithContext).not.toHaveBeenCalled();
|
||||||
expect(taskHelperService.refreshMetadataTask).not.toHaveBeenCalled();
|
expect(taskHelperService.refreshMetadataTask).not.toHaveBeenCalled();
|
||||||
expect(confirmationService.confirm).not.toHaveBeenCalled();
|
expect(confirmationService.confirm).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -199,7 +199,10 @@ describe('LibraryShelfMenuService', () => {
|
|||||||
expect(bookDialogHelperService.openAddPhysicalBookDialog).toHaveBeenCalledWith(42);
|
expect(bookDialogHelperService.openAddPhysicalBookDialog).toHaveBeenCalledWith(42);
|
||||||
expect(bookDialogHelperService.openBulkIsbnImportDialog).toHaveBeenCalledWith(42);
|
expect(bookDialogHelperService.openBulkIsbnImportDialog).toHaveBeenCalledWith(42);
|
||||||
expect(dialogLauncherService.openLibraryEditDialog).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({
|
expect(taskHelperService.refreshMetadataTask).toHaveBeenCalledWith({
|
||||||
refreshType: MetadataRefreshType.LIBRARY,
|
refreshType: MetadataRefreshType.LIBRARY,
|
||||||
libraryId: 42,
|
libraryId: 42,
|
||||||
|
|||||||
@@ -36,177 +36,176 @@ export class LibraryShelfMenuService {
|
|||||||
|
|
||||||
initializeLibraryMenuItems(entity: Library | null): MenuItem[] {
|
initializeLibraryMenuItems(entity: Library | null): MenuItem[] {
|
||||||
const libraryId = entity?.id;
|
const libraryId = entity?.id;
|
||||||
const disableLibraryActions = libraryId == null;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'),
|
label: this.t.translate('book.shelfMenuService.library.optionsLabel'),
|
||||||
icon: 'pi pi-book',
|
items: [
|
||||||
disabled: disableLibraryActions,
|
{
|
||||||
command: () => {
|
label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'),
|
||||||
if (libraryId == null) {
|
icon: 'pi pi-book',
|
||||||
return;
|
disabled: libraryId == null,
|
||||||
}
|
command: () => {
|
||||||
|
if (libraryId == null) {
|
||||||
this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId);
|
return;
|
||||||
}
|
}
|
||||||
},
|
this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId);
|
||||||
{
|
}
|
||||||
label: this.t.translate('book.shelfMenuService.library.bulkIsbnImport'),
|
},
|
||||||
icon: 'pi pi-barcode',
|
{
|
||||||
disabled: disableLibraryActions,
|
label: this.t.translate('book.shelfMenuService.library.bulkIsbnImport'),
|
||||||
command: () => {
|
icon: 'pi pi-barcode',
|
||||||
if (libraryId == null) {
|
disabled: libraryId == null,
|
||||||
return;
|
command: () => {
|
||||||
}
|
if (libraryId == null) {
|
||||||
|
return;
|
||||||
this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId);
|
}
|
||||||
}
|
this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId);
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
separator: true
|
{
|
||||||
},
|
separator: true
|
||||||
{
|
},
|
||||||
label: this.t.translate('book.shelfMenuService.library.editLibrary'),
|
{
|
||||||
icon: 'pi pi-pen-to-square',
|
label: this.t.translate('book.shelfMenuService.library.editLibrary'),
|
||||||
disabled: disableLibraryActions,
|
icon: 'pi pi-pen-to-square',
|
||||||
command: () => {
|
disabled: libraryId == null,
|
||||||
if (libraryId == null) {
|
command: () => {
|
||||||
return;
|
if (libraryId == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
this.dialogLauncherService.openLibraryEditDialog(libraryId);
|
this.dialogLauncherService.openLibraryEditDialog(libraryId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: this.t.translate('book.shelfMenuService.library.rescanLibrary'),
|
label: this.t.translate('book.shelfMenuService.library.rescanLibrary'),
|
||||||
icon: 'pi pi-refresh',
|
icon: 'pi pi-refresh',
|
||||||
disabled: disableLibraryActions,
|
disabled: libraryId == null,
|
||||||
command: () => {
|
command: () => {
|
||||||
if (libraryId == null) {
|
if (libraryId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.confirmationService.confirm({
|
||||||
this.confirmationService.confirm({
|
message: this.t.translate('book.shelfMenuService.confirm.rescanLibraryMessage', {name: entity?.name}),
|
||||||
message: this.t.translate('book.shelfMenuService.confirm.rescanLibraryMessage', {name: entity?.name}),
|
header: this.t.translate('book.shelfMenuService.confirm.header'),
|
||||||
header: this.t.translate('book.shelfMenuService.confirm.header'),
|
icon: undefined,
|
||||||
icon: undefined,
|
acceptLabel: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||||
acceptLabel: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
rejectLabel: this.t.translate('common.cancel'),
|
||||||
rejectLabel: this.t.translate('common.cancel'),
|
acceptIcon: undefined,
|
||||||
acceptIcon: undefined,
|
rejectIcon: undefined,
|
||||||
rejectIcon: undefined,
|
acceptButtonStyleClass: undefined,
|
||||||
acceptButtonStyleClass: undefined,
|
rejectButtonStyleClass: undefined,
|
||||||
rejectButtonStyleClass: undefined,
|
rejectButtonProps: {
|
||||||
rejectButtonProps: {
|
label: this.t.translate('common.cancel'),
|
||||||
label: this.t.translate('common.cancel'),
|
severity: 'secondary',
|
||||||
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')});
|
|
||||||
},
|
},
|
||||||
error: () => {
|
acceptButtonProps: {
|
||||||
this.messageService.add({
|
label: this.t.translate('book.shelfMenuService.confirm.rescanLabel'),
|
||||||
severity: 'error',
|
severity: 'success',
|
||||||
summary: this.t.translate('book.shelfMenuService.toast.failedSummary'),
|
},
|
||||||
detail: this.t.translate('book.shelfMenuService.toast.libraryRefreshFailedDetail'),
|
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',
|
||||||
label: this.t.translate('book.shelfMenuService.library.customFetchMetadata'),
|
disabled: libraryId == null,
|
||||||
icon: 'pi pi-sync',
|
command: () => {
|
||||||
disabled: disableLibraryActions,
|
if (libraryId == null) {
|
||||||
command: () => {
|
return;
|
||||||
if (libraryId == null) {
|
}
|
||||||
return;
|
this.bookDialogHelperService.openMetadataRefreshDialogWithContext({
|
||||||
}
|
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
||||||
|
libraryId
|
||||||
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.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'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
+34
@@ -52,6 +52,7 @@ describe('MetadataFetchOptionsComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
expect(component.libraryId).toBe(7);
|
expect(component.libraryId).toBe(7);
|
||||||
expect(component.bookIds).toEqual([1, 2]);
|
expect(component.bookIds).toEqual([1, 2]);
|
||||||
@@ -59,6 +60,38 @@ describe('MetadataFetchOptionsComponent', () => {
|
|||||||
expect(component.currentMetadataOptions).toEqual(defaultMetadataRefreshOptions);
|
expect(component.currentMetadataOptions).toEqual(defaultMetadataRefreshOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('gives precedence to dialogData Input over dynamicDialogConfig.data', () => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: DynamicDialogConfig,
|
||||||
|
useValue: {
|
||||||
|
data: {
|
||||||
|
libraryId: 7,
|
||||||
|
bookIds: [1, 2],
|
||||||
|
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{provide: DynamicDialogRef, useValue: {close}},
|
||||||
|
{provide: TaskHelperService, useValue: {refreshMetadataTask}},
|
||||||
|
{provide: AppSettingsService, useValue: {appSettings: () => null}},
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
||||||
|
component.dialogData = {
|
||||||
|
libraryId: 9,
|
||||||
|
bookIds: [10],
|
||||||
|
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||||
|
};
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.libraryId).toBe(9);
|
||||||
|
expect(component.bookIds).toEqual([10]);
|
||||||
|
expect(component.metadataRefreshType).toBe(MetadataRefreshType.BOOKS);
|
||||||
|
});
|
||||||
|
|
||||||
it('submits a metadata refresh task and closes the dialog', () => {
|
it('submits a metadata refresh task and closes the dialog', () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -79,6 +112,7 @@ describe('MetadataFetchOptionsComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
||||||
|
component.ngOnInit();
|
||||||
const options: MetadataRefreshOptions = {
|
const options: MetadataRefreshOptions = {
|
||||||
libraryId: 7,
|
libraryId: 7,
|
||||||
refreshCovers: false,
|
refreshCovers: false,
|
||||||
|
|||||||
+31
-8
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject} from '@angular/core';
|
import {Component, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
import {MetadataRefreshRequest} from '../../../model/request/metadata-refresh-request.model';
|
import {MetadataRefreshRequest} from '../../../model/request/metadata-refresh-request.model';
|
||||||
import {MetadataRefreshType} from '../../../model/request/metadata-refresh-type.enum';
|
import {MetadataRefreshType} from '../../../model/request/metadata-refresh-type.enum';
|
||||||
@@ -18,10 +18,16 @@ import {TranslocoDirective} from '@jsverse/transloco';
|
|||||||
],
|
],
|
||||||
styleUrl: './metadata-fetch-options.component.scss'
|
styleUrl: './metadata-fetch-options.component.scss'
|
||||||
})
|
})
|
||||||
export class MetadataFetchOptionsComponent {
|
export class MetadataFetchOptionsComponent implements OnInit, OnChanges {
|
||||||
libraryId!: number;
|
@Input() dialogData?: {
|
||||||
bookIds!: number[];
|
libraryId?: number | null;
|
||||||
metadataRefreshType!: MetadataRefreshType;
|
bookIds?: number[];
|
||||||
|
metadataRefreshType?: MetadataRefreshType;
|
||||||
|
};
|
||||||
|
|
||||||
|
libraryId?: number;
|
||||||
|
bookIds: number[] = [];
|
||||||
|
metadataRefreshType: MetadataRefreshType = MetadataRefreshType.BOOKS;
|
||||||
currentMetadataOptions!: MetadataRefreshOptions;
|
currentMetadataOptions!: MetadataRefreshOptions;
|
||||||
|
|
||||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||||
@@ -30,15 +36,22 @@ export class MetadataFetchOptionsComponent {
|
|||||||
private appSettingsService = inject(AppSettingsService);
|
private appSettingsService = inject(AppSettingsService);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.libraryId = this.dynamicDialogConfig.data.libraryId;
|
|
||||||
this.bookIds = this.dynamicDialogConfig.data.bookIds;
|
|
||||||
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
|
|
||||||
const settings = this.appSettingsService.appSettings();
|
const settings = this.appSettingsService.appSettings();
|
||||||
if (settings) {
|
if (settings) {
|
||||||
this.currentMetadataOptions = settings.defaultMetadataRefreshOptions;
|
this.currentMetadataOptions = settings.defaultMetadataRefreshOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.applyContext(this.dialogData ?? this.dynamicDialogConfig.data ?? {});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if ('dialogData' in changes) {
|
||||||
|
this.applyContext(changes['dialogData'].currentValue ?? {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) {
|
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) {
|
||||||
const metadataRefreshRequest: MetadataRefreshRequest = {
|
const metadataRefreshRequest: MetadataRefreshRequest = {
|
||||||
refreshType: this.metadataRefreshType,
|
refreshType: this.metadataRefreshType,
|
||||||
@@ -49,4 +62,14 @@ export class MetadataFetchOptionsComponent {
|
|||||||
this.taskHelperService.refreshMetadataTask(metadataRefreshRequest).subscribe();
|
this.taskHelperService.refreshMetadataTask(metadataRefreshRequest).subscribe();
|
||||||
this.dynamicDialogRef.close();
|
this.dynamicDialogRef.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private applyContext(context: {
|
||||||
|
libraryId?: number | null;
|
||||||
|
bookIds?: number[];
|
||||||
|
metadataRefreshType?: MetadataRefreshType;
|
||||||
|
}): void {
|
||||||
|
this.libraryId = context.libraryId ?? undefined;
|
||||||
|
this.bookIds = context.bookIds ?? [];
|
||||||
|
this.metadataRefreshType = context.metadataRefreshType ?? MetadataRefreshType.BOOKS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-12
@@ -5,7 +5,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="header-text">
|
<div class="header-text">
|
||||||
<h2 class="panel-title">Metadata Refresh Options</h2>
|
<h2 class="panel-title">Metadata Refresh Options</h2>
|
||||||
<p class="panel-description">{{ booksToShow.length }} books selected</p>
|
@if (isLibraryRefresh) {
|
||||||
|
<p class="panel-description">Library-level custom metadata fetch</p>
|
||||||
|
} @else {
|
||||||
|
<p class="panel-description">{{ booksToShow.length }} books selected</p>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<p-button
|
<p-button
|
||||||
icon="pi pi-times"
|
icon="pi pi-times"
|
||||||
@@ -18,18 +22,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dialog-content">
|
<div class="dialog-content">
|
||||||
<div class="book-list-section">
|
@if (!isLibraryRefresh) {
|
||||||
<div class="book-list-container">
|
<div class="book-list-section">
|
||||||
<ul class="book-list">
|
<div class="book-list-container">
|
||||||
@for (book of booksToShow; track book.id) {
|
<ul class="book-list">
|
||||||
<li>
|
@for (book of booksToShow; track book.id) {
|
||||||
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
<li>
|
||||||
</li>
|
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
||||||
}
|
</li>
|
||||||
</ul>
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
|
|
||||||
<app-metadata-fetch-options></app-metadata-fetch-options>
|
<app-metadata-fetch-options
|
||||||
|
[dialogData]="{ bookIds: bookIds, libraryId: libraryId, metadataRefreshType: metadataRefreshType }"></app-metadata-fetch-options>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+14
@@ -43,6 +43,7 @@ describe('MultiBookMetadataFetchComponent', () => {
|
|||||||
|
|
||||||
it('reads dialog data and resolves the books to show on construction', () => {
|
it('reads dialog data and resolves the books to show on construction', () => {
|
||||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
expect(component.bookIds).toEqual([3, 5]);
|
expect(component.bookIds).toEqual([3, 5]);
|
||||||
expect(component.metadataRefreshType).toBe(MetadataRefreshType.BOOKS);
|
expect(component.metadataRefreshType).toBe(MetadataRefreshType.BOOKS);
|
||||||
@@ -53,8 +54,21 @@ describe('MultiBookMetadataFetchComponent', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('gives precedence to dialogData Input over dynamicDialogConfig.data', () => {
|
||||||
|
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||||
|
component.dialogData = {
|
||||||
|
bookIds: [10],
|
||||||
|
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||||
|
};
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.bookIds).toEqual([10]);
|
||||||
|
expect(getBooksByIds).toHaveBeenCalledWith([10]);
|
||||||
|
});
|
||||||
|
|
||||||
it('adopts the default metadata refresh options when app settings become available', () => {
|
it('adopts the default metadata refresh options when app settings become available', () => {
|
||||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
expect(component.currentMetadataOptions).toBeUndefined();
|
expect(component.currentMetadataOptions).toBeUndefined();
|
||||||
|
|
||||||
|
|||||||
+36
-8
@@ -1,4 +1,4 @@
|
|||||||
import {Component, effect, inject} from '@angular/core';
|
import {Component, effect, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||||
|
|
||||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||||
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
|
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
|
||||||
@@ -18,10 +18,17 @@ import {Button} from 'primeng/button';
|
|||||||
styleUrl: './multi-book-metadata-fetch-component.scss',
|
styleUrl: './multi-book-metadata-fetch-component.scss',
|
||||||
imports: [MetadataFetchOptionsComponent, FormsModule, Button],
|
imports: [MetadataFetchOptionsComponent, FormsModule, Button],
|
||||||
})
|
})
|
||||||
export class MultiBookMetadataFetchComponent {
|
export class MultiBookMetadataFetchComponent implements OnInit, OnChanges {
|
||||||
bookIds!: number[];
|
@Input() dialogData?: {
|
||||||
|
libraryId?: number | null;
|
||||||
|
bookIds?: number[];
|
||||||
|
metadataRefreshType?: MetadataRefreshType;
|
||||||
|
};
|
||||||
|
|
||||||
|
bookIds: number[] = [];
|
||||||
|
libraryId: number | null = null;
|
||||||
booksToShow: Book[] = [];
|
booksToShow: Book[] = [];
|
||||||
metadataRefreshType!: MetadataRefreshType;
|
metadataRefreshType: MetadataRefreshType = MetadataRefreshType.BOOKS;
|
||||||
currentMetadataOptions!: MetadataRefreshOptions;
|
currentMetadataOptions!: MetadataRefreshOptions;
|
||||||
|
|
||||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||||
@@ -31,10 +38,6 @@ export class MultiBookMetadataFetchComponent {
|
|||||||
expanded = false;
|
expanded = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.bookIds = this.dynamicDialogConfig.data.bookIds;
|
|
||||||
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
|
|
||||||
this.booksToShow = this.bookService.getBooksByIds(this.bookIds);
|
|
||||||
|
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const settings = this.appSettingsService.appSettings();
|
const settings = this.appSettingsService.appSettings();
|
||||||
if (settings) {
|
if (settings) {
|
||||||
@@ -42,4 +45,29 @@ export class MultiBookMetadataFetchComponent {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.applyContext(this.dialogData ?? this.dynamicDialogConfig.data ?? {});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if ('dialogData' in changes) {
|
||||||
|
this.applyContext(changes['dialogData'].currentValue ?? {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private applyContext(context: {
|
||||||
|
libraryId?: number | null;
|
||||||
|
bookIds?: number[];
|
||||||
|
metadataRefreshType?: MetadataRefreshType;
|
||||||
|
}): void {
|
||||||
|
this.bookIds = context.bookIds ?? [];
|
||||||
|
this.libraryId = context.libraryId ?? null;
|
||||||
|
this.metadataRefreshType = context.metadataRefreshType ?? MetadataRefreshType.BOOKS;
|
||||||
|
this.booksToShow = this.bookService.getBooksByIds(this.bookIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLibraryRefresh(): boolean {
|
||||||
|
return this.metadataRefreshType === MetadataRefreshType.LIBRARY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import {DirectoryPickerComponent} from '../components/directory-picker/directory
|
|||||||
import {BookdropFinalizeResultDialogComponent} from '../../features/bookdrop/component/bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog.component';
|
import {BookdropFinalizeResultDialogComponent} from '../../features/bookdrop/component/bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog.component';
|
||||||
import {BookdropFinalizeResult} from '../../features/bookdrop/service/bookdrop.service';
|
import {BookdropFinalizeResult} from '../../features/bookdrop/service/bookdrop.service';
|
||||||
import {MetadataReviewDialogComponent} from '../../features/metadata/component/metadata-review-dialog/metadata-review-dialog-component';
|
import {MetadataReviewDialogComponent} from '../../features/metadata/component/metadata-review-dialog/metadata-review-dialog-component';
|
||||||
import {MetadataRefreshType} from '../../features/metadata/model/request/metadata-refresh-type.enum';
|
|
||||||
import {MetadataFetchOptionsComponent} from '../../features/metadata/component/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
|
||||||
import {ShelfEditDialogComponent} from '../../features/book/components/shelf-edit-dialog/shelf-edit-dialog.component';
|
import {ShelfEditDialogComponent} from '../../features/book/components/shelf-edit-dialog/shelf-edit-dialog.component';
|
||||||
import {IconPickerComponent} from '../components/icon-picker/icon-picker-component';
|
import {IconPickerComponent} from '../components/icon-picker/icon-picker-component';
|
||||||
|
|
||||||
@@ -94,17 +92,6 @@ export class DialogLauncherService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openLibraryMetadataFetchDialog(libraryId: number): DynamicDialogRef | null {
|
|
||||||
return this.openDialog(MetadataFetchOptionsComponent, {
|
|
||||||
showHeader: false,
|
|
||||||
styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`,
|
|
||||||
data: {
|
|
||||||
libraryId: libraryId,
|
|
||||||
metadataRefreshType: MetadataRefreshType.LIBRARY,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
openShelfEditDialog(shelfId: number): DynamicDialogRef | null {
|
openShelfEditDialog(shelfId: number): DynamicDialogRef | null {
|
||||||
return this.openDialog(ShelfEditDialogComponent, {
|
return this.openDialog(ShelfEditDialogComponent, {
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user