From d855acd426297a57205e64a1c4f500bdb9cb5866 Mon Sep 17 00:00:00 2001 From: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> Date: Fri, 25 Apr 2025 13:56:38 -0600 Subject: [PATCH] Implement sorting and display of file size in the table view * Display the file size in the Book Metadata details section * Implement sorting and display of file size in the table view * Implement AppMigration feature * Populate missing file sizes for books with null file size in 'populateFileSizes' migration * Implement sorting and display of file size in the table view --------- Co-authored-by: adityachandelgit --- .../book/components/book-browser/book-browser.component.ts | 1 + .../book-browser/book-table/book-table.component.html | 5 +++++ .../book-browser/book-table/book-table.component.ts | 6 ++++++ booklore-ui/src/app/book/service/sort.service.ts | 3 ++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index 559e20cd0..937854760 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -117,6 +117,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { {label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')}, {label: 'Last Read', field: 'lastReadTime', command: () => this.sortBooks('lastReadTime')}, {label: 'Added On', field: 'addedOn', command: () => this.sortBooks('addedOn')}, + {label: 'File Size', icon: '', field: 'fileSizeKb', command: () => this.sortBooks('fileSizeKb')}, {label: 'Locked', icon: '', field: 'locked', command: () => this.sortBooks('locked')}, {label: 'Publisher', icon: '', field: 'publisher', command: () => this.sortBooks('publisher')}, {label: 'Published Date', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')}, diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html index 7665f458a..c4d0c9fea 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.html @@ -25,6 +25,7 @@ Published Last Read Added + File Size Lang Pages Amazon @@ -67,6 +68,10 @@ {{ book.addedOn ? (book.addedOn | date: 'dd-MMM-yyyy') : '' }} + + {{ formatFileSize(book.fileSizeKb) }} + {{ metadata.language }} {{ metadata.pageCount }} diff --git a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts index ace7eecae..e9a12756a 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-table/book-table.component.ts @@ -106,6 +106,12 @@ export class BookTableComponent implements OnChanges { .every(key => metadata[key] === true); } + formatFileSize(kb?: number): string { + if (kb == null || isNaN(kb)) return '-'; + const mb = kb / 1024; + return mb >= 1 ? `${mb.toFixed(1)} MB` : `${mb.toFixed(2)} MB`; + } + toggleMetadataLock(metadata: BookMetadata): void { const lockKeys = Object.keys(metadata).filter(key => key.endsWith('Locked')); const allLocked = lockKeys.every(key => metadata[key] === true); diff --git a/booklore-ui/src/app/book/service/sort.service.ts b/booklore-ui/src/app/book/service/sort.service.ts index 89a59e417..5525471d8 100644 --- a/booklore-ui/src/app/book/service/sort.service.ts +++ b/booklore-ui/src/app/book/service/sort.service.ts @@ -24,7 +24,8 @@ export class SortService { .filter((key) => key.endsWith('Locked')) .every((key) => book.metadata?.[key] === true), lastReadTime: (book) => book.lastReadTime ? new Date(book.lastReadTime).getTime() : null, - addedOn: (book) => book.addedOn ? new Date(book.addedOn).getTime() : null + addedOn: (book) => book.addedOn ? new Date(book.addedOn).getTime() : null, + fileSizeKb: (book) => book.fileSizeKb || null }; applySort(books: Book[], selectedSort: SortOption | null): Book[] {