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
This commit is contained in:
Aditya Chandel
2025-04-25 13:56:38 -06:00
committed by GitHub
co-authored by adityachandelgit
parent 2df8e193cc
commit d855acd426
4 changed files with 14 additions and 1 deletions
@@ -117,6 +117,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')}, {label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
{label: 'Last Read', field: 'lastReadTime', command: () => this.sortBooks('lastReadTime')}, {label: 'Last Read', field: 'lastReadTime', command: () => this.sortBooks('lastReadTime')},
{label: 'Added On', field: 'addedOn', command: () => this.sortBooks('addedOn')}, {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: 'Locked', icon: '', field: 'locked', command: () => this.sortBooks('locked')},
{label: 'Publisher', icon: '', field: 'publisher', command: () => this.sortBooks('publisher')}, {label: 'Publisher', icon: '', field: 'publisher', command: () => this.sortBooks('publisher')},
{label: 'Published Date', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')}, {label: 'Published Date', icon: '', field: 'publishedDate', command: () => this.sortBooks('publishedDate')},
@@ -25,6 +25,7 @@
<th>Published</th> <th>Published</th>
<th>Last Read</th> <th>Last Read</th>
<th>Added</th> <th>Added</th>
<th>File Size</th>
<th>Lang</th> <th>Lang</th>
<th>Pages</th> <th>Pages</th>
<th>Amazon</th> <th>Amazon</th>
@@ -67,6 +68,10 @@
<td class="min-w-[9rem] max-w-[9rem] overflow-hidden truncate text-right"> <td class="min-w-[9rem] max-w-[9rem] overflow-hidden truncate text-right">
{{ book.addedOn ? (book.addedOn | date: 'dd-MMM-yyyy') : '' }} {{ book.addedOn ? (book.addedOn | date: 'dd-MMM-yyyy') : '' }}
</td> </td>
<td class="min-w-[7rem] max-w-[9rem] overflow-hidden truncate"
[title]="book.fileSizeKb + ' KB'">
{{ formatFileSize(book.fileSizeKb) }}
</td>
<td class="min-w-[6rem] max-w-[6rem] overflow-hidden truncate">{{ metadata.language }}</td> <td class="min-w-[6rem] max-w-[6rem] overflow-hidden truncate">{{ metadata.language }}</td>
<td class="min-w-[4rem] max-w-[5rem] overflow-hidden truncate">{{ metadata.pageCount }}</td> <td class="min-w-[4rem] max-w-[5rem] overflow-hidden truncate">{{ metadata.pageCount }}</td>
<td class="min-w-[10rem] max-w-[10rem] overflow-hidden truncate"> <td class="min-w-[10rem] max-w-[10rem] overflow-hidden truncate">
@@ -106,6 +106,12 @@ export class BookTableComponent implements OnChanges {
.every(key => metadata[key] === true); .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 { toggleMetadataLock(metadata: BookMetadata): void {
const lockKeys = Object.keys(metadata).filter(key => key.endsWith('Locked')); const lockKeys = Object.keys(metadata).filter(key => key.endsWith('Locked'));
const allLocked = lockKeys.every(key => metadata[key] === true); const allLocked = lockKeys.every(key => metadata[key] === true);
@@ -24,7 +24,8 @@ export class SortService {
.filter((key) => key.endsWith('Locked')) .filter((key) => key.endsWith('Locked'))
.every((key) => book.metadata?.[key] === true), .every((key) => book.metadata?.[key] === true),
lastReadTime: (book) => book.lastReadTime ? new Date(book.lastReadTime).getTime() : null, 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[] { applySort(books: Book[], selectedSort: SortOption | null): Book[] {