Add toggle to enable/disable book recommendations (#152)
Co-authored-by: adityachandelgit
This commit is contained in:
co-authored by
adityachandelgit
parent
b8a493d264
commit
c903044dc1
@@ -30,20 +30,42 @@
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<p class="text-xl pb-4 pt-8">Auto Book Search
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="If enabled, Booklore will automatically perform a metadata match/search when the book information tab is opened."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Enable:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="autoMetadataChecked"
|
||||
(onChange)="onAutoMetaChange($event)"
|
||||
/>
|
||||
<div class="flex flex-row gap-11">
|
||||
<div>
|
||||
<p class="text-xl pb-4 pt-8">Auto Book Search
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="If enabled, Booklore will automatically perform a metadata match/search when the book information tab is opened."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Enable:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="autoMetadataChecked"
|
||||
(onChange)="onAutoMetaChange($event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xl pb-4 pt-8">Similar Book Recommendation
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Enable or disable similar book recommendations entirely."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="text-lg py-1">Enable:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="recommendationEnabled"
|
||||
(onChange)="onToggleRecommendation($event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {BookService} from '../../book/service/book.service';
|
||||
import {AppSettings} from '../../core/model/app-settings.model';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {MetadataAdvancedFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-global-preferences',
|
||||
@@ -43,6 +44,7 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
selectedResolution = '250x350';
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
autoMetadataChecked = false;
|
||||
recommendationEnabled = false;
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private bookService = inject(BookService);
|
||||
@@ -50,15 +52,20 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.subscribe(settings => {
|
||||
if (settings?.coverSettings) {
|
||||
this.appSettings$.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1)
|
||||
).subscribe(settings => {
|
||||
if (settings.coverSettings) {
|
||||
this.selectedResolution = settings.coverSettings.resolution;
|
||||
}
|
||||
if (settings?.metadataRefreshOptions) {
|
||||
if (settings.metadataRefreshOptions) {
|
||||
this.currentMetadataOptions = settings.metadataRefreshOptions;
|
||||
}
|
||||
this.autoMetadataChecked = settings?.autoBookSearch ?? false;
|
||||
this.autoMetadataChecked = settings.autoBookSearch ?? false;
|
||||
this.recommendationEnabled = settings.similarBookRecommendation ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,6 +79,10 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
this.saveSetting('auto_book_search', event.checked);
|
||||
}
|
||||
|
||||
onToggleRecommendation(event: { checked: boolean }) {
|
||||
this.saveSetting('similar_book_recommendation', event.checked);
|
||||
}
|
||||
|
||||
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions): void {
|
||||
this.saveSetting('quick_book_match', metadataRefreshOptions);
|
||||
}
|
||||
|
||||
@@ -1,34 +1,26 @@
|
||||
<div class="card" *ngIf="userService.userData$ | async as userData">
|
||||
<p-tabs value="0">
|
||||
<p-tabs [(value)]="activeTab">
|
||||
<p-tablist>
|
||||
<p-tab value="0">Book Preferences</p-tab>
|
||||
<p-tab [value]="SettingsTab.BookReader">Book Reader</p-tab>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="1">User Management</p-tab>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="2">Email</p-tab>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tab value="3">Global Preferences</p-tab>
|
||||
<p-tab [value]="SettingsTab.UserManagement">User Management</p-tab>
|
||||
<p-tab [value]="SettingsTab.Email">Email</p-tab>
|
||||
<p-tab [value]="SettingsTab.GlobalSettings">Global Settings</p-tab>
|
||||
</ng-container>
|
||||
</p-tablist>
|
||||
|
||||
<p-tabpanels>
|
||||
<p-tabpanel value="0">
|
||||
<p-tabpanel [value]="SettingsTab.BookReader">
|
||||
<app-book-preferences></app-book-preferences>
|
||||
</p-tabpanel>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="1">
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<app-admin></app-admin>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="2">
|
||||
<p-tabpanel [value]="SettingsTab.Email">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="userData.permissions.admin">
|
||||
<p-tabpanel value="3">
|
||||
<p-tabpanel [value]="SettingsTab.GlobalSettings">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
</ng-container>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {BookPreferences} from './book-preferences/book-preferences.component';
|
||||
import {AdminComponent} from './admin/admin.component';
|
||||
@@ -6,6 +6,15 @@ import {UserService} from '../user.service';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {EmailComponent} from './email/email.component';
|
||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
export enum SettingsTab {
|
||||
BookReader = 'book-reader',
|
||||
UserManagement = 'user-management',
|
||||
Email = 'email',
|
||||
GlobalSettings = 'global-settings'
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
@@ -25,8 +34,50 @@ import {GlobalPreferencesComponent} from './global-preferences/global-preference
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
})
|
||||
export class SettingsComponent {
|
||||
export class SettingsComponent implements OnInit, OnDestroy {
|
||||
|
||||
protected userService = inject(UserService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
|
||||
private routeSub!: Subscription;
|
||||
|
||||
SettingsTab = SettingsTab;
|
||||
|
||||
private validTabs = Object.values(SettingsTab);
|
||||
private _activeTab: SettingsTab = SettingsTab.BookReader;
|
||||
|
||||
get activeTab(): SettingsTab {
|
||||
return this._activeTab;
|
||||
}
|
||||
|
||||
set activeTab(value: SettingsTab) {
|
||||
this._activeTab = value;
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { tab: value },
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.routeSub = this.route.queryParams.subscribe(params => {
|
||||
const tabParam = params['tab'];
|
||||
if (this.validTabs.includes(tabParam)) {
|
||||
this._activeTab = tabParam as SettingsTab;
|
||||
} else {
|
||||
this._activeTab = SettingsTab.BookReader;
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { tab: this._activeTab },
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routeSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user