owntone-server/web-src/src/pages/PageArtists.vue

171 lines
4.7 KiB
Vue
Raw Normal View History

<template>
2022-02-19 06:18:01 +01:00
<div class="fd-page-with-tabs">
<tabs-music />
<content-with-heading>
<template #options>
2024-02-27 16:27:37 +01:00
<index-button-list :indices="artists.indices" />
<div class="columns">
<div class="column">
<p class="heading mb-5" v-text="$t('page.artists.filter')" />
<div class="field">
<div class="control">
<input
id="switchHideSingles"
v-model="hide_singles"
type="checkbox"
class="switch is-rounded"
/>
<label
for="switchHideSingles"
v-text="$t('page.artists.hide-singles')"
/>
</div>
2022-05-20 13:44:22 +02:00
<p class="help" v-text="$t('page.artists.hide-singles-help')" />
</div>
<div v-if="spotify_enabled" class="field">
<div class="control">
<input
id="switchHideSpotify"
v-model="hide_spotify"
type="checkbox"
class="switch is-rounded"
/>
<label
for="switchHideSpotify"
v-text="$t('page.artists.hide-spotify')"
/>
</div>
2022-05-20 13:44:22 +02:00
<p class="help" v-text="$t('page.artists.hide-spotify-help')" />
</div>
</div>
<div class="column">
<p class="heading mb-5" v-text="$t('page.artists.sort.title')" />
<control-dropdown
2024-02-22 19:32:11 +01:00
v-model:value="selected_grouping_option_id"
:options="grouping_options"
/>
</div>
</div>
</template>
<template #heading-left>
2022-05-20 13:44:22 +02:00
<p class="title is-4" v-text="$t('page.artists.title')" />
<p
class="heading"
v-text="$t('page.artists.count', { count: artists.count })"
/>
</template>
<template #heading-right />
<template #content>
<list-artists :items="artists" />
</template>
</content-with-heading>
</div>
</template>
<script>
import * as types from '@/store/mutation_types'
2022-02-19 06:18:01 +01:00
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ControlDropdown from '@/components/ControlDropdown.vue'
import { GroupedList } from '@/lib/GroupedList'
2022-02-19 06:18:01 +01:00
import IndexButtonList from '@/components/IndexButtonList.vue'
import ListArtists from '@/components/ListArtists.vue'
import TabsMusic from '@/components/TabsMusic.vue'
import webapi from '@/webapi'
2022-02-19 06:18:01 +01:00
const dataObject = {
load(to) {
return webapi.library_artists('music')
},
set(vm, response) {
2024-02-22 19:32:11 +01:00
vm.artists_list = new GroupedList(response.data)
}
}
export default {
name: 'PageArtists',
components: {
ContentWithHeading,
ControlDropdown,
IndexButtonList,
ListArtists,
TabsMusic
},
beforeRouteEnter(to, from, next) {
dataObject.load(to).then((response) => {
next((vm) => dataObject.set(vm, response))
})
},
data() {
return {
2024-02-22 19:32:11 +01:00
artists_list: new GroupedList(),
grouping_options: [
{
2022-05-20 13:44:22 +02:00
id: 1,
name: this.$t('page.artists.sort.name'),
options: { index: { field: 'name_sort', type: String } }
2022-05-20 13:44:22 +02:00
},
{
id: 2,
name: this.$t('page.artists.sort.recently-added'),
options: {
2024-03-26 12:04:04 +01:00
criteria: [{ field: 'time_added', order: -1, type: Date }],
index: { field: 'time_added', type: Date }
}
}
]
}
},
computed: {
2024-02-22 19:32:11 +01:00
// Wraps GroupedList and updates it if filter or sort changes
artists() {
if (!this.artists_list) {
return []
}
2024-02-22 19:32:11 +01:00
const grouping = this.grouping_options.find(
(o) => o.id === this.selected_grouping_option_id
)
grouping.options.filters = [
(artist) =>
!this.hide_singles || artist.track_count > artist.album_count * 2,
(artist) => !this.hide_spotify || artist.data_kind !== 'spotify'
]
this.artists_list.group(grouping.options)
return this.artists_list
},
hide_singles: {
get() {
return this.$store.state.hide_singles
},
set(value) {
this.$store.commit(types.HIDE_SINGLES, value)
}
},
hide_spotify: {
get() {
return this.$store.state.hide_spotify
},
set(value) {
this.$store.commit(types.HIDE_SPOTIFY, value)
}
},
selected_grouping_option_id: {
get() {
return this.$store.state.artists_sort
},
set(value) {
this.$store.commit(types.ARTISTS_SORT, value)
}
},
spotify_enabled() {
return this.$store.state.spotify.webapi_token_valid
}
}
}
</script>
<style></style>