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>
This commit is contained in:
+2
-1
@@ -49,7 +49,8 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
});
|
||||
}
|
||||
|
||||
onPageChange(event: any) {
|
||||
onPageChange(event: { first?: number; rows?: number | null }): void {
|
||||
if (event.first === undefined || event.rows === undefined || event.rows === null) return;
|
||||
this.first = event.first;
|
||||
const page = Math.floor(event.first / event.rows);
|
||||
this.loadSessions(page);
|
||||
|
||||
+10
-9
@@ -17,6 +17,7 @@ import {filter, take, finalize} from "rxjs/operators";
|
||||
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
||||
import {MetadataRefreshType} from "../../../model/request/metadata-refresh-type.enum";
|
||||
import {AutoComplete} from "primeng/autocomplete";
|
||||
import {AutoCompleteSelectEvent} from "primeng/autocomplete";
|
||||
import {DatePicker} from "primeng/datepicker";
|
||||
import {Textarea} from "primeng/textarea";
|
||||
import {Image} from "primeng/image";
|
||||
@@ -383,10 +384,10 @@ export class MetadataEditorComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
onAutoCompleteSelect(fieldName: string, event: any) {
|
||||
const values = this.metadataForm.get(fieldName)?.value || [];
|
||||
if (!values.includes(event.value)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value]);
|
||||
onAutoCompleteSelect(fieldName: string, event: AutoCompleteSelectEvent) {
|
||||
const values = (this.metadataForm.get(fieldName)?.value as string[]) || [];
|
||||
if (!values.includes(event.value as string)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value as string]);
|
||||
}
|
||||
(event.originalEvent.target as HTMLInputElement).value = "";
|
||||
}
|
||||
@@ -550,10 +551,10 @@ export class MetadataEditorComponent implements OnInit {
|
||||
const original = this.originalMetadata;
|
||||
|
||||
const wasCleared = (key: keyof BookMetadata): boolean => {
|
||||
const current = (metadata[key] as any) ?? null;
|
||||
const prev = (original[key] as any) ?? null;
|
||||
const current = (metadata[key] as unknown) ?? null;
|
||||
const prev = (original[key] as unknown) ?? null;
|
||||
|
||||
const isEmpty = (val: any): boolean =>
|
||||
const isEmpty = (val: unknown): boolean =>
|
||||
val === null || val === "" || (Array.isArray(val) && val.length === 0);
|
||||
|
||||
return isEmpty(current) && !isEmpty(prev);
|
||||
@@ -630,8 +631,8 @@ export class MetadataEditorComponent implements OnInit {
|
||||
}
|
||||
|
||||
onUpload(event: FileUploadEvent): void {
|
||||
const response: HttpResponse<any> =
|
||||
event.originalEvent as HttpResponse<any>;
|
||||
const response: HttpResponse<unknown> =
|
||||
event.originalEvent as HttpResponse<unknown>;
|
||||
if (response && response.status === 200) {
|
||||
const bookMetadata: BookMetadata = response.body as BookMetadata;
|
||||
this.bookService.handleBookMetadataUpdate(
|
||||
|
||||
+11
-10
@@ -14,6 +14,7 @@ import {Textarea} from 'primeng/textarea';
|
||||
import {filter, map, take} from 'rxjs/operators';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {AutoCompleteSelectEvent} from 'primeng/autocomplete';
|
||||
import {Image} from 'primeng/image';
|
||||
import {LazyLoadImageModule} from 'ng-lazyload-image';
|
||||
|
||||
@@ -349,10 +350,10 @@ export class MetadataPickerComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onAutoCompleteSelect(fieldName: string, event: any) {
|
||||
const values = this.metadataForm.get(fieldName)?.value || [];
|
||||
if (!values.includes(event.value)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value]);
|
||||
onAutoCompleteSelect(fieldName: string, event: AutoCompleteSelectEvent) {
|
||||
const values = (this.metadataForm.get(fieldName)?.value as string[]) || [];
|
||||
if (!values.includes(event.value as string)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value as string]);
|
||||
}
|
||||
(event.originalEvent.target as HTMLInputElement).value = '';
|
||||
}
|
||||
@@ -604,7 +605,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || null;
|
||||
return (this.fetchedMetadata[field as keyof BookMetadata] as number | null) || null;
|
||||
}
|
||||
return Number(formValue);
|
||||
}
|
||||
@@ -613,7 +614,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
const formValue = this.metadataForm.get('pageCount')?.value;
|
||||
if (formValue === '' || formValue === null || isNaN(formValue)) {
|
||||
this.copiedFields['pageCount'] = true;
|
||||
return this.fetchedMetadata.pageCount || null;
|
||||
return (this.fetchedMetadata.pageCount as number | null) || null;
|
||||
}
|
||||
return Number(formValue);
|
||||
}
|
||||
@@ -622,20 +623,20 @@ export class MetadataPickerComponent implements OnInit {
|
||||
const formValue = this.metadataForm.get(field)?.value;
|
||||
if (!formValue || formValue === '') {
|
||||
this.copiedFields[field] = true;
|
||||
return this.fetchedMetadata[field] || '';
|
||||
return (this.fetchedMetadata[field as keyof BookMetadata] as string) || '';
|
||||
}
|
||||
return formValue;
|
||||
}
|
||||
|
||||
getArrayFromFormField(field: string, fallbackValue: any): any[] {
|
||||
getArrayFromFormField(field: string, fallbackValue: unknown): string[] {
|
||||
const fieldValue = this.metadataForm.get(field)?.value;
|
||||
if (!fieldValue) {
|
||||
return fallbackValue ? (Array.isArray(fallbackValue) ? fallbackValue : [fallbackValue]) : [];
|
||||
return fallbackValue ? (Array.isArray(fallbackValue) ? fallbackValue as string[] : [fallbackValue as string]) : [];
|
||||
}
|
||||
if (typeof fieldValue === 'string') {
|
||||
return fieldValue.split(',').map(item => item.trim());
|
||||
}
|
||||
return Array.isArray(fieldValue) ? fieldValue : [];
|
||||
return Array.isArray(fieldValue) ? fieldValue as string[] : [];
|
||||
}
|
||||
|
||||
lockAll(): void {
|
||||
|
||||
+5
-4
@@ -11,6 +11,7 @@ import {BookService} from '../../../book/service/book.service';
|
||||
import {Book, BulkMetadataUpdateRequest} from '../../../book/model/book.model';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {AutoCompleteSelectEvent} from 'primeng/autocomplete';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {filter, take} from "rxjs/operators";
|
||||
|
||||
@@ -181,10 +182,10 @@ export class BulkMetadataUpdateComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
onAutoCompleteSelect(fieldName: string, event: any) {
|
||||
const values = this.metadataForm.get(fieldName)?.value || [];
|
||||
if (!values.includes(event.value)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value]);
|
||||
onAutoCompleteSelect(fieldName: string, event: AutoCompleteSelectEvent) {
|
||||
const values = (this.metadataForm.get(fieldName)?.value as string[]) || [];
|
||||
if (!values.includes(event.value as string)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value as string]);
|
||||
}
|
||||
(event.originalEvent.target as HTMLInputElement).value = "";
|
||||
}
|
||||
|
||||
+5
-2
@@ -556,8 +556,11 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
filterGlobal(event: any, dt: any) {
|
||||
dt.filterGlobal(event.target.value, 'contains');
|
||||
filterGlobal(event: Event, dt: { filterGlobal: (value: string, matchMode: string) => void }): void {
|
||||
const target = event.target as HTMLInputElement;
|
||||
if (target) {
|
||||
dt.filterGlobal(target.value, 'contains');
|
||||
}
|
||||
}
|
||||
|
||||
onMetadataClick(type: MetadataType, value: string): void {
|
||||
|
||||
Reference in New Issue
Block a user