2021-08-19 03:18:44 +02:00
|
|
|
<template>
|
|
|
|
<div ref="wrapper" class="relative" v-click-outside="clickOutside">
|
2024-12-11 00:19:47 +01:00
|
|
|
<button type="button" class="relative w-full h-full bg-fg border border-gray-500 hover:border-gray-400 rounded shadow-sm pl-3 pr-3 py-0 text-left focus:outline-none sm:text-sm cursor-pointer" aria-haspopup="menu" :aria-expanded="showMenu" @click.prevent="showMenu = !showMenu">
|
2021-08-19 03:18:44 +02:00
|
|
|
<span class="flex items-center justify-between">
|
2021-08-20 00:29:36 +02:00
|
|
|
<span class="block truncate text-xs" :class="!selectedText ? 'text-gray-300' : ''">{{ selectedText }}</span>
|
2024-12-11 00:19:47 +01:00
|
|
|
<span class="material-symbols text-lg text-yellow-400" :aria-label="descending ? $strings.LabelSortDescending : $strings.LabelSortAscending">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
2021-08-19 03:18:44 +02:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
|
2024-12-11 00:19:47 +01:00
|
|
|
<ul v-show="showMenu" class="absolute z-10 mt-1 w-full bg-bg border border-black-200 shadow-lg max-h-96 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none text-sm" role="menu">
|
2022-04-12 02:42:09 +02:00
|
|
|
<template v-for="item in selectItems">
|
2024-12-11 00:19:47 +01:00
|
|
|
<li :key="item.value" class="select-none relative py-2 pr-9 cursor-pointer hover:bg-white/5" :class="item.value === selected ? 'bg-white/5 text-yellow-400' : 'text-gray-200 hover:text-white'" role="menuitem" @click="clickedOption(item.value)">
|
2021-08-19 03:18:44 +02:00
|
|
|
<div class="flex items-center">
|
2023-06-10 22:46:12 +02:00
|
|
|
<span class="font-normal ml-3 block truncate">{{ item.text }}</span>
|
2021-08-19 03:18:44 +02:00
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<span v-if="item.value === selected" class="text-yellow-400 absolute inset-y-0 right-0 flex items-center pr-4">
|
2024-12-11 00:19:47 +01:00
|
|
|
<span class="material-symbols text-xl" :aria-label="descending ? $strings.LabelSortDescending : $strings.LabelSortAscending">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
2021-08-19 03:18:44 +02:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: String,
|
|
|
|
descending: Boolean
|
|
|
|
},
|
|
|
|
data() {
|
2022-11-09 00:10:08 +01:00
|
|
|
return {
|
|
|
|
showMenu: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
selected: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
2022-11-03 14:11:33 +01:00
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedDesc: {
|
|
|
|
get() {
|
|
|
|
return this.descending
|
2022-11-03 14:11:33 +01:00
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
set(val) {
|
|
|
|
this.$emit('update:descending', val)
|
2022-11-03 14:11:33 +01:00
|
|
|
}
|
2022-11-09 00:10:08 +01:00
|
|
|
},
|
2023-01-04 01:00:01 +01:00
|
|
|
libraryMediaType() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryMediaType']
|
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
isPodcast() {
|
2023-01-04 01:00:01 +01:00
|
|
|
return this.libraryMediaType === 'podcast'
|
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
podcastItems() {
|
|
|
|
return [
|
2022-04-12 02:42:09 +02:00
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelTitle,
|
2022-04-12 02:42:09 +02:00
|
|
|
value: 'media.metadata.title'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelAuthor,
|
2022-04-12 02:42:09 +02:00
|
|
|
value: 'media.metadata.author'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelAddedAt,
|
2022-04-12 02:42:09 +02:00
|
|
|
value: 'addedAt'
|
|
|
|
},
|
2021-08-19 03:18:44 +02:00
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelSize,
|
2021-08-19 03:18:44 +02:00
|
|
|
value: 'size'
|
2022-02-28 01:18:38 +01:00
|
|
|
},
|
2022-05-04 00:50:19 +02:00
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelNumberOfEpisodes,
|
2022-05-04 00:50:19 +02:00
|
|
|
value: 'media.numTracks'
|
|
|
|
},
|
2022-02-28 01:18:38 +01:00
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelFileBirthtime,
|
2022-02-28 01:18:38 +01:00
|
|
|
value: 'birthtimeMs'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelFileModified,
|
2022-02-28 01:18:38 +01:00
|
|
|
value: 'mtimeMs'
|
2024-07-25 23:10:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: this.$strings.LabelRandomly,
|
|
|
|
value: 'random'
|
2021-08-19 03:18:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
bookItems() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
text: this.$strings.LabelTitle,
|
|
|
|
value: 'media.metadata.title'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelAuthorFirstLast,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'media.metadata.authorName'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelAuthorLastFirst,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'media.metadata.authorNameLF'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelPublishYear,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'media.metadata.publishedYear'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelAddedAt,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'addedAt'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelSize,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'size'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelDuration,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'media.duration'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelFileBirthtime,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'birthtimeMs'
|
|
|
|
},
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelFileModified,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'mtimeMs'
|
2024-07-25 23:10:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: this.$strings.LabelRandomly,
|
|
|
|
value: 'random'
|
2022-11-09 00:10:08 +01:00
|
|
|
}
|
|
|
|
]
|
2021-08-19 03:18:44 +02:00
|
|
|
},
|
2022-11-09 00:10:08 +01:00
|
|
|
seriesItems() {
|
|
|
|
return [
|
|
|
|
...this.bookItems,
|
|
|
|
{
|
2022-11-18 23:59:11 +01:00
|
|
|
text: this.$strings.LabelSequence,
|
2022-11-09 00:10:08 +01:00
|
|
|
value: 'sequence'
|
|
|
|
}
|
|
|
|
]
|
2022-04-12 02:42:09 +02:00
|
|
|
},
|
|
|
|
selectItems() {
|
2022-11-03 14:11:33 +01:00
|
|
|
let items = null
|
|
|
|
if (this.isPodcast) {
|
|
|
|
items = this.podcastItems
|
|
|
|
} else if (this.$store.getters['user/getUserSetting']('filterBy').startsWith('series.')) {
|
|
|
|
items = this.seriesItems
|
|
|
|
} else {
|
|
|
|
items = this.bookItems
|
|
|
|
}
|
|
|
|
|
2022-11-09 00:10:08 +01:00
|
|
|
if (!items.some((i) => i.value === this.selected)) {
|
2022-11-03 14:11:33 +01:00
|
|
|
this.selected = items[0].value
|
|
|
|
this.selectedDesc = !this.defaultsToAsc(items[0].value)
|
|
|
|
}
|
|
|
|
|
|
|
|
return items
|
2022-04-12 02:42:09 +02:00
|
|
|
},
|
2021-08-19 03:18:44 +02:00
|
|
|
selectedText() {
|
2022-03-11 01:45:02 +01:00
|
|
|
var _selected = this.selected
|
2022-03-12 02:46:32 +01:00
|
|
|
if (!_selected) return ''
|
2022-03-11 01:45:02 +01:00
|
|
|
if (this.selected.startsWith('book.')) _selected = _selected.replace('book.', 'media.metadata.')
|
2022-04-12 02:42:09 +02:00
|
|
|
var _sel = this.selectItems.find((i) => i.value === _selected)
|
2021-08-19 03:18:44 +02:00
|
|
|
if (!_sel) return ''
|
|
|
|
return _sel.text
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickOutside() {
|
|
|
|
this.showMenu = false
|
|
|
|
},
|
|
|
|
clickedOption(val) {
|
|
|
|
if (this.selected === val) {
|
|
|
|
this.selectedDesc = !this.selectedDesc
|
|
|
|
} else {
|
|
|
|
this.selected = val
|
2022-11-03 14:11:33 +01:00
|
|
|
if (this.defaultsToAsc(val)) this.selectedDesc = false
|
2021-08-19 03:18:44 +02:00
|
|
|
}
|
|
|
|
this.showMenu = false
|
|
|
|
this.$nextTick(() => this.$emit('change', val))
|
2022-11-03 14:11:33 +01:00
|
|
|
},
|
|
|
|
defaultsToAsc(val) {
|
2022-11-09 00:10:08 +01:00
|
|
|
return val == 'media.metadata.title' || val == 'media.metadata.author' || val == 'media.metadata.authorName' || val == 'media.metadata.authorNameLF' || val == 'sequence'
|
2021-08-19 03:18:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-25 23:10:42 +02:00
|
|
|
</script>
|