refactor(settings): replace unsubscribe logic with takeUntilDestroyed for better resource management (#443)
* refactor(settings): replace unsubscribe logic with takeUntilDestroyed for better resource management * refactor(settings): streamline saveSettings method and improve error handling * fix(settings): improve error handling in saveSetting method * refactor(settings): update tab structure * refactor(settings): implement OnDestroy interface and clean up unused destroyRef instances
This commit is contained in:
@@ -50,6 +50,7 @@ export class AuditLogsComponent implements OnInit {
|
||||
private readonly auditLogService = inject(AuditLogService);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
logs: AuditLog[] = [];
|
||||
totalRecords = 0;
|
||||
@@ -61,7 +62,6 @@ export class AuditLogsComponent implements OnInit {
|
||||
expandedRows = new Set<number>();
|
||||
autoRefresh = false;
|
||||
private autoRefreshSub?: Subscription;
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
usernameOptions: UsernameOption[] = [{label: 'All Users', value: ''}];
|
||||
|
||||
@@ -115,7 +115,7 @@ export class AuditLogsComponent implements OnInit {
|
||||
}
|
||||
|
||||
loadUsernames(): void {
|
||||
this.auditLogService.getDistinctUsernames().subscribe({
|
||||
this.auditLogService.getDistinctUsernames().pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
||||
next: (usernames) => {
|
||||
this.usernameOptions = [
|
||||
{label: 'All Users', value: ''},
|
||||
@@ -133,7 +133,9 @@ export class AuditLogsComponent implements OnInit {
|
||||
const username = this.selectedUsername || undefined;
|
||||
const from = this.dateRange?.[0] ? this.formatDateTime(this.dateRange[0]) : undefined;
|
||||
const to = this.dateRange?.[1] ? this.formatDateTime(this.dateRange[1], true) : undefined;
|
||||
this.auditLogService.getAuditLogs(this.currentPage, this.rows, action, username, from, to).subscribe({
|
||||
this.auditLogService.getAuditLogs(this.currentPage, this.rows, action, username, from, to).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (response) => {
|
||||
this.logs = response.content;
|
||||
this.totalRecords = response.page.totalElements;
|
||||
@@ -167,9 +169,10 @@ export class AuditLogsComponent implements OnInit {
|
||||
toggleAutoRefresh(): void {
|
||||
this.autoRefresh = !this.autoRefresh;
|
||||
if (this.autoRefresh) {
|
||||
this.autoRefreshSub?.unsubscribe();
|
||||
this.autoRefreshSub = interval(10000)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => this.loadLogs(false));
|
||||
.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.loadLogs(false));
|
||||
} else {
|
||||
this.autoRefreshSub?.unsubscribe();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {take} from 'rxjs/operators';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {CustomFontService} from '../../../shared/service/custom-font.service';
|
||||
@@ -86,7 +85,9 @@ export class CustomFontsComponent implements OnInit {
|
||||
});
|
||||
|
||||
if (this.uploadDialogRef) {
|
||||
this.uploadDialogRef.onClose.pipe(take(1), takeUntilDestroyed(this.destroyRef)).subscribe((font: CustomFont | null) => {
|
||||
this.uploadDialogRef.onClose.pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe((font: CustomFont | null) => {
|
||||
if (font) {
|
||||
this.customFonts.push(font);
|
||||
}
|
||||
@@ -101,7 +102,9 @@ export class CustomFontsComponent implements OnInit {
|
||||
header: this.t.translate('settingsReader.fonts.deleteFontHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.customFontService.deleteFont(font.id).subscribe({
|
||||
this.customFontService.deleteFont(font.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.customFonts = this.customFonts.filter(f => f.id !== font.id);
|
||||
this.messageService.add({
|
||||
|
||||
+9
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
@@ -31,6 +32,7 @@ export class HardcoverSettingsComponent {
|
||||
private readonly hardcoverSyncSettingsService = inject(HardcoverSyncSettingsService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
hasPermission = false;
|
||||
hardcoverSyncEnabled = false;
|
||||
@@ -55,7 +57,9 @@ export class HardcoverSettingsComponent {
|
||||
}
|
||||
|
||||
private loadHardcoverSettings() {
|
||||
this.hardcoverSyncSettingsService.getSettings().subscribe({
|
||||
this.hardcoverSyncSettingsService.getSettings().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: settings => {
|
||||
this.hardcoverSyncEnabled = settings.hardcoverSyncEnabled ?? false;
|
||||
this.hardcoverApiKey = settings.hardcoverApiKey ?? '';
|
||||
@@ -89,7 +93,9 @@ export class HardcoverSettingsComponent {
|
||||
this.hardcoverSyncSettingsService.updateSettings({
|
||||
hardcoverSyncEnabled: this.hardcoverSyncEnabled,
|
||||
hardcoverApiKey: this.hardcoverApiKey
|
||||
}).subscribe({
|
||||
}).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: settings => {
|
||||
this.hardcoverSyncEnabled = settings.hardcoverSyncEnabled ?? false;
|
||||
this.hardcoverApiKey = settings.hardcoverApiKey ?? '';
|
||||
|
||||
+17
-31
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {KoboService, KoboSyncSettings} from './kobo.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
@@ -7,7 +8,7 @@ import {InputText} from 'primeng/inputtext';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {Subject} from 'rxjs';
|
||||
import {debounceTime, takeUntil} from 'rxjs/operators';
|
||||
import {debounceTime} from 'rxjs/operators';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Divider} from 'primeng/divider';
|
||||
@@ -27,7 +28,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
imports: [FormsModule, Button, InputText, ConfirmDialog, ToggleSwitch, Slider, Divider, ExternalDocLinkComponent, Toast, TranslocoDirective],
|
||||
providers: [MessageService, ConfirmationService]
|
||||
})
|
||||
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
export class KoboSyncSettingsComponent implements OnInit {
|
||||
private koboService = inject(KoboService);
|
||||
private messageService = inject(MessageService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
@@ -37,7 +38,7 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
private shelfService = inject(ShelfService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly sliderChange$ = new Subject<void>();
|
||||
private readonly progressThresholdChange$ = new Subject<void>();
|
||||
|
||||
@@ -72,14 +73,14 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
private setupSliderDebouncing() {
|
||||
this.sliderChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(() => {
|
||||
this.saveSettings();
|
||||
});
|
||||
|
||||
this.progressThresholdChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(() => {
|
||||
this.updateKoboSettings(this.t.translate('settingsDevice.kobo.progressUpdated'));
|
||||
});
|
||||
@@ -114,7 +115,9 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
private loadKoboUserSettings() {
|
||||
this.koboService.getUser().subscribe({
|
||||
this.koboService.getUser().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (settings: KoboSyncSettings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.koboSyncSettings.syncEnabled = settings.syncEnabled;
|
||||
@@ -178,7 +181,9 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private regenerateToken() {
|
||||
this.koboService.createOrUpdateToken().subscribe({
|
||||
this.koboService.createOrUpdateToken().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (settings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.credentialsSaved = true;
|
||||
@@ -233,7 +238,9 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateKoboSettings(successMessage: string) {
|
||||
this.koboService.updateSettings(this.koboSyncSettings).subscribe({
|
||||
this.koboService.updateSettings(this.koboSyncSettings).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -253,27 +260,6 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.kobo.settingsSaved'),
|
||||
detail: this.t.translate('settingsDevice.kobo.settingsSuccess')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.kobo.saveFailed'),
|
||||
detail: this.t.translate('settingsDevice.kobo.saveError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
@@ -42,6 +43,7 @@ export class KoreaderSettingsComponent {
|
||||
private readonly koreaderService = inject(KoreaderService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
hasPermission = false;
|
||||
private prevHasPermission = false;
|
||||
@@ -61,7 +63,9 @@ export class KoreaderSettingsComponent {
|
||||
}
|
||||
|
||||
private loadKoreaderSettings() {
|
||||
this.koreaderService.getUser().subscribe({
|
||||
this.koreaderService.getUser().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: koreaderUser => {
|
||||
this.koReaderUsername = koreaderUser.username;
|
||||
this.koReaderPassword = koreaderUser.password;
|
||||
@@ -96,7 +100,9 @@ export class KoreaderSettingsComponent {
|
||||
}
|
||||
|
||||
onToggleEnabled(enabled: boolean) {
|
||||
this.koreaderService.toggleSync(enabled).subscribe({
|
||||
this.koreaderService.toggleSync(enabled).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.koReaderSyncEnabled = enabled;
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('settingsDevice.koreader.syncUpdated'), detail: enabled ? this.t.translate('settingsDevice.koreader.syncEnabled') : this.t.translate('settingsDevice.koreader.syncDisabled')});
|
||||
@@ -108,7 +114,9 @@ export class KoreaderSettingsComponent {
|
||||
}
|
||||
|
||||
onToggleSyncWithGrimmoryReader(enabled: boolean) {
|
||||
this.koreaderService.toggleSyncProgressWithGrimmoryReader(enabled).subscribe({
|
||||
this.koreaderService.toggleSyncProgressWithGrimmoryReader(enabled).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.syncWithGrimmoryReader = enabled;
|
||||
this.messageService.add({
|
||||
@@ -134,6 +142,7 @@ export class KoreaderSettingsComponent {
|
||||
|
||||
saveCredentials() {
|
||||
this.koreaderService.createUser(this.koReaderUsername, this.koReaderPassword)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.credentialsSaved = true;
|
||||
|
||||
+19
-7
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -38,6 +39,7 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
defaultProviderId: unknown;
|
||||
currentUserId: number | null = null;
|
||||
isAdmin: boolean = false;
|
||||
@@ -54,7 +56,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
}
|
||||
|
||||
loadEmailProviders(): void {
|
||||
this.emailProvidersService.getEmailProviders().subscribe({
|
||||
this.emailProvidersService.getEmailProviders().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (emailProviders: EmailProvider[]) => {
|
||||
this.emailProviders = emailProviders.map((provider) => ({
|
||||
...provider,
|
||||
@@ -83,7 +87,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
}
|
||||
|
||||
saveProvider(provider: EmailProvider): void {
|
||||
this.emailProvidersService.updateProvider(provider).subscribe({
|
||||
this.emailProvidersService.updateProvider(provider).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
provider.isEditing = false;
|
||||
this.messageService.add({
|
||||
@@ -105,7 +111,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
|
||||
deleteProvider(provider: EmailProvider): void {
|
||||
if (confirm(this.t.translate('settingsEmail.provider.deleteConfirm', {name: provider.name}))) {
|
||||
this.emailProvidersService.deleteProvider(provider.id).subscribe({
|
||||
this.emailProvidersService.deleteProvider(provider.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -127,7 +135,7 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
|
||||
openCreateProviderDialog() {
|
||||
this.ref = this.dialogLauncherService.openEmailProviderDialog();
|
||||
this.ref?.onClose.subscribe((result) => {
|
||||
this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadEmailProviders();
|
||||
}
|
||||
@@ -135,7 +143,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
}
|
||||
|
||||
setDefaultProvider(provider: EmailProvider) {
|
||||
this.emailProvidersService.setDefaultProvider(provider.id).subscribe({
|
||||
this.emailProvidersService.setDefaultProvider(provider.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.defaultProviderId = provider.id;
|
||||
this.messageService.add({
|
||||
@@ -160,7 +170,9 @@ export class EmailV2ProviderComponent implements OnInit {
|
||||
}
|
||||
|
||||
toggleShared(provider: EmailProvider): void {
|
||||
this.emailProvidersService.updateProvider(provider).subscribe({
|
||||
this.emailProvidersService.updateProvider(provider).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
const status = this.t.translate(provider.shared ? 'settingsEmail.provider.sharedStatusOn' : 'settingsEmail.provider.sharedStatusOff');
|
||||
this.messageService.add({
|
||||
|
||||
+16
-6
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
@@ -34,6 +35,7 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
private emailRecipientService = inject(EmailV2RecipientService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
defaultRecipientId: unknown;
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -41,7 +43,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
}
|
||||
|
||||
loadRecipientEmails(): void {
|
||||
this.emailRecipientService.getRecipients().subscribe({
|
||||
this.emailRecipientService.getRecipients().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (recipients: EmailRecipient[]) => {
|
||||
this.recipientEmails = recipients.map((recipient) => ({
|
||||
...recipient,
|
||||
@@ -70,7 +74,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
}
|
||||
|
||||
saveRecipient(recipient: EmailRecipient): void {
|
||||
this.emailRecipientService.updateRecipient(recipient).subscribe({
|
||||
this.emailRecipientService.updateRecipient(recipient).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
recipient.isEditing = false;
|
||||
this.messageService.add({
|
||||
@@ -92,7 +98,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
|
||||
deleteRecipient(recipient: EmailRecipient): void {
|
||||
if (confirm(this.t.translate('settingsEmail.recipient.deleteConfirm', {email: recipient.email}))) {
|
||||
this.emailRecipientService.deleteRecipient(recipient.id).subscribe({
|
||||
this.emailRecipientService.deleteRecipient(recipient.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -114,7 +122,7 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
|
||||
openAddRecipientDialog() {
|
||||
this.ref = this.dialogLauncherService.openEmailRecipientDialog();
|
||||
this.ref?.onClose.subscribe((result) => {
|
||||
this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadRecipientEmails();
|
||||
}
|
||||
@@ -122,7 +130,9 @@ export class EmailV2RecipientComponent implements OnInit {
|
||||
}
|
||||
|
||||
setDefaultRecipient(recipient: EmailRecipient) {
|
||||
this.emailRecipientService.setDefaultRecipient(recipient.id).subscribe(() => {
|
||||
this.emailRecipientService.setDefaultRecipient(recipient.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(() => {
|
||||
this.defaultRecipientId = recipient.id;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
+7
-2
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -41,6 +42,7 @@ export class FileNamingPatternComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
ngOnInit(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
@@ -112,6 +114,7 @@ export class FileNamingPatternComponent implements OnInit {
|
||||
.saveSettings([
|
||||
{key: AppSettingKey.UPLOAD_FILE_PATTERN, newValue: this.defaultPattern},
|
||||
])
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: () => this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsNaming.defaultPattern.saveSuccess')),
|
||||
error: () => this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsNaming.defaultPattern.saveError')),
|
||||
@@ -124,7 +127,9 @@ export class FileNamingPatternComponent implements OnInit {
|
||||
catchError(() => of(null))
|
||||
)
|
||||
);
|
||||
forkJoin(patchRequests).subscribe(results => {
|
||||
forkJoin(patchRequests).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe(results => {
|
||||
const failures = results.filter(result => result === null);
|
||||
if (failures.length === 0) {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsNaming.libraryOverrides.saveSuccess'));
|
||||
|
||||
+9
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MenuItem, MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
@@ -46,6 +47,7 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
@@ -103,7 +105,9 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
}
|
||||
|
||||
regenerateCovers(missingOnly = false): void {
|
||||
this.bookMetadataManageService.regenerateCovers(missingOnly).subscribe({
|
||||
this.bookMetadataManageService.regenerateCovers(missingOnly).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.covers.regenerateStarted'), this.t.translate('settingsApp.covers.regenerateStartedDetail')),
|
||||
error: () =>
|
||||
@@ -112,7 +116,9 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.settingsSaved'), this.t.translate('settingsApp.settingsSavedDetail')),
|
||||
error: () =>
|
||||
|
||||
+9
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataMatchWeightsService} from '../../../../shared/service/metadata-match-weights.service';
|
||||
@@ -39,6 +40,7 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private fb = inject(FormBuilder);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.fb.group({
|
||||
@@ -95,7 +97,9 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
this.appSettingsService.saveSettings(payload).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -117,7 +121,9 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
|
||||
recalculate(): void {
|
||||
this.isRecalculating = true;
|
||||
this.weightsService.recalculateAll().subscribe({
|
||||
this.weightsService.recalculateAll().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
+6
-2
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
@@ -100,6 +101,7 @@ export class MetadataProviderSettingsComponent {
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
@@ -174,7 +176,9 @@ export class MetadataProviderSettingsComponent {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
this.appSettingsService.saveSettings(payload).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
+15
-5
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Accordion, AccordionPanel, AccordionHeader, AccordionContent} from 'primeng/accordion';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -28,6 +29,7 @@ export class LibraryMetadataSettingsComponent {
|
||||
private messageService = inject(MessageService);
|
||||
private sidecarService = inject(SidecarService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
defaultMetadataOptions: MetadataRefreshOptions = this.getDefaultMetadataOptions();
|
||||
libraryMetadataOptions: Record<number, MetadataRefreshOptions> = {};
|
||||
@@ -102,7 +104,9 @@ export class LibraryMetadataSettingsComponent {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
this.appSettingsService.saveSettings(settingsToSave).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsLibMeta.defaultSettings.saveSuccess'));
|
||||
this.updateLibrariesUsingDefaults();
|
||||
@@ -126,7 +130,9 @@ export class LibraryMetadataSettingsComponent {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
this.appSettingsService.saveSettings(settingsToSave).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsLibMeta.libraryOverrides.saveSuccess'));
|
||||
},
|
||||
@@ -244,7 +250,9 @@ export class LibraryMetadataSettingsComponent {
|
||||
event.stopPropagation();
|
||||
this.sidecarExporting[libraryId] = true;
|
||||
|
||||
this.sidecarService.bulkExport(libraryId).subscribe({
|
||||
this.sidecarService.bulkExport(libraryId).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (response) => {
|
||||
this.sidecarExporting[libraryId] = false;
|
||||
this.showMessage('success', this.t.translate('settingsLibMeta.libraryOverrides.exportComplete'), this.t.translate('settingsLibMeta.libraryOverrides.exportSuccess', {count: response.exported}));
|
||||
@@ -261,7 +269,9 @@ export class LibraryMetadataSettingsComponent {
|
||||
event.stopPropagation();
|
||||
this.sidecarImporting[libraryId] = true;
|
||||
|
||||
this.sidecarService.bulkImport(libraryId).subscribe({
|
||||
this.sidecarService.bulkImport(libraryId).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (response) => {
|
||||
this.sidecarImporting[libraryId] = false;
|
||||
this.showMessage('success', this.t.translate('settingsLibMeta.libraryOverrides.importComplete'), this.t.translate('settingsLibMeta.libraryOverrides.importSuccess', {count: response.imported}));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
@@ -10,9 +11,9 @@ import {FormsModule} from '@angular/forms';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {OpdsService, OpdsSortOrder, OpdsUserV2, OpdsUserV2CreateRequest} from './opds.service';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {UserService} from '../user-management/user.service';
|
||||
import {of, Subject} from 'rxjs';
|
||||
import {of} from 'rxjs';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {AppSettingKey} from '../../../shared/model/app-settings.model';
|
||||
@@ -40,7 +41,7 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
|
||||
templateUrl: './opds-settings.html',
|
||||
styleUrl: './opds-settings.scss'
|
||||
})
|
||||
export class OpdsSettings implements OnInit, OnDestroy {
|
||||
export class OpdsSettings implements OnInit {
|
||||
|
||||
opdsEndpoint = `${API_CONFIG.BASE_URL}/api/v1/opds`;
|
||||
komgaEndpoint = `${API_CONFIG.BASE_URL}/komga`;
|
||||
@@ -65,7 +66,7 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
editingUserId: number | null = null;
|
||||
editingSortOrder: OpdsSortOrder | null = null;
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
dummyPassword: string = "***********************";
|
||||
|
||||
sortOrderOptions = [
|
||||
@@ -113,7 +114,7 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
|
||||
private loadUsers(): void {
|
||||
this.opdsService.getUser().pipe(
|
||||
takeUntil(this.destroy$),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
catchError(err => {
|
||||
console.error('Error loading users:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.loadError'));
|
||||
@@ -130,7 +131,7 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
if (!this.newUser.username || !this.newUser.password) return;
|
||||
|
||||
this.opdsService.createUser(this.newUser).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: user => {
|
||||
this.users.push(user);
|
||||
@@ -159,7 +160,7 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
if (!user.id) return;
|
||||
|
||||
this.opdsService.deleteCredential(user.id).pipe(
|
||||
takeUntil(this.destroy$),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
catchError(err => {
|
||||
console.error('Error deleting user:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.deleteError'));
|
||||
@@ -206,7 +207,9 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
toggleKomgaGroupUnknown(): void {
|
||||
this.appSettingsService.saveSettings([{key: AppSettingKey.KOMGA_GROUP_UNKNOWN, newValue: this.komgaGroupUnknown}]).subscribe({
|
||||
this.appSettingsService.saveSettings([{key: AppSettingKey.KOMGA_GROUP_UNKNOWN, newValue: this.komgaGroupUnknown}]).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (this.komgaGroupUnknown === true)
|
||||
? this.t.translate('settingsOpds.groupEnabled')
|
||||
@@ -220,7 +223,9 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (value === true)
|
||||
? this.t.translate('settingsOpds.opdsEnabled')
|
||||
@@ -234,7 +239,9 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private saveKomgaSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (value === true)
|
||||
? this.t.translate('settingsOpds.komgaEnabled')
|
||||
@@ -276,7 +283,7 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
if (!this.editingSortOrder || !user.id) return;
|
||||
|
||||
this.opdsService.updateUser(user.id, this.editingSortOrder).pipe(
|
||||
takeUntil(this.destroy$),
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
catchError(err => {
|
||||
console.error('Error updating sort order:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.sortUpdateError'));
|
||||
@@ -293,9 +300,4 @@ export class OpdsSettings implements OnInit, OnDestroy {
|
||||
this.cancelEdit();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -1,5 +1,5 @@
|
||||
import {DecimalPipe} from '@angular/common';
|
||||
import {Component, effect, inject, Input, OnDestroy} from '@angular/core';
|
||||
import {Component, effect, inject, Input} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
@@ -8,7 +8,6 @@ import {UserSettings} from '../../user-management/user.service';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {CustomFontService} from '../../../../shared/service/custom-font.service';
|
||||
import {CustomFont} from '../../../../shared/model/custom-font.model';
|
||||
import {Subject} from 'rxjs';
|
||||
import {addCustomFontsToDropdown} from '../../../../shared/util/custom-font.util';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {themes} from '../../../readers/ebook-reader/state/themes.constant';
|
||||
@@ -26,13 +25,12 @@ import {themes} from '../../../readers/ebook-reader/state/themes.constant';
|
||||
templateUrl: './epub-reader-preferences-component.html',
|
||||
styleUrl: './epub-reader-preferences-component.scss'
|
||||
})
|
||||
export class EpubReaderPreferencesComponent implements OnDestroy {
|
||||
export class EpubReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
private readonly customFontService = inject(CustomFontService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
customFonts: CustomFont[] = [];
|
||||
|
||||
@@ -59,11 +57,6 @@ export class EpubReaderPreferencesComponent implements OnDestroy {
|
||||
}
|
||||
});
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private async onFontsChanged(fonts: CustomFont[]): Promise<void> {
|
||||
try {
|
||||
const selectedFontDeleted = this.isCurrentlySelectedFontDeleted(fonts);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {UserService} from './user-management/user.service';
|
||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {UserManagementComponent} from './user-management/user-management.component';
|
||||
import {AuthenticationSettingsComponent} from '../../core/security/oauth2-management/authentication-settings.component';
|
||||
import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
|
||||
@@ -61,13 +61,12 @@ export enum SettingsTab {
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
})
|
||||
export class SettingsComponent implements OnInit, OnDestroy {
|
||||
export class SettingsComponent implements OnInit {
|
||||
protected userService = inject(UserService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
|
||||
private routeSub!: Subscription;
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
SettingsTab = SettingsTab;
|
||||
|
||||
@@ -91,7 +90,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle('Settings');
|
||||
|
||||
this.routeSub = this.route.queryParams.subscribe(params => {
|
||||
this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
||||
const tabParam = params['tab'];
|
||||
if (this.validTabs.includes(tabParam)) {
|
||||
this._activeTab = tabParam as SettingsTab;
|
||||
@@ -106,8 +105,4 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routeSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
} from './task.service';
|
||||
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
|
||||
import {finalize, forkJoin} from 'rxjs';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
+12
-4
@@ -1,4 +1,5 @@
|
||||
import {Component, computed, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
|
||||
import {Component, computed, DestroyRef, EventEmitter, inject, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
@@ -38,6 +39,7 @@ export class ContentRestrictionsEditorComponent implements OnInit, OnChanges {
|
||||
private bookService = inject(BookService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private readonly sortedMetadata = computed(() => {
|
||||
const md = this.bookService.uniqueMetadata();
|
||||
return {
|
||||
@@ -87,7 +89,9 @@ export class ContentRestrictionsEditorComponent implements OnInit, OnChanges {
|
||||
loadRestrictions() {
|
||||
if (!this.userId) return;
|
||||
|
||||
this.contentRestrictionService.getUserRestrictions(this.userId).subscribe({
|
||||
this.contentRestrictionService.getUserRestrictions(this.userId).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (restrictions) => {
|
||||
this.restrictions = restrictions;
|
||||
this.restrictionsChanged.emit(this.restrictions);
|
||||
@@ -150,7 +154,9 @@ export class ContentRestrictionsEditorComponent implements OnInit, OnChanges {
|
||||
value: this.newRestriction.value!
|
||||
};
|
||||
|
||||
this.contentRestrictionService.addRestriction(this.userId, restriction).subscribe({
|
||||
this.contentRestrictionService.addRestriction(this.userId, restriction).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: (added) => {
|
||||
this.restrictions.push(added);
|
||||
this.restrictionsChanged.emit(this.restrictions);
|
||||
@@ -174,7 +180,9 @@ export class ContentRestrictionsEditorComponent implements OnInit, OnChanges {
|
||||
removeRestriction(restriction: ContentRestriction) {
|
||||
if (!restriction.id) return;
|
||||
|
||||
this.contentRestrictionService.deleteRestriction(this.userId, restriction.id).subscribe({
|
||||
this.contentRestrictionService.deleteRestriction(this.userId, restriction.id).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.restrictions = this.restrictions.filter(r => r.id !== restriction.id);
|
||||
this.restrictionsChanged.emit(this.restrictions);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
@@ -13,7 +14,6 @@ import {LibraryService} from '../../book/service/library.service';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {Password} from 'primeng/password';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Subject} from 'rxjs';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DialogLauncherService} from '../../../shared/services/dialog-launcher.service';
|
||||
import {ContentRestrictionsEditorComponent} from './content-restrictions-editor/content-restrictions-editor.component';
|
||||
@@ -46,14 +46,14 @@ interface UserWithEditing extends User {
|
||||
templateUrl: './user-management.component.html',
|
||||
styleUrls: ['./user-management.component.scss'],
|
||||
})
|
||||
export class UserManagementComponent implements OnInit, OnDestroy {
|
||||
export class UserManagementComponent implements OnInit {
|
||||
ref: DynamicDialogRef | undefined | null;
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
private userService = inject(UserService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private destroyRef = inject(DestroyRef);
|
||||
get allLibraries() { return this.libraryService.libraries(); }
|
||||
|
||||
users: UserWithEditing[] = [];
|
||||
@@ -78,14 +78,9 @@ export class UserManagementComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
|
||||
loadUsers() {
|
||||
this.userService.getUsers().subscribe({
|
||||
this.userService.getUsers().pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
||||
next: (data) => {
|
||||
this.users = data.map((user) => ({
|
||||
...user,
|
||||
@@ -107,7 +102,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
|
||||
|
||||
openCreateUserDialog() {
|
||||
this.ref = this.dialogLauncherService.openCreateUserDialog();
|
||||
this.ref?.onClose.subscribe((result) => {
|
||||
this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadUsers();
|
||||
}
|
||||
|
||||
+5
-11
@@ -1,10 +1,9 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Select} from 'primeng/select';
|
||||
import {SidebarLibrarySorting, SidebarMagicShelfSorting, SidebarShelfSorting, User, UserService, UserSettings} from '../../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Subject} from 'rxjs';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type MutableSettingsBranch = Record<string, unknown>;
|
||||
@@ -19,7 +18,7 @@ type MutableSettingsBranch = Record<string, unknown>;
|
||||
templateUrl: './sidebar-sorting-preferences.component.html',
|
||||
styleUrl: './sidebar-sorting-preferences.component.scss'
|
||||
})
|
||||
export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
|
||||
export class SidebarSortingPreferencesComponent implements OnInit {
|
||||
|
||||
private readonly sortingOptionDefs = [
|
||||
{value: {field: 'name', order: 'asc'}, translationKey: 'nameAsc'},
|
||||
@@ -37,7 +36,7 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
private currentUser: User | null = null;
|
||||
private hasInitialized = false;
|
||||
@@ -55,12 +54,7 @@ export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.buildSortingOptions();
|
||||
this.t.langChanges$.pipe(takeUntil(this.destroy$)).subscribe(() => this.buildSortingOptions());
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
this.t.langChanges$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.buildSortingOptions());
|
||||
}
|
||||
|
||||
private buildSortingOptions(): void {
|
||||
|
||||
+5
-11
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, ElementRef, inject, Injector, OnDestroy, OnInit, viewChild} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, ElementRef, inject, Injector, OnInit, viewChild} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -8,11 +9,9 @@ import {DEFAULT_VISIBLE_SORT_FIELDS, SortCriterion, User, UserService} from '../
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {ShelfService} from '../../../book/service/shelf.service';
|
||||
import {MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service';
|
||||
import {Subject} from 'rxjs';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {SortDirection, SortOption} from '../../../book/model/sort.model';
|
||||
@@ -40,7 +39,7 @@ import {CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray} from
|
||||
templateUrl: './view-preferences.component.html',
|
||||
styleUrl: './view-preferences.component.scss'
|
||||
})
|
||||
export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
export class ViewPreferencesComponent implements OnInit {
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
private readonly sortOptionDefs: {field: string; translationKey: string}[] = [
|
||||
@@ -125,7 +124,7 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
}[] = [];
|
||||
|
||||
private user: User | null = null;
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly injector = inject(Injector);
|
||||
|
||||
private libraryService = inject(LibraryService);
|
||||
@@ -138,7 +137,7 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.rebuildTranslatedLabels();
|
||||
this.t.langChanges$.pipe(takeUntil(this.destroy$)).subscribe(() => {
|
||||
this.t.langChanges$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
|
||||
this.rebuildTranslatedLabels();
|
||||
this.allSortAsOptions = this.sortOptions.map(o => ({
|
||||
label: this.t.translate('settingsView.librarySort.' + o.translationKey),
|
||||
@@ -217,11 +216,6 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
];
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
getAvailableEntities(index: number, type: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF') {
|
||||
const selected = this.overrides.map((o, i) => i !== index ? o.library : null);
|
||||
let source: { label: string; value: number }[];
|
||||
|
||||
@@ -15,7 +15,6 @@ import { AuthService } from '../../service/auth.service';
|
||||
import { UserService } from '../../../features/settings/user-management/user.service';
|
||||
import { Popover } from 'primeng/popover';
|
||||
import { MetadataProgressService } from '../../service/metadata-progress.service';
|
||||
|
||||
import { MetadataBatchProgressNotification } from '../../model/metadata-batch-progress.model';
|
||||
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
||||
@@ -69,8 +68,8 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
hasAnyTasks = false;
|
||||
hasPendingBookdropFiles = false;
|
||||
|
||||
private eventTimer: number | undefined;
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private eventTimer: number | undefined;
|
||||
|
||||
private latestTasks: Record<string, MetadataBatchProgressNotification> = {};
|
||||
private latestHasPendingFiles = false;
|
||||
@@ -85,6 +84,8 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
this.subscribeToMetadataProgress();
|
||||
this.subscribeToNotifications();
|
||||
|
||||
this.destroyRef.onDestroy(() => clearTimeout(this.eventTimer));
|
||||
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((tasks) => {
|
||||
@@ -158,7 +159,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
|
||||
switchLanguage(lang: string) {
|
||||
if (lang === this.activeLang) return;
|
||||
this.translocoService.load(lang).subscribe(() => {
|
||||
this.translocoService.load(lang).pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
|
||||
this.translocoService.setActiveLang(lang);
|
||||
localStorage.setItem(LANG_STORAGE_KEY, lang);
|
||||
this.activeLang = lang;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {computed, effect, inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {lastValueFrom, Observable, of} from 'rxjs';
|
||||
import {catchError, map, switchMap} from 'rxjs/operators';
|
||||
import {lastValueFrom, Observable} from 'rxjs';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {AppSettings, OidcProviderDetails, OidcTestResult} from '../model/app-settings.model';
|
||||
import {AuthService} from './auth.service';
|
||||
@@ -99,15 +99,8 @@ export class AppSettingsService {
|
||||
}));
|
||||
|
||||
return this.http.put<void>(this.apiUrl, payload).pipe(
|
||||
switchMap(() => {
|
||||
void this.queryClient.invalidateQueries({queryKey: APP_SETTINGS_QUERY_KEY});
|
||||
return of(void 0);
|
||||
}),
|
||||
map(() => void 0),
|
||||
catchError(err => {
|
||||
console.error('Error saving settings:', err);
|
||||
return of();
|
||||
})
|
||||
switchMap(() => this.queryClient.invalidateQueries({queryKey: APP_SETTINGS_QUERY_KEY})),
|
||||
map(() => void 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,10 +114,6 @@ export class AppSettingsService {
|
||||
this.queryClient.setQueryData(APP_SETTINGS_QUERY_KEY, updated);
|
||||
this.syncPublicSettings(updated);
|
||||
}
|
||||
}),
|
||||
catchError(err => {
|
||||
console.error('Error toggling OIDC:', err);
|
||||
return of();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {firstValueFrom, of, throwError} from 'rxjs';
|
||||
import {of, throwError} from 'rxjs';
|
||||
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@@ -39,10 +39,10 @@ describe('SettingsHelperService', () => {
|
||||
service = TestBed.inject(SettingsHelperService);
|
||||
});
|
||||
|
||||
it('saves a setting and shows a success message', async () => {
|
||||
it('saves a setting and shows a success message', () => {
|
||||
appSettingsService.saveSettings.mockReturnValue(of(undefined));
|
||||
|
||||
await firstValueFrom(service.saveSetting('theme', 'dark'));
|
||||
service.saveSetting('theme', 'dark');
|
||||
|
||||
expect(appSettingsService.saveSettings).toHaveBeenCalledWith([{key: 'theme', newValue: 'dark'}]);
|
||||
expect(messageService.add).toHaveBeenCalledWith({
|
||||
@@ -52,12 +52,12 @@ describe('SettingsHelperService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('shows an error message when saving fails', async () => {
|
||||
it('shows an error message when saving fails', () => {
|
||||
const error = new Error('save failed');
|
||||
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
appSettingsService.saveSettings.mockReturnValue(throwError(() => error));
|
||||
|
||||
await expect(firstValueFrom(service.saveSetting('theme', 'dark'))).rejects.toThrow('save failed');
|
||||
service.saveSetting('theme', 'dark');
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith('Failed to save setting:', error);
|
||||
expect(messageService.add).toHaveBeenCalledWith({
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {of} from 'rxjs';
|
||||
import {AppSettingsService} from './app-settings.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {Observable} from 'rxjs';
|
||||
import {catchError, map} from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -13,18 +14,20 @@ export class SettingsHelperService {
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
saveSetting(key: string, value: unknown): Observable<void> {
|
||||
const observable = this.appSettingsService.saveSettings([{key, newValue: value}]);
|
||||
|
||||
observable.subscribe({
|
||||
next: () => this.showSuccessMessage(),
|
||||
error: (error) => {
|
||||
saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).pipe(
|
||||
map(() => true),
|
||||
catchError((error) => {
|
||||
console.error('Failed to save setting:', error);
|
||||
return of(false);
|
||||
})
|
||||
).subscribe((saved) => {
|
||||
if (saved) {
|
||||
this.showSuccessMessage();
|
||||
} else {
|
||||
this.showErrorMessage();
|
||||
}
|
||||
});
|
||||
|
||||
return observable;
|
||||
}
|
||||
|
||||
private showSuccessMessage(): void {
|
||||
|
||||
@@ -17,6 +17,7 @@ export class NotificationEventService {
|
||||
notificationHighlight$ = this.notificationHighlightSubject.asObservable();
|
||||
|
||||
private highlightTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
private clearTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
handleNewNotification(notification: LogNotification): void {
|
||||
this.latestNotificationSubject.next(notification);
|
||||
@@ -25,12 +26,15 @@ export class NotificationEventService {
|
||||
if (this.highlightTimeout) {
|
||||
clearTimeout(this.highlightTimeout);
|
||||
}
|
||||
if (this.clearTimeout) {
|
||||
clearTimeout(this.clearTimeout);
|
||||
}
|
||||
|
||||
this.highlightTimeout = setTimeout(() => {
|
||||
this.notificationHighlightSubject.next(false);
|
||||
}, 7500);
|
||||
|
||||
setTimeout(() => {
|
||||
this.clearTimeout = setTimeout(() => {
|
||||
if (!this.notificationHighlightSubject.value) {
|
||||
this.latestNotificationSubject.next(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user