Files
grimmory/booklore-ui/src/app/shared/services/dialog-launcher.service.ts
T
Balázs Szücs ab96eee5bc refactor(types): replace most usages of 'any' with 'unknown' and improve type safety across services and components (#2050)
* refactor(types): replace most usages of 'any' with 'unknown' and improve type safety across services and components

- Update method signatures, variables, and interfaces to use 'unknown' instead of 'any'
- Refine event and observable typings for better type inference
- Add or adjust explicit types for function parameters and return values
- Update Chart.js tooltip and context typings for chart services
- Improve type safety in Book, BookState, and related models
- Adjust template bindings and method calls to match stricter typings
- Add SecureSrcDirective for secure image loading with fallback and error handling

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* chore(angular): remove proxy configuration from development build settings

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(book-browser): streamline entity and book state management with reactive streams

- Refactor entity type and entity fetching logic to use observables and combine route params
- Simplify book state handling by consolidating filtering and fetching into a single reactive pipeline
- Remove redundant applySortOption logic and related subscriptions
- Fix book card index binding in template for improved rendering performance
- Ensure proper cleanup of epub rendition in epub-reader component

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(book-browser, book-uploader): improve permission checks and enhance file upload handling

- Use optional chaining for user permission checks in book-browser.component.html to prevent runtime errors when user data is undefined
- Refactor book-uploader.component.ts to pass destination and IDs explicitly to uploadBatch, reconstruct files for strict type handling, and ensure proper upload flow and UI feedback

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(charts, services): improve type safety for book state validation and update form field checks

- Refactor isValidBookState methods across chart components and services to use type predicates and stricter type checks for BookState
- Update metadata-picker.component to simplify array field checks for authors, categories, moods, and tags
- Adjust magic-shelf-utils to remove unnecessary fallback in object spread
- Update notification-event.service to use correct timeout type for highlightTimeout

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(theme): ensure safe merging of theme properties and improve type definition for themesMap

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(epub-reader): streamline book and rendition initialization logic

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
2026-01-02 18:22:54 -07:00

193 lines
6.6 KiB
TypeScript

import {inject, Injectable, Type} from '@angular/core';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {GithubSupportDialog} from '../components/github-support-dialog/github-support-dialog';
import {LibraryCreatorComponent} from '../../features/library-creator/library-creator.component';
import {BookUploaderComponent} from '../components/book-uploader/book-uploader.component';
import {UserProfileDialogComponent} from '../../features/settings/user-profile-dialog/user-profile-dialog.component';
import {MagicShelfComponent} from '../../features/magic-shelf/component/magic-shelf-component';
import {DashboardSettingsComponent} from '../../features/dashboard/components/dashboard-settings/dashboard-settings.component';
import {VersionChangelogDialogComponent} from '../layout/component/layout-menu/version-changelog-dialog/version-changelog-dialog.component';
import {CreateUserDialogComponent} from '../../features/settings/user-management/create-user-dialog/create-user-dialog.component';
import {CreateEmailRecipientDialogComponent} from '../../features/settings/email-v2/create-email-recipient-dialog/create-email-recipient-dialog.component';
import {CreateEmailProviderDialogComponent} from '../../features/settings/email-v2/create-email-provider-dialog/create-email-provider-dialog.component';
import {DirectoryPickerComponent} from '../components/directory-picker/directory-picker.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 {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';
@Injectable({
providedIn: 'root',
})
export class DialogLauncherService {
dialogService = inject(DialogService);
private defaultDialogOptions = {
baseZIndex: 10,
closable: true,
dismissableMask: true,
draggable: false,
modal: true,
resizable: false,
showHeader: true,
maximizable: false,
}
openDialog(component: unknown, options: {}): DynamicDialogRef | null {
return this.dialogService.open(component as Type<any>, {
...this.defaultDialogOptions,
...options,
});
}
openDashboardSettingsDialog(): DynamicDialogRef | null {
return this.openDialog(DashboardSettingsComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openGithubSupportDialog(): DynamicDialogRef | null {
return this.openDialog(GithubSupportDialog, {
header: 'Support Booklore',
});
}
openLibraryCreateDialog(): DynamicDialogRef | null {
return this.openDialog(LibraryCreatorComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openDirectoryPickerDialog(): DynamicDialogRef | null {
return this.openDialog(DirectoryPickerComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openLibraryEditDialog(libraryId: number): DynamicDialogRef | null {
return this.openDialog(LibraryCreatorComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
data: {
mode: 'edit',
libraryId: libraryId
}
});
}
openLibraryMetadataFetchDialog(libraryId: number): DynamicDialogRef | null {
return this.openDialog(MetadataFetchOptionsComponent, {
header: 'Metadata Refresh Options',
data: {
libraryId: libraryId,
metadataRefreshType: MetadataRefreshType.LIBRARY,
},
});
}
openShelfEditDialog(shelfId: number): DynamicDialogRef | null {
return this.openDialog(ShelfEditDialogComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
data: {
shelfId: shelfId
},
})
}
openFileUploadDialog(): DynamicDialogRef | null {
return this.openDialog(BookUploaderComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openCreateUserDialog(): DynamicDialogRef | null {
return this.openDialog(CreateUserDialogComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openUserProfileDialog(): DynamicDialogRef | null {
return this.openDialog(UserProfileDialogComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openMagicShelfCreateDialog(): DynamicDialogRef | null {
return this.openDialog(MagicShelfComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openMagicShelfEditDialog(shelfId: number): DynamicDialogRef | null {
return this.openDialog(MagicShelfComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
data: {
id: shelfId,
editMode: true,
}
})
}
openVersionChangelogDialog(): DynamicDialogRef | null {
return this.openDialog(VersionChangelogDialogComponent, {
header: "What's New",
styleClass: 'dialog-medium',
});
}
openEmailRecipientDialog(): DynamicDialogRef | null {
return this.openDialog(CreateEmailRecipientDialogComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openEmailProviderDialog(): DynamicDialogRef | null {
return this.openDialog(CreateEmailProviderDialogComponent, {
showHeader: false,
styleClass: 'dynamic-dialog-minimal',
});
}
openBookdropFinalizeResultDialog(result: BookdropFinalizeResult): DynamicDialogRef | null {
return this.openDialog(BookdropFinalizeResultDialogComponent, {
header: 'Import Summary',
data: {
result: result,
},
});
}
openMetadataReviewDialog(taskId: string): DynamicDialogRef | null {
return this.openDialog(MetadataReviewDialogComponent, {
header: 'Review Metadata Proposal',
data: {
taskId,
},
styleClass: 'dialog-maximal',
});
}
openIconPickerDialog(): DynamicDialogRef | null {
return this.openDialog(IconPickerComponent, {
header: 'Choose an Icon',
styleClass: 'dialog-medium',
});
}
}