From 3be32a2813b98deb0d3b067fcc38c8067dab4689 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 14 Feb 2022 16:01:53 -0600 Subject: [PATCH] Add:Alternate bookshelf view show sorting/filtering keys and ignore The prefix title #232 #361 --- client/components/app/LazyBookshelf.vue | 6 ++-- client/components/cards/LazyBookCard.vue | 35 +++++++++++++++++++++--- client/mixins/bookshelfCardsHelpers.js | 5 ++++ client/plugins/init.client.js | 15 +++++++--- server/controllers/LibraryController.js | 2 +- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/client/components/app/LazyBookshelf.vue b/client/components/app/LazyBookshelf.vue index e99fbbc7..d3fdb388 100644 --- a/client/components/app/LazyBookshelf.vue +++ b/client/components/app/LazyBookshelf.vue @@ -2,9 +2,6 @@
@@ -116,6 +113,9 @@ export default { bookshelfView() { return this.$store.getters['getServerSetting']('bookshelfView') }, + sortingIgnorePrefix() { + return this.$store.getters['getServerSetting']('sortingIgnorePrefix') + }, isCoverSquareAspectRatio() { return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE }, diff --git a/client/components/cards/LazyBookCard.vue b/client/components/cards/LazyBookCard.vue index 19e3640e..d2074a9b 100644 --- a/client/components/cards/LazyBookCard.vue +++ b/client/components/cards/LazyBookCard.vue @@ -5,11 +5,12 @@
-
+

- #{{ volumeNumber }} {{ title }} + #{{ volumeNumber }} {{ displayTitle }}

-

{{ authorFL }}

+

{{ displayAuthor }}

+

{{ displaySortLine }}

{{ booksInSeries }}
@@ -99,7 +100,10 @@ export default { // Book can be passed as prop or set with setEntity() type: Object, default: () => null - } + }, + orderBy: String, + filterBy: String, + sortingIgnorePrefix: Boolean }, data() { return { @@ -180,6 +184,24 @@ export default { volumeNumber() { return this.book.volumeNumber || null }, + displayTitle() { + if (this.orderBy === 'book.title' && this.sortingIgnorePrefix && this.title.toLowerCase().startsWith('the ')) { + return this.title.substr(4) + ', The' + } else { + console.log('DOES NOT COMPUTE', this.orderBy, this.sortingIgnorePrefix, this.title.toLowerCase()) + } + return this.title + }, + displayAuthor() { + if (this.orderBy === 'book.authorLF') return this.authorLF + return this.authorFL + }, + displaySortLine() { + if (this.orderBy === 'addedAt') return 'Added ' + this.$formatDate(this._audiobook.addedAt) + if (this.orderBy === 'duration') return 'Duration: ' + this.$elapsedPrettyExtended(this._audiobook.duration, false) + if (this.orderBy === 'size') return 'Size: ' + this.$bytesPretty(this._audiobook.size) + return null + }, userProgress() { return this.store.getters['user/getUserAudiobook'](this.audiobookId) }, @@ -322,6 +344,11 @@ export default { isAlternativeBookshelfView() { var constants = this.$constants || this.$nuxt.$constants return this.bookshelfView === constants.BookshelfView.TITLES + }, + titleDisplayBottomOffset() { + if (!this.isAlternativeBookshelfView) return 0 + else if (!this.displaySortLine) return 3 * this.sizeMultiplier + return 4.25 * this.sizeMultiplier } }, methods: { diff --git a/client/mixins/bookshelfCardsHelpers.js b/client/mixins/bookshelfCardsHelpers.js index a25f4d65..829d7fe7 100644 --- a/client/mixins/bookshelfCardsHelpers.js +++ b/client/mixins/bookshelfCardsHelpers.js @@ -55,6 +55,11 @@ export default { bookshelfView: this.bookshelfView } if (this.entityName === 'series-books') props.showVolumeNumber = true + if (this.entityName === 'books') { + props.filterBy = this.filterBy + props.orderBy = this.orderBy + props.sortingIgnorePrefix = !!this.sortingIgnorePrefix + } var _this = this var instance = new ComponentClass({ diff --git a/client/plugins/init.client.js b/client/plugins/init.client.js index 33b9bdc8..e06fbb93 100644 --- a/client/plugins/init.client.js +++ b/client/plugins/init.client.js @@ -25,7 +25,7 @@ Vue.prototype.$addDaysToToday = (daysToAdd) => { } Vue.prototype.$bytesPretty = (bytes, decimals = 2) => { - if (bytes === 0) { + if (isNaN(bytes) || !bytes === 0) { return '0 Bytes' } const k = 1024 @@ -61,13 +61,20 @@ Vue.prototype.$secondsToTimestamp = (seconds) => { return `${_hours}:${_minutes.toString().padStart(2, '0')}:${_seconds.toString().padStart(2, '0')}` } -Vue.prototype.$elapsedPrettyExtended = (seconds) => { +Vue.prototype.$elapsedPrettyExtended = (seconds, useDays = true) => { + if (isNaN(seconds) || seconds === null) return '' + seconds = Math.round(seconds) + var minutes = Math.floor(seconds / 60) seconds -= minutes * 60 var hours = Math.floor(minutes / 60) minutes -= hours * 60 - var days = Math.floor(hours / 24) - hours -= days * 24 + + var days = 0 + if (useDays || Math.floor(hours / 24) >= 100) { + days = Math.floor(hours / 24) + hours -= days * 24 + } var strs = [] if (days) strs.push(`${days}d`) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index 771b1960..15ec8e1d 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -214,7 +214,7 @@ class LibraryController { var sortingIgnorePrefix = this.db.serverSettings.sortingIgnorePrefix series = sort(series).asc(s => { - if (sortingIgnorePrefix && s.name.toLowerCase().startsWith('the')) { + if (sortingIgnorePrefix && s.name.toLowerCase().startsWith('the ')) { return s.name.substr(4) } return s.name