[web] Rewrite of the GroupedList to accept multiple sort criteria

This commit is contained in:
Alain Nussbaumer 2024-03-18 21:34:43 +01:00
parent 824a37f0a6
commit 3f8ca8cda3
26 changed files with 225 additions and 222 deletions

View File

@ -2,9 +2,9 @@
<template v-for="album in albums" :key="album.itemId"> <template v-for="album in albums" :key="album.itemId">
<div v-if="!album.isItem && !hide_group_title" class="mt-6 mb-5 py-2"> <div v-if="!album.isItem && !hide_group_title" class="mt-6 mb-5 py-2">
<span <span
:id="'index_' + album.groupKey" :id="'index_' + album.index"
class="tag is-info is-light is-small has-text-weight-bold" class="tag is-info is-light is-small has-text-weight-bold"
v-text="album.groupKey" v-text="album.index"
/> />
</div> </div>
<div <div

View File

@ -3,9 +3,9 @@
<div v-if="!artist.isItem && !hide_group_title" class="mt-6 mb-5 py-2"> <div v-if="!artist.isItem && !hide_group_title" class="mt-6 mb-5 py-2">
<div class="media-content is-clipped"> <div class="media-content is-clipped">
<span <span
:id="'index_' + artist.groupKey" :id="'index_' + artist.index"
class="tag is-info is-light is-small has-text-weight-bold" class="tag is-info is-light is-small has-text-weight-bold"
v-text="artist.groupKey" v-text="artist.index"
/> />
</div> </div>
</div> </div>

View File

@ -3,9 +3,9 @@
<div v-if="!composer.isItem && !hide_group_title" class="mt-6 mb-5 py-2"> <div v-if="!composer.isItem && !hide_group_title" class="mt-6 mb-5 py-2">
<div class="media-content is-clipped"> <div class="media-content is-clipped">
<span <span
:id="'index_' + composer.groupKey" :id="'index_' + composer.index"
class="tag is-info is-light is-small has-text-weight-bold" class="tag is-info is-light is-small has-text-weight-bold"
v-text="composer.groupKey" v-text="composer.index"
/> />
</div> </div>
</div> </div>

View File

@ -3,9 +3,9 @@
<div v-if="!genre.isItem && !hide_group_title" class="mt-6 mb-5 py-2"> <div v-if="!genre.isItem && !hide_group_title" class="mt-6 mb-5 py-2">
<div class="media-content is-clipped"> <div class="media-content is-clipped">
<span <span
:id="'index_' + genre.groupKey" :id="'index_' + genre.index"
class="tag is-info is-light is-small has-text-weight-bold" class="tag is-info is-light is-small has-text-weight-bold"
v-text="genre.groupKey" v-text="genre.index"
/> />
</div> </div>
</div> </div>

View File

@ -2,9 +2,9 @@
<template v-for="track in tracks" :key="track.itemId"> <template v-for="track in tracks" :key="track.itemId">
<div v-if="!track.isItem" class="mt-6 mb-5 py-2"> <div v-if="!track.isItem" class="mt-6 mb-5 py-2">
<span <span
:id="'index_' + track.groupKey" :id="'index_' + track.index"
class="tag is-info is-light is-small has-text-weight-bold" class="tag is-info is-light is-small has-text-weight-bold"
v-text="track.groupKey" v-text="track.index"
/> />
</div> </div>
<div <div

View File

@ -35,7 +35,7 @@
"duration": "Dauer", "duration": "Dauer",
"mark-as-played": "Markiere als gespielt", "mark-as-played": "Markiere als gespielt",
"play": "Spielen", "play": "Spielen",
"release-date": "Veröffentlichungsdatum", "release-date": "Erscheinungsdatum",
"remove-podcast": "Entferne podcast", "remove-podcast": "Entferne podcast",
"tracks": "Track Nummer", "tracks": "Track Nummer",
"type": "Art", "type": "Art",
@ -117,7 +117,7 @@
"add": "Hinzufügen", "add": "Hinzufügen",
"album-artist": "Album-Künstler", "album-artist": "Album-Künstler",
"play": "Spielen", "play": "Spielen",
"release-date": "Veröffentlichungsdatum", "release-date": "Erscheinungsdatum",
"type": "Art" "type": "Art"
}, },
"artist": { "artist": {
@ -144,7 +144,7 @@
"path": "Pfad", "path": "Pfad",
"play": "Spielen", "play": "Spielen",
"position": "Disc / Track", "position": "Disc / Track",
"release-date": "Veröffentlichungsdatum" "release-date": "Erscheinungsdatum"
} }
}, },
"track": { "track": {
@ -167,7 +167,7 @@
"quality": "Qualität", "quality": "Qualität",
"rating-value": "{rating} / 10", "rating-value": "{rating} / 10",
"rating": "Bewertung", "rating": "Bewertung",
"release-date": "Veröffentlichungsdatum", "release-date": "Erscheinungsdatum",
"samplerate": " {'|'} {rate} Hz", "samplerate": " {'|'} {rate} Hz",
"spotify-album": "Album", "spotify-album": "Album",
"spotify-artist": "Künstler", "spotify-artist": "Künstler",
@ -262,6 +262,8 @@
"hide-spotify": "Verbirgt Spotify-Alben", "hide-spotify": "Verbirgt Spotify-Alben",
"title": "Alben", "title": "Alben",
"sort": { "sort": {
"artist-name": "Künstler Name",
"artist-date": "Künstler Erscheinungsdatum",
"title": "Sortieren", "title": "Sortieren",
"name": "Name", "name": "Name",
"recently-added": "Kürzlich hinzugefügt", "recently-added": "Kürzlich hinzugefügt",
@ -588,10 +590,11 @@
"appended-tracks": "{count} Track an die Abspielliste angehängt|{count} Tracks an die Abspielliste angehängt", "appended-tracks": "{count} Track an die Abspielliste angehängt|{count} Tracks an die Abspielliste angehängt",
"empty-queue": "Warteschlange ist leer" "empty-queue": "Warteschlange ist leer"
}, },
"group-by-list": { "grouped-list": {
"today": "Heute", "today": "Heute",
"last-week": "Letzte Woche", "last-week": "Letzte Woche",
"last-month": "Letzer Monat" "last-month": "Letzer Monat",
"undefined": "Unbestimmt"
}, },
"filter": { "filter": {
"mono": "Mono", "mono": "Mono",

View File

@ -262,6 +262,8 @@
"hide-spotify": "Hide albums from Spotify", "hide-spotify": "Hide albums from Spotify",
"title": "Albums", "title": "Albums",
"sort": { "sort": {
"artist-name": "Artist Name",
"artist-date": "Artist Release date",
"title": "Sort", "title": "Sort",
"name": "Name", "name": "Name",
"recently-added": "Recently added", "recently-added": "Recently added",
@ -588,10 +590,11 @@
"appended-tracks": "{count} track appended to the queue|{count} tracks appended to the queue", "appended-tracks": "{count} track appended to the queue|{count} tracks appended to the queue",
"empty-queue": "Queue is empty" "empty-queue": "Queue is empty"
}, },
"group-by-list": { "grouped-list": {
"today": "Today", "today": "Today",
"last-week": "Last week", "last-week": "Last week",
"last-month": "Last month" "last-month": "Last month",
"undefined": "Undefined"
}, },
"filter": { "filter": {
"mono": "mono", "mono": "mono",

View File

@ -262,6 +262,8 @@
"hide-spotify": "Masquer les albums de Spotify", "hide-spotify": "Masquer les albums de Spotify",
"title": "Albums", "title": "Albums",
"sort": { "sort": {
"artist-name": "Artiste Nom",
"artist-date": "Artiste Date de sortie",
"title": "Trier", "title": "Trier",
"name": "Nom", "name": "Nom",
"recently-added": "Ajouts récents", "recently-added": "Ajouts récents",
@ -588,10 +590,11 @@
"appended-tracks": "{count} piste ajoutée à la file dattente|{count} pistes ajoutées à la file dattente", "appended-tracks": "{count} piste ajoutée à la file dattente|{count} pistes ajoutées à la file dattente",
"empty-queue": "La file dattente est vide" "empty-queue": "La file dattente est vide"
}, },
"group-by-list": { "grouped-list": {
"today": "Aujourdhui", "today": "Aujourdhui",
"last-week": "La semaine dernière", "last-week": "La semaine dernière",
"last-month": "Le mois dernier" "last-month": "Le mois dernier",
"undefined": "Indéfini"
}, },
"filter": { "filter": {
"mono": "mono", "mono": "mono",

View File

@ -262,6 +262,8 @@
"hide-spotify": "隐藏来自Spotify的专辑", "hide-spotify": "隐藏来自Spotify的专辑",
"title": "专辑", "title": "专辑",
"sort": { "sort": {
"artist-name": "艺人 名称",
"artist-date": "艺人 发行日期",
"title": "分类", "title": "分类",
"name": "名称", "name": "名称",
"recently-added": "最近添加", "recently-added": "最近添加",
@ -588,10 +590,11 @@
"appended-tracks": "已附加到队列的 {count} 只曲目|已附加到队列的 {count} 只曲目", "appended-tracks": "已附加到队列的 {count} 只曲目|已附加到队列的 {count} 只曲目",
"empty-queue": "清单是空的" "empty-queue": "清单是空的"
}, },
"group-by-list": { "grouped-list": {
"today": "今日", "today": "今日",
"last-week": "上周", "last-week": "上周",
"last-month": "上月" "last-month": "上月",
"undefined": "未定义"
}, },
"filter": { "filter": {
"mono": "单声道", "mono": "单声道",

View File

@ -1,27 +1,28 @@
import i18n from '@/i18n' import i18n from '@/i18n'
const { t, locale } = i18n.global const { t, locale } = i18n.global
const GROUP_KEY_NONE = 'GROUP_KEY_NONE' const NO_INDEX = 'NO_INDEX'
export function noop() { const numberComparator = (a, b) => a - b
return { const stringComparator = (a, b) => a.localeCompare(b, locale.value)
compareFn: null, const dateComparator = (a, b) =>
groupKeyFn: (item) => GROUP_KEY_NONE new Date(a) - new Date(b) || (!a ? -1 : !b ? 1 : 0)
function createComparators(criteria) {
return criteria.map(({ field, type, order = 1 }) => {
switch (type) {
case String:
return (a, b) => stringComparator(a[field], b[field]) * order
case Number:
return (a, b) => numberComparator(a[field], b[field]) * order
case Date:
return (a, b) => dateComparator(a[field], b[field]) * order
} }
})
} }
export function byName(field, keepSortOrder = false, defaultValue = '_') { const characterIndex = (string = '') => {
return { const value = string.charAt(0)
compareFn: keepSortOrder
? null
: (a, b) => {
const fieldA = a[field] || defaultValue
const fieldB = b[field] || defaultValue
return fieldA.localeCompare(fieldB, locale.value)
},
groupKeyFn: (item) => {
const value = (item[field] || defaultValue).charAt(0)
if (value.match(/\p{Letter}/gu)) { if (value.match(/\p{Letter}/gu)) {
return value.toUpperCase() return value.toUpperCase()
} else if (value.match(/\p{Number}/gu)) { } else if (value.match(/\p{Number}/gu)) {
@ -29,109 +30,69 @@ export function byName(field, keepSortOrder = false, defaultValue = '_') {
} }
return '⌘' return '⌘'
} }
}
export const numberIndex = (number) => {
return Math.floor(number / 10)
} }
export function byRating(field, { direction = 'asc', defaultValue = 0 }) { const times = [
return { { difference: NaN, text: () => t('grouped-list.undefined') },
compareFn: (a, b) => { { difference: 86400000, text: () => t('grouped-list.today') },
const fieldA = a[field] || defaultValue { difference: 604800000, text: () => t('grouped-list.last-week') },
const fieldB = b[field] || defaultValue { difference: 2592000000, text: () => t('grouped-list.last-month') },
const result = fieldA - fieldB { difference: Infinity, text: (date) => date.getFullYear() }
return direction === 'asc' ? result : result * -1 ]
},
groupKeyFn: (item) => { const timeIndex = (string) => {
const fieldValue = item[field] || defaultValue const date = new Date(string)
return Math.floor(fieldValue / 10) const diff = new Date() - date
} return times.find((item) => isNaN(diff) || diff < item.difference)?.text(date)
}
} }
export function byMedium(field, direction = 'asc', defaultValue = 1) { function createIndexer({ field, type = undefined } = {}) {
return { switch (type) {
compareFn: (a, b) => { case String:
const fieldA = a[field] || defaultValue return (item) => characterIndex(item[field])
const fieldB = b[field] || defaultValue case Number:
const result = fieldA - fieldB return (item) => item[field]
return direction === 'asc' ? result : result * -1 case Date:
}, return (item) => timeIndex(item[field])
case 'Digits':
groupKeyFn: (item) => { return (item) => numberIndex(item[field])
return item[field] || defaultValue default:
} return (item) => NO_INDEX
}
}
export function byYear(field, { direction = 'asc', defaultValue = '0000' }) {
return {
compareFn: (a, b) => {
const fieldA = a[field] || defaultValue
const fieldB = b[field] || defaultValue
const result = fieldA.localeCompare(fieldB, locale.value)
return direction === 'asc' ? result : result * -1
},
groupKeyFn: (item) => {
const fieldValue = item[field] || defaultValue
return fieldValue.substring(0, 4)
}
}
}
export function byDateSinceToday(field, defaultValue = '0000') {
return {
compareFn: (a, b) => {
const fieldA = a[field] || defaultValue
const fieldB = b[field] || defaultValue
return fieldB.localeCompare(fieldA, locale.value)
},
groupKeyFn: (item) => {
const fieldValue = item[field]
if (!fieldValue) {
return defaultValue
}
const diff = new Date().getTime() - new Date(fieldValue).getTime()
if (diff < 86400000) {
// 24h
return t('group-by-list.today')
} else if (diff < 604800000) {
// 7 days
return t('group-by-list.last-week')
} else if (diff < 2592000000) {
// 30 days
return t('group-by-list.last-month')
}
return fieldValue.substring(0, 4)
}
} }
} }
export class GroupedList { export class GroupedList {
constructor({ items = [], total = 0, offset = 0, limit = -1 } = {}) { constructor({ items = [], total = 0, offset = 0, limit = -1 } = {}, options) {
this.items = items this.items = items
this.total = total this.total = total
this.offset = offset this.offset = offset
this.limit = limit this.limit = limit
this.count = items.length this.count = items.length
this.indices = [] this.indices = []
this.group(noop()) this.group(options)
} }
group(options, filterFns = []) { group({ criteria = [], filters = [], index } = {}) {
const indexer = createIndexer(index)
const itemsFiltered = this.items.filter((item) => const itemsFiltered = this.items.filter((item) =>
filterFns.every((fn) => fn(item)) filters.every((filter) => filter(item))
) )
this.count = itemsFiltered.length this.count = itemsFiltered.length
// Sort item list // Sort item list
const itemsSorted = [...itemsFiltered].sort( const comparators = createComparators(criteria)
options.compareFn ?? (() => true) const itemsSorted = itemsFiltered.sort((a, b) =>
comparators.reduce(
(comparison, comparator) => comparison || comparator(a, b),
0
)
) )
// Group item list // Group item list
this.itemsGrouped = itemsSorted.reduce((map, item) => { this.itemsGrouped = itemsSorted.reduce((map, item) => {
const groupKey = options.groupKeyFn(item) const index = indexer(item)
map.set(groupKey, [...(map.get(groupKey) || []), item]) map.set(index, [...(map.get(index) || []), item])
return map return map
}, new Map()) }, new Map())
// Create index list // Create index list
@ -139,18 +100,18 @@ export class GroupedList {
} }
*generate() { *generate() {
for (const [key, items] of this.itemsGrouped.entries()) { for (const [index, items] of this.itemsGrouped.entries()) {
if (key !== GROUP_KEY_NONE) { if (index !== NO_INDEX) {
yield { yield {
groupKey: key, index: index,
itemId: key, itemId: index,
isItem: false, isItem: false,
item: {} item: {}
} }
} }
for (const item of items) { for (const item of items) {
yield { yield {
groupKey: key, index: index,
itemId: item.id, itemId: item.id,
isItem: true, isItem: true,
item: item item: item

View File

@ -45,7 +45,7 @@
</template> </template>
<script> <script>
import { GroupedList, byMedium, noop } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHero from '@/templates/ContentWithHero.vue' import ContentWithHero from '@/templates/ContentWithHero.vue'
import CoverArtwork from '@/components/CoverArtwork.vue' import CoverArtwork from '@/components/CoverArtwork.vue'
import ListTracks from '@/components/ListTracks.vue' import ListTracks from '@/components/ListTracks.vue'
@ -62,10 +62,12 @@ const dataObject = {
set(vm, response) { set(vm, response) {
vm.album = response[0].data vm.album = response[0].data
vm.tracks = new GroupedList(response[1].data) vm.tracks = new GroupedList(response[1].data, {
vm.tracks.group(byMedium('disc_number')) criteria: [{ field: 'disc_number', type: Number }],
if (vm.tracks.indices <= 1) { index: { field: 'disc_number', type: Number }
vm.tracks.group(noop()) })
if (vm.tracks.indices.length < 2) {
vm.tracks.group({ index: { type: undefined } })
} }
} }
} }

View File

@ -64,7 +64,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byYear } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
@ -113,21 +113,45 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.albums.sort.name'), name: this.$t('page.albums.sort.name'),
options: byName('name_sort', true) options: { index: { field: 'name_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.albums.sort.recently-added'), name: this.$t('page.albums.sort.recently-added'),
options: byYear('time_added', { options: {
direction: 'desc' criteria: [{ field: 'time_added', type: Date, order: -1 }],
}) index: { field: 'time_added', type: Date }
}
}, },
{ {
id: 3, id: 3,
name: this.$t('page.albums.sort.recently-released'), name: this.$t('page.albums.sort.recently-released'),
options: byYear('date_released', { options: {
direction: 'desc' criteria: [{ field: 'date_released', type: Date, order: -1 }],
}) index: { field: 'date_released', type: Date }
}
},
{
id: 4,
name: this.$t('page.albums.sort.artist-name'),
options: {
criteria: [
{ field: 'artist', type: String },
{ field: 'name_sort', type: String }
],
index: { field: 'artist', type: String }
}
},
{
id: 5,
name: this.$t('page.albums.sort.artist-date'),
options: {
criteria: [
{ field: 'artist', type: String },
{ field: 'date_released', type: Date }
],
index: { field: 'artist', type: String }
}
} }
] ]
} }
@ -138,10 +162,11 @@ export default {
const grouping = this.grouping_options.find( const grouping = this.grouping_options.find(
(o) => o.id === this.selected_grouping_option_id (o) => o.id === this.selected_grouping_option_id
) )
this.albums_list.group(grouping.options, [ grouping.options.filters = [
(album) => !this.hide_singles || album.track_count > 2, (album) => !this.hide_singles || album.track_count > 2,
(album) => !this.hide_spotify || album.data_kind !== 'spotify' (album) => !this.hide_spotify || album.data_kind !== 'spotify'
]) ]
this.albums_list.group(grouping.options)
return this.albums_list return this.albums_list
}, },

View File

@ -72,7 +72,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byYear } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import ListAlbums from '@/components/ListAlbums.vue' import ListAlbums from '@/components/ListAlbums.vue'
@ -123,14 +123,15 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.artist.sort.name'), name: this.$t('page.artist.sort.name'),
options: byName('name_sort', true) options: { index: { field: 'name_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.artist.sort.release-date'), name: this.$t('page.artist.sort.release-date'),
options: byYear('date_released', { options: {
direction: 'asc' criteria: [{ field: 'date_released', type: Date }],
}) index: { field: 'date_released', type: Date }
}
} }
], ],
show_details_modal: false show_details_modal: false
@ -142,9 +143,10 @@ export default {
const grouping = this.grouping_options.find( const grouping = this.grouping_options.find(
(o) => o.id === this.selected_grouping_option_id (o) => o.id === this.selected_grouping_option_id
) )
this.albums_list.group(grouping.options, [ grouping.options.filters = [
(album) => !this.hide_spotify || album.data_kind !== 'spotify' (album) => !this.hide_spotify || album.data_kind !== 'spotify'
]) ]
this.albums_list.group(grouping.options)
return this.albums_list return this.albums_list
}, },
hide_spotify: { hide_spotify: {

View File

@ -73,7 +73,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byRating } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
@ -125,14 +125,15 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.artist.sort.name'), name: this.$t('page.artist.sort.name'),
options: byName('title_sort') options: { index: { field: 'title_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.artist.sort.rating'), name: this.$t('page.artist.sort.rating'),
options: byRating('rating', { options: {
direction: 'desc' criteria: [{ field: 'rating', type: Number, order: -1 }],
}) index: { field: 'rating', type: 'Digits' }
}
} }
], ],
show_details_modal: false, show_details_modal: false,
@ -171,9 +172,10 @@ export default {
const grouping = this.grouping_options.find( const grouping = this.grouping_options.find(
(o) => o.id === this.selected_grouping_option_id (o) => o.id === this.selected_grouping_option_id
) )
this.tracks_list.group(grouping.options, [ grouping.options.filters = [
(track) => !this.hide_spotify || track.data_kind !== 'spotify' (track) => !this.hide_spotify || track.data_kind !== 'spotify'
]) ]
this.tracks_list.group(grouping.options)
return this.tracks_list return this.tracks_list
}, },
track_uris() { track_uris() {

View File

@ -64,7 +64,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byYear } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
@ -113,14 +113,15 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.artists.sort.name'), name: this.$t('page.artists.sort.name'),
options: byName('name_sort', true) options: { index: { field: 'name_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.artists.sort.recently-added'), name: this.$t('page.artists.sort.recently-added'),
options: byYear('time_added', { options: {
direction: 'desc' criteria: [{ field: 'time_added', type: Date, order: -1 }],
}) index: { field: 'time_added', type: Date }
}
} }
] ]
} }
@ -136,11 +137,12 @@ export default {
const grouping = this.grouping_options.find( const grouping = this.grouping_options.find(
(o) => o.id === this.selected_grouping_option_id (o) => o.id === this.selected_grouping_option_id
) )
this.artists_list.group(grouping.options, [ grouping.options.filters = [
(artist) => (artist) =>
!this.hide_singles || artist.track_count > artist.album_count * 2, !this.hide_singles || artist.track_count > artist.album_count * 2,
(artist) => !this.hide_spotify || artist.data_kind !== 'spotify' (artist) => !this.hide_spotify || artist.data_kind !== 'spotify'
]) ]
this.artists_list.group(grouping.options)
return this.artists_list return this.artists_list
}, },

View File

@ -20,7 +20,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListAlbums from '@/components/ListAlbums.vue' import ListAlbums from '@/components/ListAlbums.vue'
@ -33,8 +33,9 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.albums = new GroupedList(response.data) vm.albums = new GroupedList(response.data, {
vm.albums.group(byName('name_sort', true)) index: { field: 'name_sort', type: String }
})
} }
} }

View File

@ -21,7 +21,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListArtists from '@/components/ListArtists.vue' import ListArtists from '@/components/ListArtists.vue'
@ -34,7 +34,9 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.artists_list = new GroupedList(response.data) vm.artists = new GroupedList(response.data, {
index: { field: 'name_sort', type: String }
})
} }
} }
@ -63,17 +65,7 @@ export default {
data() { data() {
return { return {
artists_list: new GroupedList() artists: new GroupedList()
}
},
computed: {
artists() {
if (!this.artists_list) {
return []
}
this.artists_list.group(byName('name_sort', true))
return this.artists_list
} }
} }
} }

View File

@ -20,7 +20,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListGenres from '@/components/ListGenres.vue' import ListGenres from '@/components/ListGenres.vue'
@ -33,9 +33,9 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.genres = response.data vm.genres = new GroupedList(response.data, {
vm.genres = new GroupedList(response.data) index: { field: 'name_sort', type: String }
vm.genres.group(byName('name_sort')) })
} }
} }

View File

@ -34,7 +34,7 @@
" "
/> />
</p> </p>
<list-albums :albums="albums_list" :hide_group_title="true" /> <list-albums :albums="albums" :hide_group_title="true" />
<modal-dialog-composer <modal-dialog-composer
:show="show_details_modal" :show="show_details_modal"
:composer="composer" :composer="composer"
@ -62,7 +62,7 @@ const dataObject = {
set(vm, response) { set(vm, response) {
vm.composer = response[0].data vm.composer = response[0].data
vm.albums_list = new GroupedList(response[1].data.albums) vm.albums = new GroupedList(response[1].data.albums)
} }
} }
@ -89,7 +89,7 @@ export default {
data() { data() {
return { return {
albums_list: new GroupedList(), albums: new GroupedList(),
composer: {}, composer: {},
show_details_modal: false show_details_modal: false
} }

View File

@ -61,7 +61,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byRating } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
@ -113,14 +113,15 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.composer.sort.name'), name: this.$t('page.composer.sort.name'),
options: byName('title_sort') options: { index: { field: 'title_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.composer.sort.rating'), name: this.$t('page.composer.sort.rating'),
options: byRating('rating', { options: {
direction: 'desc' criteria: [{ field: 'rating', type: Number, order: -1 }],
}) index: { field: 'rating', type: 'Digits' }
}
} }
], ],
show_details_modal: false, show_details_modal: false,

View File

@ -20,7 +20,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListComposers from '@/components/ListComposers.vue' import ListComposers from '@/components/ListComposers.vue'
@ -33,8 +33,9 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.composers = new GroupedList(response.data) vm.composers = new GroupedList(response.data, {
vm.composers.group(byName('name_sort')) index: { field: 'name_sort', type: String }
})
} }
} }

View File

@ -46,7 +46,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListAlbums from '@/components/ListAlbums.vue' import ListAlbums from '@/components/ListAlbums.vue'
@ -63,8 +63,9 @@ const dataObject = {
set(vm, response) { set(vm, response) {
vm.genre = response[0].data vm.genre = response[0].data
vm.albums = new GroupedList(response[1].data.albums) vm.albums = new GroupedList(response[1].data.albums, {
vm.albums.group(byName('name_sort', true)) index: { field: 'name_sort', type: String }
})
} }
} }

View File

@ -56,7 +56,7 @@
<script> <script>
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
import { GroupedList, byName, byRating } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue' import ControlDropdown from '@/components/ControlDropdown.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
@ -108,14 +108,15 @@ export default {
{ {
id: 1, id: 1,
name: this.$t('page.genre.sort.name'), name: this.$t('page.genre.sort.name'),
options: byName('title_sort') options: { index: { field: 'title_sort', type: String } }
}, },
{ {
id: 2, id: 2,
name: this.$t('page.genre.sort.rating'), name: this.$t('page.genre.sort.rating'),
options: byRating('rating', { options: {
direction: 'desc' criteria: [{ field: 'rating', type: Number, order: -1 }],
}) index: { field: 'rating', type: 'Digits' }
}
} }
], ],
media_kind: this.$route.query.media_kind, media_kind: this.$route.query.media_kind,

View File

@ -20,7 +20,7 @@
</template> </template>
<script> <script>
import { GroupedList, byName } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import IndexButtonList from '@/components/IndexButtonList.vue' import IndexButtonList from '@/components/IndexButtonList.vue'
import ListGenres from '@/components/ListGenres.vue' import ListGenres from '@/components/ListGenres.vue'
@ -33,9 +33,9 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.genres = response.data vm.genres = new GroupedList(response.data, {
vm.genres = new GroupedList(response.data) index: { field: 'name_sort', type: String }
vm.genres.group(byName('name_sort')) })
} }
} }

View File

@ -13,7 +13,7 @@
</template> </template>
<script> <script>
import { GroupedList, byDateSinceToday } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListAlbums from '@/components/ListAlbums.vue' import ListAlbums from '@/components/ListAlbums.vue'
import TabsMusic from '@/components/TabsMusic.vue' import TabsMusic from '@/components/TabsMusic.vue'
@ -32,12 +32,10 @@ const dataObject = {
}, },
set(vm, response) { set(vm, response) {
vm.recently_added = new GroupedList(response.data.albums) vm.recently_added = new GroupedList(response.data.albums, {
vm.recently_added.group( criteria: [{ field: 'time_added', type: Date, order: -1 }],
byDateSinceToday('time_added', { index: { field: 'time_added', type: Date }
direction: 'desc'
}) })
)
} }
} }

View File

@ -21,7 +21,7 @@
</template> </template>
<script> <script>
import { GroupedList, noop } from '@/lib/GroupedList' import { GroupedList } from '@/lib/GroupedList'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListPlaylists from '@/components/ListPlaylists.vue' import ListPlaylists from '@/components/ListPlaylists.vue'
import webapi from '@/webapi' import webapi from '@/webapi'
@ -66,13 +66,15 @@ export default {
computed: { computed: {
playlists() { playlists() {
this.playlists_list.group(noop(), [ this.playlists_list.group({
filters: [
(playlist) => (playlist) =>
playlist.folder || playlist.folder ||
this.radio_playlists || this.radio_playlists ||
playlist.stream_count === 0 || playlist.stream_count === 0 ||
playlist.item_count > playlist.stream_count playlist.item_count > playlist.stream_count
]) ]
})
return this.playlists_list return this.playlists_list
}, },
radio_playlists() { radio_playlists() {