Move MetadataDialog to Service
This commit is contained in:
@@ -8,18 +8,14 @@ import {ShelfAssignerComponent} from '../../shelf-assigner/shelf-assigner.compon
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {CheckboxModule} from 'primeng/checkbox';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {BookMetadataCenterComponent} from '../../../../metadata/book-metadata-center/book-metadata-center.component';
|
||||
import {MetadataDialogService} from '../../../../metadata/service/metadata-dialog.service';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
templateUrl: './book-card.component.html',
|
||||
styleUrls: ['./book-card.component.scss'],
|
||||
imports: [
|
||||
Button,
|
||||
MenuModule,
|
||||
CheckboxModule,
|
||||
FormsModule
|
||||
],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule],
|
||||
})
|
||||
export class BookCardComponent implements OnInit {
|
||||
@Input() book!: Book;
|
||||
@@ -30,7 +26,8 @@ export class BookCardComponent implements OnInit {
|
||||
items: MenuItem[] | undefined;
|
||||
isHovered: boolean = false;
|
||||
|
||||
constructor(private bookService: BookService, private dialogService: DialogService) {
|
||||
constructor(private bookService: BookService, private dialogService: DialogService,
|
||||
private metadataDialogService: MetadataDialogService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -67,36 +64,13 @@ export class BookCardComponent implements OnInit {
|
||||
{
|
||||
label: 'View metadata',
|
||||
icon: 'pi pi-info-circle',
|
||||
command: () => this.openBookDetailsDialog(this.book.id),
|
||||
command: () => this.metadataDialogService.openBookDetailsDialog(this.book.id),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
openBookDetailsDialog(bookId: number): void {
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
|
||||
next: (book) => {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
header: 'Open book details',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '1200px',
|
||||
height: '835px',
|
||||
showHeader: false,
|
||||
closeOnEscape: true,
|
||||
dismissableMask: true,
|
||||
data: {
|
||||
book: book
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching book:', error);
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
private openShelfDialog(book: Book): void {
|
||||
this.dialogService.open(ShelfAssignerComponent, {
|
||||
header: `Update Shelves: ${book.metadata?.title}`,
|
||||
@@ -112,6 +86,6 @@ export class BookCardComponent implements OnInit {
|
||||
}
|
||||
|
||||
openBookInfo(book: Book): void {
|
||||
this.openBookDetailsDialog(book.id)
|
||||
this.metadataDialogService.openBookDetailsDialog(book.id);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-26
@@ -8,6 +8,7 @@ import {BookMetadataCenterComponent} from '../../../../metadata/book-metadata-ce
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {Book} from '../../../model/book.model';
|
||||
import {SortOption} from '../../../model/sort.model';
|
||||
import {MetadataDialogService} from '../../../../metadata/service/metadata-dialog.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-table',
|
||||
@@ -29,7 +30,7 @@ export class BookTableComponent implements OnChanges {
|
||||
@Input() books: Book[] = [];
|
||||
@Input() sortOption: SortOption | null = null;
|
||||
|
||||
constructor(private bookService: BookService, private dialogService: DialogService) {
|
||||
constructor(private bookService: BookService, private metadataDialogService: MetadataDialogService) {
|
||||
}
|
||||
|
||||
// Hack to set virtual-scroller height
|
||||
@@ -71,33 +72,9 @@ export class BookTableComponent implements OnChanges {
|
||||
}
|
||||
|
||||
openMetadataCenter(id: number): void {
|
||||
this.openBookDetailsDialog(id);
|
||||
this.metadataDialogService.openBookDetailsDialog(id);
|
||||
}
|
||||
|
||||
openBookDetailsDialog(bookId: number): void {
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe({
|
||||
next: (book) => {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
header: 'Open book details',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '1200px',
|
||||
height: '835px',
|
||||
showHeader: false,
|
||||
closeOnEscape: true,
|
||||
dismissableMask: true,
|
||||
data: {
|
||||
book: book
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching book:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getStarColor(rating: number): string {
|
||||
if (rating >= 4.5) {
|
||||
return 'rgb(34, 197, 94)';
|
||||
|
||||
@@ -10,6 +10,7 @@ import {BookMetadataCenterComponent} from '../../../metadata/book-metadata-cente
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {MetadataDialogService} from '../../../metadata/service/metadata-dialog.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-searcher',
|
||||
@@ -30,7 +31,8 @@ export class BookSearcherComponent implements OnInit, OnDestroy {
|
||||
#searchSubject = new Subject<string>();
|
||||
#subscription!: Subscription;
|
||||
|
||||
constructor(private bookService: BookService, private router: Router, private dialogService: DialogService) {}
|
||||
constructor(private bookService: BookService, private metadataDialogService: MetadataDialogService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.initializeSearch();
|
||||
@@ -58,30 +60,7 @@ export class BookSearcherComponent implements OnInit, OnDestroy {
|
||||
|
||||
onBookClick(book: Book): void {
|
||||
this.clearSearch();
|
||||
this.openBookDetailsDialog(book.id);
|
||||
}
|
||||
|
||||
openBookDetailsDialog(bookId: number): void {
|
||||
this.bookService.getBookByIdFromAPI(bookId, true).subscribe(({
|
||||
next: (book) => {
|
||||
this.dialogService.open(BookMetadataCenterComponent, {
|
||||
header: 'Open book details',
|
||||
modal: true,
|
||||
closable: true,
|
||||
width: '1200px',
|
||||
height: '835px',
|
||||
showHeader: false,
|
||||
closeOnEscape: true,
|
||||
dismissableMask: true,
|
||||
data: {
|
||||
book: book
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error fetching book:', error);
|
||||
}
|
||||
}))
|
||||
this.metadataDialogService.openBookDetailsDialog(book.id);
|
||||
}
|
||||
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
|
||||
Reference in New Issue
Block a user