fix(loading): update loading checks to use signal() for reactive state management (#727)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<ng-container *transloco="let t; prefix: 'app'">
|
<ng-container *transloco="let t; prefix: 'app'">
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="splash-screen">
|
<div class="splash-screen">
|
||||||
<div class="splash-content">
|
<div class="splash-content">
|
||||||
<svg class="logo" viewBox="0 0 100 126" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg class="logo" viewBox="0 0 100 126" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</linearGradient>
|
</linearGradient>
|
||||||
</defs>
|
</defs>
|
||||||
</svg>
|
</svg>
|
||||||
@if (offline) {
|
@if (offline()) {
|
||||||
<h1>{{ t('offline') }}</h1>
|
<h1>{{ t('offline') }}</h1>
|
||||||
<p>{{ t('offlineLoadingDescription') }}</p>
|
<p>{{ t('offlineLoadingDescription') }}</p>
|
||||||
<p>{{ t('offlineDescription') }}</p>
|
<p>{{ t('offlineDescription') }}</p>
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
} @else if (offline) {
|
} @else if (offline()) {
|
||||||
<div class="splash-screen">
|
<div class="splash-screen">
|
||||||
<div class="splash-content">
|
<div class="splash-content">
|
||||||
<svg class="logo" viewBox="0 0 100 126" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg class="logo" viewBox="0 0 100 126" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ describe("AppComponent", () => {
|
|||||||
it("boots the websocket wiring when auth initialization is ready", () => {
|
it("boots the websocket wiring when auth initialization is ready", () => {
|
||||||
configureComponent();
|
configureComponent();
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(libraryHealthService.initWebsocket).toHaveBeenCalledOnce();
|
expect(libraryHealthService.initWebsocket).toHaveBeenCalledOnce();
|
||||||
expect(libraryHealthService.fetchHealth).toHaveBeenCalledOnce();
|
expect(libraryHealthService.fetchHealth).toHaveBeenCalledOnce();
|
||||||
expect(rxStompService.watch).toHaveBeenCalledWith("/user/queue/book-add");
|
expect(rxStompService.watch).toHaveBeenCalledWith("/user/queue/book-add");
|
||||||
@@ -148,7 +148,7 @@ describe("AppComponent", () => {
|
|||||||
it("boots the websocket wiring but don't fetch library health when not authenticated", () => {
|
it("boots the websocket wiring but don't fetch library health when not authenticated", () => {
|
||||||
configureComponent({ ready: true, authenticated: false });
|
configureComponent({ ready: true, authenticated: false });
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(libraryHealthService.initWebsocket).toHaveBeenCalledOnce();
|
expect(libraryHealthService.initWebsocket).toHaveBeenCalledOnce();
|
||||||
expect(libraryHealthService.fetchHealth).not.toHaveBeenCalled();
|
expect(libraryHealthService.fetchHealth).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
import {Component, effect, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
||||||
import {RxStompService} from './shared/websocket/rx-stomp.service';
|
import {RxStompService} from './shared/websocket/rx-stomp.service';
|
||||||
import {BookService} from './features/book/service/book.service';
|
import {BookService} from './features/book/service/book.service';
|
||||||
import {NotificationEventService} from './shared/websocket/notification-event.service';
|
import {NotificationEventService} from './shared/websocket/notification-event.service';
|
||||||
@@ -29,8 +29,8 @@ import {AuthService} from './shared/service/auth.service';
|
|||||||
})
|
})
|
||||||
export class AppComponent implements OnInit, OnDestroy {
|
export class AppComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
loading = true;
|
loading = signal(true);
|
||||||
offline = false;
|
offline = signal(false);
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
private subscriptionsInitialized = false;
|
private subscriptionsInitialized = false;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
private authService = inject(AuthService);
|
private authService = inject(AuthService);
|
||||||
private readonly syncAuthInitializationEffect = effect(() => {
|
private readonly syncAuthInitializationEffect = effect(() => {
|
||||||
const ready = this.authInit.initialized();
|
const ready = this.authInit.initialized();
|
||||||
this.loading = !ready;
|
this.loading.set(!ready);
|
||||||
|
|
||||||
if (ready && !this.subscriptionsInitialized) {
|
if (ready && !this.subscriptionsInitialized) {
|
||||||
this.setupWebSocketSubscriptions();
|
this.setupWebSocketSubscriptions();
|
||||||
@@ -71,12 +71,12 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onOnline = () => {
|
private onOnline = () => {
|
||||||
this.offline = false;
|
this.offline.set(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onOffline = () => {
|
private onOffline = () => {
|
||||||
this.checkServerReachable().then(reachable => {
|
this.checkServerReachable().then(reachable => {
|
||||||
this.offline = !reachable;
|
this.offline.set(!reachable);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,7 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (isUploading) {
|
@if (isUploading()) {
|
||||||
<p-progressSpinner class="upload-spinner" strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
<p-progressSpinner class="upload-spinner" strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,9 +123,9 @@
|
|||||||
<p-divider layout="vertical"/>
|
<p-divider layout="vertical"/>
|
||||||
<p-button
|
<p-button
|
||||||
type="submit"
|
type="submit"
|
||||||
[label]="isSaving ? t('saving') : t('saveBtn')"
|
[label]="isSaving() ? t('saving') : t('saveBtn')"
|
||||||
[icon]="isSaving ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
[icon]="isSaving() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||||
[disabled]="isSaving">
|
[disabled]="isSaving()">
|
||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+7
-7
@@ -145,7 +145,7 @@ describe('AuthorEditorComponent', () => {
|
|||||||
|
|
||||||
component.onSave();
|
component.onSave();
|
||||||
|
|
||||||
expect(component.isSaving).toBe(true);
|
expect(component.isSaving()).toBe(true);
|
||||||
expect(updateAuthor).toHaveBeenCalledWith(9, {
|
expect(updateAuthor).toHaveBeenCalledWith(9, {
|
||||||
name: undefined,
|
name: undefined,
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
@@ -159,7 +159,7 @@ describe('AuthorEditorComponent', () => {
|
|||||||
save$.next(updatedAuthor);
|
save$.next(updatedAuthor);
|
||||||
save$.complete();
|
save$.complete();
|
||||||
|
|
||||||
expect(component.isSaving).toBe(false);
|
expect(component.isSaving()).toBe(false);
|
||||||
expect(emitSpy).toHaveBeenCalledWith(updatedAuthor);
|
expect(emitSpy).toHaveBeenCalledWith(updatedAuthor);
|
||||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successSummary');
|
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successSummary');
|
||||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successDetail');
|
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.successDetail');
|
||||||
@@ -179,7 +179,7 @@ describe('AuthorEditorComponent', () => {
|
|||||||
|
|
||||||
component.onSave();
|
component.onSave();
|
||||||
|
|
||||||
expect(component.isSaving).toBe(false);
|
expect(component.isSaving()).toBe(false);
|
||||||
expect(emitSpy).not.toHaveBeenCalled();
|
expect(emitSpy).not.toHaveBeenCalled();
|
||||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorSummary');
|
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorSummary');
|
||||||
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorDetail');
|
expect(translate).toHaveBeenCalledWith('authorBrowser.editor.toast.errorDetail');
|
||||||
@@ -224,12 +224,12 @@ describe('AuthorEditorComponent', () => {
|
|||||||
const emitSpy = vi.spyOn(component.authorUpdated, 'emit');
|
const emitSpy = vi.spyOn(component.authorUpdated, 'emit');
|
||||||
const nowSpy = vi.spyOn(Date, 'now').mockReturnValue(999);
|
const nowSpy = vi.spyOn(Date, 'now').mockReturnValue(999);
|
||||||
|
|
||||||
component.isUploading = true;
|
component.isUploading.set(true);
|
||||||
component.hasPhoto = false;
|
component.hasPhoto = false;
|
||||||
|
|
||||||
component.onUpload();
|
component.onUpload();
|
||||||
|
|
||||||
expect(component.isUploading).toBe(false);
|
expect(component.isUploading()).toBe(false);
|
||||||
expect(component.hasPhoto).toBe(true);
|
expect(component.hasPhoto).toBe(true);
|
||||||
expect(component.photoTimestamp).toBe(999);
|
expect(component.photoTimestamp).toBe(999);
|
||||||
expect(emitSpy).toHaveBeenCalledWith(component.author);
|
expect(emitSpy).toHaveBeenCalledWith(component.author);
|
||||||
@@ -243,11 +243,11 @@ describe('AuthorEditorComponent', () => {
|
|||||||
|
|
||||||
it('clears upload progress and shows an error toast when upload fails', () => {
|
it('clears upload progress and shows an error toast when upload fails', () => {
|
||||||
const component = createComponent();
|
const component = createComponent();
|
||||||
component.isUploading = true;
|
component.isUploading.set(true);
|
||||||
|
|
||||||
component.onUploadError();
|
component.onUploadError();
|
||||||
|
|
||||||
expect(component.isUploading).toBe(false);
|
expect(component.isUploading()).toBe(false);
|
||||||
expect(messageService.add).toHaveBeenCalledWith({
|
expect(messageService.add).toHaveBeenCalledWith({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'authorBrowser.editor.toast.errorSummary',
|
summary: 'authorBrowser.editor.toast.errorSummary',
|
||||||
|
|||||||
+10
-10
@@ -1,4 +1,4 @@
|
|||||||
import {Component, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
|
import {Component, EventEmitter, inject, Input, OnChanges, OnInit, Output, signal, SimpleChanges} from '@angular/core';
|
||||||
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
@@ -46,8 +46,8 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
private t = inject(TranslocoService);
|
private t = inject(TranslocoService);
|
||||||
|
|
||||||
form!: FormGroup;
|
form!: FormGroup;
|
||||||
isSaving = false;
|
isSaving = signal(false);
|
||||||
isUploading = false;
|
isUploading = signal(false);
|
||||||
hasPhoto = true;
|
hasPhoto = true;
|
||||||
photoTimestamp = Date.now();
|
photoTimestamp = Date.now();
|
||||||
|
|
||||||
@@ -152,11 +152,11 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onBeforeUpload(): void {
|
onBeforeUpload(): void {
|
||||||
this.isUploading = true;
|
this.isUploading.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpload(): void {
|
onUpload(): void {
|
||||||
this.isUploading = false;
|
this.isUploading.set(false);
|
||||||
this.photoTimestamp = Date.now();
|
this.photoTimestamp = Date.now();
|
||||||
this.hasPhoto = true;
|
this.hasPhoto = true;
|
||||||
this.authorUpdated.emit(this.author);
|
this.authorUpdated.emit(this.author);
|
||||||
@@ -168,7 +168,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onUploadError(): void {
|
onUploadError(): void {
|
||||||
this.isUploading = false;
|
this.isUploading.set(false);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||||
@@ -177,8 +177,8 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private saveMetadata(): void {
|
private saveMetadata(): void {
|
||||||
if (this.isSaving) return;
|
if (this.isSaving()) return;
|
||||||
this.isSaving = true;
|
this.isSaving.set(true);
|
||||||
|
|
||||||
const formValue = this.form.getRawValue();
|
const formValue = this.form.getRawValue();
|
||||||
const request = {
|
const request = {
|
||||||
@@ -193,7 +193,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
this.authorService.updateAuthor(this.authorId, request).subscribe({
|
this.authorService.updateAuthor(this.authorId, request).subscribe({
|
||||||
next: (updated) => {
|
next: (updated) => {
|
||||||
this.isSaving = false;
|
this.isSaving.set(false);
|
||||||
this.authorUpdated.emit(updated);
|
this.authorUpdated.emit(updated);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
@@ -202,7 +202,7 @@ export class AuthorEditorComponent implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.isSaving = false;
|
this.isSaving.set(false);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
summary: this.t.translate('authorBrowser.editor.toast.errorSummary'),
|
||||||
|
|||||||
+4
-4
@@ -83,8 +83,8 @@
|
|||||||
[text]="true"
|
[text]="true"
|
||||||
severity="info"
|
severity="info"
|
||||||
(onClick)="fetchMetadataByIsbn()"
|
(onClick)="fetchMetadataByIsbn()"
|
||||||
[disabled]="!isbn.trim() || isFetchingMetadata"
|
[disabled]="!isbn.trim() || isFetchingMetadata()"
|
||||||
[loading]="isFetchingMetadata"
|
[loading]="isFetchingMetadata()"
|
||||||
[pTooltip]="t('fetchMetadataTooltip')"
|
[pTooltip]="t('fetchMetadataTooltip')"
|
||||||
tooltipPosition="top"/>
|
tooltipPosition="top"/>
|
||||||
</div>
|
</div>
|
||||||
@@ -250,8 +250,8 @@
|
|||||||
icon="pi pi-plus"
|
icon="pi pi-plus"
|
||||||
severity="success"
|
severity="success"
|
||||||
(onClick)="createBook()"
|
(onClick)="createBook()"
|
||||||
[disabled]="!canCreate() || isLoading"
|
[disabled]="!canCreate() || isLoading()"
|
||||||
[loading]="isLoading"/>
|
[loading]="isLoading()"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+9
-9
@@ -181,7 +181,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
component.fetchMetadataByIsbn();
|
component.fetchMetadataByIsbn();
|
||||||
|
|
||||||
expect(lookupByIsbn).toHaveBeenCalledWith('9780441172719');
|
expect(lookupByIsbn).toHaveBeenCalledWith('9780441172719');
|
||||||
expect(component.isFetchingMetadata).toBe(true);
|
expect(component.isFetchingMetadata()).toBe(true);
|
||||||
|
|
||||||
lookupResult$.next(createMetadata({
|
lookupResult$.next(createMetadata({
|
||||||
title: 'Dune',
|
title: 'Dune',
|
||||||
@@ -205,7 +205,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
expect(component.pageCount).toBe(412);
|
expect(component.pageCount).toBe(412);
|
||||||
expect(component.categories).toEqual(['Science Fiction']);
|
expect(component.categories).toEqual(['Science Fiction']);
|
||||||
expect(component.coverUrl).toBe('https://covers.example/dune.jpg');
|
expect(component.coverUrl).toBe('https://covers.example/dune.jpg');
|
||||||
expect(component.isFetchingMetadata).toBe(false);
|
expect(component.isFetchingMetadata()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not start isbn lookup for blank or in-flight requests and clears the flag on error', () => {
|
it('does not start isbn lookup for blank or in-flight requests and clears the flag on error', () => {
|
||||||
@@ -216,17 +216,17 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
expect(lookupByIsbn).not.toHaveBeenCalled();
|
expect(lookupByIsbn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
component.isbn = '9780441172719';
|
component.isbn = '9780441172719';
|
||||||
component.isFetchingMetadata = true;
|
component.isFetchingMetadata.set(true);
|
||||||
component.fetchMetadataByIsbn();
|
component.fetchMetadataByIsbn();
|
||||||
expect(lookupByIsbn).not.toHaveBeenCalled();
|
expect(lookupByIsbn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
component.isFetchingMetadata = false;
|
component.isFetchingMetadata.set(false);
|
||||||
lookupByIsbn.mockReturnValueOnce(throwError(() => new Error('lookup failed')));
|
lookupByIsbn.mockReturnValueOnce(throwError(() => new Error('lookup failed')));
|
||||||
|
|
||||||
component.fetchMetadataByIsbn();
|
component.fetchMetadataByIsbn();
|
||||||
|
|
||||||
expect(lookupByIsbn).toHaveBeenCalledWith('9780441172719');
|
expect(lookupByIsbn).toHaveBeenCalledWith('9780441172719');
|
||||||
expect(component.isFetchingMetadata).toBe(false);
|
expect(component.isFetchingMetadata()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gates creation on required fields and does not submit when already loading', () => {
|
it('gates creation on required fields and does not submit when already loading', () => {
|
||||||
@@ -240,7 +240,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
component.title = 'Physical Copy';
|
component.title = 'Physical Copy';
|
||||||
expect(component.canCreate()).toBe(true);
|
expect(component.canCreate()).toBe(true);
|
||||||
|
|
||||||
component.isLoading = true;
|
component.isLoading.set(true);
|
||||||
component.createBook();
|
component.createBook();
|
||||||
|
|
||||||
expect(createPhysicalBook).not.toHaveBeenCalled();
|
expect(createPhysicalBook).not.toHaveBeenCalled();
|
||||||
@@ -270,7 +270,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
|
|
||||||
component.createBook();
|
component.createBook();
|
||||||
|
|
||||||
expect(component.isLoading).toBe(true);
|
expect(component.isLoading()).toBe(true);
|
||||||
expect(createPhysicalBook).toHaveBeenCalledWith({
|
expect(createPhysicalBook).toHaveBeenCalledWith({
|
||||||
libraryId: 2,
|
libraryId: 2,
|
||||||
title: 'The Left Hand of Darkness',
|
title: 'The Left Hand of Darkness',
|
||||||
@@ -288,7 +288,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
createResult$.next(createdBook);
|
createResult$.next(createdBook);
|
||||||
createResult$.complete();
|
createResult$.complete();
|
||||||
|
|
||||||
expect(component.isLoading).toBe(false);
|
expect(component.isLoading()).toBe(false);
|
||||||
expect(dialogRef.close).toHaveBeenCalledWith(createdBook);
|
expect(dialogRef.close).toHaveBeenCalledWith(createdBook);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ describe('AddPhysicalBookDialogComponent', () => {
|
|||||||
categories: undefined,
|
categories: undefined,
|
||||||
thumbnailUrl: undefined,
|
thumbnailUrl: undefined,
|
||||||
});
|
});
|
||||||
expect(component.isLoading).toBe(false);
|
expect(component.isLoading()).toBe(false);
|
||||||
expect(dialogRef.close).not.toHaveBeenCalled();
|
expect(dialogRef.close).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
import {Component, computed, effect, inject} from '@angular/core';
|
import {Component, computed, effect, inject, signal} from '@angular/core';
|
||||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
@@ -57,8 +57,8 @@ export class AddPhysicalBookDialogComponent {
|
|||||||
filteredCategories: string[] = [];
|
filteredCategories: string[] = [];
|
||||||
|
|
||||||
coverUrl: string | null = null;
|
coverUrl: string | null = null;
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
isFetchingMetadata: boolean = false;
|
isFetchingMetadata = signal(false);
|
||||||
private readonly initializeSelectedLibraryEffect = effect(() => {
|
private readonly initializeSelectedLibraryEffect = effect(() => {
|
||||||
const libraries = this.libraries;
|
const libraries = this.libraries;
|
||||||
if (libraries.length === 0) {
|
if (libraries.length === 0) {
|
||||||
@@ -117,9 +117,9 @@ export class AddPhysicalBookDialogComponent {
|
|||||||
|
|
||||||
fetchMetadataByIsbn(): void {
|
fetchMetadataByIsbn(): void {
|
||||||
const isbnValue = this.isbn.trim();
|
const isbnValue = this.isbn.trim();
|
||||||
if (!isbnValue || this.isFetchingMetadata) return;
|
if (!isbnValue || this.isFetchingMetadata()) return;
|
||||||
|
|
||||||
this.isFetchingMetadata = true;
|
this.isFetchingMetadata.set(true);
|
||||||
this.bookMetadataService.lookupByIsbn(isbnValue).subscribe({
|
this.bookMetadataService.lookupByIsbn(isbnValue).subscribe({
|
||||||
next: (metadata) => {
|
next: (metadata) => {
|
||||||
if (metadata.title) this.title = metadata.title;
|
if (metadata.title) this.title = metadata.title;
|
||||||
@@ -131,10 +131,10 @@ export class AddPhysicalBookDialogComponent {
|
|||||||
if (metadata.pageCount) this.pageCount = metadata.pageCount;
|
if (metadata.pageCount) this.pageCount = metadata.pageCount;
|
||||||
if (metadata.categories?.length) this.categories = [...metadata.categories];
|
if (metadata.categories?.length) this.categories = [...metadata.categories];
|
||||||
this.coverUrl = metadata.thumbnailUrl || null;
|
this.coverUrl = metadata.thumbnailUrl || null;
|
||||||
this.isFetchingMetadata = false;
|
this.isFetchingMetadata.set(false);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.isFetchingMetadata = false;
|
this.isFetchingMetadata.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -148,9 +148,9 @@ export class AddPhysicalBookDialogComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createBook(): void {
|
createBook(): void {
|
||||||
if (!this.canCreate() || this.isLoading) return;
|
if (!this.canCreate() || this.isLoading()) return;
|
||||||
|
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
|
|
||||||
const request: CreatePhysicalBookRequest = {
|
const request: CreatePhysicalBookRequest = {
|
||||||
libraryId: this.selectedLibraryId!,
|
libraryId: this.selectedLibraryId!,
|
||||||
@@ -168,11 +168,11 @@ export class AddPhysicalBookDialogComponent {
|
|||||||
|
|
||||||
this.bookService.createPhysicalBook(request).subscribe({
|
this.bookService.createPhysicalBook(request).subscribe({
|
||||||
next: (book) => {
|
next: (book) => {
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
this.dynamicDialogRef.close(book);
|
this.dynamicDialogRef.close(book);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="book-notes-container">
|
<div class="book-notes-container">
|
||||||
<div class="notes-content">
|
<div class="notes-content">
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<p-progressSpinner/>
|
<p-progressSpinner/>
|
||||||
<span class="loading-text">Loading notes...</span>
|
<span class="loading-text">Loading notes...</span>
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ describe('BookNotesComponent', () => {
|
|||||||
component.loadNotes();
|
component.loadNotes();
|
||||||
|
|
||||||
expect(bookNoteService.getNotesForBook).not.toHaveBeenCalled();
|
expect(bookNoteService.getNotesForBook).not.toHaveBeenCalled();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads notes and orders them by most recent update first', () => {
|
it('loads notes and orders them by most recent update first', () => {
|
||||||
@@ -98,7 +98,7 @@ describe('BookNotesComponent', () => {
|
|||||||
|
|
||||||
expect(bookNoteService.getNotesForBook).toHaveBeenCalledWith(42);
|
expect(bookNoteService.getNotesForBook).toHaveBeenCalledWith(42);
|
||||||
expect(component.notes.map(note => note.id)).toEqual([2, 3, 1]);
|
expect(component.notes.map(note => note.id)).toEqual([2, 3, 1]);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows an error toast when loading notes fails', () => {
|
it('shows an error toast when loading notes fails', () => {
|
||||||
@@ -106,7 +106,7 @@ describe('BookNotesComponent', () => {
|
|||||||
|
|
||||||
component.loadNotes();
|
component.loadNotes();
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(messageService.add).toHaveBeenCalledWith({
|
expect(messageService.add).toHaveBeenCalledWith({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'common.error',
|
summary: 'common.error',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, signal, SimpleChanges} from '@angular/core';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
@@ -38,7 +38,7 @@ export class BookNotesComponent implements OnInit, OnChanges {
|
|||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
|
|
||||||
notes: BookNote[] = [];
|
notes: BookNote[] = [];
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
showCreateDialog = false;
|
showCreateDialog = false;
|
||||||
showEditDialog = false;
|
showEditDialog = false;
|
||||||
selectedNote: BookNote | null = null;
|
selectedNote: BookNote | null = null;
|
||||||
@@ -70,7 +70,7 @@ export class BookNotesComponent implements OnInit, OnChanges {
|
|||||||
loadNotes(): void {
|
loadNotes(): void {
|
||||||
if (!this.bookId) return;
|
if (!this.bookId) return;
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.bookNoteService.getNotesForBook(this.bookId)
|
this.bookNoteService.getNotesForBook(this.bookId)
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
@@ -78,11 +78,11 @@ export class BookNotesComponent implements OnInit, OnChanges {
|
|||||||
this.notes = notes.sort((a, b) =>
|
this.notes = notes.sort((a, b) =>
|
||||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||||
);
|
);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Failed to load notes:', error);
|
console.error('Failed to load notes:', error);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('common.error'),
|
summary: this.t.translate('common.error'),
|
||||||
|
|||||||
+12
-12
@@ -1,7 +1,7 @@
|
|||||||
<ng-container *transloco="let t; prefix: 'book.reviews'">
|
<ng-container *transloco="let t; prefix: 'book.reviews'">
|
||||||
<div class="book-reviews-container">
|
<div class="book-reviews-container">
|
||||||
<div class="reviews-content">
|
<div class="reviews-content">
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<p-progressSpinner/>
|
<p-progressSpinner/>
|
||||||
<span class="loading-text">{{ t('labels.loadingReviews') }}</span>
|
<span class="loading-text">{{ t('labels.loadingReviews') }}</span>
|
||||||
@@ -156,9 +156,9 @@
|
|||||||
[icon]="reviewsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
[icon]="reviewsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||||
size="small"
|
size="small"
|
||||||
[severity]="reviewsLocked ? 'danger' : 'success'"
|
[severity]="reviewsLocked ? 'danger' : 'success'"
|
||||||
[disabled]="!reviewDownloadEnabled || loading"
|
[disabled]="!reviewDownloadEnabled || loading()"
|
||||||
(click)="toggleReviewsLock()"
|
(click)="toggleReviewsLock()"
|
||||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.unlockReviews') : t('tooltip.lockReviews')))"
|
[pTooltip]="loading() ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.unlockReviews') : t('tooltip.lockReviews')))"
|
||||||
tooltipPosition="left"
|
tooltipPosition="left"
|
||||||
class="action-btn"/>
|
class="action-btn"/>
|
||||||
|
|
||||||
@@ -167,10 +167,10 @@
|
|||||||
icon="pi pi-refresh"
|
icon="pi pi-refresh"
|
||||||
size="small"
|
size="small"
|
||||||
severity="primary"
|
severity="primary"
|
||||||
[loading]="loading"
|
[loading]="loading()"
|
||||||
[disabled]="reviewsLocked || !reviewDownloadEnabled || loading"
|
[disabled]="reviewsLocked || !reviewDownloadEnabled || loading()"
|
||||||
(click)="fetchNewReviews()"
|
(click)="fetchNewReviews()"
|
||||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.fetchNewReviews')))"
|
[pTooltip]="loading() ? t('tooltip.pleaseWait') : (!reviewDownloadEnabled ? t('tooltip.enableDownloads') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.fetchNewReviews')))"
|
||||||
tooltipPosition="left"
|
tooltipPosition="left"
|
||||||
class="action-btn"/>
|
class="action-btn"/>
|
||||||
}
|
}
|
||||||
@@ -181,9 +181,9 @@
|
|||||||
icon="pi pi-trash"
|
icon="pi pi-trash"
|
||||||
size="small"
|
size="small"
|
||||||
severity="danger"
|
severity="danger"
|
||||||
[disabled]="reviewsLocked || loading"
|
[disabled]="reviewsLocked || loading()"
|
||||||
(click)="deleteAllReviews()"
|
(click)="deleteAllReviews()"
|
||||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.deleteAllReviews'))"
|
[pTooltip]="loading() ? t('tooltip.pleaseWait') : (reviewsLocked ? t('tooltip.reviewsLocked') : t('tooltip.deleteAllReviews'))"
|
||||||
tooltipPosition="left"
|
tooltipPosition="left"
|
||||||
class="action-btn"/>
|
class="action-btn"/>
|
||||||
}
|
}
|
||||||
@@ -194,9 +194,9 @@
|
|||||||
[icon]="allSpoilersRevealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
[icon]="allSpoilersRevealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||||
size="small"
|
size="small"
|
||||||
[severity]="allSpoilersRevealed ? 'warn' : 'info'"
|
[severity]="allSpoilersRevealed ? 'warn' : 'info'"
|
||||||
[disabled]="loading"
|
[disabled]="loading()"
|
||||||
(click)="toggleSpoilerVisibility()"
|
(click)="toggleSpoilerVisibility()"
|
||||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (allSpoilersRevealed ? t('tooltip.hideAllSpoilers') : t('tooltip.revealAllSpoilers'))"
|
[pTooltip]="loading() ? t('tooltip.pleaseWait') : (allSpoilersRevealed ? t('tooltip.hideAllSpoilers') : t('tooltip.revealAllSpoilers'))"
|
||||||
tooltipPosition="left"
|
tooltipPosition="left"
|
||||||
class="action-btn"/>
|
class="action-btn"/>
|
||||||
|
|
||||||
@@ -205,9 +205,9 @@
|
|||||||
icon="pi pi-sort-amount-down"
|
icon="pi pi-sort-amount-down"
|
||||||
size="small"
|
size="small"
|
||||||
severity="contrast"
|
severity="contrast"
|
||||||
[disabled]="loading"
|
[disabled]="loading()"
|
||||||
(click)="toggleSortOrder()"
|
(click)="toggleSortOrder()"
|
||||||
[pTooltip]="loading ? t('tooltip.pleaseWait') : (sortAscending ? t('tooltip.sortNewest') : t('tooltip.sortOldest'))"
|
[pTooltip]="loading() ? t('tooltip.pleaseWait') : (sortAscending ? t('tooltip.sortNewest') : t('tooltip.sortOldest'))"
|
||||||
tooltipPosition="left"
|
tooltipPosition="left"
|
||||||
class="action-btn"/>
|
class="action-btn"/>
|
||||||
}
|
}
|
||||||
|
|||||||
+95
-4
@@ -1,6 +1,7 @@
|
|||||||
import {SimpleChange} from '@angular/core';
|
import {SimpleChange} from '@angular/core';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {of, throwError} from 'rxjs';
|
import {of, throwError, delay} from 'rxjs';
|
||||||
|
|
||||||
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||||
import {TranslocoService} from '@jsverse/transloco';
|
import {TranslocoService} from '@jsverse/transloco';
|
||||||
@@ -151,7 +152,7 @@ describe('BookReviewsComponent', () => {
|
|||||||
expect(reviewService.getByBookId).toHaveBeenCalledWith(42);
|
expect(reviewService.getByBookId).toHaveBeenCalledWith(42);
|
||||||
expect(component.reviews?.map(review => review.id)).toEqual([3, 2, 1]);
|
expect(component.reviews?.map(review => review.id)).toEqual([3, 2, 1]);
|
||||||
expect(component.reviewsLocked).toBe(true);
|
expect(component.reviewsLocked).toBe(true);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('refreshes reviews, clears revealed spoilers, and shows a success toast', () => {
|
it('refreshes reviews, clears revealed spoilers, and shows a success toast', () => {
|
||||||
@@ -167,7 +168,7 @@ describe('BookReviewsComponent', () => {
|
|||||||
expect(component.reviews?.map(review => review.id)).toEqual([5, 4]);
|
expect(component.reviews?.map(review => review.id)).toEqual([5, 4]);
|
||||||
expect(component.revealedSpoilers.size).toBe(0);
|
expect(component.revealedSpoilers.size).toBe(0);
|
||||||
expect(component.allSpoilersRevealed).toBe(false);
|
expect(component.allSpoilersRevealed).toBe(false);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(messageService.add).toHaveBeenCalledWith({
|
expect(messageService.add).toHaveBeenCalledWith({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'book.reviews.toast.reviewsUpdatedSummary',
|
summary: 'book.reviews.toast.reviewsUpdatedSummary',
|
||||||
@@ -184,7 +185,7 @@ describe('BookReviewsComponent', () => {
|
|||||||
component.fetchNewReviews();
|
component.fetchNewReviews();
|
||||||
|
|
||||||
expect(errorSpy).toHaveBeenCalledWith('Failed to fetch new reviews:', error);
|
expect(errorSpy).toHaveBeenCalledWith('Failed to fetch new reviews:', error);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(messageService.add).toHaveBeenCalledWith({
|
expect(messageService.add).toHaveBeenCalledWith({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'book.reviews.toast.fetchFailedSummary',
|
summary: 'book.reviews.toast.fetchFailedSummary',
|
||||||
@@ -339,4 +340,94 @@ describe('BookReviewsComponent', () => {
|
|||||||
expect(component.getProviderSeverity('goodreads')).toBe('success');
|
expect(component.getProviderSeverity('goodreads')).toBe('success');
|
||||||
expect(component.formatDate('2026-03-28T12:00:00.000Z')).toBe('March 28, 2026');
|
expect(component.formatDate('2026-03-28T12:00:00.000Z')).toBe('March 28, 2026');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ignores stale responses if the bookId changes while a request is in-flight', async () => {
|
||||||
|
const book1Reviews = [createReview(1)];
|
||||||
|
const book2Reviews = [createReview(2)];
|
||||||
|
|
||||||
|
// First request is slow
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of(book1Reviews).pipe(delay(50)));
|
||||||
|
// Second request is fast
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of(book2Reviews));
|
||||||
|
|
||||||
|
// Select book 1
|
||||||
|
component.bookId = 1;
|
||||||
|
component.ngOnChanges({
|
||||||
|
bookId: new SimpleChange(undefined, 1, true),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Immediately select book 2 while book 1 is still loading
|
||||||
|
component.bookId = 2;
|
||||||
|
component.ngOnChanges({
|
||||||
|
bookId: new SimpleChange(1, 2, false),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for both to complete
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
|
||||||
|
// Should only have book 2's reviews
|
||||||
|
expect(component.reviews?.map(r => r.id)).toEqual([2]);
|
||||||
|
expect(component.loading()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not prematurely clear loading if a refresh finishes while a new book load is in-flight', async () => {
|
||||||
|
// 1. fetchNewReviews(42) starts
|
||||||
|
reviewService.refreshReviews.mockReturnValueOnce(of([]).pipe(delay(50)));
|
||||||
|
component.fetchNewReviews();
|
||||||
|
expect(component.loading()).toBe(true);
|
||||||
|
|
||||||
|
// 2. Switch to book 43 -> loadReviews(43) starts
|
||||||
|
// Use a longer delay for the new book load
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of([]).pipe(delay(100)));
|
||||||
|
component.bookId = 43;
|
||||||
|
component.ngOnChanges({
|
||||||
|
bookId: new SimpleChange(42, 43, false),
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. Wait for fetchNewReviews(42) to finish (after 50ms)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 75));
|
||||||
|
|
||||||
|
// 4. loading should still be true because loadReviews(43) is in flight
|
||||||
|
expect(component.loading()).toBe(true);
|
||||||
|
|
||||||
|
// 5. Wait for loadReviews(43) to finish (after 100ms total)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 50));
|
||||||
|
expect(component.loading()).toBe(false);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores stale responses in a 1 -> 2 -> 1 navigation sequence (ABA problem)', async () => {
|
||||||
|
const book1InitialReviews = [createReview(1, {body: 'First Request'})];
|
||||||
|
const book1LatestReviews = [createReview(1, {body: 'Second Request'})];
|
||||||
|
const book2Reviews = [createReview(2)];
|
||||||
|
|
||||||
|
// 1. First request for Book 1 is very slow
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of(book1InitialReviews).pipe(delay(100)));
|
||||||
|
// 2. Request for Book 2 is fast
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of(book2Reviews));
|
||||||
|
// 3. Second request for Book 1 is slow
|
||||||
|
reviewService.getByBookId.mockReturnValueOnce(of(book1LatestReviews).pipe(delay(50)));
|
||||||
|
|
||||||
|
// Navigate: Book 1
|
||||||
|
component.bookId = 1;
|
||||||
|
component.ngOnChanges({bookId: new SimpleChange(undefined, 1, true)});
|
||||||
|
|
||||||
|
// Navigate: Book 2
|
||||||
|
component.bookId = 2;
|
||||||
|
component.ngOnChanges({bookId: new SimpleChange(1, 2, false)});
|
||||||
|
|
||||||
|
// Navigate: Book 1 again
|
||||||
|
component.bookId = 1;
|
||||||
|
component.ngOnChanges({bookId: new SimpleChange(2, 1, false)});
|
||||||
|
|
||||||
|
// Wait for all requests to finish
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 150));
|
||||||
|
|
||||||
|
// Should have the reviews from the SECOND request for Book 1, not the first
|
||||||
|
expect(component.reviews?.[0].body).toBe('Second Request');
|
||||||
|
expect(component.loading()).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {Component, DestroyRef, effect, inject, Input, OnChanges, OnInit, signal, SimpleChanges} from '@angular/core';
|
import {Component, DestroyRef, effect, inject, Input, OnChanges, OnInit, signal, SimpleChanges} from '@angular/core';
|
||||||
|
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
|
import {finalize} from 'rxjs';
|
||||||
|
|
||||||
import {BookReview, BookReviewService} from './book-review-service';
|
import {BookReview, BookReviewService} from './book-review-service';
|
||||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
import {Rating} from 'primeng/rating';
|
import {Rating} from 'primeng/rating';
|
||||||
@@ -37,8 +39,13 @@ export class BookReviewsComponent implements OnInit, OnChanges {
|
|||||||
private destroyRef = inject(DestroyRef);
|
private destroyRef = inject(DestroyRef);
|
||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
private bookIdState = signal<number | null>(null);
|
private bookIdState = signal<number | null>(null);
|
||||||
|
private loadingBookId: number | null = null;
|
||||||
|
private loadingRequestSeq = 0;
|
||||||
|
private activeLoadingRequestSeq: number | null = null;
|
||||||
|
|
||||||
loading = false;
|
|
||||||
|
|
||||||
|
loading = signal(false);
|
||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
revealedSpoilers = new Set<number>();
|
revealedSpoilers = new Set<number>();
|
||||||
sortAscending = false;
|
sortAscending = false;
|
||||||
@@ -72,22 +79,36 @@ export class BookReviewsComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadReviews(): void {
|
private loadReviews(): void {
|
||||||
if (this.loading || !this.bookId) {
|
const requestedBookId = this.bookId;
|
||||||
|
if (!requestedBookId || this.loadingBookId === requestedBookId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = true;
|
const requestSeq = ++this.loadingRequestSeq;
|
||||||
this.reviewService.getByBookId(this.bookId)
|
this.loadingBookId = requestedBookId;
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
this.activeLoadingRequestSeq = requestSeq;
|
||||||
|
this.loading.set(true);
|
||||||
|
this.reviewService.getByBookId(requestedBookId)
|
||||||
|
.pipe(
|
||||||
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
finalize(() => {
|
||||||
|
if (this.activeLoadingRequestSeq === requestSeq) {
|
||||||
|
this.loadingBookId = null;
|
||||||
|
this.activeLoadingRequestSeq = null;
|
||||||
|
this.loading.set(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (reviews) => {
|
next: (reviews) => {
|
||||||
|
if (this.bookId !== requestedBookId || this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||||
this.loading = false;
|
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Failed to load reviews for bookId', this.bookId, ':', error);
|
if (this.bookId !== requestedBookId || this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
|
console.error('Failed to load reviews for bookId', requestedBookId, ':', error);
|
||||||
this.reviews = [];
|
this.reviews = [];
|
||||||
this.loading = false;
|
|
||||||
|
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
@@ -99,18 +120,33 @@ export class BookReviewsComponent implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchNewReviews(): void {
|
|
||||||
if (!this.bookId || this.loading || this.reviewsLocked) return;
|
|
||||||
|
|
||||||
this.loading = true;
|
fetchNewReviews(): void {
|
||||||
|
const requestedBookId = this.bookId;
|
||||||
|
if (!requestedBookId || this.loadingBookId === requestedBookId || this.loading() || this.reviewsLocked) return;
|
||||||
|
|
||||||
|
const requestSeq = ++this.loadingRequestSeq;
|
||||||
|
this.loadingBookId = requestedBookId;
|
||||||
|
this.activeLoadingRequestSeq = requestSeq;
|
||||||
|
this.loading.set(true);
|
||||||
this.revealedSpoilers.clear();
|
this.revealedSpoilers.clear();
|
||||||
|
|
||||||
this.reviewService.refreshReviews(this.bookId)
|
this.reviewService.refreshReviews(requestedBookId)
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
.pipe(
|
||||||
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
finalize(() => {
|
||||||
|
if (this.activeLoadingRequestSeq === requestSeq) {
|
||||||
|
this.loadingBookId = null;
|
||||||
|
this.activeLoadingRequestSeq = null;
|
||||||
|
this.loading.set(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (reviews) => {
|
next: (reviews) => {
|
||||||
|
if (this.bookId !== requestedBookId || this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||||
this.loading = false;
|
|
||||||
this.updateSpoilerState();
|
this.updateSpoilerState();
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
@@ -120,8 +156,9 @@ export class BookReviewsComponent implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
|
if (this.bookId !== requestedBookId || this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
console.error('Failed to fetch new reviews:', error);
|
console.error('Failed to fetch new reviews:', error);
|
||||||
this.loading = false;
|
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('book.reviews.toast.fetchFailedSummary'),
|
summary: this.t.translate('book.reviews.toast.fetchFailedSummary'),
|
||||||
@@ -132,6 +169,8 @@ export class BookReviewsComponent implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deleteAllReviews(): void {
|
deleteAllReviews(): void {
|
||||||
if (!this.reviews || this.reviews.length === 0 || this.reviewsLocked) return;
|
if (!this.reviews || this.reviews.length === 0 || this.reviewsLocked) return;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
|
|
||||||
<div class="loading-overlay">
|
<div class="loading-overlay">
|
||||||
<div class="loading-content">
|
<div class="loading-content">
|
||||||
@@ -269,7 +269,7 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (!loading) {
|
@if (!loading()) {
|
||||||
<p-divider></p-divider>
|
<p-divider></p-divider>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
|
|||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit, QueryList, ViewChildren} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, QueryList, signal, ViewChildren} from '@angular/core';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
import {startWith, take, tap} from 'rxjs/operators';
|
import {startWith, take, tap} from 'rxjs/operators';
|
||||||
import {PageTitleService} from "../../../../shared/service/page-title.service";
|
import {PageTitleService} from "../../../../shared/service/page-title.service";
|
||||||
@@ -86,7 +86,7 @@ export class BookdropFileReviewComponent implements OnInit {
|
|||||||
bookdropFileUis: BookdropFileUI[] = [];
|
bookdropFileUis: BookdropFileUI[] = [];
|
||||||
fileUiCache: Record<number, BookdropFileUI> = {};
|
fileUiCache: Record<number, BookdropFileUI> = {};
|
||||||
copiedFlags: Record<number, boolean> = {};
|
copiedFlags: Record<number, boolean> = {};
|
||||||
loading = true;
|
loading = signal(true);
|
||||||
saving = false;
|
saving = false;
|
||||||
includeCoversOnCopy = true;
|
includeCoversOnCopy = true;
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ export class BookdropFileReviewComponent implements OnInit {
|
|||||||
|
|
||||||
this.activatedRoute.queryParams
|
this.activatedRoute.queryParams
|
||||||
.pipe(startWith({}), tap(() => {
|
.pipe(startWith({}), tap(() => {
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.loadPage(0);
|
this.loadPage(0);
|
||||||
}))
|
}))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
@@ -198,12 +198,12 @@ export class BookdropFileReviewComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
this.totalRecords = response.page.totalElements;
|
this.totalRecords = response.page.totalElements;
|
||||||
this.currentPage = page;
|
this.currentPage = page;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.syncCurrentPageSelection();
|
this.syncCurrentPageSelection();
|
||||||
},
|
},
|
||||||
error: err => {
|
error: err => {
|
||||||
console.error('Error loading files:', err);
|
console.error('Error loading files:', err);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
<div class="reading-sessions-container" *transloco="let t; prefix: 'metadata.readingSessions'">
|
<div class="reading-sessions-container" *transloco="let t; prefix: 'metadata.readingSessions'">
|
||||||
@if (loading && sessions.length === 0) {
|
@if (loading() && sessions.length === 0) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<p-progressSpinner strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
<p-progressSpinner strokeWidth="4" fill="transparent" animationDuration=".8s"></p-progressSpinner>
|
||||||
<p class="loading-text">{{ t('loading') }}</p>
|
<p class="loading-text">{{ t('loading') }}</p>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
[value]="sessions"
|
[value]="sessions"
|
||||||
[paginator]="true"
|
[paginator]="true"
|
||||||
[rows]="rows"
|
[rows]="rows"
|
||||||
[loading]="loading"
|
[loading]="loading()"
|
||||||
[showCurrentPageReport]="true"
|
[showCurrentPageReport]="true"
|
||||||
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} sessions"
|
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} sessions"
|
||||||
class="p-datatable-sm">
|
class="p-datatable-sm">
|
||||||
|
|||||||
+3
-3
@@ -59,7 +59,7 @@ describe('BookReadingSessionsComponent', () => {
|
|||||||
|
|
||||||
expect(getSessionsByBookId).toHaveBeenCalledWith(7, 0, 100);
|
expect(getSessionsByBookId).toHaveBeenCalledWith(7, 0, 100);
|
||||||
expect(component.sessions).toEqual([session]);
|
expect(component.sessions).toEqual([session]);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.pageReportTemplate).toBe('translated:metadata.readingSessions.pageReport');
|
expect(component.pageReportTemplate).toBe('translated:metadata.readingSessions.pageReport');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ describe('BookReadingSessionsComponent', () => {
|
|||||||
component.bookId = 7;
|
component.bookId = 7;
|
||||||
|
|
||||||
component.loadSessions();
|
component.loadSessions();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.sessions).toEqual([]);
|
expect(component.sessions).toEqual([]);
|
||||||
|
|
||||||
component.bookId = 9;
|
component.bookId = 9;
|
||||||
@@ -85,7 +85,7 @@ describe('BookReadingSessionsComponent', () => {
|
|||||||
|
|
||||||
expect(getSessionsByBookId).toHaveBeenNthCalledWith(2, 9, 0, 100);
|
expect(getSessionsByBookId).toHaveBeenNthCalledWith(2, 9, 0, 100);
|
||||||
expect(component.sessions).toEqual([createSession({id: 2, bookId: 9})]);
|
expect(component.sessions).toEqual([createSession({id: 2, bookId: 9})]);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores the initial ngOnChanges first-change event', () => {
|
it('ignores the initial ngOnChanges first-change event', () => {
|
||||||
|
|||||||
+17
-5
@@ -1,5 +1,8 @@
|
|||||||
import {Component, inject, Input, OnInit, OnChanges, SimpleChanges} from '@angular/core';
|
import {Component, DestroyRef, inject, Input, OnInit, OnChanges, signal, SimpleChanges} from '@angular/core';
|
||||||
import {ReadingSessionApiService, ReadingSessionResponse} from '../../../../../shared/service/reading-session-api.service';
|
import {ReadingSessionApiService, ReadingSessionResponse} from '../../../../../shared/service/reading-session-api.service';
|
||||||
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
|
import {finalize, Subject, takeUntil} from 'rxjs';
|
||||||
|
|
||||||
import {TableModule} from 'primeng/table';
|
import {TableModule} from 'primeng/table';
|
||||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||||
@@ -16,11 +19,14 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
|||||||
@Input() bookId!: number;
|
@Input() bookId!: number;
|
||||||
|
|
||||||
private readonly readingSessionService = inject(ReadingSessionApiService);
|
private readonly readingSessionService = inject(ReadingSessionApiService);
|
||||||
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
private readonly cancelLoad$ = new Subject<void>();
|
||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
|
|
||||||
|
|
||||||
sessions: ReadingSessionResponse[] = [];
|
sessions: ReadingSessionResponse[] = [];
|
||||||
rows = 5;
|
rows = 5;
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
|
|
||||||
get pageReportTemplate(): string {
|
get pageReportTemplate(): string {
|
||||||
return this.t.translate('metadata.readingSessions.pageReport');
|
return this.t.translate('metadata.readingSessions.pageReport');
|
||||||
@@ -37,19 +43,25 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadSessions() {
|
loadSessions() {
|
||||||
this.loading = true;
|
this.cancelLoad$.next();
|
||||||
|
this.loading.set(true);
|
||||||
this.readingSessionService.getSessionsByBookId(this.bookId, 0, 100)
|
this.readingSessionService.getSessionsByBookId(this.bookId, 0, 100)
|
||||||
|
.pipe(
|
||||||
|
takeUntil(this.cancelLoad$),
|
||||||
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
finalize(() => this.loading.set(false))
|
||||||
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.sessions = response.content;
|
this.sessions = response.content;
|
||||||
this.loading = false;
|
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.loading = false;
|
this.sessions = [];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
formatDuration(seconds: number): string {
|
formatDuration(seconds: number): string {
|
||||||
const hours = Math.floor(seconds / 3600);
|
const hours = Math.floor(seconds / 3600);
|
||||||
const minutes = Math.floor((seconds % 3600) / 60);
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
|||||||
+6
-6
@@ -3,7 +3,7 @@
|
|||||||
<app-metadata-picker
|
<app-metadata-picker
|
||||||
[fetchedMetadata]="selectedFetchedMetadata"
|
[fetchedMetadata]="selectedFetchedMetadata"
|
||||||
[book]="book"
|
[book]="book"
|
||||||
[detailLoading]="detailLoading"
|
[detailLoading]="detailLoading()"
|
||||||
(goBack)="onGoBack()">
|
(goBack)="onGoBack()">
|
||||||
</app-metadata-picker>
|
</app-metadata-picker>
|
||||||
</div>
|
</div>
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
<p-button
|
<p-button
|
||||||
[label]="t('searchBtn')"
|
[label]="t('searchBtn')"
|
||||||
type="submit"
|
type="submit"
|
||||||
[disabled]="!isSearchEnabled || loading"
|
[disabled]="!isSearchEnabled || loading()"
|
||||||
icon="pi pi-search"
|
icon="pi pi-search"
|
||||||
class="'custom-search-button'">
|
class="'custom-search-button'">
|
||||||
</p-button>
|
</p-button>
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@if (loading || searchTriggered) {
|
@if (loading() || searchTriggered()) {
|
||||||
<div class="provider-status">
|
<div class="provider-status">
|
||||||
<div class="status-header">
|
<div class="status-header">
|
||||||
<div class="results-info">
|
<div class="results-info">
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
<span class="results-count">{{ t('booksFound', { count: filteredMetadata().length }) }}</span>
|
<span class="results-count">{{ t('booksFound', { count: filteredMetadata().length }) }}</span>
|
||||||
</div>
|
</div>
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<span class="fetching-badge">
|
<span class="fetching-badge">
|
||||||
<i class="pi pi-spin pi-spinner"></i>
|
<i class="pi pi-spin pi-spinner"></i>
|
||||||
{{ t('fetching') }}
|
{{ t('fetching') }}
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!searchTriggered && allFetchedMetadata().length === 0) {
|
@if (!searchTriggered() && allFetchedMetadata().length === 0) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="empty-icon">
|
<div class="empty-icon">
|
||||||
<i class="pi pi-search"></i>
|
<i class="pi pi-search"></i>
|
||||||
@@ -139,7 +139,7 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (searchTriggered && allFetchedMetadata().length === 0 && !loading) {
|
@if (searchTriggered() && allFetchedMetadata().length === 0 && !loading()) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="empty-icon no-results">
|
<div class="empty-icon no-results">
|
||||||
<i class="pi pi-inbox"></i>
|
<i class="pi pi-inbox"></i>
|
||||||
|
|||||||
+13
-13
@@ -36,8 +36,8 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
providers: string[] = [];
|
providers: string[] = [];
|
||||||
|
|
||||||
bookId!: number;
|
bookId!: number;
|
||||||
loading: boolean = false;
|
loading = signal(false);
|
||||||
searchTriggered = false;
|
searchTriggered = signal(false);
|
||||||
|
|
||||||
private currentBook: Book | null = null;
|
private currentBook: Book | null = null;
|
||||||
private currentSettings: AppSettings | null = null;
|
private currentSettings: AppSettings | null = null;
|
||||||
@@ -55,7 +55,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
@Input() isActiveTab: boolean = false;
|
@Input() isActiveTab: boolean = false;
|
||||||
|
|
||||||
readonly selectedFetchedMetadata = signal<BookMetadata | null>(null);
|
readonly selectedFetchedMetadata = signal<BookMetadata | null>(null);
|
||||||
detailLoading = false;
|
detailLoading = signal(false);
|
||||||
|
|
||||||
private formBuilder = inject(FormBuilder);
|
private formBuilder = inject(FormBuilder);
|
||||||
private bookMetadataService = inject(BookMetadataService);
|
private bookMetadataService = inject(BookMetadataService);
|
||||||
@@ -190,8 +190,8 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
|
|
||||||
private resetFormFromBook(book: Book): void {
|
private resetFormFromBook(book: Book): void {
|
||||||
this.cancelRequest$.next();
|
this.cancelRequest$.next();
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.detailLoading = false;
|
this.detailLoading.set(false);
|
||||||
this.selectedFetchedMetadata.set(null);
|
this.selectedFetchedMetadata.set(null);
|
||||||
this.allFetchedMetadata.set([]);
|
this.allFetchedMetadata.set([]);
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
this.searchTriggered = true;
|
this.searchTriggered.set(true);
|
||||||
if (this.form.valid) {
|
if (this.form.valid) {
|
||||||
const providerKeys = this.form.get('provider')?.value;
|
const providerKeys = this.form.get('provider')?.value;
|
||||||
if (!providerKeys) return;
|
if (!providerKeys) return;
|
||||||
@@ -252,7 +252,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
isbn: this.form.get('isbn')?.value
|
isbn: this.form.get('isbn')?.value
|
||||||
};
|
};
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.allFetchedMetadata.set([]);
|
this.allFetchedMetadata.set([]);
|
||||||
|
|
||||||
const initialCounts = new Map<string, number>();
|
const initialCounts = new Map<string, number>();
|
||||||
@@ -304,11 +304,11 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Error fetching metadata:', error);
|
console.error('Error fetching metadata:', error);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.providerLoading.set(new Map());
|
this.providerLoading.set(new Map());
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
activeProviders.forEach((provider: string) => {
|
activeProviders.forEach((provider: string) => {
|
||||||
if (!this.providerCompletionStatus().get(provider)) {
|
if (!this.providerCompletionStatus().get(provider)) {
|
||||||
this.providerLoading.update(map => new Map(map).set(provider, false));
|
this.providerLoading.update(map => new Map(map).set(provider, false));
|
||||||
@@ -391,7 +391,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
const enrichment = this.getDetailEnrichmentInfo(fetchedMetadata);
|
const enrichment = this.getDetailEnrichmentInfo(fetchedMetadata);
|
||||||
|
|
||||||
if (enrichment) {
|
if (enrichment) {
|
||||||
this.detailLoading = true;
|
this.detailLoading.set(true);
|
||||||
this.bookMetadataService.fetchMetadataDetail(enrichment.provider, enrichment.id)
|
this.bookMetadataService.fetchMetadataDetail(enrichment.provider, enrichment.id)
|
||||||
.pipe(takeUntil(this.cancelRequest$))
|
.pipe(takeUntil(this.cancelRequest$))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
@@ -401,11 +401,11 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
if (currentId === enrichment.id) {
|
if (currentId === enrichment.id) {
|
||||||
this.selectedFetchedMetadata.set(enriched);
|
this.selectedFetchedMetadata.set(enriched);
|
||||||
}
|
}
|
||||||
this.detailLoading = false;
|
this.detailLoading.set(false);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
console.error('Error fetching detailed metadata:', err);
|
console.error('Error fetching detailed metadata:', err);
|
||||||
this.detailLoading = false;
|
this.detailLoading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -445,7 +445,7 @@ export class MetadataSearcherComponent implements OnDestroy, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onGoBack() {
|
onGoBack() {
|
||||||
this.detailLoading = false;
|
this.detailLoading.set(false);
|
||||||
this.selectedFetchedMetadata.set(null);
|
this.selectedFetchedMetadata.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<i class="pi pi-spin pi-spinner"></i>
|
<i class="pi pi-spin pi-spinner"></i>
|
||||||
<span>{{ t('loading') }}</span>
|
<span>{{ t('loading') }}</span>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<p-button
|
<p-button
|
||||||
[label]="t('exportBtn')"
|
[label]="t('exportBtn')"
|
||||||
icon="pi pi-upload"
|
icon="pi pi-upload"
|
||||||
[loading]="exporting"
|
[loading]="exporting()"
|
||||||
(onClick)="exportToSidecar()"
|
(onClick)="exportToSidecar()"
|
||||||
severity="primary"
|
severity="primary"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
<p-button
|
<p-button
|
||||||
[label]="t('importBtn')"
|
[label]="t('importBtn')"
|
||||||
icon="pi pi-download"
|
icon="pi pi-download"
|
||||||
[loading]="importing"
|
[loading]="importing()"
|
||||||
[disabled]="syncStatus === 'MISSING'"
|
[disabled]="syncStatus === 'MISSING'"
|
||||||
(onClick)="importFromSidecar()"
|
(onClick)="importFromSidecar()"
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
|
|||||||
+11
-11
@@ -65,7 +65,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
component.currentBookId = 7;
|
component.currentBookId = 7;
|
||||||
component.sidecarContent = createMetadata();
|
component.sidecarContent = createMetadata();
|
||||||
component.syncStatus = 'IN_SYNC';
|
component.syncStatus = 'IN_SYNC';
|
||||||
component.loading = true;
|
component.loading.set(true);
|
||||||
component.error = 'failed';
|
component.error = 'failed';
|
||||||
|
|
||||||
component.book = null;
|
component.book = null;
|
||||||
@@ -73,7 +73,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
expect(component.currentBookId).toBeNull();
|
expect(component.currentBookId).toBeNull();
|
||||||
expect(component.sidecarContent).toBeNull();
|
expect(component.sidecarContent).toBeNull();
|
||||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.error).toBeNull();
|
expect(component.error).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
expect(component.currentBookId).toBe(7);
|
expect(component.currentBookId).toBe(7);
|
||||||
expect(component.syncStatus).toBe('IN_SYNC');
|
expect(component.syncStatus).toBe('IN_SYNC');
|
||||||
expect(component.sidecarContent).toEqual(metadata);
|
expect(component.sidecarContent).toEqual(metadata);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('skips content loading when the sidecar is missing or not applicable', () => {
|
it('skips content loading when the sidecar is missing or not applicable', () => {
|
||||||
@@ -102,14 +102,14 @@ describe('SidecarViewerComponent', () => {
|
|||||||
expect(getSidecarContent).not.toHaveBeenCalled();
|
expect(getSidecarContent).not.toHaveBeenCalled();
|
||||||
expect(component.syncStatus).toBe('MISSING');
|
expect(component.syncStatus).toBe('MISSING');
|
||||||
expect(component.sidecarContent).toBeNull();
|
expect(component.sidecarContent).toBeNull();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
|
|
||||||
getSyncStatus.mockReturnValue(of({status: 'NOT_APPLICABLE'}));
|
getSyncStatus.mockReturnValue(of({status: 'NOT_APPLICABLE'}));
|
||||||
component.book = createBook(4);
|
component.book = createBook(4);
|
||||||
|
|
||||||
expect(getSidecarContent).not.toHaveBeenCalled();
|
expect(getSidecarContent).not.toHaveBeenCalled();
|
||||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to NOT_APPLICABLE when sync status lookup fails', () => {
|
it('falls back to NOT_APPLICABLE when sync status lookup fails', () => {
|
||||||
@@ -121,7 +121,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
|
|
||||||
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
expect(component.syncStatus).toBe('NOT_APPLICABLE');
|
||||||
expect(component.sidecarContent).toBeNull();
|
expect(component.sidecarContent).toBeNull();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(consoleError).toHaveBeenCalledOnce();
|
expect(consoleError).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
component.book = createBook(6);
|
component.book = createBook(6);
|
||||||
|
|
||||||
expect(component.sidecarContent).toBeNull();
|
expect(component.sidecarContent).toBeNull();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(consoleError).not.toHaveBeenCalled();
|
expect(consoleError).not.toHaveBeenCalled();
|
||||||
|
|
||||||
getSidecarContent.mockReturnValue(throwError(() => ({status: 500})));
|
getSidecarContent.mockReturnValue(throwError(() => ({status: 500})));
|
||||||
@@ -159,7 +159,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
detail: 'translated:metadata.sidecar.toast.exportSuccessDetail',
|
detail: 'translated:metadata.sidecar.toast.exportSuccessDetail',
|
||||||
});
|
});
|
||||||
expect(reload).toHaveBeenCalledWith(9);
|
expect(reload).toHaveBeenCalledWith(9);
|
||||||
expect(component.exporting).toBe(false);
|
expect(component.exporting()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows an error toast when export fails and ignores export without a selected book', () => {
|
it('shows an error toast when export fails and ignores export without a selected book', () => {
|
||||||
@@ -179,7 +179,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
summary: 'translated:metadata.sidecar.toast.exportFailedSummary',
|
summary: 'translated:metadata.sidecar.toast.exportFailedSummary',
|
||||||
detail: 'translated:metadata.sidecar.toast.exportFailedDetail',
|
detail: 'translated:metadata.sidecar.toast.exportFailedDetail',
|
||||||
});
|
});
|
||||||
expect(component.exporting).toBe(false);
|
expect(component.exporting()).toBe(false);
|
||||||
expect(consoleError).toHaveBeenCalledOnce();
|
expect(consoleError).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
detail: 'translated:metadata.sidecar.toast.importSuccessDetail',
|
detail: 'translated:metadata.sidecar.toast.importSuccessDetail',
|
||||||
});
|
});
|
||||||
expect(reload).toHaveBeenCalledWith(12);
|
expect(reload).toHaveBeenCalledWith(12);
|
||||||
expect(component.importing).toBe(false);
|
expect(component.importing()).toBe(false);
|
||||||
|
|
||||||
component.importFromSidecar();
|
component.importFromSidecar();
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ describe('SidecarViewerComponent', () => {
|
|||||||
summary: 'translated:metadata.sidecar.toast.importFailedSummary',
|
summary: 'translated:metadata.sidecar.toast.importFailedSummary',
|
||||||
detail: 'translated:metadata.sidecar.toast.importFailedDetail',
|
detail: 'translated:metadata.sidecar.toast.importFailedDetail',
|
||||||
});
|
});
|
||||||
expect(component.importing).toBe(false);
|
expect(component.importing()).toBe(false);
|
||||||
expect(consoleError).toHaveBeenCalledOnce();
|
expect(consoleError).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+16
-16
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, Input, OnDestroy} from '@angular/core';
|
import {Component, inject, Input, OnDestroy, signal} from '@angular/core';
|
||||||
import {Subject} from 'rxjs';
|
import {Subject} from 'rxjs';
|
||||||
import {takeUntil} from 'rxjs/operators';
|
import {takeUntil} from 'rxjs/operators';
|
||||||
import {Book} from '../../../../book/model/book.model';
|
import {Book} from '../../../../book/model/book.model';
|
||||||
@@ -24,7 +24,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
this.currentBookId = null;
|
this.currentBookId = null;
|
||||||
this.sidecarContent = null;
|
this.sidecarContent = null;
|
||||||
this.syncStatus = 'NOT_APPLICABLE';
|
this.syncStatus = 'NOT_APPLICABLE';
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.error = null;
|
this.error = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -40,14 +40,14 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
|
|
||||||
sidecarContent: SidecarMetadata | null = null;
|
sidecarContent: SidecarMetadata | null = null;
|
||||||
syncStatus: SidecarSyncStatus = 'NOT_APPLICABLE';
|
syncStatus: SidecarSyncStatus = 'NOT_APPLICABLE';
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
exporting = false;
|
exporting = signal(false);
|
||||||
importing = false;
|
importing = signal(false);
|
||||||
currentBookId: number | null = null;
|
currentBookId: number | null = null;
|
||||||
error: string | null = null;
|
error: string | null = null;
|
||||||
|
|
||||||
loadSidecarData(bookId: number): void {
|
loadSidecarData(bookId: number): void {
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
this.sidecarService.getSyncStatus(bookId).pipe(
|
this.sidecarService.getSyncStatus(bookId).pipe(
|
||||||
@@ -60,13 +60,13 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
this.loadSidecarContent(bookId);
|
this.loadSidecarContent(bookId);
|
||||||
} else {
|
} else {
|
||||||
this.sidecarContent = null;
|
this.sidecarContent = null;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.syncStatus = 'NOT_APPLICABLE';
|
this.syncStatus = 'NOT_APPLICABLE';
|
||||||
this.sidecarContent = null;
|
this.sidecarContent = null;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
console.error('Failed to get sync status:', err);
|
console.error('Failed to get sync status:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -78,11 +78,11 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
).subscribe({
|
).subscribe({
|
||||||
next: (content) => {
|
next: (content) => {
|
||||||
this.sidecarContent = content;
|
this.sidecarContent = content;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.sidecarContent = null;
|
this.sidecarContent = null;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
if (err.status !== 404) {
|
if (err.status !== 404) {
|
||||||
console.error('Failed to load sidecar content:', err);
|
console.error('Failed to load sidecar content:', err);
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
exportToSidecar(): void {
|
exportToSidecar(): void {
|
||||||
if (!this.currentBookId) return;
|
if (!this.currentBookId) return;
|
||||||
|
|
||||||
this.exporting = true;
|
this.exporting.set(true);
|
||||||
this.sidecarService.exportToSidecar(this.currentBookId).pipe(
|
this.sidecarService.exportToSidecar(this.currentBookId).pipe(
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
).subscribe({
|
).subscribe({
|
||||||
@@ -104,7 +104,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
detail: this.t.translate('metadata.sidecar.toast.exportSuccessDetail')
|
detail: this.t.translate('metadata.sidecar.toast.exportSuccessDetail')
|
||||||
});
|
});
|
||||||
this.loadSidecarData(this.currentBookId!);
|
this.loadSidecarData(this.currentBookId!);
|
||||||
this.exporting = false;
|
this.exporting.set(false);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -112,7 +112,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
summary: this.t.translate('metadata.sidecar.toast.exportFailedSummary'),
|
summary: this.t.translate('metadata.sidecar.toast.exportFailedSummary'),
|
||||||
detail: this.t.translate('metadata.sidecar.toast.exportFailedDetail')
|
detail: this.t.translate('metadata.sidecar.toast.exportFailedDetail')
|
||||||
});
|
});
|
||||||
this.exporting = false;
|
this.exporting.set(false);
|
||||||
console.error('Export failed:', err);
|
console.error('Export failed:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -121,7 +121,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
importFromSidecar(): void {
|
importFromSidecar(): void {
|
||||||
if (!this.currentBookId) return;
|
if (!this.currentBookId) return;
|
||||||
|
|
||||||
this.importing = true;
|
this.importing.set(true);
|
||||||
this.sidecarService.importFromSidecar(this.currentBookId).pipe(
|
this.sidecarService.importFromSidecar(this.currentBookId).pipe(
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
).subscribe({
|
).subscribe({
|
||||||
@@ -132,7 +132,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
detail: this.t.translate('metadata.sidecar.toast.importSuccessDetail')
|
detail: this.t.translate('metadata.sidecar.toast.importSuccessDetail')
|
||||||
});
|
});
|
||||||
this.loadSidecarData(this.currentBookId!);
|
this.loadSidecarData(this.currentBookId!);
|
||||||
this.importing = false;
|
this.importing.set(false);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -140,7 +140,7 @@ export class SidecarViewerComponent implements OnDestroy {
|
|||||||
summary: this.t.translate('metadata.sidecar.toast.importFailedSummary'),
|
summary: this.t.translate('metadata.sidecar.toast.importFailedSummary'),
|
||||||
detail: this.t.translate('metadata.sidecar.toast.importFailedDetail')
|
detail: this.t.translate('metadata.sidecar.toast.importFailedDetail')
|
||||||
});
|
});
|
||||||
this.importing = false;
|
this.importing.set(false);
|
||||||
console.error('Import failed:', err);
|
console.error('Import failed:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-3
@@ -61,7 +61,7 @@
|
|||||||
type="submit"
|
type="submit"
|
||||||
[label]="t('searchBtn')"
|
[label]="t('searchBtn')"
|
||||||
icon="pi pi-search"
|
icon="pi pi-search"
|
||||||
[loading]="loading"
|
[loading]="loading()"
|
||||||
[disabled]="searchForm.invalid">
|
[disabled]="searchForm.invalid">
|
||||||
</p-button>
|
</p-button>
|
||||||
<p-button
|
<p-button
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
|
|
||||||
<!-- Results Area -->
|
<!-- Results Area -->
|
||||||
<div class="results-section">
|
<div class="results-section">
|
||||||
@if (!hasSearched) {
|
@if (!hasSearched()) {
|
||||||
<!-- Initial State -->
|
<!-- Initial State -->
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<div class="empty-state-icon">
|
<div class="empty-state-icon">
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
<h3>{{ t('searchForCovers') }}</h3>
|
<h3>{{ t('searchForCovers') }}</h3>
|
||||||
<p>{{ t('searchForCoversDescription') }}</p>
|
<p>{{ t('searchForCoversDescription') }}</p>
|
||||||
</div>
|
</div>
|
||||||
} @else if (loading) {
|
} @else if (loading()) {
|
||||||
<!-- Loading State -->
|
<!-- Loading State -->
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<p-progressSpinner strokeWidth="3" animationDuration="1s"></p-progressSpinner>
|
<p-progressSpinner strokeWidth="3" animationDuration="1s"></p-progressSpinner>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
import {Component, inject, Input, OnInit, signal} from '@angular/core';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {BookCoverService, CoverFetchRequest, CoverImage} from '../../../../shared/services/book-cover.service';
|
import {BookCoverService, CoverFetchRequest, CoverImage} from '../../../../shared/services/book-cover.service';
|
||||||
@@ -32,8 +32,8 @@ export class CoverSearchComponent implements OnInit {
|
|||||||
@Input() bookId!: number;
|
@Input() bookId!: number;
|
||||||
searchForm: FormGroup;
|
searchForm: FormGroup;
|
||||||
coverImages: CoverImage[] = [];
|
coverImages: CoverImage[] = [];
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
hasSearched = false;
|
hasSearched = signal(false);
|
||||||
coverType: 'ebook' | 'audiobook' = 'ebook';
|
coverType: 'ebook' | 'audiobook' = 'ebook';
|
||||||
|
|
||||||
private fb = inject(FormBuilder);
|
private fb = inject(FormBuilder);
|
||||||
@@ -79,7 +79,7 @@ export class CoverSearchComponent implements OnInit {
|
|||||||
|
|
||||||
onSearch() {
|
onSearch() {
|
||||||
if (this.searchForm.valid) {
|
if (this.searchForm.valid) {
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.coverImages = [];
|
this.coverImages = [];
|
||||||
const request: CoverFetchRequest = {
|
const request: CoverFetchRequest = {
|
||||||
bookId: this.bookId,
|
bookId: this.bookId,
|
||||||
@@ -90,8 +90,8 @@ export class CoverSearchComponent implements OnInit {
|
|||||||
|
|
||||||
this.bookCoverService.fetchBookCovers(request)
|
this.bookCoverService.fetchBookCovers(request)
|
||||||
.pipe(finalize(() => {
|
.pipe(finalize(() => {
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.hasSearched = true;
|
this.hasSearched.set(true);
|
||||||
}))
|
}))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (image) => {
|
next: (image) => {
|
||||||
@@ -139,6 +139,6 @@ export class CoverSearchComponent implements OnInit {
|
|||||||
onClear() {
|
onClear() {
|
||||||
this.searchForm.reset();
|
this.searchForm.reset();
|
||||||
this.coverImages = [];
|
this.coverImages = [];
|
||||||
this.hasSearched = false;
|
this.hasSearched.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-19
@@ -70,7 +70,7 @@
|
|||||||
<p-table
|
<p-table
|
||||||
#dataTable
|
#dataTable
|
||||||
[value]="getMetadataItems(tab.type)"
|
[value]="getMetadataItems(tab.type)"
|
||||||
[loading]="loading"
|
[loading]="loading()"
|
||||||
[globalFilterFields]="['value']"
|
[globalFilterFields]="['value']"
|
||||||
[paginator]="true"
|
[paginator]="true"
|
||||||
[rows]="50"
|
[rows]="50"
|
||||||
@@ -195,7 +195,7 @@
|
|||||||
<small class="help-text" [innerHTML]="t('multiMergeHowItWorks', { type: getTypeLabel(currentMergeType, true) })"></small>
|
<small class="help-text" [innerHTML]="t('multiMergeHowItWorks', { type: getTypeLabel(currentMergeType, true) })"></small>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@if (mergingInProgress) {
|
@if (mergingInProgress()) {
|
||||||
<div class="processing-note">
|
<div class="processing-note">
|
||||||
<i class="pi pi-info-circle"></i>
|
<i class="pi pi-info-circle"></i>
|
||||||
<span>{{ t('processingNote') }}</span>
|
<span>{{ t('processingNote') }}</span>
|
||||||
@@ -209,14 +209,14 @@
|
|||||||
[label]="'common.cancel' | transloco"
|
[label]="'common.cancel' | transloco"
|
||||||
icon="pi pi-times"
|
icon="pi pi-times"
|
||||||
(onClick)="showMergeDialog = false"
|
(onClick)="showMergeDialog = false"
|
||||||
[disabled]="mergingInProgress"
|
[disabled]="mergingInProgress()"
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
outlined></p-button>
|
outlined></p-button>
|
||||||
<p-button
|
<p-button
|
||||||
[label]="mergingInProgress ? t('processing') : ('common.confirm' | transloco)"
|
[label]="mergingInProgress() ? t('processing') : ('common.confirm' | transloco)"
|
||||||
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
[icon]="mergingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||||
[loading]="mergingInProgress"
|
[loading]="mergingInProgress()"
|
||||||
[disabled]="mergingInProgress"
|
[disabled]="mergingInProgress()"
|
||||||
(onClick)="confirmMerge()"
|
(onClick)="confirmMerge()"
|
||||||
severity="success"></p-button>
|
severity="success"></p-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -252,7 +252,7 @@
|
|||||||
<small class="help-text" [innerHTML]="t('multiRenameHowItWorks', { singular: getTypeLabel(currentMergeType, false), type: getTypeLabel(currentMergeType, true) })"></small>
|
<small class="help-text" [innerHTML]="t('multiRenameHowItWorks', { singular: getTypeLabel(currentMergeType, false), type: getTypeLabel(currentMergeType, true) })"></small>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@if (mergingInProgress) {
|
@if (mergingInProgress()) {
|
||||||
<div class="processing-note">
|
<div class="processing-note">
|
||||||
<i class="pi pi-info-circle"></i>
|
<i class="pi pi-info-circle"></i>
|
||||||
<span>{{ t('renameProcessingNote') }}</span>
|
<span>{{ t('renameProcessingNote') }}</span>
|
||||||
@@ -266,14 +266,14 @@
|
|||||||
[label]="'common.cancel' | transloco"
|
[label]="'common.cancel' | transloco"
|
||||||
icon="pi pi-times"
|
icon="pi pi-times"
|
||||||
(onClick)="showRenameDialog = false"
|
(onClick)="showRenameDialog = false"
|
||||||
[disabled]="mergingInProgress"
|
[disabled]="mergingInProgress()"
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
outlined></p-button>
|
outlined></p-button>
|
||||||
<p-button
|
<p-button
|
||||||
[label]="mergingInProgress ? t('processing') : ('common.confirm' | transloco)"
|
[label]="mergingInProgress() ? t('processing') : ('common.confirm' | transloco)"
|
||||||
[icon]="mergingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
[icon]="mergingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-check'"
|
||||||
[loading]="mergingInProgress"
|
[loading]="mergingInProgress()"
|
||||||
[disabled]="mergingInProgress"
|
[disabled]="mergingInProgress()"
|
||||||
(onClick)="confirmRename()"
|
(onClick)="confirmRename()"
|
||||||
severity="success"></p-button>
|
severity="success"></p-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -315,7 +315,7 @@
|
|||||||
<li>{{ t('totalBooksAffected') }} <strong>{{ currentDeleteItem ? currentDeleteItem.count : getTotalAffectedBooks(getSelectedItems(currentMergeType)) }}</strong></li>
|
<li>{{ t('totalBooksAffected') }} <strong>{{ currentDeleteItem ? currentDeleteItem.count : getTotalAffectedBooks(getSelectedItems(currentMergeType)) }}</strong></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@if (deletingInProgress) {
|
@if (deletingInProgress()) {
|
||||||
<div class="processing-note">
|
<div class="processing-note">
|
||||||
<i class="pi pi-info-circle"></i>
|
<i class="pi pi-info-circle"></i>
|
||||||
<span>{{ t('renameProcessingNote') }}</span>
|
<span>{{ t('renameProcessingNote') }}</span>
|
||||||
@@ -329,14 +329,14 @@
|
|||||||
[label]="'common.cancel' | transloco"
|
[label]="'common.cancel' | transloco"
|
||||||
icon="pi pi-times"
|
icon="pi pi-times"
|
||||||
(onClick)="showDeleteDialog = false"
|
(onClick)="showDeleteDialog = false"
|
||||||
[disabled]="deletingInProgress"
|
[disabled]="deletingInProgress()"
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
outlined></p-button>
|
outlined></p-button>
|
||||||
<p-button
|
<p-button
|
||||||
[label]="deletingInProgress ? t('deleting') : ('common.delete' | transloco)"
|
[label]="deletingInProgress() ? t('deleting') : ('common.delete' | transloco)"
|
||||||
[icon]="deletingInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-trash'"
|
[icon]="deletingInProgress() ? 'pi pi-spin pi-spinner' : 'pi pi-trash'"
|
||||||
[loading]="deletingInProgress"
|
[loading]="deletingInProgress()"
|
||||||
[disabled]="deletingInProgress"
|
[disabled]="deletingInProgress()"
|
||||||
(onClick)="confirmDelete()"
|
(onClick)="confirmDelete()"
|
||||||
severity="danger"></p-button>
|
severity="danger"></p-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+3
-3
@@ -89,7 +89,7 @@ describe('MetadataManagerComponent', () => {
|
|||||||
const component = createComponent();
|
const component = createComponent();
|
||||||
TestBed.flushEffects();
|
TestBed.flushEffects();
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.authors[0]).toEqual({value: 'Alice', count: 2, bookIds: [1, 2], selected: false});
|
expect(component.authors[0]).toEqual({value: 'Alice', count: 2, bookIds: [1, 2], selected: false});
|
||||||
expect(component.categories[0]).toEqual({value: 'Fantasy', count: 2, bookIds: [1, 2], selected: false});
|
expect(component.categories[0]).toEqual({value: 'Fantasy', count: 2, bookIds: [1, 2], selected: false});
|
||||||
expect(component.series).toEqual([{value: 'Series A', count: 2, bookIds: [1, 2], selected: false}]);
|
expect(component.series).toEqual([{value: 'Series A', count: 2, bookIds: [1, 2], selected: false}]);
|
||||||
@@ -110,13 +110,13 @@ describe('MetadataManagerComponent', () => {
|
|||||||
const component = createComponent();
|
const component = createComponent();
|
||||||
TestBed.flushEffects();
|
TestBed.flushEffects();
|
||||||
|
|
||||||
expect(component.loading).toBe(true);
|
expect(component.loading()).toBe(true);
|
||||||
expect(component.authors).toEqual([]);
|
expect(component.authors).toEqual([]);
|
||||||
|
|
||||||
isBooksLoading.set(false);
|
isBooksLoading.set(false);
|
||||||
TestBed.flushEffects();
|
TestBed.flushEffects();
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.authors).toEqual([{value: 'Alice', count: 1, bookIds: [1], selected: false}]);
|
expect(component.authors).toEqual([{value: 'Alice', count: 1, bookIds: [1], selected: false}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+23
-23
@@ -1,4 +1,4 @@
|
|||||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
import {Component, effect, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
||||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||||
import {TableModule} from 'primeng/table';
|
import {TableModule} from 'primeng/table';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
@@ -75,7 +75,7 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
private routeSub!: Subscription;
|
private routeSub!: Subscription;
|
||||||
private readonly syncMetadataEffect = effect(() => {
|
private readonly syncMetadataEffect = effect(() => {
|
||||||
const isLoading = this.bookService.isBooksLoading();
|
const isLoading = this.bookService.isBooksLoading();
|
||||||
this.loading = isLoading;
|
this.loading.set(isLoading);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return;
|
return;
|
||||||
@@ -100,9 +100,9 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
selectAllPublishers = false;
|
selectAllPublishers = false;
|
||||||
selectAllLanguages = false;
|
selectAllLanguages = false;
|
||||||
|
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
mergingInProgress = false;
|
mergingInProgress = signal(false);
|
||||||
deletingInProgress = false;
|
deletingInProgress = signal(false);
|
||||||
showMergeDialog = false;
|
showMergeDialog = false;
|
||||||
showRenameDialog = false;
|
showRenameDialog = false;
|
||||||
showDeleteDialog = false;
|
showDeleteDialog = false;
|
||||||
@@ -322,8 +322,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
? `"${targetValues[0]}"`
|
? `"${targetValues[0]}"`
|
||||||
: `${targetValues.length} values`;
|
: `${targetValues.length} values`;
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.mergingInProgress = true;
|
this.mergingInProgress.set(true);
|
||||||
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, [oldValue]).subscribe({
|
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, [oldValue]).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -339,8 +339,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
this.showRenameDialog = false;
|
this.showRenameDialog = false;
|
||||||
this.currentRenameItem = null;
|
this.currentRenameItem = null;
|
||||||
this.renameTarget = '';
|
this.renameTarget = '';
|
||||||
this.mergingInProgress = false;
|
this.mergingInProgress.set(false);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -352,8 +352,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
? this.t.translate('metadata.manager.toast.renameFailedDetail')
|
? this.t.translate('metadata.manager.toast.renameFailedDetail')
|
||||||
: this.t.translate('metadata.manager.toast.splitFailedDetail'))
|
: this.t.translate('metadata.manager.toast.splitFailedDetail'))
|
||||||
});
|
});
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.mergingInProgress = false;
|
this.mergingInProgress.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -397,8 +397,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
const affectedBooks = this.getTotalAffectedBooks(selected);
|
const affectedBooks = this.getTotalAffectedBooks(selected);
|
||||||
const operation = targetValues.length === 1 ? 'merge' : 'merge/split';
|
const operation = targetValues.length === 1 ? 'merge' : 'merge/split';
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.mergingInProgress = true;
|
this.mergingInProgress.set(true);
|
||||||
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, valuesToMerge).subscribe({
|
this.bookMetadataManageService.consolidateMetadata(this.currentMergeType, targetValues, valuesToMerge).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -414,8 +414,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
this.showMergeDialog = false;
|
this.showMergeDialog = false;
|
||||||
this.mergeTarget = '';
|
this.mergeTarget = '';
|
||||||
this.clearSelection(this.currentMergeType);
|
this.clearSelection(this.currentMergeType);
|
||||||
this.mergingInProgress = false;
|
this.mergingInProgress.set(false);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -427,8 +427,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
? this.t.translate('metadata.manager.toast.mergeFailedDetail')
|
? this.t.translate('metadata.manager.toast.mergeFailedDetail')
|
||||||
: this.t.translate('metadata.manager.toast.mergeSplitFailedDetail'))
|
: this.t.translate('metadata.manager.toast.mergeSplitFailedDetail'))
|
||||||
});
|
});
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.mergingInProgress = false;
|
this.mergingInProgress.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -456,8 +456,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
? this.currentDeleteItem.count
|
? this.currentDeleteItem.count
|
||||||
: this.getTotalAffectedBooks(this.getSelectedItems(this.currentMergeType));
|
: this.getTotalAffectedBooks(this.getSelectedItems(this.currentMergeType));
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.deletingInProgress = true;
|
this.deletingInProgress.set(true);
|
||||||
this.bookMetadataManageService.deleteMetadata(this.currentMergeType, valuesToDelete).subscribe({
|
this.bookMetadataManageService.deleteMetadata(this.currentMergeType, valuesToDelete).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -469,8 +469,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
this.showDeleteDialog = false;
|
this.showDeleteDialog = false;
|
||||||
this.currentDeleteItem = null;
|
this.currentDeleteItem = null;
|
||||||
this.clearSelection(this.currentMergeType);
|
this.clearSelection(this.currentMergeType);
|
||||||
this.deletingInProgress = false;
|
this.deletingInProgress.set(false);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -478,8 +478,8 @@ export class MetadataManagerComponent implements OnInit, OnDestroy {
|
|||||||
summary: this.t.translate('metadata.manager.toast.deleteFailedSummary'),
|
summary: this.t.translate('metadata.manager.toast.deleteFailedSummary'),
|
||||||
detail: error?.error?.message || this.t.translate('metadata.manager.toast.deleteFailedDetail')
|
detail: error?.error?.message || this.t.translate('metadata.manager.toast.deleteFailedDetail')
|
||||||
});
|
});
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.deletingInProgress = false;
|
this.deletingInProgress.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (!loading) {
|
@if (!loading()) {
|
||||||
<div class="dialog-content">
|
<div class="dialog-content">
|
||||||
@if (currentProposal?.metadataJson; as proposed) {
|
@if (currentProposal?.metadataJson; as proposed) {
|
||||||
<app-metadata-picker
|
<app-metadata-picker
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ describe('MetadataReviewDialogComponent', () => {
|
|||||||
expect(getTaskWithProposals).toHaveBeenCalledWith('task-1');
|
expect(getTaskWithProposals).toHaveBeenCalledWith('task-1');
|
||||||
expect(component.currentProposal).toEqual(createProposal({proposalId: 5}));
|
expect(component.currentProposal).toEqual(createProposal({proposalId: 5}));
|
||||||
expect(component.currentBook()).toEqual({id: 11, title: 'Book 11'});
|
expect(component.currentBook()).toEqual({id: 11, title: 'Book 11'});
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('closes when loading the task proposals fails', () => {
|
it('closes when loading the task proposals fails', () => {
|
||||||
|
|||||||
+2
-2
@@ -31,7 +31,7 @@ export class MetadataReviewDialogComponent implements OnInit {
|
|||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
private progressService = inject(MetadataProgressService);
|
private progressService = inject(MetadataProgressService);
|
||||||
|
|
||||||
loading = true;
|
loading = signal(true);
|
||||||
readonly proposals = signal<FetchedProposal[]>([]);
|
readonly proposals = signal<FetchedProposal[]>([]);
|
||||||
readonly currentIndex = signal(0);
|
readonly currentIndex = signal(0);
|
||||||
readonly currentBook = computed<Book | null>(() => {
|
readonly currentBook = computed<Book | null>(() => {
|
||||||
@@ -52,7 +52,7 @@ export class MetadataReviewDialogComponent implements OnInit {
|
|||||||
|
|
||||||
const bookIds = new Set(proposals.map(proposal => proposal.bookId));
|
const bookIds = new Set(proposals.map(proposal => proposal.bookId));
|
||||||
const matchedBooks = this.bookService.books().filter(book => bookIds.has(book.id));
|
const matchedBooks = this.bookService.books().filter(book => bookIds.has(book.id));
|
||||||
this.loading = matchedBooks.length !== bookIds.size;
|
this.loading.set(matchedBooks.length !== bookIds.size);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
<!-- Scrollable Content Area -->
|
<!-- Scrollable Content Area -->
|
||||||
<div class="entries-scroll-area">
|
<div class="entries-scroll-area">
|
||||||
<!-- Loading State -->
|
<!-- Loading State -->
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="settings-card">
|
<div class="settings-card">
|
||||||
<div class="state-container">
|
<div class="state-container">
|
||||||
<i class="pi pi-spin pi-spinner"></i>
|
<i class="pi pi-spin pi-spinner"></i>
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<!-- Empty State: No annotations at all -->
|
<!-- Empty State: No annotations at all -->
|
||||||
@if (!loading && totalEntries === 0 && !searchQuery.trim() && selectedBookId === null && showHighlights && showNotes && showBookmarks) {
|
@if (!loading() && totalEntries === 0 && !searchQuery.trim() && selectedBookId === null && showHighlights && showNotes && showBookmarks) {
|
||||||
<div class="settings-card">
|
<div class="settings-card">
|
||||||
<div class="state-container">
|
<div class="state-container">
|
||||||
<div class="state-icon">
|
<div class="state-icon">
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<!-- Empty State: No results match filters -->
|
<!-- Empty State: No results match filters -->
|
||||||
@if (!loading && totalEntries === 0 && (searchQuery.trim() || selectedBookId !== null || !showHighlights || !showNotes || !showBookmarks)) {
|
@if (!loading() && totalEntries === 0 && (searchQuery.trim() || selectedBookId !== null || !showHighlights || !showNotes || !showBookmarks)) {
|
||||||
<div class="settings-card">
|
<div class="settings-card">
|
||||||
<div class="state-container">
|
<div class="state-container">
|
||||||
<div class="state-icon warn">
|
<div class="state-icon warn">
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<!-- Book Groups -->
|
<!-- Book Groups -->
|
||||||
@if (!loading && filteredGroups.length > 0) {
|
@if (!loading() && filteredGroups.length > 0) {
|
||||||
@for (group of filteredGroups; track group.bookId) {
|
@for (group of filteredGroups; track group.bookId) {
|
||||||
<div class="settings-card book-group-card">
|
<div class="settings-card book-group-card">
|
||||||
<!-- Book Header -->
|
<!-- Book Header -->
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {of, Subject} from 'rxjs';
|
import {of, Subject} from 'rxjs';
|
||||||
import {debounceTime, switchMap} from 'rxjs/operators';
|
import {debounceTime, switchMap} from 'rxjs/operators';
|
||||||
@@ -62,7 +62,7 @@ export class NotebookComponent implements OnInit {
|
|||||||
|
|
||||||
filteredGroups: BookGroup[] = [];
|
filteredGroups: BookGroup[] = [];
|
||||||
totalEntries = 0;
|
totalEntries = 0;
|
||||||
loading = true;
|
loading = signal(true);
|
||||||
exporting = false;
|
exporting = false;
|
||||||
|
|
||||||
searchQuery = '';
|
searchQuery = '';
|
||||||
@@ -89,7 +89,7 @@ export class NotebookComponent implements OnInit {
|
|||||||
if (types.length === 0) {
|
if (types.length === 0) {
|
||||||
return of(EMPTY_PAGE);
|
return of(EMPTY_PAGE);
|
||||||
}
|
}
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
return this.notebookService.getNotebookEntries(
|
return this.notebookService.getNotebookEntries(
|
||||||
this.page, this.pageSize, types, this.selectedBookId, this.searchQuery, this.sortDirection
|
this.page, this.pageSize, types, this.selectedBookId, this.searchQuery, this.sortDirection
|
||||||
);
|
);
|
||||||
@@ -98,7 +98,7 @@ export class NotebookComponent implements OnInit {
|
|||||||
).subscribe(result => {
|
).subscribe(result => {
|
||||||
this.totalEntries = result.page.totalElements;
|
this.totalEntries = result.page.totalElements;
|
||||||
this.groupEntries(result.content);
|
this.groupEntries(result.content);
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.searchSubject.pipe(
|
this.searchSubject.pipe(
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
[rows]="rows"
|
[rows]="rows"
|
||||||
[first]="currentPage * rows"
|
[first]="currentPage * rows"
|
||||||
[totalRecords]="totalRecords"
|
[totalRecords]="totalRecords"
|
||||||
[loading]="loading"
|
[loading]="loading()"
|
||||||
[showCurrentPageReport]="true"
|
[showCurrentPageReport]="true"
|
||||||
[currentPageReportTemplate]="t('pageReport')"
|
[currentPageReportTemplate]="t('pageReport')"
|
||||||
(onLazyLoad)="onLazyLoad($event)"
|
(onLazyLoad)="onLazyLoad($event)"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {TableLazyLoadEvent, TableModule} from 'primeng/table';
|
import {TableLazyLoadEvent, TableModule} from 'primeng/table';
|
||||||
@@ -55,7 +55,7 @@ export class AuditLogsComponent implements OnInit {
|
|||||||
logs: AuditLog[] = [];
|
logs: AuditLog[] = [];
|
||||||
totalRecords = 0;
|
totalRecords = 0;
|
||||||
rows = 25;
|
rows = 25;
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
selectedAction: string | null = null;
|
selectedAction: string | null = null;
|
||||||
selectedUsername: string | null = null;
|
selectedUsername: string | null = null;
|
||||||
dateRange: Date[] | null = null;
|
dateRange: Date[] | null = null;
|
||||||
@@ -127,7 +127,7 @@ export class AuditLogsComponent implements OnInit {
|
|||||||
|
|
||||||
loadLogs(showLoading = true): void {
|
loadLogs(showLoading = true): void {
|
||||||
if (showLoading) {
|
if (showLoading) {
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
}
|
}
|
||||||
const action = this.selectedAction || undefined;
|
const action = this.selectedAction || undefined;
|
||||||
const username = this.selectedUsername || undefined;
|
const username = this.selectedUsername || undefined;
|
||||||
@@ -139,10 +139,10 @@ export class AuditLogsComponent implements OnInit {
|
|||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.logs = response.content;
|
this.logs = response.content;
|
||||||
this.totalRecords = response.page.totalElements;
|
this.totalRecords = response.page.totalElements;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -23,7 +23,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-body">
|
<div class="section-body">
|
||||||
@if (emailProviders.length === 0) {
|
@if (loading()) {
|
||||||
|
<div class="loading-state">
|
||||||
|
<p-progressSpinner/>
|
||||||
|
<p class="loading-text">{{ 'common.loading' | transloco }}</p>
|
||||||
|
</div>
|
||||||
|
} @else if (emailProviders.length === 0) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<i class="pi pi-envelope"></i>
|
<i class="pi pi-envelope"></i>
|
||||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||||
|
|||||||
+24
-4
@@ -1,5 +1,6 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
|
import {finalize} from 'rxjs';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {Checkbox} from 'primeng/checkbox';
|
import {Checkbox} from 'primeng/checkbox';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
@@ -13,6 +14,7 @@ import {EmailProvider} from '../email-provider.model';
|
|||||||
import {UserService} from '../../user-management/user.service';
|
import {UserService} from '../../user-management/user.service';
|
||||||
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
||||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||||
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-email-v2-provider',
|
selector: 'app-email-v2-provider',
|
||||||
@@ -25,7 +27,8 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
TranslocoPipe
|
TranslocoPipe,
|
||||||
|
ProgressSpinner
|
||||||
],
|
],
|
||||||
templateUrl: './email-v2-provider.component.html',
|
templateUrl: './email-v2-provider.component.html',
|
||||||
styleUrl: './email-v2-provider.component.scss'
|
styleUrl: './email-v2-provider.component.scss'
|
||||||
@@ -40,6 +43,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
|||||||
private userService = inject(UserService);
|
private userService = inject(UserService);
|
||||||
private t = inject(TranslocoService);
|
private t = inject(TranslocoService);
|
||||||
private destroyRef = inject(DestroyRef);
|
private destroyRef = inject(DestroyRef);
|
||||||
|
loading = signal(false);
|
||||||
|
private loadingRequestSeq = 0;
|
||||||
|
private activeLoadingRequestSeq: number | null = null;
|
||||||
defaultProviderId: unknown;
|
defaultProviderId: unknown;
|
||||||
currentUserId: number | null = null;
|
currentUserId: number | null = null;
|
||||||
isAdmin: boolean = false;
|
isAdmin: boolean = false;
|
||||||
@@ -56,10 +62,21 @@ export class EmailV2ProviderComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadEmailProviders(): void {
|
loadEmailProviders(): void {
|
||||||
|
const requestSeq = ++this.loadingRequestSeq;
|
||||||
|
this.activeLoadingRequestSeq = requestSeq;
|
||||||
|
this.loading.set(true);
|
||||||
|
|
||||||
this.emailProvidersService.getEmailProviders().pipe(
|
this.emailProvidersService.getEmailProviders().pipe(
|
||||||
takeUntilDestroyed(this.destroyRef)
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
finalize(() => {
|
||||||
|
if (this.activeLoadingRequestSeq === requestSeq) {
|
||||||
|
this.loading.set(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: (emailProviders: EmailProvider[]) => {
|
next: (emailProviders: EmailProvider[]) => {
|
||||||
|
if (this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
|
|
||||||
this.emailProviders = emailProviders.map((provider) => ({
|
this.emailProviders = emailProviders.map((provider) => ({
|
||||||
...provider,
|
...provider,
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
@@ -68,6 +85,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
|||||||
this.defaultProviderId = defaultProvider ? defaultProvider.id : null;
|
this.defaultProviderId = defaultProvider ? defaultProvider.id : null;
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
|
if (this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
|
|
||||||
|
this.emailProviders = [];
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('common.error'),
|
summary: this.t.translate('common.error'),
|
||||||
@@ -154,7 +174,7 @@ export class EmailV2ProviderComponent implements OnInit {
|
|||||||
detail: this.t.translate('settingsEmail.provider.defaultSetDetail', {name: provider.name}),
|
detail: this.t.translate('settingsEmail.provider.defaultSetDetail', {name: provider.name}),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err: unknown) => {
|
||||||
console.error('Failed to set default provider', err);
|
console.error('Failed to set default provider', err);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
|
|||||||
+6
-1
@@ -23,7 +23,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-body">
|
<div class="section-body">
|
||||||
@if (recipientEmails.length === 0) {
|
@if (loading()) {
|
||||||
|
<div class="loading-state">
|
||||||
|
<p-progressSpinner/>
|
||||||
|
<p class="loading-text">{{ 'common.loading' | transloco }}</p>
|
||||||
|
</div>
|
||||||
|
} @else if (recipientEmails.length === 0) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<i class="pi pi-users"></i>
|
<i class="pi pi-users"></i>
|
||||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||||
|
|||||||
+23
-3
@@ -1,5 +1,6 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
|
import {finalize} from 'rxjs';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {RadioButton} from 'primeng/radiobutton';
|
import {RadioButton} from 'primeng/radiobutton';
|
||||||
@@ -11,6 +12,7 @@ import {EmailV2RecipientService} from './email-v2-recipient.service';
|
|||||||
import {EmailRecipient} from '../email-recipient.model';
|
import {EmailRecipient} from '../email-recipient.model';
|
||||||
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
||||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||||
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-email-v2-recipient',
|
selector: 'app-email-v2-recipient',
|
||||||
@@ -22,7 +24,8 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
TranslocoPipe
|
TranslocoPipe,
|
||||||
|
ProgressSpinner
|
||||||
],
|
],
|
||||||
templateUrl: './email-v2-recipient.component.html',
|
templateUrl: './email-v2-recipient.component.html',
|
||||||
styleUrl: './email-v2-recipient.component.scss'
|
styleUrl: './email-v2-recipient.component.scss'
|
||||||
@@ -36,6 +39,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
|||||||
private messageService = inject(MessageService);
|
private messageService = inject(MessageService);
|
||||||
private t = inject(TranslocoService);
|
private t = inject(TranslocoService);
|
||||||
private destroyRef = inject(DestroyRef);
|
private destroyRef = inject(DestroyRef);
|
||||||
|
loading = signal(false);
|
||||||
|
private loadingRequestSeq = 0;
|
||||||
|
private activeLoadingRequestSeq: number | null = null;
|
||||||
defaultRecipientId: unknown;
|
defaultRecipientId: unknown;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -43,10 +49,21 @@ export class EmailV2RecipientComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadRecipientEmails(): void {
|
loadRecipientEmails(): void {
|
||||||
|
const requestSeq = ++this.loadingRequestSeq;
|
||||||
|
this.activeLoadingRequestSeq = requestSeq;
|
||||||
|
this.loading.set(true);
|
||||||
|
|
||||||
this.emailRecipientService.getRecipients().pipe(
|
this.emailRecipientService.getRecipients().pipe(
|
||||||
takeUntilDestroyed(this.destroyRef)
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
finalize(() => {
|
||||||
|
if (this.activeLoadingRequestSeq === requestSeq) {
|
||||||
|
this.loading.set(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: (recipients: EmailRecipient[]) => {
|
next: (recipients: EmailRecipient[]) => {
|
||||||
|
if (this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
|
|
||||||
this.recipientEmails = recipients.map((recipient) => ({
|
this.recipientEmails = recipients.map((recipient) => ({
|
||||||
...recipient,
|
...recipient,
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
@@ -55,6 +72,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
|||||||
this.defaultRecipientId = defaultRecipient ? defaultRecipient.id : null;
|
this.defaultRecipientId = defaultRecipient ? defaultRecipient.id : null;
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
|
if (this.activeLoadingRequestSeq !== requestSeq) return;
|
||||||
|
|
||||||
|
this.recipientEmails = [];
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('common.error'),
|
summary: this.t.translate('common.error'),
|
||||||
|
|||||||
+3
-3
@@ -40,9 +40,9 @@
|
|||||||
<span class="setting-description">Current size occupied by Cache Storage</span>
|
<span class="setting-description">Current size occupied by Cache Storage</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-control action-buttons">
|
<div class="setting-control action-buttons">
|
||||||
<span class="setting-value">{{ cacheStorageUsageMb | number: '1.2-2' }} MB</span>
|
<span class="setting-value">{{ cacheStorageUsageMb() | number: '1.2-2' }} MB</span>
|
||||||
<p-button type="button" label="Refresh" icon="pi pi-refresh" severity="secondary" [outlined]="true"
|
<p-button type="button" label="Refresh" icon="pi pi-refresh" severity="secondary" [outlined]="true"
|
||||||
[disabled]="isLoadingCacheStorageUsage" [loading]="isLoadingCacheStorageUsage" (onClick)="loadCacheStorageUsage()">
|
[disabled]="isLoadingCacheStorageUsage()" [loading]="isLoadingCacheStorageUsage()" (onClick)="loadCacheStorageUsage()">
|
||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="setting-control">
|
<div class="setting-control">
|
||||||
<p-button type="button" label="Clear Cache" icon="pi pi-trash" severity="danger" [outlined]="true"
|
<p-button type="button" label="Clear Cache" icon="pi pi-trash" severity="danger" [outlined]="true"
|
||||||
[disabled]="isClearingCacheStorage" [loading]="isClearingCacheStorage" (onClick)="clearCacheStorage()">
|
[disabled]="isClearingCacheStorage()" [loading]="isClearingCacheStorage()" (onClick)="clearCacheStorage()">
|
||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+10
-10
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, OnInit} from "@angular/core";
|
import {Component, inject, OnInit, signal} from "@angular/core";
|
||||||
import {FormsModule} from "@angular/forms";
|
import {FormsModule} from "@angular/forms";
|
||||||
import {DecimalPipe} from "@angular/common";
|
import {DecimalPipe} from "@angular/common";
|
||||||
import {Checkbox} from "primeng/checkbox";
|
import {Checkbox} from "primeng/checkbox";
|
||||||
@@ -28,9 +28,9 @@ export class LocalSettingsComponent implements OnInit {
|
|||||||
|
|
||||||
protected settings: LocalSettings = this.localSettingsService.get();
|
protected settings: LocalSettings = this.localSettingsService.get();
|
||||||
|
|
||||||
protected isLoadingCacheStorageUsage = false;
|
protected isLoadingCacheStorageUsage = signal(false);
|
||||||
protected isClearingCacheStorage = false;
|
protected isClearingCacheStorage = signal(false);
|
||||||
protected cacheStorageUsageMb = 0;
|
protected cacheStorageUsageMb = signal(0);
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
await this.loadCacheStorageUsage();
|
await this.loadCacheStorageUsage();
|
||||||
@@ -57,7 +57,7 @@ export class LocalSettingsComponent implements OnInit {
|
|||||||
severity: "secondary",
|
severity: "secondary",
|
||||||
},
|
},
|
||||||
accept: async () => {
|
accept: async () => {
|
||||||
this.isClearingCacheStorage = true;
|
this.isClearingCacheStorage.set(true);
|
||||||
try {
|
try {
|
||||||
await this.cacheStorageService.clear();
|
await this.cacheStorageService.clear();
|
||||||
await this.loadCacheStorageUsage();
|
await this.loadCacheStorageUsage();
|
||||||
@@ -73,22 +73,22 @@ export class LocalSettingsComponent implements OnInit {
|
|||||||
detail: "Unable to clear Cache Storage. Please try again.",
|
detail: "Unable to clear Cache Storage. Please try again.",
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
this.isClearingCacheStorage = false;
|
this.isClearingCacheStorage.set(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadCacheStorageUsage(): Promise<void> {
|
async loadCacheStorageUsage(): Promise<void> {
|
||||||
this.isLoadingCacheStorageUsage = true;
|
this.isLoadingCacheStorageUsage.set(true);
|
||||||
try {
|
try {
|
||||||
const totalBytes = await this.cacheStorageService.getCacheSizeInBytes();
|
const totalBytes = await this.cacheStorageService.getCacheSizeInBytes();
|
||||||
this.cacheStorageUsageMb = totalBytes / (1024 * 1024);
|
this.cacheStorageUsageMb.set(totalBytes / (1024 * 1024));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading Cache Storage usage:", error);
|
console.error("Error loading Cache Storage usage:", error);
|
||||||
this.cacheStorageUsageMb = 0;
|
this.cacheStorageUsageMb.set(0);
|
||||||
} finally {
|
} finally {
|
||||||
this.isLoadingCacheStorageUsage = false;
|
this.isLoadingCacheStorageUsage.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
@if (userService.currentUser(); as currentUser) {
|
@if (userService.currentUser(); as currentUser) {
|
||||||
@if (currentUser) {
|
@if (currentUser) {
|
||||||
<div class="settings-container">
|
<div class="settings-container">
|
||||||
<p-tabs [(value)]="activeTab" lazy scrollable>
|
<p-tabs [(value)]="activeTab" scrollable>
|
||||||
<p-tablist>
|
<p-tablist>
|
||||||
<p-tab [value]="SettingsTab.ReaderSettings">
|
<p-tab [value]="SettingsTab.ReaderSettings">
|
||||||
<i class="pi pi-book"></i> {{ t('reader') }}
|
<i class="pi pi-book"></i> {{ t('reader') }}
|
||||||
@@ -59,84 +59,93 @@
|
|||||||
</p-tab>
|
</p-tab>
|
||||||
</p-tablist>
|
</p-tablist>
|
||||||
<p-tabpanels>
|
<p-tabpanels>
|
||||||
|
<!-- [GROUP: Lazy Tabs] -->
|
||||||
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.ReaderSettings)) {
|
||||||
<app-reader-preferences></app-reader-preferences>
|
<app-reader-preferences></app-reader-preferences>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.ViewPreferences)) {
|
||||||
<app-view-preferences-parent></app-view-preferences-parent>
|
<app-view-preferences-parent></app-view-preferences-parent>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
|
|
||||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||||
<p-tabpanel [value]="SettingsTab.MetadataSettings">
|
<p-tabpanel [value]="SettingsTab.MetadataSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.MetadataSettings)) {
|
||||||
<app-metadata-settings-component></app-metadata-settings-component>
|
<app-metadata-settings-component></app-metadata-settings-component>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<p-tabpanel [value]="SettingsTab.LibraryMetadataSettings">
|
<p-tabpanel [value]="SettingsTab.LibraryMetadataSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.LibraryMetadataSettings)) {
|
||||||
<app-library-metadata-settings-component></app-library-metadata-settings-component>
|
<app-library-metadata-settings-component></app-library-metadata-settings-component>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageGlobalPreferences) {
|
@if (currentUser.permissions.admin || currentUser.permissions.canManageGlobalPreferences) {
|
||||||
<p-tabpanel [value]="SettingsTab.ApplicationSettings">
|
<p-tabpanel [value]="SettingsTab.ApplicationSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.ApplicationSettings)) {
|
||||||
<app-global-preferences></app-global-preferences>
|
<app-global-preferences></app-global-preferences>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<!-- [GROUP: Eager Tabs (Always Rendered to ensure initialization)] -->
|
||||||
@if (currentUser.permissions.admin) {
|
@if (currentUser.permissions.admin) {
|
||||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||||
<ng-template #content>
|
|
||||||
<app-user-management></app-user-management>
|
<app-user-management></app-user-management>
|
||||||
</ng-template>
|
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
<p-tabpanel [value]="SettingsTab.EmailSettingsV2">
|
<p-tabpanel [value]="SettingsTab.EmailSettingsV2">
|
||||||
<ng-template #content>
|
|
||||||
<app-email-v2></app-email-v2>
|
<app-email-v2></app-email-v2>
|
||||||
</ng-template>
|
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
|
|
||||||
|
<!-- [GROUP: Lazy Tabs Continued] -->
|
||||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||||
<p-tabpanel [value]="SettingsTab.NamingPattern">
|
<p-tabpanel [value]="SettingsTab.NamingPattern">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.NamingPattern)) {
|
||||||
<app-file-naming-pattern></app-file-naming-pattern>
|
<app-file-naming-pattern></app-file-naming-pattern>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (currentUser.permissions.admin) {
|
@if (currentUser.permissions.admin) {
|
||||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.AuthenticationSettings)) {
|
||||||
<app-authentication-settings></app-authentication-settings>
|
<app-authentication-settings></app-authentication-settings>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (currentUser.permissions.admin || currentUser.permissions.canAccessTaskManager) {
|
@if (currentUser.permissions.admin || currentUser.permissions.canAccessTaskManager) {
|
||||||
<p-tabpanel [value]="SettingsTab.Tasks">
|
<p-tabpanel [value]="SettingsTab.Tasks">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.Tasks)) {
|
||||||
<app-task-management></app-task-management>
|
<app-task-management></app-task-management>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (currentUser.permissions.admin) {
|
@if (currentUser.permissions.admin) {
|
||||||
<p-tabpanel [value]="SettingsTab.AuditLogs">
|
<p-tabpanel [value]="SettingsTab.AuditLogs">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.AuditLogs)) {
|
||||||
<app-audit-logs></app-audit-logs>
|
<app-audit-logs></app-audit-logs>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
}
|
}
|
||||||
|
|
||||||
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.OpdsV2)) {
|
||||||
<app-opds-settings></app-opds-settings>
|
<app-opds-settings></app-opds-settings>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
|
|
||||||
<p-tabpanel [value]="SettingsTab.DeviceSettings">
|
<p-tabpanel [value]="SettingsTab.DeviceSettings">
|
||||||
<ng-template #content>
|
@if (visitedTabs().has(SettingsTab.DeviceSettings)) {
|
||||||
<app-device-settings-component></app-device-settings-component>
|
<app-device-settings-component></app-device-settings-component>
|
||||||
</ng-template>
|
}
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
</p-tabpanels>
|
</p-tabpanels>
|
||||||
</p-tabs>
|
</p-tabs>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, effect, inject, OnInit, signal} from '@angular/core';
|
||||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||||
import {UserService} from './user-management/user.service';
|
import {UserService} from './user-management/user.service';
|
||||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||||
@@ -71,14 +71,19 @@ export class SettingsComponent implements OnInit {
|
|||||||
SettingsTab = SettingsTab;
|
SettingsTab = SettingsTab;
|
||||||
|
|
||||||
private validTabs = Object.values(SettingsTab);
|
private validTabs = Object.values(SettingsTab);
|
||||||
private _activeTab: SettingsTab = SettingsTab.ReaderSettings;
|
private _activeTab = signal<SettingsTab>(SettingsTab.ReaderSettings);
|
||||||
|
|
||||||
|
visitedTabs = signal<Set<SettingsTab>>(new Set([
|
||||||
|
SettingsTab.UserManagement,
|
||||||
|
SettingsTab.EmailSettingsV2
|
||||||
|
]));
|
||||||
|
|
||||||
get activeTab(): SettingsTab {
|
get activeTab(): SettingsTab {
|
||||||
return this._activeTab;
|
return this._activeTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
set activeTab(value: SettingsTab) {
|
set activeTab(value: SettingsTab) {
|
||||||
this._activeTab = value;
|
this._activeTab.set(value);
|
||||||
|
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
@@ -87,22 +92,44 @@ export class SettingsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const pageTitle = inject(PageTitleService);
|
||||||
|
pageTitle.setPageTitle('Settings');
|
||||||
|
|
||||||
|
effect(() => {
|
||||||
|
const active = this._activeTab();
|
||||||
|
this.visitedTabs.update(set => {
|
||||||
|
if (set.has(active)) return set;
|
||||||
|
const newSet = new Set(set);
|
||||||
|
newSet.add(active);
|
||||||
|
return newSet;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.pageTitle.setPageTitle('Settings');
|
|
||||||
|
// Initialize from snapshot synchronously to ensure p-tabs (lazy) picks up the correct value on first render
|
||||||
|
const initialTab = this.route.snapshot.queryParams['tab'];
|
||||||
|
if (this.validTabs.includes(initialTab)) {
|
||||||
|
this._activeTab.set(initialTab as SettingsTab);
|
||||||
|
}
|
||||||
|
|
||||||
this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
||||||
const tabParam = params['tab'];
|
const tabParam = params['tab'];
|
||||||
if (this.validTabs.includes(tabParam)) {
|
if (this.validTabs.includes(tabParam)) {
|
||||||
this._activeTab = tabParam as SettingsTab;
|
this._activeTab.set(tabParam as SettingsTab);
|
||||||
} else {
|
} else {
|
||||||
this._activeTab = SettingsTab.ReaderSettings;
|
const defaultTab = SettingsTab.ReaderSettings;
|
||||||
|
this._activeTab.set(defaultTab);
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
queryParams: {tab: this._activeTab},
|
queryParams: {tab: defaultTab},
|
||||||
queryParamsHandling: 'merge',
|
queryParamsHandling: 'merge',
|
||||||
replaceUrl: true
|
replaceUrl: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-body">
|
<div class="section-body">
|
||||||
@if (loading && taskInfos.length === 0) {
|
@if (loading() && taskInfos.length === 0) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<i class="pi pi-spin pi-spinner"></i>
|
<i class="pi pi-spin pi-spinner"></i>
|
||||||
<span>{{ t('loading') }}</span>
|
<span>{{ t('loading') }}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!loading && taskInfos.length === 0) {
|
@if (!loading() && taskInfos.length === 0) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<i class="pi pi-check-circle"></i>
|
<i class="pi pi-check-circle"></i>
|
||||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||||
|
|||||||
+1
-1
@@ -152,7 +152,7 @@ describe('TaskManagementComponent', () => {
|
|||||||
id: 'task-1',
|
id: 'task-1',
|
||||||
status: TaskStatus.PENDING,
|
status: TaskStatus.PENDING,
|
||||||
});
|
});
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports load failures through the message service', () => {
|
it('reports load failures through the message service', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
|
||||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {ProgressBar} from 'primeng/progressbar';
|
import {ProgressBar} from 'primeng/progressbar';
|
||||||
@@ -54,7 +54,7 @@ export class TaskManagementComponent implements OnInit {
|
|||||||
// State
|
// State
|
||||||
taskInfos: TaskInfo[] = [];
|
taskInfos: TaskInfo[] = [];
|
||||||
taskHistories = new Map<string, TaskHistory>();
|
taskHistories = new Map<string, TaskHistory>();
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
executingTasks = new Set<string>();
|
executingTasks = new Set<string>();
|
||||||
|
|
||||||
// Metadata Replace Options
|
// Metadata Replace Options
|
||||||
@@ -98,13 +98,13 @@ export class TaskManagementComponent implements OnInit {
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
loadTasks(): void {
|
loadTasks(): void {
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
|
|
||||||
forkJoin({
|
forkJoin({
|
||||||
available: this.taskService.getAvailableTasks(),
|
available: this.taskService.getAvailableTasks(),
|
||||||
latest: this.taskService.getLatestTasksForEachType()
|
latest: this.taskService.getLatestTasksForEachType()
|
||||||
})
|
})
|
||||||
.pipe(finalize(() => this.loading = false))
|
.pipe(finalize(() => this.loading.set(false)))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: ({available, latest}) => {
|
next: ({available, latest}) => {
|
||||||
this.taskInfos = this.sortTasksByDisplayOrder(available);
|
this.taskInfos = this.sortTasksByDisplayOrder(available);
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
[label]="t('clearBtn')"
|
[label]="t('clearBtn')"
|
||||||
severity="danger"
|
severity="danger"
|
||||||
[outlined]="true"
|
[outlined]="true"
|
||||||
[disabled]="!filesPresent() || isUploading"
|
[disabled]="!filesPresent() || isUploading()"
|
||||||
[pTooltip]="t('clearTooltip')"
|
[pTooltip]="t('clearTooltip')"
|
||||||
tooltipPosition="top"/>
|
tooltipPosition="top"/>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,11 +127,11 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #content let-files let-removeFileCallback="removeFileCallback">
|
<ng-template #content let-files let-removeFileCallback="removeFileCallback">
|
||||||
@if (files?.length > 0) {
|
@if (files?.length > 0) {
|
||||||
@if (isUploading || uploadCompleted) {
|
@if (isUploading() || uploadCompleted()) {
|
||||||
<div class="upload-progress-summary">
|
<div class="upload-progress-summary">
|
||||||
<div class="progress-row">
|
<div class="progress-row">
|
||||||
<span class="progress-status">
|
<span class="progress-status">
|
||||||
@if (isUploading) {
|
@if (isUploading()) {
|
||||||
<i class="pi pi-spin pi-spinner"></i>
|
<i class="pi pi-spin pi-spinner"></i>
|
||||||
{{ t('uploading') }}
|
{{ t('uploading') }}
|
||||||
} @else {
|
} @else {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {ChangeDetectorRef, Component, inject, ViewChild, effect} from '@angular/core';
|
import {ChangeDetectorRef, Component, inject, ViewChild, effect, signal} from '@angular/core';
|
||||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
@@ -47,8 +47,8 @@ export class BookUploaderComponent {
|
|||||||
@ViewChild(FileUpload) fileUpload!: FileUpload;
|
@ViewChild(FileUpload) fileUpload!: FileUpload;
|
||||||
|
|
||||||
files: UploadingFile[] = [];
|
files: UploadingFile[] = [];
|
||||||
isUploading: boolean = false;
|
isUploading = signal(false);
|
||||||
uploadCompleted: boolean = false;
|
uploadCompleted = signal(false);
|
||||||
_selectedLibrary: Library | null = null;
|
_selectedLibrary: Library | null = null;
|
||||||
selectedPath: LibraryPath | null = null;
|
selectedPath: LibraryPath | null = null;
|
||||||
|
|
||||||
@@ -112,10 +112,14 @@ export class BookUploaderComponent {
|
|||||||
onClear(clearCallback: () => void): void {
|
onClear(clearCallback: () => void): void {
|
||||||
clearCallback();
|
clearCallback();
|
||||||
this.files = [];
|
this.files = [];
|
||||||
|
this.uploadCompleted.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onFilesSelect(event: FileSelectEvent): void {
|
onFilesSelect(event: FileSelectEvent): void {
|
||||||
|
this.uploadCompleted.set(false);
|
||||||
if (this.value === 'library' && (!this.selectedLibrary || !this.selectedPath)) {
|
if (this.value === 'library' && (!this.selectedLibrary || !this.selectedPath)) {
|
||||||
|
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: this.t.translate('shared.bookUploader.toast.noDestinationSummary'),
|
summary: this.t.translate('shared.bookUploader.toast.noDestinationSummary'),
|
||||||
@@ -185,8 +189,8 @@ export class BookUploaderComponent {
|
|||||||
const filesToUpload = this.files.filter(f => f.status === 'Pending');
|
const filesToUpload = this.files.filter(f => f.status === 'Pending');
|
||||||
if (filesToUpload.length === 0) return;
|
if (filesToUpload.length === 0) return;
|
||||||
|
|
||||||
this.isUploading = true;
|
this.isUploading.set(true);
|
||||||
this.uploadCompleted = false;
|
this.uploadCompleted.set(false);
|
||||||
const destination = this.value;
|
const destination = this.value;
|
||||||
const libraryId = this.selectedLibrary?.id?.toString();
|
const libraryId = this.selectedLibrary?.id?.toString();
|
||||||
const pathId = this.selectedPath?.id?.toString();
|
const pathId = this.selectedPath?.id?.toString();
|
||||||
@@ -197,9 +201,9 @@ export class BookUploaderComponent {
|
|||||||
private uploadBatch(files: UploadingFile[], startIndex: number, batchSize: number, destination: string, libraryId?: string, pathId?: string): void {
|
private uploadBatch(files: UploadingFile[], startIndex: number, batchSize: number, destination: string, libraryId?: string, pathId?: string): void {
|
||||||
const batch = files.slice(startIndex, startIndex + batchSize);
|
const batch = files.slice(startIndex, startIndex + batchSize);
|
||||||
if (batch.length === 0) {
|
if (batch.length === 0) {
|
||||||
this.isUploading = false;
|
this.isUploading.set(false);
|
||||||
this.uploadCompleted = true;
|
this.uploadCompleted.set(true);
|
||||||
this.cdr.detectChanges();
|
|
||||||
if (destination === 'bookdrop') {
|
if (destination === 'bookdrop') {
|
||||||
this.ref.close('uploaded_to_bookdrop');
|
this.ref.close('uploaded_to_bookdrop');
|
||||||
}
|
}
|
||||||
@@ -266,9 +270,9 @@ export class BookUploaderComponent {
|
|||||||
|
|
||||||
isChooseDisabled(): boolean {
|
isChooseDisabled(): boolean {
|
||||||
if (this.value === 'bookdrop') {
|
if (this.value === 'bookdrop') {
|
||||||
return this.isUploading;
|
return this.isUploading();
|
||||||
}
|
}
|
||||||
return !this.selectedLibrary || !this.selectedPath || this.isUploading;
|
return !this.selectedLibrary || !this.selectedPath || this.isUploading();
|
||||||
}
|
}
|
||||||
|
|
||||||
isUploadDisabled(): boolean {
|
isUploadDisabled(): boolean {
|
||||||
@@ -324,7 +328,7 @@ export class BookUploaderComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasUploadCompleted(): boolean {
|
hasUploadCompleted(): boolean {
|
||||||
return this.uploadCompleted;
|
return this.uploadCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDialog(): void {
|
closeDialog(): void {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="directories-container">
|
<div class="directories-container">
|
||||||
@if (isLoading) {
|
@if (isLoading()) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
<p-progressSpinner
|
<p-progressSpinner
|
||||||
class="custom-spinner"
|
class="custom-spinner"
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="directories-grid" [class.fade-in]="!isLoading && filteredPaths.length > 0">
|
<div class="directories-grid" [class.fade-in]="!isLoading() && filteredPaths.length > 0">
|
||||||
@for (folder of filteredPaths; track folder) {
|
@for (folder of filteredPaths; track folder) {
|
||||||
<div
|
<div
|
||||||
class="directory-item"
|
class="directory-item"
|
||||||
|
|||||||
+3
-3
@@ -46,13 +46,13 @@ describe('DirectoryPickerComponent', () => {
|
|||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
|
|
||||||
expect(utilityService.getFolders).toHaveBeenCalledWith('/');
|
expect(utilityService.getFolders).toHaveBeenCalledWith('/');
|
||||||
expect(component.isLoading).toBe(true);
|
expect(component.isLoading()).toBe(true);
|
||||||
|
|
||||||
vi.advanceTimersByTime(100);
|
vi.advanceTimersByTime(100);
|
||||||
|
|
||||||
expect(component.paths).toEqual(['/books', '/comics']);
|
expect(component.paths).toEqual(['/books', '/comics']);
|
||||||
expect(component.filteredPaths).toEqual(['/books', '/comics']);
|
expect(component.filteredPaths).toEqual(['/books', '/comics']);
|
||||||
expect(component.isLoading).toBe(false);
|
expect(component.isLoading()).toBe(false);
|
||||||
expect(component.breadcrumbItems).toEqual([]);
|
expect(component.breadcrumbItems).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ describe('DirectoryPickerComponent', () => {
|
|||||||
|
|
||||||
component.getFolders('/broken');
|
component.getFolders('/broken');
|
||||||
|
|
||||||
expect(component.isLoading).toBe(false);
|
expect(component.isLoading()).toBe(false);
|
||||||
expect(console.error).toHaveBeenCalled();
|
expect(console.error).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
import {UtilityService} from './utility.service';
|
import {UtilityService} from './utility.service';
|
||||||
import {TableModule} from 'primeng/table';
|
import {TableModule} from 'primeng/table';
|
||||||
@@ -42,7 +42,7 @@ export class DirectoryPickerComponent implements OnInit {
|
|||||||
selectedFolders: string[] = [];
|
selectedFolders: string[] = [];
|
||||||
selectedFoldersMap: Record<string, boolean> = {};
|
selectedFoldersMap: Record<string, boolean> = {};
|
||||||
searchQuery: string = '';
|
searchQuery: string = '';
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
breadcrumbItems: MenuItem[] = [];
|
breadcrumbItems: MenuItem[] = [];
|
||||||
home: MenuItem = {icon: 'pi pi-home', command: () => this.navigateToRoot()};
|
home: MenuItem = {icon: 'pi pi-home', command: () => this.navigateToRoot()};
|
||||||
|
|
||||||
@@ -55,14 +55,14 @@ export class DirectoryPickerComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFolders(path: string): void {
|
getFolders(path: string): void {
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
this.filteredPaths = [];
|
this.filteredPaths = [];
|
||||||
this.utilityService.getFolders(path).subscribe({
|
this.utilityService.getFolders(path).subscribe({
|
||||||
next: (folders: string[]) => {
|
next: (folders: string[]) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.paths = folders;
|
this.paths = folders;
|
||||||
this.filteredPaths = folders;
|
this.filteredPaths = folders;
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
this.updateBreadcrumb(path);
|
this.updateBreadcrumb(path);
|
||||||
folders.forEach(folder => {
|
folders.forEach(folder => {
|
||||||
this.selectedFoldersMap[folder] = this.selectedFolders.includes(folder);
|
this.selectedFoldersMap[folder] = this.selectedFolders.includes(folder);
|
||||||
@@ -71,7 +71,7 @@ export class DirectoryPickerComponent implements OnInit {
|
|||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Error fetching folders:', error);
|
console.error('Error fetching folders:', error);
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,9 +153,9 @@
|
|||||||
<p-button
|
<p-button
|
||||||
fluid
|
fluid
|
||||||
type="submit"
|
type="submit"
|
||||||
[label]="loading ? t('creatingAccountBtn') : t('createAccountBtn')"
|
[label]="loading() ? t('creatingAccountBtn') : t('createAccountBtn')"
|
||||||
[icon]="loading ? 'pi pi-spin pi-spinner' : 'pi pi-user-plus'"
|
[icon]="loading() ? 'pi pi-spin pi-spinner' : 'pi pi-user-plus'"
|
||||||
[disabled]="loading || setupForm.invalid"
|
[disabled]="loading() || setupForm.invalid"
|
||||||
class="setup-button"
|
class="setup-button"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ describe('SetupComponent', () => {
|
|||||||
component.onSubmit();
|
component.onSubmit();
|
||||||
|
|
||||||
expect(setupService.createAdmin).not.toHaveBeenCalled();
|
expect(setupService.createAdmin).not.toHaveBeenCalled();
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('submits the admin payload without confirmPassword', () => {
|
it('submits the admin payload without confirmPassword', () => {
|
||||||
@@ -71,7 +71,7 @@ describe('SetupComponent', () => {
|
|||||||
|
|
||||||
component.onSubmit();
|
component.onSubmit();
|
||||||
|
|
||||||
expect(component.loading).toBe(true);
|
expect(component.loading()).toBe(true);
|
||||||
expect(component.error).toBe(null);
|
expect(component.error).toBe(null);
|
||||||
expect(setupService.createAdmin).toHaveBeenCalledWith({
|
expect(setupService.createAdmin).toHaveBeenCalledWith({
|
||||||
name: 'Admin User',
|
name: 'Admin User',
|
||||||
@@ -87,7 +87,7 @@ describe('SetupComponent', () => {
|
|||||||
component.onSubmit();
|
component.onSubmit();
|
||||||
|
|
||||||
expect(component.success).toBe(true);
|
expect(component.success).toBe(true);
|
||||||
expect(component.loading).toBe(true);
|
expect(component.loading()).toBe(true);
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
|
|
||||||
vi.advanceTimersByTime(1500);
|
vi.advanceTimersByTime(1500);
|
||||||
@@ -104,7 +104,7 @@ describe('SetupComponent', () => {
|
|||||||
|
|
||||||
component.onSubmit();
|
component.onSubmit();
|
||||||
|
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
expect(component.error).toBe('Setup failed');
|
expect(component.error).toBe('Setup failed');
|
||||||
expect(component.success).toBe(false);
|
expect(component.success).toBe(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject} from '@angular/core';
|
import {Component, inject, signal} from '@angular/core';
|
||||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {SetupService} from './setup.service';
|
import {SetupService} from './setup.service';
|
||||||
@@ -26,7 +26,7 @@ export class SetupComponent {
|
|||||||
private setupService = inject(SetupService);
|
private setupService = inject(SetupService);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
setupForm: FormGroup;
|
setupForm: FormGroup;
|
||||||
loading = false;
|
loading = signal(false);
|
||||||
error: string | null = null;
|
error: string | null = null;
|
||||||
success = false;
|
success = false;
|
||||||
private readonly t = inject(TranslocoService);
|
private readonly t = inject(TranslocoService);
|
||||||
@@ -44,7 +44,7 @@ export class SetupComponent {
|
|||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
if (this.setupForm.invalid) return;
|
if (this.setupForm.invalid) return;
|
||||||
|
|
||||||
this.loading = true;
|
this.loading.set(true);
|
||||||
this.error = null;
|
this.error = null;
|
||||||
// Remove confirm password from the payload, as it does not need to be sent to backend
|
// Remove confirm password from the payload, as it does not need to be sent to backend
|
||||||
const { confirmPassword, ...payload } = this.setupForm.value;
|
const { confirmPassword, ...payload } = this.setupForm.value;
|
||||||
@@ -55,7 +55,7 @@ export class SetupComponent {
|
|||||||
setTimeout(() => this.router.navigate(['/login']), 1500);
|
setTimeout(() => this.router.navigate(['/login']), 1500);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
this.error =
|
this.error =
|
||||||
err?.error?.message || this.t.translate('shared.setup.toast.createFailedDefault');
|
err?.error?.message || this.t.translate('shared.setup.toast.createFailedDefault');
|
||||||
},
|
},
|
||||||
|
|||||||
+3
-3
@@ -19,19 +19,19 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dialog-content">
|
<div class="dialog-content">
|
||||||
@if (loading) {
|
@if (loading()) {
|
||||||
<div class="loading-state">
|
<div class="loading-state">
|
||||||
{{ t('loading') }}
|
{{ t('loading') }}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!loading && changelog.length === 0) {
|
@if (!loading() && changelog.length === 0) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
{{ t('empty') }}
|
{{ t('empty') }}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!loading && changelog.length > 0) {
|
@if (!loading() && changelog.length > 0) {
|
||||||
<div class="changelog-list">
|
<div class="changelog-list">
|
||||||
@for (release of changelog; track release) {
|
@for (release of changelog; track release) {
|
||||||
<div class="release-item">
|
<div class="release-item">
|
||||||
|
|||||||
+2
-2
@@ -47,7 +47,7 @@ describe('VersionChangelogDialogComponent', () => {
|
|||||||
|
|
||||||
expect(versionService.getChangelog).toHaveBeenCalled();
|
expect(versionService.getChangelog).toHaveBeenCalled();
|
||||||
expect(component.changelog).toHaveLength(1);
|
expect(component.changelog).toHaveLength(1);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('clears the loading state when the changelog request fails', () => {
|
it('clears the loading state when the changelog request fails', () => {
|
||||||
@@ -58,7 +58,7 @@ describe('VersionChangelogDialogComponent', () => {
|
|||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
|
|
||||||
expect(component.changelog).toEqual([]);
|
expect(component.changelog).toEqual([]);
|
||||||
expect(component.loading).toBe(false);
|
expect(component.loading()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts markdown to sanitized HTML and normalizes headings to h3', () => {
|
it('converts markdown to sanitized HTML and normalizes headings to h3', () => {
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
import { Component, inject, OnInit } from '@angular/core';
|
import { Component, inject, OnInit, signal } from '@angular/core';
|
||||||
import { ReleaseNote, VersionService } from '../../../service/version.service';
|
import { ReleaseNote, VersionService } from '../../../service/version.service';
|
||||||
|
|
||||||
import showdown from 'showdown';
|
import showdown from 'showdown';
|
||||||
@@ -25,7 +25,7 @@ export class VersionChangelogDialogComponent implements OnInit {
|
|||||||
dialogRef = inject(DynamicDialogRef);
|
dialogRef = inject(DynamicDialogRef);
|
||||||
|
|
||||||
changelog: ReleaseNote[] = [];
|
changelog: ReleaseNote[] = [];
|
||||||
loading = true;
|
loading = signal(true);
|
||||||
|
|
||||||
private converter = new showdown.Converter({ tables: true, emoji: true });
|
private converter = new showdown.Converter({ tables: true, emoji: true });
|
||||||
|
|
||||||
@@ -33,10 +33,10 @@ export class VersionChangelogDialogComponent implements OnInit {
|
|||||||
this.versionService.getChangelog().subscribe({
|
this.versionService.getChangelog().subscribe({
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
this.changelog = data;
|
this.changelog = data;
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.loading = false;
|
this.loading.set(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user