Fix:Library collapsed series to respect ignore prefixes setting #866

This commit is contained in:
advplyr 2022-07-30 16:18:26 -05:00
parent 377ae7ab19
commit 06b8d1194c
6 changed files with 28 additions and 16 deletions

View File

@ -249,11 +249,9 @@ export default {
}, },
displayTitle() { displayTitle() {
if (this.recentEpisode) return this.recentEpisode.title if (this.recentEpisode) return this.recentEpisode.title
if (this.collapsedSeries) return this.collapsedSeries.name const ignorePrefix = this.orderBy === 'media.metadata.title' && this.sortingIgnorePrefix
if (this.orderBy === 'media.metadata.title' && this.sortingIgnorePrefix) { if (this.collapsedSeries) return ignorePrefix ? this.collapsedSeries.nameIgnorePrefix : this.collapsedSeries.name
return this.mediaMetadata.titleIgnorePrefix return ignorePrefix ? this.mediaMetadata.titleIgnorePrefix : this.title
}
return this.title
}, },
displayLineTwo() { displayLineTwo() {
if (this.recentEpisode) return this.title if (this.recentEpisode) return this.title

View File

@ -69,6 +69,7 @@ export default {
}, },
methods: { methods: {
clickedOutside(evt) { clickedOutside(evt) {
if (!this.show) return
if (evt) { if (evt) {
evt.stopPropagation() evt.stopPropagation()
evt.preventDefault() evt.preventDefault()

View File

@ -190,7 +190,7 @@ class LibraryController {
// When collapsing by series and sorting by title use the series name instead of the book title // When collapsing by series and sorting by title use the series name instead of the book title
if (payload.mediaType === 'book' && payload.collapseseries && li.media.metadata.seriesName) { if (payload.mediaType === 'book' && payload.collapseseries && li.media.metadata.seriesName) {
if (sortByTitle) { if (sortByTitle) {
return li.media.metadata.seriesName return this.db.serverSettings.sortingIgnorePrefix ? li.media.metadata.seriesNameIgnorePrefix : li.media.metadata.seriesName
} else { } else {
// When not sorting by title always show the collapsed series at the end // When not sorting by title always show the collapsed series at the end
return direction === 'desc' ? -1 : 'zzzz' return direction === 'desc' ? -1 : 'zzzz'

View File

@ -1,5 +1,5 @@
const Logger = require('../../Logger') const Logger = require('../../Logger')
const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index') const { areEquivalent, copyValue, cleanStringForSearch, getTitleIgnorePrefix } = require('../../utils/index')
const parseNameString = require('../../utils/parsers/parseNameString') const parseNameString = require('../../utils/parsers/parseNameString')
class BookMetadata { class BookMetadata {
constructor(metadata) { constructor(metadata) {
@ -109,15 +109,7 @@ class BookMetadata {
} }
get titleIgnorePrefix() { get titleIgnorePrefix() {
if (!this.title) return '' return getTitleIgnorePrefix(this.title)
var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
for (const prefix of prefixesToIgnore) {
// e.g. for prefix "the". If title is "The Book Title" return "Book Title, The"
if (this.title.toLowerCase().startsWith(`${prefix} `)) {
return this.title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
}
}
return this.title
} }
get authorName() { get authorName() {
if (!this.authors.length) return '' if (!this.authors.length) return ''
@ -134,6 +126,13 @@ class BookMetadata {
return `${se.name} #${se.sequence}` return `${se.name} #${se.sequence}`
}).join(', ') }).join(', ')
} }
get seriesNameIgnorePrefix() {
if (!this.series.length) return ''
return this.series.map(se => {
if (!se.sequence) return getTitleIgnorePrefix(se.name)
return `${getTitleIgnorePrefix(se.name)} #${se.sequence}`
}).join(', ')
}
get narratorName() { get narratorName() {
return this.narrators.join(', ') return this.narrators.join(', ')
} }

View File

@ -135,4 +135,16 @@ module.exports.cleanStringForSearch = (str) => {
if (!str) return '' if (!str) return ''
// Remove ' . ` " , // Remove ' . ` " ,
return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim() return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim()
}
module.exports.getTitleIgnorePrefix = (title) => {
if (!title) return ''
var prefixesToIgnore = global.ServerSettings.sortingPrefixes || []
for (const prefix of prefixesToIgnore) {
// e.g. for prefix "the". If title is "The Book" return "Book, The"
if (title.toLowerCase().startsWith(`${prefix} `)) {
return title.substr(prefix.length + 1) + `, ${prefix.substr(0, 1).toUpperCase() + prefix.substr(1)}`
}
}
return title
} }

View File

@ -1,4 +1,5 @@
const { sort, createNewSortInstance } = require('../libs/fastSort') const { sort, createNewSortInstance } = require('../libs/fastSort')
const { getTitleIgnorePrefix } = require('../utils/index')
const Logger = require('../Logger') const Logger = require('../Logger')
const naturalSort = createNewSortInstance({ const naturalSort = createNewSortInstance({
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
@ -228,6 +229,7 @@ module.exports = {
libraryItemJson.collapsedSeries = { libraryItemJson.collapsedSeries = {
id: seriesToUse[li.id].id, id: seriesToUse[li.id].id,
name: seriesToUse[li.id].name, name: seriesToUse[li.id].name,
nameIgnorePrefix: getTitleIgnorePrefix(seriesToUse[li.id].name),
numBooks: seriesToUse[li.id].books.length numBooks: seriesToUse[li.id].books.length
} }
} }