Book additional files support UI (2/3) (#870)
* feat(api/model): add new entity BookAdditionalFileEntity * feat(api/db): add book additional file repository * feat(api/db): add migration * test(api/db): add book additional file repository test * test(api/db): add book additional file repository tests for hash uniqueness * feat(api/domain): add support to additional file model * feat(api): add additional files controller * refactor(api): move addAdditionalFile to FileUploadService as uploadAdditionalFile method * feat(service): search book by additional file * feat(services): process deleted additional files with ability to promote alternative formats to book instead of deleting them * refactor(util): use common code to resolve patter for entity and domain object * feat(service): move additional files * test(service): test move additional files along with book itself * feat(ui/domain): add alternativeFormats and supplementaryFiles to book model * feat(ui/domain): add download additional file method to book service * refactor(api/domain): extract FileInfo interface with common fields Allow to share the same interface thet is implemented by AdditionFile and Book * feat(ui): show multiple download options * feat(ui/domain): add delete additional file method to book service * feat(ui): add delete additional file ui * feat(ui): add additional-file-uploader.component * feat(ui/domain): add uploadAdditionalFile to the service * feat(ui): add Upload File menu item * feat(ui): show supplementary files in download menu item * feat(ui): show supplementary files in delete file menu item * feat(ui): book card allow to select single file to download or delete
This commit is contained in:
+20
-8
@@ -419,13 +419,25 @@
|
||||
(onClick)="assignShelf(book.id)">
|
||||
</p-button>
|
||||
@if (userState.user!.permissions.canDownload || userState.user!.permissions.admin) {
|
||||
<p-button
|
||||
label="Download"
|
||||
icon="pi pi-download"
|
||||
severity="success"
|
||||
outlined
|
||||
(onClick)="download(book!.id)">
|
||||
</p-button>
|
||||
@if ((book!.alternativeFormats && book!.alternativeFormats.length > 0) || (book!.supplementaryFiles && book!.supplementaryFiles.length > 0)) {
|
||||
@if (downloadMenuItems$ | async; as downloadItems) {
|
||||
<p-splitbutton
|
||||
label="Download"
|
||||
icon="pi pi-download"
|
||||
[model]="downloadItems"
|
||||
(onClick)="download(book!.id)"
|
||||
severity="success"
|
||||
outlined/>
|
||||
}
|
||||
} @else {
|
||||
<p-button
|
||||
label="Download"
|
||||
icon="pi pi-download"
|
||||
severity="success"
|
||||
outlined
|
||||
(onClick)="download(book!.id)">
|
||||
</p-button>
|
||||
}
|
||||
}
|
||||
@if (userState.user!.permissions.canEmailBook || userState.user!.permissions.admin) {
|
||||
@if (emailMenuItems$ | async; as emailItems) {
|
||||
@@ -457,7 +469,7 @@
|
||||
@if (userState.user!.permissions.canDeleteBook || userState.user!.permissions.admin) {
|
||||
@if (otherItems$ | async; as otherItems) {
|
||||
<p-button icon="pi pi-ellipsis-v" outlined severity="danger" (click)="entitymenu.toggle($event)"></p-button>
|
||||
<p-menu #entitymenu [model]="otherItems" [popup]="true" appendTo="body"></p-menu>
|
||||
<p-tieredMenu #entitymenu [model]="otherItems" [popup]="true" appendTo="body"></p-tieredMenu>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
+188
-32
@@ -6,7 +6,7 @@ import {BookService} from '../../../book/service/book.service';
|
||||
import {Rating, RatingRateEvent} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Book, BookMetadata, BookRecommendation, ReadStatus} from '../../../book/model/book.model';
|
||||
import {Book, BookMetadata, BookRecommendation, ReadStatus, FileInfo} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
@@ -33,13 +33,15 @@ import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {BookReviewsComponent} from '../../../book/components/book-reviews/book-reviews.component';
|
||||
import {BookNotesComponent} from '../../../book/components/book-notes-component/book-notes-component';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {TieredMenu} from 'primeng/tieredmenu';
|
||||
import {AdditionalFileUploaderComponent} from '../../../book/components/additional-file-uploader/additional-file-uploader.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, SplitButton, NgClass, Tooltip, DecimalPipe, Editor, ProgressBar, Menu, InfiniteScrollDirective, BookCardLiteComponent, DatePicker, Tab, TabList, TabPanel, TabPanels, Tabs, BookReviewsComponent, BookNotesComponent, ProgressSpinner]
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, SplitButton, NgClass, Tooltip, DecimalPipe, Editor, ProgressBar, Menu, InfiniteScrollDirective, BookCardLiteComponent, DatePicker, Tab, TabList, TabPanel, TabPanels, Tabs, BookReviewsComponent, BookNotesComponent, ProgressSpinner, TieredMenu]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@@ -62,7 +64,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
readMenuItems$!: Observable<MenuItem[]>;
|
||||
refreshMenuItems$!: Observable<MenuItem[]>;
|
||||
otherItems$!: Observable<MenuItem[]>;
|
||||
|
||||
downloadMenuItems$!: Observable<MenuItem[]>;
|
||||
bookInSeries: Book[] = [];
|
||||
isExpanded = false;
|
||||
showFilePath = false;
|
||||
@@ -135,37 +137,140 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
])
|
||||
);
|
||||
|
||||
this.downloadMenuItems$ = this.book$.pipe(
|
||||
filter((book): book is Book => book !== null &&
|
||||
((book.alternativeFormats !== undefined && book.alternativeFormats.length > 0) ||
|
||||
(book.supplementaryFiles !== undefined && book.supplementaryFiles.length > 0))),
|
||||
map((book): MenuItem[] => {
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
// Add alternative formats
|
||||
if (book.alternativeFormats && book.alternativeFormats.length > 0) {
|
||||
book.alternativeFormats.forEach(format => {
|
||||
const extension = this.getFileExtension(format.filePath);
|
||||
items.push({
|
||||
label: `${format.fileName} (${this.getFileSizeInMB(format)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.downloadAdditionalFile(book.id, format.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Add separator if both types exist
|
||||
if (book.alternativeFormats && book.alternativeFormats.length > 0 &&
|
||||
book.supplementaryFiles && book.supplementaryFiles.length > 0) {
|
||||
items.push({ separator: true });
|
||||
}
|
||||
|
||||
// Add supplementary files
|
||||
if (book.supplementaryFiles && book.supplementaryFiles.length > 0) {
|
||||
book.supplementaryFiles.forEach(file => {
|
||||
const extension = this.getFileExtension(file.filePath);
|
||||
items.push({
|
||||
label: `${file.fileName} (${this.getFileSizeInMB(file)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.downloadAdditionalFile(book.id, file.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
})
|
||||
);
|
||||
|
||||
this.otherItems$ = this.book$.pipe(
|
||||
filter((book): book is Book => book !== null),
|
||||
map((book): MenuItem[] => [
|
||||
{
|
||||
label: 'Delete Book',
|
||||
icon: 'pi pi-trash',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete "${book.metadata?.title}"?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([book.id])).subscribe({
|
||||
next: () => {
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
this.dialogRef?.close();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
map((book): MenuItem[] => {
|
||||
const items: MenuItem[] = [
|
||||
{
|
||||
label: 'Upload File',
|
||||
icon: 'pi pi-upload',
|
||||
command: () => {
|
||||
this.dialogService.open(AdditionalFileUploaderComponent, {
|
||||
header: 'Upload Additional File',
|
||||
modal: true,
|
||||
closable: true,
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '10%',
|
||||
},
|
||||
data: {book}
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Delete Book',
|
||||
icon: 'pi pi-trash',
|
||||
command: () => {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete "${book.metadata?.title}"?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookService.deleteBooks(new Set([book.id])).subscribe({
|
||||
next: () => {
|
||||
if (this.metadataCenterViewMode === 'route') {
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
this.dialogRef?.close();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Add delete additional files menu if there are any additional files
|
||||
if ((book.alternativeFormats && book.alternativeFormats.length > 0) ||
|
||||
(book.supplementaryFiles && book.supplementaryFiles.length > 0)) {
|
||||
const deleteFileItems: MenuItem[] = [];
|
||||
|
||||
// Add alternative formats
|
||||
if (book.alternativeFormats && book.alternativeFormats.length > 0) {
|
||||
book.alternativeFormats.forEach(format => {
|
||||
const extension = this.getFileExtension(format.filePath);
|
||||
deleteFileItems.push({
|
||||
label: `${format.fileName} (${this.getFileSizeInMB(format)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.deleteAdditionalFile(book.id, format.id, format.fileName || 'file')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Add separator if both types exist
|
||||
if (book.alternativeFormats && book.alternativeFormats.length > 0 &&
|
||||
book.supplementaryFiles && book.supplementaryFiles.length > 0) {
|
||||
deleteFileItems.push({ separator: true });
|
||||
}
|
||||
|
||||
// Add supplementary files
|
||||
if (book.supplementaryFiles && book.supplementaryFiles.length > 0) {
|
||||
book.supplementaryFiles.forEach(file => {
|
||||
const extension = this.getFileExtension(file.filePath);
|
||||
deleteFileItems.push({
|
||||
label: `${file.fileName} (${this.getFileSizeInMB(file)})`,
|
||||
icon: this.getFileIcon(extension),
|
||||
command: () => this.deleteAdditionalFile(book.id, file.id, file.fileName || 'file')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: 'Delete Additional Files',
|
||||
icon: 'pi pi-trash',
|
||||
items: deleteFileItems
|
||||
});
|
||||
}
|
||||
])
|
||||
|
||||
return items;
|
||||
})
|
||||
);
|
||||
|
||||
this.userService.userState$
|
||||
@@ -240,6 +345,39 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
this.bookService.downloadFile(bookId);
|
||||
}
|
||||
|
||||
downloadAdditionalFile(bookId: number, fileId: number) {
|
||||
this.bookService.downloadAdditionalFile(bookId, fileId);
|
||||
}
|
||||
|
||||
deleteAdditionalFile(bookId: number, fileId: number, fileName: string) {
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete the additional file "${fileName}"?`,
|
||||
header: 'Confirm File Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.bookService.deleteAdditionalFile(bookId, fileId).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: `Additional file "${fileName}" deleted successfully`
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: `Failed to delete additional file: ${error.message || 'Unknown error'}`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
quickRefresh(bookId: number) {
|
||||
this.isAutoFetching = true;
|
||||
const request: MetadataRefreshRequest = {
|
||||
@@ -436,8 +574,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
return lockedKeys.length > 0 && lockedKeys.every(k => metadata[k] === true);
|
||||
}
|
||||
|
||||
getFileSizeInMB(book: Book | null): string {
|
||||
const sizeKb = book?.fileSizeKb;
|
||||
getFileSizeInMB(fileInfo: FileInfo | null | undefined): string {
|
||||
const sizeKb = fileInfo?.fileSizeKb;
|
||||
return sizeKb != null ? `${(sizeKb / 1024).toFixed(2)} MB` : '-';
|
||||
}
|
||||
|
||||
@@ -468,6 +606,24 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
return parts.pop()?.toUpperCase() || null;
|
||||
}
|
||||
|
||||
getFileIcon(fileType: string | null): string {
|
||||
if (!fileType) return 'pi pi-file';
|
||||
switch (fileType.toLowerCase()) {
|
||||
case 'pdf':
|
||||
return 'pi pi-file-pdf';
|
||||
case 'epub':
|
||||
case 'mobi':
|
||||
case 'azw3':
|
||||
return 'pi pi-book';
|
||||
case 'cbz':
|
||||
case 'cbr':
|
||||
case 'cbx':
|
||||
return 'pi pi-image';
|
||||
default:
|
||||
return 'pi pi-file';
|
||||
}
|
||||
}
|
||||
|
||||
getFileTypeColorClass(fileType: string | null | undefined): string {
|
||||
if (!fileType) return 'bg-gray-600 text-white';
|
||||
switch (fileType.toLowerCase()) {
|
||||
|
||||
Reference in New Issue
Block a user