Transition book metadata center from dynamic dialog to routed view (#146)
Co-authored-by: adityachandelgit <>
This commit is contained in:
co-authored by
adityachandelgit
parent
b0d1493e59
commit
6fa394e1ed
+20
-18
@@ -1,18 +1,20 @@
|
||||
<p-tabs [value]="tab" lazy="true" style="height: 100%; overflow: hidden;">
|
||||
<p-tablist>
|
||||
<p-tab value="view">Book Details</p-tab>
|
||||
<p-tab *ngIf="canEditMetadata" value="edit">Edit Details</p-tab>
|
||||
<p-tab *ngIf="canEditMetadata" value="match">Match Book</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels style="height: 100%; overflow: hidden; padding-bottom: 0">
|
||||
<p-tabpanel value="view" style="height: 100%; overflow: hidden;">
|
||||
<app-metadata-viewer [book]="book"></app-metadata-viewer>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel *ngIf="canEditMetadata" value="edit" style="height: 100%; overflow: hidden;">
|
||||
<app-metadata-editor></app-metadata-editor>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel *ngIf="canEditMetadata" value="match" style="height: 100%; overflow: hidden;">
|
||||
<app-metadata-searcher></app-metadata-searcher>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
<div class="rounded-xl overflow-hidden bg-card">
|
||||
<p-tabs [value]="tab" lazy="true">
|
||||
<p-tablist>
|
||||
<p-tab value="view">Book Details</p-tab>
|
||||
<p-tab *ngIf="canEditMetadata" value="edit">Edit Details</p-tab>
|
||||
<p-tab *ngIf="canEditMetadata" value="match">Match Book</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels class="h-[calc(100vh-10rem)]">
|
||||
<p-tabpanel value="view">
|
||||
<app-metadata-viewer [book]="book"></app-metadata-viewer>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel *ngIf="canEditMetadata" value="edit">
|
||||
<app-metadata-editor></app-metadata-editor>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel *ngIf="canEditMetadata" value="match">
|
||||
<app-metadata-searcher></app-metadata-searcher>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
|
||||
+55
-32
@@ -1,59 +1,82 @@
|
||||
import {Component, inject, OnInit, OnDestroy} from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { BookMetadataCenterService } from './book-metadata-center.service';
|
||||
import { UserService } from '../../user.service';
|
||||
import { Book } from '../../book/model/book.model';
|
||||
import { Subscription, switchMap } from 'rxjs';
|
||||
import { BookService } from '../../book/service/book.service';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||
import {BookMetadataCenterService} from './book-metadata-center.service';
|
||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||
import {UserService} from '../../user.service';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {Book} from '../../book/model/book.model';
|
||||
import {MetadataViewerComponent} from './metadata-viewer/metadata-viewer.component';
|
||||
import {MetadataEditorComponent} from './metadata-editor/metadata-editor.component';
|
||||
import {MetadataSearcherComponent} from './metadata-searcher/metadata-searcher.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-metadata-center',
|
||||
standalone: true,
|
||||
templateUrl: './book-metadata-center.component.html',
|
||||
styleUrl: './book-metadata-center.component.scss',
|
||||
imports: [Tabs, TabList, Tab, TabPanels, MetadataEditorComponent, TabPanel, MetadataSearcherComponent, MetadataViewerComponent, NgIf],
|
||||
imports: [
|
||||
TabList,
|
||||
Tabs,
|
||||
Tab,
|
||||
NgIf,
|
||||
TabPanels,
|
||||
MetadataViewerComponent,
|
||||
TabPanel,
|
||||
MetadataEditorComponent,
|
||||
MetadataSearcherComponent
|
||||
]
|
||||
})
|
||||
export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
||||
|
||||
private dynamicDialogConfig = inject(DynamicDialogConfig);
|
||||
private dynamicDialogRef = inject(DynamicDialogRef);
|
||||
private route = inject(ActivatedRoute);
|
||||
private bookService = inject(BookService);
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
private userService = inject(UserService);
|
||||
|
||||
tab = 'view';
|
||||
canEditMetadata: boolean = false;
|
||||
private userSubscription: Subscription = Subscription.EMPTY;
|
||||
book: Book | undefined;
|
||||
tab: string = 'view';
|
||||
canEditMetadata: boolean = false;
|
||||
|
||||
private userSubscription: Subscription = Subscription.EMPTY;
|
||||
private routeSubscription: Subscription = Subscription.EMPTY;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.book = this.dynamicDialogConfig.data.book;
|
||||
this.tab = this.dynamicDialogConfig.data.tab;
|
||||
this.routeSubscription = this.route.paramMap
|
||||
.pipe(
|
||||
switchMap(params => {
|
||||
const bookIdStr = params.get('bookId');
|
||||
const bookId = Number(bookIdStr);
|
||||
|
||||
if (this.book?.metadata) {
|
||||
this.metadataCenterService.emit(this.book.metadata);
|
||||
}
|
||||
if (isNaN(bookId)) {
|
||||
throw new Error('Invalid book ID');
|
||||
}
|
||||
|
||||
return this.route.queryParamMap.pipe(
|
||||
switchMap(queryParams => {
|
||||
const rawTab = queryParams.get('tab');
|
||||
const validTabs = ['view', 'edit', 'match'];
|
||||
this.tab = validTabs.includes(rawTab || '') ? rawTab! : 'view';
|
||||
return this.bookService.getBookByIdFromAPI(bookId, true);
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
.subscribe(book => {
|
||||
this.book = book;
|
||||
if (book?.metadata) {
|
||||
this.metadataCenterService.emit(book.metadata);
|
||||
}
|
||||
});
|
||||
|
||||
this.userSubscription = this.userService.userData$.subscribe(userData => {
|
||||
const userPermissions = userData?.permissions;
|
||||
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
|
||||
});
|
||||
|
||||
this.metadataCenterService.dialogClose$.subscribe((close) => {
|
||||
if (close) {
|
||||
this.metadataCenterService.closeDialog(false);
|
||||
this.dynamicDialogRef.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
// Clean up subscription to prevent memory leaks
|
||||
if (this.userSubscription) {
|
||||
this.userSubscription.unsubscribe();
|
||||
}
|
||||
this.userSubscription.unsubscribe();
|
||||
this.routeSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,8 @@ export class BookMetadataCenterService {
|
||||
private bookMetadataSubject = new BehaviorSubject<BookMetadata | null>(null);
|
||||
currentMetadata$ = this.bookMetadataSubject.asObservable();
|
||||
|
||||
private dialogCloseSubject = new BehaviorSubject<boolean | null>(null);
|
||||
dialogClose$ = this.dialogCloseSubject.asObservable();
|
||||
|
||||
emit(bookMetadata: BookMetadata) {
|
||||
this.bookMetadataSubject.next(bookMetadata);
|
||||
}
|
||||
|
||||
closeDialog(close: boolean) {
|
||||
return this.dialogCloseSubject.next(close);
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -259,7 +259,6 @@
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
-4
@@ -292,10 +292,6 @@ export class MetadataEditorComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.metadataCenterService.closeDialog(true);
|
||||
}
|
||||
|
||||
getUploadCoverUrl(): string {
|
||||
return this.bookService.getUploadCoverUrl(this.currentBookId);
|
||||
}
|
||||
|
||||
-1
@@ -141,7 +141,6 @@
|
||||
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||
<p-divider layout="vertical"/>
|
||||
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
-4
@@ -414,10 +414,6 @@ export class MetadataPickerComponent implements OnInit {
|
||||
this.goBack.emit(true);
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
this.metadataCenterService.closeDialog(true);
|
||||
}
|
||||
|
||||
hoveredFields: { [key: string]: boolean } = {};
|
||||
|
||||
onMouseEnter(controlName: string): void {
|
||||
|
||||
-19
@@ -70,13 +70,6 @@
|
||||
<p-button *ngIf="userData.permissions.canDownload" label="Download" icon="pi pi-download" severity="info" outlined (onClick)="download(metadata.bookId)"></p-button>
|
||||
<p-splitbutton *ngIf="userData.permissions.canEmailBook" label="Quick Send" icon="pi pi-send" [model]="items" (onClick)="quickSend(metadata.bookId)" outlined
|
||||
severity="info"/>
|
||||
<!--<p-button
|
||||
outlined
|
||||
[label]="metadata.allFieldsLocked ? 'Unlock Metadata' : 'Lock Metadata'"
|
||||
[icon]="metadata.allFieldsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||
[severity]="metadata.allFieldsLocked ? 'danger' : 'success'"
|
||||
(onClick)="toggleMetadataLock(metadata)">
|
||||
</p-button>-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -87,18 +80,6 @@
|
||||
|
||||
<div *ngIf="metadata$ | async as metadata" class="book-description space-y-4 overflow-y-auto flex-1">
|
||||
<p class="pt-2 px-2" [innerHTML]="metadata.description || 'No description available.'"></p>
|
||||
<!--<div class="pt-6">
|
||||
<p-editor [(ngModel)]="metadata.description" [style]="{ height: '350px' }" [readonly]="true">
|
||||
<ng-template #header>
|
||||
</ng-template>
|
||||
</p-editor>
|
||||
</div>-->
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-x-4 mt-auto">
|
||||
<p-divider></p-divider>
|
||||
<div class="flex gap-x-4 justify-end">
|
||||
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+19
@@ -23,3 +23,22 @@
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none; /* for IE 10+ */
|
||||
}
|
||||
|
||||
.dashboard-scroller-infinite {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 0.25rem;
|
||||
gap: 1.25rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
height: 165px;
|
||||
width: 101px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
flex-basis: 101px;
|
||||
}
|
||||
|
||||
-24
@@ -72,10 +72,6 @@ export class MetadataViewerComponent implements OnInit {
|
||||
this.bookService.readBook(bookId);
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.metadataCenterService.closeDialog(true);
|
||||
}
|
||||
|
||||
getAuthorNames(authors: string[]): string {
|
||||
return authors.join(', ');
|
||||
}
|
||||
@@ -120,24 +116,4 @@ export class MetadataViewerComponent implements OnInit {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/*toggleMetadataLock(metadata: BookMetadata): void {
|
||||
const lockAction = metadata.allFieldsLocked ? 'UNLOCK' : 'LOCK';
|
||||
this.bookService.toggleAllLock(new Set([metadata.bookId]), lockAction).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: `Metadata ${lockAction === 'LOCK' ? 'Locked' : 'Unlocked'}`,
|
||||
detail: `Book metadata has been ${lockAction === 'LOCK' ? 'locked' : 'unlocked'} successfully.`,
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: `Failed to ${lockAction === 'LOCK' ? 'Lock' : 'Unlock'}`,
|
||||
detail: `An error occurred while ${lockAction === 'LOCK' ? 'locking' : 'unlocking'} the metadata.`,
|
||||
});
|
||||
}
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {BookMetadataCenterComponent} from '../book-metadata-center/book-metadata-center.component';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MetadataDialogService {
|
||||
|
||||
private dialogService = inject(DialogService);
|
||||
private bookService = inject(BookService);
|
||||
|
||||
|
||||
public openBookMetadataCenterDialog(bookId: number, tab: string): void {
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe({
|
||||
next: (book) => {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
header: 'Open book details',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '1400px',
|
||||
height: '875px',
|
||||
showHeader: false,
|
||||
closeOnEscape: true,
|
||||
dismissableMask: true,
|
||||
data: {
|
||||
book: book,
|
||||
tab: tab
|
||||
},
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching book:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user