Merge pull request #163 from adityachandelgit/develop
Merge Develop into Master - Release v0.2.1
This commit is contained in:
@@ -2,22 +2,38 @@ import { Injectable } from '@angular/core';
|
|||||||
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router';
|
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class CustomReuseStrategy implements RouteReuseStrategy {
|
export class CustomReuseStrategy implements RouteReuseStrategy {
|
||||||
shouldDetach(route: ActivatedRouteSnapshot): boolean {
|
private storedRoutes = new Map<string, DetachedRouteHandle>();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void {
|
|
||||||
|
|
||||||
|
// Only detach the route if it's for the book details page
|
||||||
|
shouldDetach(route: ActivatedRouteSnapshot): boolean {
|
||||||
|
return route.routeConfig?.path === 'book/:id'; // Match the path of the route you want to reuse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the route component instance when detaching
|
||||||
|
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void {
|
||||||
|
if (handle) {
|
||||||
|
// Save the handle if we are detaching this route
|
||||||
|
this.storedRoutes.set(route.routeConfig?.path || '', handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we should attach the route (reuse it) when navigating back to it
|
||||||
shouldAttach(route: ActivatedRouteSnapshot): boolean {
|
shouldAttach(route: ActivatedRouteSnapshot): boolean {
|
||||||
return false;
|
// Attach the route only if there's a stored instance for this route
|
||||||
|
return !!this.storedRoutes.get(route.routeConfig?.path || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve the stored route component instance
|
||||||
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
|
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
|
||||||
return null;
|
return this.storedRoutes.get(route.routeConfig?.path || '') || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine if the route should be reused based on its configuration
|
||||||
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
|
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
|
||||||
return future.routeConfig === curr.routeConfig;
|
// Reuse the route if the path and parameters match
|
||||||
|
return future.routeConfig === curr.routeConfig && future.params['id'] === curr.params['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-28
@@ -3,12 +3,12 @@ import {ActivatedRoute} from '@angular/router';
|
|||||||
import {BookMetadataCenterService} from './book-metadata-center.service';
|
import {BookMetadataCenterService} from './book-metadata-center.service';
|
||||||
import {UserService} from '../../user.service';
|
import {UserService} from '../../user.service';
|
||||||
import {Book, BookRecommendation} from '../../book/model/book.model';
|
import {Book, BookRecommendation} from '../../book/model/book.model';
|
||||||
import {Subscription, switchMap} from 'rxjs';
|
import {Subscription} from 'rxjs';
|
||||||
import {filter, take} from 'rxjs/operators';
|
import {distinctUntilChanged, filter, map, switchMap, take} from 'rxjs/operators';
|
||||||
import {BookService} from '../../book/service/book.service';
|
import {BookService} from '../../book/service/book.service';
|
||||||
import {AppSettingsService} from '../../core/service/app-settings.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 {NgIf} from '@angular/common';
|
import {NgIf, NgTemplateOutlet} from '@angular/common';
|
||||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||||
@@ -27,7 +27,8 @@ import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.c
|
|||||||
MetadataViewerComponent,
|
MetadataViewerComponent,
|
||||||
TabPanel,
|
TabPanel,
|
||||||
MetadataEditorComponent,
|
MetadataEditorComponent,
|
||||||
MetadataSearcherComponent
|
MetadataSearcherComponent,
|
||||||
|
NgTemplateOutlet
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||||
@@ -51,30 +52,30 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.bookService.loadBooks();
|
this.bookService.loadBooks();
|
||||||
|
|
||||||
this.routeSubscription = this.route.paramMap
|
this.routeSubscription = this.route.paramMap.pipe(
|
||||||
.pipe(
|
switchMap(params => {
|
||||||
switchMap(params => {
|
const bookId = Number(params.get('bookId'));
|
||||||
const bookIdStr = params.get('bookId');
|
if (isNaN(bookId)) throw new Error('Invalid book ID');
|
||||||
const bookId = Number(bookIdStr);
|
return this.route.queryParamMap.pipe(
|
||||||
if (isNaN(bookId)) throw new Error('Invalid book ID');
|
map(queryParams => ({
|
||||||
|
bookId,
|
||||||
return this.route.queryParamMap.pipe(
|
tab: queryParams.get('tab') ?? 'view'
|
||||||
switchMap(queryParams => {
|
}))
|
||||||
const rawTab = queryParams.get('tab');
|
);
|
||||||
const validTabs = ['view', 'edit', 'match'];
|
}),
|
||||||
this.tab = validTabs.includes(rawTab || '') ? rawTab! : 'view';
|
switchMap(({bookId, tab}) => {
|
||||||
return this.bookService.getBookByIdFromAPI(bookId, true);
|
const validTabs = ['view', 'edit', 'match'];
|
||||||
})
|
this.tab = validTabs.includes(tab) ? tab : 'view';
|
||||||
);
|
return this.bookService.getBookByIdFromAPI(bookId, true);
|
||||||
})
|
}),
|
||||||
)
|
filter(book => !!book && !!book.metadata),
|
||||||
.subscribe(book => {
|
distinctUntilChanged((prev, curr) => prev.id === curr.id)
|
||||||
this.book = book;
|
).subscribe(book => {
|
||||||
if (book?.metadata) {
|
this.book = book;
|
||||||
this.metadataCenterService.emit(book.metadata);
|
this.metadataCenterService.emitBookChanged(book);
|
||||||
this.fetchBookRecommendationsIfNeeded(book.metadata.bookId);
|
this.metadataCenterService.emitMetadata(book.metadata!);
|
||||||
}
|
this.fetchBookRecommendationsIfNeeded(book.metadata!.bookId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.userSubscription = this.userService.userData$.subscribe(userData => {
|
this.userSubscription = this.userService.userData$.subscribe(userData => {
|
||||||
const userPermissions = userData?.permissions;
|
const userPermissions = userData?.permissions;
|
||||||
@@ -85,6 +86,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.userSubscription.unsubscribe();
|
this.userSubscription.unsubscribe();
|
||||||
this.routeSubscription.unsubscribe();
|
this.routeSubscription.unsubscribe();
|
||||||
|
this.metadataCenterService.emitBookChanged(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
private fetchBookRecommendationsIfNeeded(bookId: number): void {
|
||||||
|
|||||||
@@ -10,7 +10,15 @@ export class BookMetadataCenterService {
|
|||||||
private bookMetadataSubject = new BehaviorSubject<BookMetadata | null>(null);
|
private bookMetadataSubject = new BehaviorSubject<BookMetadata | null>(null);
|
||||||
currentMetadata$ = this.bookMetadataSubject.asObservable();
|
currentMetadata$ = this.bookMetadataSubject.asObservable();
|
||||||
|
|
||||||
emit(bookMetadata: BookMetadata) {
|
emitMetadata(bookMetadata: BookMetadata) {
|
||||||
this.bookMetadataSubject.next(bookMetadata);
|
this.bookMetadataSubject.next(bookMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bookChangedSubject = new BehaviorSubject<Book | null>(null);
|
||||||
|
bookChanged$ = this.bookChangedSubject.asObservable();
|
||||||
|
|
||||||
|
emitBookChanged(book: Book | null) {
|
||||||
|
this.bookChangedSubject.next(book);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -243,7 +243,7 @@
|
|||||||
<div class="flex flex-col gap-1 w-full">
|
<div class="flex flex-col gap-1 w-full">
|
||||||
<label for="description">Description</label>
|
<label for="description">Description</label>
|
||||||
<div class="flex justify-between items-center gap-2">
|
<div class="flex justify-between items-center gap-2">
|
||||||
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
|
<textarea rows="14" pTextarea id="description" formControlName="description" class="w-full"></textarea>
|
||||||
<p-button *ngIf="!metadata['descriptionLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
|
<p-button *ngIf="!metadata['descriptionLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
|
||||||
<p-button *ngIf="metadata['descriptionLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
|
<p-button *ngIf="metadata['descriptionLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+3
-3
@@ -174,7 +174,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
|
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(undefined), false).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||||
this.metadataCenterService.emit(response);
|
this.metadataCenterService.emitMetadata(response);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||||
@@ -270,7 +270,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
||||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.metadataCenterService.emit(response);
|
this.metadataCenterService.emitMetadata(response);
|
||||||
|
|
||||||
if (shouldLockAllFields !== undefined) {
|
if (shouldLockAllFields !== undefined) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@@ -305,7 +305,7 @@ export class MetadataEditorComponent implements OnInit {
|
|||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
const bookMetadata: BookMetadata = response.body as BookMetadata;
|
const bookMetadata: BookMetadata = response.body as BookMetadata;
|
||||||
this.bookService.handleBookMetadataUpdate(this.currentBookId, bookMetadata);
|
this.bookService.handleBookMetadataUpdate(this.currentBookId, bookMetadata);
|
||||||
this.metadataCenterService.emit(bookMetadata);
|
this.metadataCenterService.emitMetadata(bookMetadata);
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
} else {
|
} else {
|
||||||
this.isUploading = false;
|
this.isUploading = false;
|
||||||
|
|||||||
+2
-2
@@ -201,7 +201,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||||
this.metadataCenterService.emit(bookMetadata);
|
this.metadataCenterService.emitMetadata(bookMetadata);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
|
||||||
@@ -268,7 +268,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
||||||
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
this.bookService.updateBookMetadata(this.currentBookId, this.buildMetadata(shouldLockAllFields), false).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.metadataCenterService.emit(response);
|
this.metadataCenterService.emitMetadata(response);
|
||||||
|
|
||||||
if (shouldLockAllFields !== undefined) {
|
if (shouldLockAllFields !== undefined) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
|
|||||||
+39
-26
@@ -1,4 +1,4 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {FormBuilder, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
import {FormBuilder, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {InputText} from 'primeng/inputtext';
|
import {InputText} from 'primeng/inputtext';
|
||||||
@@ -10,12 +10,12 @@ import {ProgressSpinner} from 'primeng/progressspinner';
|
|||||||
import {MetadataPickerComponent} from '../metadata-picker/metadata-picker.component';
|
import {MetadataPickerComponent} from '../metadata-picker/metadata-picker.component';
|
||||||
import {BookMetadataCenterService} from '../book-metadata-center.service';
|
import {BookMetadataCenterService} from '../book-metadata-center.service';
|
||||||
import {MultiSelect} from 'primeng/multiselect';
|
import {MultiSelect} from 'primeng/multiselect';
|
||||||
import {BookMetadata} from '../../../book/model/book.model';
|
import {Book, BookMetadata} from '../../../book/model/book.model';
|
||||||
import {BookService} from '../../../book/service/book.service';
|
import {BookService} from '../../../book/service/book.service';
|
||||||
import {Observable} from 'rxjs';
|
import {combineLatest, Observable, Subscription} from 'rxjs';
|
||||||
import {AppSettings} from '../../../core/model/app-settings.model';
|
import {AppSettings} from '../../../core/model/app-settings.model';
|
||||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||||
import {filter, take} from 'rxjs/operators';
|
import {distinctUntilChanged, filter} from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-metadata-searcher',
|
selector: 'app-metadata-searcher',
|
||||||
@@ -24,8 +24,7 @@ import {filter, take} from 'rxjs/operators';
|
|||||||
imports: [ReactiveFormsModule, Button, InputText, Divider, NgForOf, NgIf, ProgressSpinner, MetadataPickerComponent, MultiSelect],
|
imports: [ReactiveFormsModule, Button, InputText, Divider, NgForOf, NgIf, ProgressSpinner, MetadataPickerComponent, MultiSelect],
|
||||||
standalone: true
|
standalone: true
|
||||||
})
|
})
|
||||||
export class MetadataSearcherComponent implements OnInit {
|
export class MetadataSearcherComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
providers = Object.values(MetadataProvider);
|
providers = Object.values(MetadataProvider);
|
||||||
allFetchedMetadata: BookMetadata[] = [];
|
allFetchedMetadata: BookMetadata[] = [];
|
||||||
@@ -38,7 +37,10 @@ export class MetadataSearcherComponent implements OnInit {
|
|||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
private appSettingsService = inject(AppSettingsService);
|
private appSettingsService = inject(AppSettingsService);
|
||||||
|
|
||||||
|
private subscription: Subscription = new Subscription();
|
||||||
|
|
||||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||||
|
bookChanged$: Observable<Book | null> = this.metadataCenterService.bookChanged$;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.form = this.formBuilder.group({
|
this.form = this.formBuilder.group({
|
||||||
@@ -49,27 +51,38 @@ export class MetadataSearcherComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.metadataCenterService.currentMetadata$.subscribe((metadata => {
|
this.subscription.add(
|
||||||
if (metadata) {
|
combineLatest([this.bookChanged$, this.appSettings$])
|
||||||
this.bookId = metadata.bookId;
|
.pipe(
|
||||||
this.form.patchValue(({
|
filter(([book, settings]) => !!book && !!settings),
|
||||||
provider: Object.values(MetadataProvider),
|
distinctUntilChanged(([prevBook], [currBook]) => prevBook?.id === currBook?.id)
|
||||||
title: metadata.title || null,
|
)
|
||||||
author: metadata.authors?.length! > 0 ? metadata.authors[0] : ''
|
.subscribe(([book, settings]) => {
|
||||||
}));
|
const autoBookSearchEnabled = settings!.autoBookSearch ?? false;
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.appSettings$
|
if (book) {
|
||||||
.pipe(
|
this.selectedFetchedMetadata = null;
|
||||||
filter(settings => settings != null),
|
this.allFetchedMetadata = [];
|
||||||
take(1)
|
this.bookId = book.id;
|
||||||
)
|
|
||||||
.subscribe(settings => {
|
this.form.patchValue({
|
||||||
if (settings.autoBookSearch) {
|
provider: Object.values(MetadataProvider),
|
||||||
this.onSubmit();
|
title: book.metadata?.title || null,
|
||||||
}
|
author: book.metadata?.authors?.length ? book.metadata.authors[0] : ''
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (autoBookSearchEnabled) {
|
||||||
|
this.onSubmit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subscription.unsubscribe();
|
||||||
|
this.allFetchedMetadata = [];
|
||||||
|
this.selectedFetchedMetadata = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isSearchEnabled(): boolean {
|
get isSearchEnabled(): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user