2021-08-19 03:18:44 +02:00
|
|
|
<template>
|
|
|
|
<div ref="wrapper" class="relative" v-click-outside="clickOutside">
|
2021-08-21 23:23:35 +02: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="listbox" aria-expanded="true" aria-labelledby="listbox-label" @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>
|
|
|
|
<span class="material-icons text-lg text-yellow-400">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
2021-08-19 03:18:44 +02:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
|
2021-12-06 02:21:06 +01:00
|
|
|
<ul v-show="showMenu" class="absolute z-10 mt-1 w-full bg-bg border border-black-200 shadow-lg max-h-80 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm" role="listbox" aria-labelledby="listbox-label">
|
2022-04-12 02:42:09 +02:00
|
|
|
<template v-for="item in selectItems">
|
2021-08-19 18:31:03 +02:00
|
|
|
<li :key="item.value" class="text-gray-50 select-none relative py-2 pr-9 cursor-pointer hover:bg-black-400" :class="item.value === selected ? 'bg-primary bg-opacity-50' : ''" role="option" @click="clickedOption(item.value)">
|
2021-08-19 03:18:44 +02:00
|
|
|
<div class="flex items-center">
|
2021-08-25 03:24:40 +02:00
|
|
|
<span class="font-normal ml-3 block truncate text-xs">{{ item.text }}</span>
|
2021-08-19 03:18:44 +02:00
|
|
|
</div>
|
|
|
|
<span v-if="item.value === selected" class="text-yellow-400 absolute inset-y-0 right-0 flex items-center pr-4">
|
|
|
|
<span class="material-icons text-xl">{{ descending ? 'expand_more' : 'expand_less' }}</span>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: String,
|
|
|
|
descending: Boolean
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showMenu: false,
|
2022-04-12 02:42:09 +02:00
|
|
|
bookItems: [
|
2021-08-19 03:18:44 +02:00
|
|
|
{
|
|
|
|
text: 'Title',
|
2022-03-11 01:45:02 +01:00
|
|
|
value: 'media.metadata.title'
|
2021-08-19 03:18:44 +02:00
|
|
|
},
|
|
|
|
{
|
2021-08-25 03:24:40 +02:00
|
|
|
text: 'Author (First Last)',
|
2022-03-17 18:25:12 +01:00
|
|
|
value: 'media.metadata.authorName'
|
2021-08-25 03:24:40 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Author (Last, First)',
|
2022-03-17 18:25:12 +01:00
|
|
|
value: 'media.metadata.authorNameLF'
|
2021-08-19 03:18:44 +02:00
|
|
|
},
|
2022-08-19 21:16:25 +02:00
|
|
|
{
|
|
|
|
text: 'Published Year',
|
|
|
|
value: 'media.metadata.publishedYear'
|
|
|
|
},
|
2021-08-19 03:18:44 +02:00
|
|
|
{
|
|
|
|
text: 'Added At',
|
|
|
|
value: 'addedAt'
|
|
|
|
},
|
2022-04-12 02:42:09 +02:00
|
|
|
{
|
|
|
|
text: 'Size',
|
|
|
|
value: 'size'
|
|
|
|
},
|
2022-05-04 00:50:19 +02:00
|
|
|
{
|
|
|
|
text: 'Duration',
|
|
|
|
value: 'media.duration'
|
|
|
|
},
|
2022-04-12 02:42:09 +02:00
|
|
|
{
|
|
|
|
text: 'File Birthtime',
|
|
|
|
value: 'birthtimeMs'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'File Modified',
|
|
|
|
value: 'mtimeMs'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
podcastItems: [
|
|
|
|
{
|
|
|
|
text: 'Title',
|
|
|
|
value: 'media.metadata.title'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Author',
|
|
|
|
value: 'media.metadata.author'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Added At',
|
|
|
|
value: 'addedAt'
|
|
|
|
},
|
2021-08-19 03:18:44 +02:00
|
|
|
{
|
|
|
|
text: 'Size',
|
|
|
|
value: 'size'
|
2022-02-28 01:18:38 +01:00
|
|
|
},
|
2022-05-04 00:50:19 +02:00
|
|
|
{
|
|
|
|
text: '# of Episodes',
|
|
|
|
value: 'media.numTracks'
|
|
|
|
},
|
2022-02-28 01:18:38 +01:00
|
|
|
{
|
|
|
|
text: 'File Birthtime',
|
|
|
|
value: 'birthtimeMs'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'File Modified',
|
|
|
|
value: 'mtimeMs'
|
2021-08-19 03:18:44 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
selected: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedDesc: {
|
|
|
|
get() {
|
|
|
|
return this.descending
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('update:descending', val)
|
|
|
|
}
|
|
|
|
},
|
2022-04-12 02:42:09 +02:00
|
|
|
isPodcast() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryMediaType'] == 'podcast'
|
|
|
|
},
|
|
|
|
selectItems() {
|
|
|
|
if (this.isPodcast) return this.podcastItems
|
|
|
|
return this.bookItems
|
|
|
|
},
|
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-04-28 00:20:44 +02:00
|
|
|
if (val == 'media.metadata.title' || val == 'media.metadata.author' || val == 'media.metadata.authorName' || val == 'media.metadata.authorNameLF') {
|
|
|
|
this.selectedDesc = false
|
|
|
|
}
|
2021-08-19 03:18:44 +02:00
|
|
|
}
|
|
|
|
this.showMenu = false
|
|
|
|
this.$nextTick(() => this.$emit('change', val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|