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'),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
+34
@@ -52,6 +52,7 @@ describe('MetadataFetchOptionsComponent', () => {
|
||||
});
|
||||
|
||||
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.libraryId).toBe(7);
|
||||
expect(component.bookIds).toEqual([1, 2]);
|
||||
@@ -59,6 +60,38 @@ describe('MetadataFetchOptionsComponent', () => {
|
||||
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', () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
@@ -79,6 +112,7 @@ describe('MetadataFetchOptionsComponent', () => {
|
||||
});
|
||||
|
||||
const component = TestBed.runInInjectionContext(() => new MetadataFetchOptionsComponent());
|
||||
component.ngOnInit();
|
||||
const options: MetadataRefreshOptions = {
|
||||
libraryId: 7,
|
||||
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 {MetadataRefreshRequest} from '../../../model/request/metadata-refresh-request.model';
|
||||
import {MetadataRefreshType} from '../../../model/request/metadata-refresh-type.enum';
|
||||
@@ -18,10 +18,16 @@ import {TranslocoDirective} from '@jsverse/transloco';
|
||||
],
|
||||
styleUrl: './metadata-fetch-options.component.scss'
|
||||
})
|
||||
export class MetadataFetchOptionsComponent {
|
||||
libraryId!: number;
|
||||
bookIds!: number[];
|
||||
metadataRefreshType!: MetadataRefreshType;
|
||||
export class MetadataFetchOptionsComponent implements OnInit, OnChanges {
|
||||
@Input() dialogData?: {
|
||||
libraryId?: number | null;
|
||||
bookIds?: number[];
|
||||
metadataRefreshType?: MetadataRefreshType;
|
||||
};
|
||||
|
||||
libraryId?: number;
|
||||
bookIds: number[] = [];
|
||||
metadataRefreshType: MetadataRefreshType = MetadataRefreshType.BOOKS;
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
@@ -30,15 +36,22 @@ export class MetadataFetchOptionsComponent {
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
|
||||
constructor() {
|
||||
this.libraryId = this.dynamicDialogConfig.data.libraryId;
|
||||
this.bookIds = this.dynamicDialogConfig.data.bookIds;
|
||||
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
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) {
|
||||
const metadataRefreshRequest: MetadataRefreshRequest = {
|
||||
refreshType: this.metadataRefreshType,
|
||||
@@ -49,4 +62,14 @@ export class MetadataFetchOptionsComponent {
|
||||
this.taskHelperService.refreshMetadataTask(metadataRefreshRequest).subscribe();
|
||||
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 class="header-text">
|
||||
<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>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
@@ -18,18 +22,21 @@
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
<div class="book-list-section">
|
||||
<div class="book-list-container">
|
||||
<ul class="book-list">
|
||||
@for (book of booksToShow; track book.id) {
|
||||
<li>
|
||||
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@if (!isLibraryRefresh) {
|
||||
<div class="book-list-section">
|
||||
<div class="book-list-container">
|
||||
<ul class="book-list">
|
||||
@for (book of booksToShow; track book.id) {
|
||||
<li>
|
||||
<span class="book-id">#{{ book.id }}</span>: {{ book.metadata?.title || 'Untitled' }}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</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>
|
||||
|
||||
+14
@@ -43,6 +43,7 @@ describe('MultiBookMetadataFetchComponent', () => {
|
||||
|
||||
it('reads dialog data and resolves the books to show on construction', () => {
|
||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.bookIds).toEqual([3, 5]);
|
||||
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', () => {
|
||||
const component = TestBed.runInInjectionContext(() => new MultiBookMetadataFetchComponent());
|
||||
component.ngOnInit();
|
||||
|
||||
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 {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
|
||||
@@ -18,10 +18,17 @@ import {Button} from 'primeng/button';
|
||||
styleUrl: './multi-book-metadata-fetch-component.scss',
|
||||
imports: [MetadataFetchOptionsComponent, FormsModule, Button],
|
||||
})
|
||||
export class MultiBookMetadataFetchComponent {
|
||||
bookIds!: number[];
|
||||
export class MultiBookMetadataFetchComponent implements OnInit, OnChanges {
|
||||
@Input() dialogData?: {
|
||||
libraryId?: number | null;
|
||||
bookIds?: number[];
|
||||
metadataRefreshType?: MetadataRefreshType;
|
||||
};
|
||||
|
||||
bookIds: number[] = [];
|
||||
libraryId: number | null = null;
|
||||
booksToShow: Book[] = [];
|
||||
metadataRefreshType!: MetadataRefreshType;
|
||||
metadataRefreshType: MetadataRefreshType = MetadataRefreshType.BOOKS;
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
@@ -31,10 +38,6 @@ export class MultiBookMetadataFetchComponent {
|
||||
expanded = false;
|
||||
|
||||
constructor() {
|
||||
this.bookIds = this.dynamicDialogConfig.data.bookIds;
|
||||
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
|
||||
this.booksToShow = this.bookService.getBooksByIds(this.bookIds);
|
||||
|
||||
effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
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 {BookdropFinalizeResult} from '../../features/bookdrop/service/bookdrop.service';
|
||||
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 {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 {
|
||||
return this.openDialog(ShelfEditDialogComponent, {
|
||||
showHeader: false,
|
||||
|
||||
Reference in New Issue
Block a user