Add configuration to launch Metadata Center as a dialog or full-page route
This commit is contained in:
+3
-2
@@ -59,8 +59,9 @@ public class BookLoreUserTransformer {
|
||||
case ENTITY_VIEW_PREFERENCES -> userSettings.setEntityViewPreferences(objectMapper.readValue(value, BookLoreUser.UserSettings.EntityViewPreferences.class));
|
||||
}
|
||||
} else {
|
||||
if (settingKey == UserSettingKey.FILTER_SORTING_MODE) {
|
||||
userSettings.setFilterSortingMode(value);
|
||||
switch (settingKey) {
|
||||
case FILTER_SORTING_MODE -> userSettings.setFilterSortingMode(value);
|
||||
case METADATA_CENTER_VIEW_MODE -> userSettings.setMetadataCenterViewMode(value);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -43,6 +43,7 @@ public class BookLoreUser {
|
||||
public SidebarSortOption sidebarShelfSorting;
|
||||
public EntityViewPreferences entityViewPreferences;
|
||||
public String filterSortingMode;
|
||||
public String metadataCenterViewMode;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
|
||||
+2
-1
@@ -12,7 +12,8 @@ public enum UserSettingKey {
|
||||
SIDEBAR_LIBRARY_SORTING("sidebarLibrarySorting", true),
|
||||
SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true),
|
||||
ENTITY_VIEW_PREFERENCES("entityViewPreferences", true),
|
||||
FILTER_SORTING_MODE("filterSortingMode", false);
|
||||
FILTER_SORTING_MODE("filterSortingMode", false),
|
||||
METADATA_CENTER_VIEW_MODE("metadataCenterViewMode", false);
|
||||
|
||||
private final String dbKey;
|
||||
private final boolean isJson;
|
||||
|
||||
+8
-3
@@ -44,15 +44,20 @@ public class DefaultSettingInitializer {
|
||||
}
|
||||
|
||||
private void addSettingIfMissing(BookLoreUserEntity user, UserSettingKey key, Object value) {
|
||||
boolean exists = user.getSettings().stream().anyMatch(s -> s.getSettingKey().equals(key.getDbKey()));
|
||||
boolean exists = user.getSettings().stream()
|
||||
.anyMatch(s -> s.getSettingKey().equals(key.getDbKey()));
|
||||
if (!exists) {
|
||||
try {
|
||||
String json = objectMapper.writeValueAsString(value);
|
||||
String serializedValue = key.isJson()
|
||||
? objectMapper.writeValueAsString(value)
|
||||
: value.toString();
|
||||
|
||||
user.getSettings().add(UserSettingEntity.builder()
|
||||
.user(user)
|
||||
.settingKey(key.getDbKey())
|
||||
.settingValue(json)
|
||||
.settingValue(serializedValue)
|
||||
.build());
|
||||
|
||||
log.info("Added default {} for user {}", key, user.getUsername());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to add default {} for user {}", key, user.getUsername(), e);
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ public class DefaultUserSettingsProvider {
|
||||
defaultSettings.put(UserSettingKey.SIDEBAR_SHELF_SORTING, this::buildDefaultSidebarShelfSorting);
|
||||
defaultSettings.put(UserSettingKey.ENTITY_VIEW_PREFERENCES, this::buildDefaultEntityViewPreferences);
|
||||
defaultSettings.put(UserSettingKey.FILTER_SORTING_MODE, () -> "count");
|
||||
defaultSettings.put(UserSettingKey.METADATA_CENTER_VIEW_MODE, () -> "route");
|
||||
}
|
||||
|
||||
public Set<UserSettingKey> getAllKeys() {
|
||||
|
||||
@@ -119,8 +119,7 @@ public class UserService {
|
||||
}
|
||||
|
||||
public void updateUserSetting(Long userId, UpdateUserSettingRequest request) {
|
||||
BookLoreUserEntity user = userRepository.findById(userId)
|
||||
.orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(userId));
|
||||
BookLoreUserEntity user = userRepository.findById(userId).orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(userId));
|
||||
|
||||
String key = request.getKey();
|
||||
Object value = request.getValue();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class BookMetadataHostService {
|
||||
private bookSwitchRequest$ = new Subject<number>();
|
||||
|
||||
requestBookSwitch(bookId: number) {
|
||||
this.bookSwitchRequest$.next(bookId);
|
||||
}
|
||||
|
||||
get bookSwitches$() {
|
||||
return this.bookSwitchRequest$.asObservable();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Component, ElementRef, EventEmitter, inject, Input, OnInit, Output, ViewChild} from '@angular/core';
|
||||
import {Component, ElementRef, EventEmitter, inject, Input, OnInit, Optional, Output, ViewChild} from '@angular/core';
|
||||
import {Book, BookMetadata} from '../../../model/book.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
@@ -20,6 +20,8 @@ import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {BookSenderComponent} from '../../book-sender/book-sender.component';
|
||||
import {Router} from '@angular/router';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {BookMetadataHostService} from '../../../../book-metadata-host-service';
|
||||
import {BookMetadataCenterComponent} from '../../../metadata/book-metadata-center/book-metadata-center.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
@@ -56,13 +58,15 @@ export class BookCardComponent implements OnInit {
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
|
||||
private userPermissions: any;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.userState$
|
||||
.pipe(filter(userData => !!userData))
|
||||
.subscribe((userData) => {
|
||||
this.userPermissions = userData.permissions;
|
||||
.pipe(filter(user => !!user))
|
||||
.subscribe((user) => {
|
||||
this.userPermissions = user.permissions;
|
||||
this.metadataCenterViewMode = user?.userSettings.metadataCenterViewMode ?? 'route';
|
||||
this.initMenu();
|
||||
});
|
||||
}
|
||||
@@ -113,9 +117,19 @@ export class BookCardComponent implements OnInit {
|
||||
icon: 'pi pi-info-circle',
|
||||
command: () => {
|
||||
setTimeout(() => {
|
||||
this.router.navigate(['/book', this.book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
})
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/book', this.book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
} else {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
width: '95%',
|
||||
data: {bookId: this.book.id},
|
||||
modal: true,
|
||||
dismissableMask: true,
|
||||
showHeader: false
|
||||
});
|
||||
}
|
||||
}, 150);
|
||||
},
|
||||
},
|
||||
@@ -274,9 +288,19 @@ export class BookCardComponent implements OnInit {
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
} else {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
width: '95%',
|
||||
data: {bookId: book.id},
|
||||
modal: true,
|
||||
dismissableMask: true,
|
||||
showHeader: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private isAdmin(): boolean {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<div class="book-cover-wrapper"
|
||||
(mouseenter)="isHovered = true"
|
||||
(mouseleave)="isHovered = false">
|
||||
<img
|
||||
[src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
<p-button
|
||||
icon="pi pi-info"
|
||||
class="info-btn"
|
||||
[rounded]="true"
|
||||
[ngClass]="{ 'visible': isHovered }"
|
||||
(onClick)="openBookInfo(book)">
|
||||
</p-button>
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
.book-cover-wrapper {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
display: block;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.info-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
z-index: 2;
|
||||
|
||||
&.visible {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {BookMetadataCenterComponent} from '../../metadata/book-metadata-center/book-metadata-center.component';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {EmailService} from '../../../settings/email/email.service';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {Router} from '@angular/router';
|
||||
import {filter} from 'rxjs';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {BookMetadataHostService} from '../../../book-metadata-host-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card-lite-component',
|
||||
imports: [
|
||||
Button,
|
||||
NgClass
|
||||
],
|
||||
templateUrl: './book-card-lite-component.html',
|
||||
styleUrl: './book-card-lite-component.scss'
|
||||
})
|
||||
export class BookCardLiteComponent implements OnInit {
|
||||
@Input() book!: Book;
|
||||
|
||||
private router = inject(Router);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
private userService = inject(UserService);
|
||||
private bookMetadataHostService = inject(BookMetadataHostService);
|
||||
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
isHovered: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.userState$
|
||||
.pipe(filter(user => !!user))
|
||||
.subscribe((user) => {
|
||||
this.metadataCenterViewMode = user?.userSettings.metadataCenterViewMode ?? 'route';
|
||||
});
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/book', book.id], {
|
||||
queryParams: {tab: 'view'}
|
||||
});
|
||||
} else {
|
||||
this.bookMetadataHostService.requestBookSwitch(book.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-47
@@ -1,44 +1,23 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, inject, OnDestroy, OnInit, Optional} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {Book, BookRecommendation} from '../../model/book.model';
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
map,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
take,
|
||||
tap
|
||||
} from 'rxjs/operators';
|
||||
import {BehaviorSubject, Observable, Subscription} from 'rxjs';
|
||||
import {distinctUntilChanged, filter, map, shareReplay, switchMap, take, tap} from 'rxjs/operators';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {
|
||||
Tab,
|
||||
TabList,
|
||||
TabPanel,
|
||||
TabPanels,
|
||||
Tabs
|
||||
} from 'primeng/tabs';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||
import {DynamicDialogConfig} from 'primeng/dynamicdialog';
|
||||
import {BookMetadataHostService} from '../../../book-metadata-host-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-metadata-center',
|
||||
standalone: true,
|
||||
templateUrl: './book-metadata-center.component.html',
|
||||
imports: [
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
MetadataViewerComponent,
|
||||
MetadataEditorComponent,
|
||||
MetadataSearcherComponent
|
||||
],
|
||||
imports: [Tabs, TabList, Tab, TabPanels, TabPanel, MetadataViewerComponent, MetadataEditorComponent, MetadataSearcherComponent],
|
||||
styleUrls: ['./book-metadata-center.component.scss']
|
||||
})
|
||||
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
@@ -46,6 +25,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private metadataHostService = inject(BookMetadataHostService);
|
||||
|
||||
book$!: Observable<Book>;
|
||||
recommendedBooks: BookRecommendation[] = [];
|
||||
@@ -57,35 +37,54 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
private tabSubscription: Subscription = Subscription.EMPTY;
|
||||
private recommendationSubscription: Subscription = Subscription.EMPTY;
|
||||
private appSettings$ = this.appSettingsService.appSettings$;
|
||||
private currentBookId$ = new BehaviorSubject<number | null>(null);
|
||||
|
||||
constructor(@Optional() private config?: DynamicDialogConfig) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.loadBooks();
|
||||
const bookIdFromDialog: number | undefined = this.config?.data?.bookId;
|
||||
if (bookIdFromDialog != null) {
|
||||
this.currentBookId$.next(bookIdFromDialog);
|
||||
} else {
|
||||
this.route.paramMap
|
||||
.pipe(
|
||||
map(params => Number(params.get('bookId'))),
|
||||
filter(bookId => !isNaN(bookId))
|
||||
)
|
||||
.subscribe(bookId => this.currentBookId$.next(bookId));
|
||||
}
|
||||
|
||||
const bookId$ = this.route.paramMap.pipe(
|
||||
map(params => Number(params.get('bookId'))),
|
||||
filter(bookId => !isNaN(bookId)),
|
||||
this.metadataHostService.bookSwitches$
|
||||
.pipe(
|
||||
filter((bookId): bookId is number => !!bookId),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
.subscribe(bookId => {
|
||||
this.currentBookId$.next(bookId);
|
||||
});
|
||||
|
||||
this.book$ = this.currentBookId$.pipe(
|
||||
filter((bookId): bookId is number => bookId != null),
|
||||
distinctUntilChanged(),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
this.book$ = bookId$.pipe(
|
||||
switchMap(bookId =>
|
||||
this.bookService.bookState$.pipe(
|
||||
map(state => state.books?.find(b => b.id === bookId)),
|
||||
filter((book): book is Book => !!book && !!book.metadata),
|
||||
distinctUntilChanged((a, b) => a.id === b.id && a.metadata === b.metadata),
|
||||
switchMap(book => this.bookService.getBookByIdFromAPI(book.id, true))
|
||||
)
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
this.recommendationSubscription = bookId$.pipe(
|
||||
this.recommendationSubscription = this.currentBookId$.pipe(
|
||||
filter((id): id is number => id != null),
|
||||
tap(bookId => this.fetchBookRecommendationsIfNeeded(bookId))
|
||||
).subscribe();
|
||||
|
||||
this.tabSubscription = this.route.queryParamMap.pipe(
|
||||
map(queryParams => queryParams.get('tab') ?? 'view'),
|
||||
map(params => params.get('tab') ?? 'view'),
|
||||
distinctUntilChanged()
|
||||
).subscribe(tab => {
|
||||
const validTabs = ['view', 'edit', 'match'];
|
||||
@@ -93,18 +92,11 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
this.userSubscription = this.userService.userState$.subscribe(userData => {
|
||||
const userPermissions = userData?.permissions;
|
||||
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
|
||||
this.admin = userPermissions?.admin ?? false;
|
||||
this.canEditMetadata = userData?.permissions?.canEditMetadata ?? false;
|
||||
this.admin = userData?.permissions?.admin ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription.unsubscribe();
|
||||
this.tabSubscription.unsubscribe();
|
||||
this.recommendationSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
||||
this.appSettings$
|
||||
.pipe(
|
||||
@@ -121,4 +113,10 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.userSubscription.unsubscribe();
|
||||
this.tabSubscription.unsubscribe();
|
||||
this.recommendationSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -412,7 +412,7 @@
|
||||
</div>
|
||||
<div class="mt-auto">
|
||||
<p-divider></p-divider>
|
||||
<div class="flex justify-between px-2 pt-1 pb-4 bg-gray-900 z-10">
|
||||
<div class="flex justify-between px-2 pt-1 pb-4 z-10">
|
||||
@if (showNavigationButtons) {
|
||||
<div class="flex gap-x-4">
|
||||
<p-button label="Close" icon="pi pi-times" [outlined]="true" severity="danger" (onClick)="closeDialog()"></p-button>
|
||||
|
||||
-1
@@ -107,7 +107,6 @@ export class MetadataSearcherComponent implements OnInit, OnDestroy {
|
||||
.filter(([_, value]) => value.enabled)
|
||||
.map(([key]) => key.charAt(0).toUpperCase() + key.slice(1));
|
||||
|
||||
console.log('aditya')
|
||||
this.resetFormFromBook(book!);
|
||||
|
||||
if (settings!.autoBookSearch) {
|
||||
|
||||
+8
-32
@@ -45,17 +45,9 @@
|
||||
</div>
|
||||
<p class="text-lg">
|
||||
@for (author of book?.metadata!.authors; track author; let isLast = $last) {
|
||||
<a
|
||||
class="underline hover:opacity-80"
|
||||
[routerLink]="['/all-books']"
|
||||
[queryParams]="{
|
||||
view: 'grid',
|
||||
sort: 'title',
|
||||
direction: 'asc',
|
||||
sidebar: true,
|
||||
filter: 'author:' + author
|
||||
}"
|
||||
>{{ author }}</a>
|
||||
<a class="underline hover:opacity-80 cursor-pointer" (click)="goToAuthorBooks(author)">
|
||||
{{ author }}
|
||||
</a>
|
||||
@if (!isLast) {
|
||||
<span>, </span>
|
||||
}
|
||||
@@ -152,17 +144,7 @@
|
||||
</div>
|
||||
<div class="flex gap-2 pt-4 overflow-x-auto scrollbar-hide">
|
||||
@for (category of book?.metadata!.categories; track category) {
|
||||
<a
|
||||
[routerLink]="['/all-books']"
|
||||
[queryParams]="{
|
||||
view: 'grid',
|
||||
sort: 'title',
|
||||
direction: 'asc',
|
||||
sidebar: true,
|
||||
filter: 'category:' + category
|
||||
}"
|
||||
class="shrink-0 no-underline"
|
||||
>
|
||||
<a (click)="goToCategory(category)" class="shrink-0 no-underline cursor-pointer">
|
||||
<p-tag [value]="category"></p-tag>
|
||||
</a>
|
||||
}
|
||||
@@ -349,12 +331,9 @@
|
||||
[horizontal]="true">
|
||||
@for (book of bookInSeries; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card
|
||||
<app-book-card-lite-component
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="false"
|
||||
[readButtonHidden]="true"
|
||||
[bottomBarHidden]="true">
|
||||
</app-book-card>
|
||||
></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -371,12 +350,9 @@
|
||||
[horizontal]="true">
|
||||
@for (book of recommendedBooks; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card
|
||||
<app-book-card-lite-component
|
||||
[book]="book.book"
|
||||
[isCheckboxEnabled]="false"
|
||||
[readButtonHidden]="true"
|
||||
[bottomBarHidden]="true">
|
||||
</app-book-card>
|
||||
></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
+69
-7
@@ -1,4 +1,4 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, Optional, SimpleChanges, ViewChild} from '@angular/core';
|
||||
import {Button, ButtonDirective} from 'primeng/button';
|
||||
import {AsyncPipe, DecimalPipe, NgClass} from '@angular/common';
|
||||
import {Observable} from 'rxjs';
|
||||
@@ -13,12 +13,10 @@ import {UserService} from '../../../../settings/user-management/user.service';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
import {BookSenderComponent} from '../../../components/book-sender/book-sender.component';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {EmailService} from '../../../../settings/email/email.service';
|
||||
import {ShelfAssignerComponent} from '../../../components/shelf-assigner/shelf-assigner.component';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {BookCardComponent} from '../../../components/book-browser/book-card/book-card.component';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Editor} from 'primeng/editor';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
@@ -26,16 +24,18 @@ import {ToggleButton} from 'primeng/togglebutton';
|
||||
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
|
||||
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {Router} from '@angular/router';
|
||||
import {filter, map, take} from 'rxjs/operators';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {BookCardLiteComponent} from '../../../components/book-card-lite/book-card-lite-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, InfiniteScrollDirective, BookCardComponent, ButtonDirective, Editor, ProgressBar, ToggleButton, RouterLink, Menu]
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, ButtonDirective, Editor, ProgressBar, ToggleButton, Menu, InfiniteScrollDirective, BookCardLiteComponent]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
|
||||
@@ -54,6 +54,12 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private router = inject(Router);
|
||||
|
||||
private dialogRef?: DynamicDialogRef;
|
||||
|
||||
constructor(@Optional() dialogRef?: DynamicDialogRef) {
|
||||
this.dialogRef = dialogRef;
|
||||
}
|
||||
|
||||
emailMenuItems$!: Observable<MenuItem[]>;
|
||||
readMenuItems$!: Observable<MenuItem[]>;
|
||||
refreshMenuItems$!: Observable<MenuItem[]>;
|
||||
@@ -63,6 +69,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
isExpanded = false;
|
||||
showFilePath = false;
|
||||
isAutoFetching = false;
|
||||
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
|
||||
|
||||
readStatusOptions = [
|
||||
{label: 'Unread', value: ReadStatus.UNREAD},
|
||||
@@ -145,7 +152,11 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([book.id])).subscribe({
|
||||
next: () => {
|
||||
this.router.navigate(['/dashboard']);
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
this.dialogRef?.close();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
}
|
||||
@@ -157,6 +168,15 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
])
|
||||
);
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(
|
||||
filter(user => !!user),
|
||||
take(1)
|
||||
)
|
||||
.subscribe(user => {
|
||||
this.metadataCenterViewMode = user?.userSettings.metadataCenterViewMode ?? 'route';
|
||||
});
|
||||
|
||||
this.book$
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
@@ -341,6 +361,48 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
});
|
||||
}
|
||||
|
||||
goToAuthorBooks(author: string): void {
|
||||
if (this.metadataCenterViewMode === 'dialog') {
|
||||
this.dialogRef?.close();
|
||||
setTimeout(() => this.navigateToAuthorBooks(author), 200);
|
||||
} else {
|
||||
this.navigateToAuthorBooks(author);
|
||||
}
|
||||
}
|
||||
|
||||
private navigateToAuthorBooks(author: string): void {
|
||||
this.router.navigate(['/all-books'], {
|
||||
queryParams: {
|
||||
view: 'grid',
|
||||
sort: 'title',
|
||||
direction: 'asc',
|
||||
sidebar: true,
|
||||
filter: `author:${author}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
goToCategory(category: string): void {
|
||||
if (this.metadataCenterViewMode === 'dialog') {
|
||||
this.dialogRef?.close();
|
||||
setTimeout(() => this.navigateToCategory(category), 200);
|
||||
} else {
|
||||
this.navigateToCategory(category);
|
||||
}
|
||||
}
|
||||
|
||||
private navigateToCategory(category: string): void {
|
||||
this.router.navigate(['/all-books'], {
|
||||
queryParams: {
|
||||
view: 'grid',
|
||||
sort: 'title',
|
||||
direction: 'asc',
|
||||
sidebar: true,
|
||||
filter: `category:${category}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getStatusSeverity(status: string): 'success' | 'secondary' | 'info' | 'warn' | 'danger' | undefined {
|
||||
const normalized = status?.toUpperCase();
|
||||
if (['UNREAD', 'PAUSED'].includes(normalized)) return 'secondary';
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface UserSettings {
|
||||
sidebarLibrarySorting: SidebarLibrarySorting;
|
||||
sidebarShelfSorting: SidebarShelfSorting;
|
||||
filterSortingMode: 'alphabetical' | 'count';
|
||||
metadataCenterViewMode: 'route' | 'dialog';
|
||||
entityViewPreferences: EntityViewPreferences;
|
||||
}
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<div class="px-4">
|
||||
<div class="flex items-center gap-2 pb-6 pt-4">
|
||||
<p class="text-lg font-medium">Open Metadata Center</p>
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Decide how you want to view book details — inline as a full page or in a pop-up dialog."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Display Mode:
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Choose whether to open the Metadata Center in the current page or as a popup dialog window."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
|
||||
<div class="flex gap-4 justify-start">
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radioButton name="viewMode"
|
||||
[value]="'route'"
|
||||
[(ngModel)]="viewMode"
|
||||
inputId="viewModeRoute"
|
||||
(onClick)="onViewModeChange('route')"></p-radioButton>
|
||||
<label for="viewModeRoute">Route</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radioButton name="viewMode"
|
||||
[value]="'dialog'"
|
||||
[(ngModel)]="viewMode"
|
||||
inputId="viewModeDialog"
|
||||
(onClick)="onViewModeChange('dialog')"></p-radioButton>
|
||||
<label for="viewModeDialog">Dialog</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {UserService} from '../../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {take} from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-meta-center-view-mode-component',
|
||||
imports: [
|
||||
Tooltip,
|
||||
RadioButton,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './meta-center-view-mode-component.html',
|
||||
styleUrl: './meta-center-view-mode-component.scss'
|
||||
})
|
||||
export class MetaCenterViewModeComponent implements OnInit {
|
||||
viewMode: 'route' | 'dialog' = 'route';
|
||||
|
||||
private userService = inject(UserService);
|
||||
private messageService = inject(MessageService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.userState$.pipe(take(1)).subscribe(user => {
|
||||
const preference = user?.userSettings?.metadataCenterViewMode;
|
||||
if (preference === 'dialog' || preference === 'route') {
|
||||
this.viewMode = preference;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onViewModeChange(value: 'route' | 'dialog'): void {
|
||||
this.viewMode = value;
|
||||
this.savePreference(value);
|
||||
}
|
||||
|
||||
private savePreference(value: 'route' | 'dialog'): void {
|
||||
const user = this.userService.getCurrentUser();
|
||||
if (!user) return;
|
||||
|
||||
user.userSettings.metadataCenterViewMode = value;
|
||||
this.userService.updateUserSetting(user.id, 'metadataCenterViewMode', value);
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preferences Updated',
|
||||
detail: 'Your metadata center view preference has been saved.',
|
||||
life: 1500,
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<div class="p-4">
|
||||
<div class="px-4 pb-2">
|
||||
<div class="flex items-center gap-2 pb-6 pt-4">
|
||||
<p class="text-lg">Sidebar Library and Shelf Sorting Preference</p>
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
|
||||
+2
@@ -2,4 +2,6 @@
|
||||
<app-view-preferences></app-view-preferences>
|
||||
<p-divider></p-divider>
|
||||
<app-sidebar-sorting-preferences></app-sidebar-sorting-preferences>
|
||||
<p-divider></p-divider>
|
||||
<app-meta-center-view-mode-component></app-meta-center-view-mode-component>
|
||||
</div>
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@ import {TableModule} from 'primeng/table';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {ViewPreferencesComponent} from './view-preferences/view-preferences.component';
|
||||
import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component';
|
||||
import {MetaCenterViewModeComponent} from './meta-center-view-mode-component/meta-center-view-mode-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-view-preferences-parent',
|
||||
@@ -15,7 +16,8 @@ import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/
|
||||
TableModule,
|
||||
ToastModule,
|
||||
ViewPreferencesComponent,
|
||||
SidebarSortingPreferencesComponent
|
||||
SidebarSortingPreferencesComponent,
|
||||
MetaCenterViewModeComponent
|
||||
],
|
||||
templateUrl: './view-preferences-parent.component.html',
|
||||
styleUrl: './view-preferences-parent.component.scss'
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center mt-10">
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center mt-8">
|
||||
<p>Overrides:</p>
|
||||
<div class="flex gap-4">
|
||||
<p-button label="Add New Override" outlined size="small" (onClick)="addOverride()" severity="info" [disabled]="availableLibraries.length === 0"></p-button>
|
||||
|
||||
Reference in New Issue
Block a user