2022-05-08 23:52:44 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import qs from 'qs'
|
|
|
|
import axios from 'axios'
|
|
|
|
import $ from 'jquery'
|
|
|
|
import { onBeforeRouteUpdate, useRouter } from 'vue-router'
|
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
|
|
import { useGettext } from 'vue3-gettext'
|
|
|
|
import { OrderingField, RouteWithPreferences } from '~/store/ui'
|
|
|
|
|
|
|
|
import AlbumCard from '~/components/audio/album/Card.vue'
|
|
|
|
import Pagination from '~/components/vui/Pagination.vue'
|
|
|
|
import TagsSelector from '~/components/library/TagsSelector.vue'
|
|
|
|
import useLogger from '~/composables/useLogger'
|
|
|
|
import useSharedLabels from '~/composables/locale/useSharedLabels'
|
|
|
|
import useOrdering from '~/composables/useOrdering'
|
|
|
|
import { useStore } from '~/store'
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
orderingConfigName: RouteWithPreferences | null
|
|
|
|
defaultPage?: number
|
|
|
|
defaultPaginateBy?: number
|
|
|
|
defaultQuery?: string
|
|
|
|
defaultTags?: string[]
|
|
|
|
scope?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
defaultPage: 1,
|
|
|
|
defaultPaginateBy: 1,
|
|
|
|
defaultQuery: '',
|
|
|
|
defaultTags: () => [],
|
|
|
|
scope: 'all'
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO (wvffle): Make sure everything is it's own type
|
|
|
|
const page = ref(+props.defaultPage)
|
|
|
|
type ResponseType = { count: number, results: any[] }
|
|
|
|
const result = ref<null | ResponseType>(null)
|
2022-06-04 12:35:19 +00:00
|
|
|
const query = ref(props.defaultQuery)
|
2022-05-08 23:52:44 +00:00
|
|
|
const tags = reactive(props.defaultTags.slice())
|
|
|
|
|
|
|
|
const orderingOptions: [OrderingField, keyof typeof sharedLabels.filters][] = [
|
|
|
|
['creation_date', 'creation_date'],
|
|
|
|
['title', 'album_title'],
|
|
|
|
['release_date', 'release_date']
|
|
|
|
]
|
|
|
|
|
|
|
|
const logger = useLogger()
|
|
|
|
const sharedLabels = useSharedLabels()
|
|
|
|
|
|
|
|
const { onOrderingUpdate, orderingString, paginateBy, ordering, orderingDirection } = useOrdering(props.orderingConfigName)
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const updateQueryString = () => router.replace({
|
|
|
|
query: {
|
|
|
|
query: query.value,
|
|
|
|
page: page.value,
|
|
|
|
tag: tags,
|
|
|
|
paginateBy: paginateBy.value,
|
|
|
|
ordering: orderingString.value
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const search = () => {
|
2022-06-04 12:35:19 +00:00
|
|
|
page.value = props.defaultPage
|
2022-05-08 23:52:44 +00:00
|
|
|
updateQueryString()
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(page, updateQueryString)
|
|
|
|
onOrderingUpdate(updateQueryString)
|
|
|
|
|
|
|
|
const isLoading = ref(false)
|
|
|
|
const fetchData = async () => {
|
|
|
|
isLoading.value = true
|
|
|
|
const params = {
|
|
|
|
scope: props.scope,
|
|
|
|
page: page.value,
|
|
|
|
page_size: paginateBy.value,
|
|
|
|
q: query.value,
|
|
|
|
ordering: orderingString.value,
|
|
|
|
playable: 'true',
|
|
|
|
tag: tags,
|
|
|
|
include_channels: 'true',
|
|
|
|
content_category: 'music'
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.time('Fetching albums')
|
|
|
|
try {
|
|
|
|
const response = await axios.get('albums/', {
|
|
|
|
params,
|
|
|
|
paramsSerializer: function (params) {
|
|
|
|
return qs.stringify(params, { indices: false })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result.value = response.data
|
|
|
|
} catch (error) {
|
|
|
|
// TODO (wvffle): Handle error
|
|
|
|
result.value = null
|
|
|
|
} finally {
|
|
|
|
logger.timeEnd('Fetching albums')
|
|
|
|
isLoading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
watch(store.state.moderation.lastUpdate, fetchData)
|
|
|
|
onBeforeRouteUpdate(fetchData)
|
|
|
|
fetchData()
|
|
|
|
|
|
|
|
// @ts-expect-error semantic ui
|
|
|
|
onMounted(() => $('.ui.dropdown').dropdown())
|
|
|
|
|
|
|
|
const { $pgettext } = useGettext()
|
|
|
|
const labels = computed(() => ({
|
|
|
|
searchPlaceholder: $pgettext('Content/Search/Input.Placeholder', 'Enter album title…'),
|
|
|
|
title: $pgettext('*/*/*', 'Albums')
|
|
|
|
}))
|
|
|
|
</script>
|
|
|
|
|
2019-02-13 07:46:38 +00:00
|
|
|
<template>
|
|
|
|
<main v-title="labels.title">
|
|
|
|
<section class="ui vertical stripe segment">
|
|
|
|
<h2 class="ui header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<translate translate-context="Content/Album/Title">
|
|
|
|
Browsing albums
|
|
|
|
</translate>
|
2019-02-13 07:46:38 +00:00
|
|
|
</h2>
|
2021-12-06 10:35:20 +00:00
|
|
|
<form
|
|
|
|
:class="['ui', {'loading': isLoading}, 'form']"
|
2022-05-08 23:52:44 +00:00
|
|
|
@submit.prevent="search"
|
2021-12-06 10:35:20 +00:00
|
|
|
>
|
2019-02-13 07:46:38 +00:00
|
|
|
<div class="fields">
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="albums-search">
|
2019-03-18 09:07:58 +00:00
|
|
|
<translate translate-context="Content/Search/Input.Label/Noun">Search</translate>
|
2019-02-13 07:46:38 +00:00
|
|
|
</label>
|
2020-07-06 11:21:07 +00:00
|
|
|
<div class="ui action input">
|
2021-12-06 10:35:20 +00:00
|
|
|
<input
|
|
|
|
id="albums-search"
|
|
|
|
v-model="query"
|
|
|
|
type="text"
|
|
|
|
name="search"
|
|
|
|
:placeholder="labels.searchPlaceholder"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="ui icon button"
|
|
|
|
type="submit"
|
|
|
|
:aria-label="$pgettext('Content/Search/Input.Label/Noun', 'Search')"
|
|
|
|
>
|
|
|
|
<i class="search icon" />
|
2020-07-06 11:21:07 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2019-02-13 07:46:38 +00:00
|
|
|
</div>
|
2020-01-27 15:10:43 +00:00
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="tags-search"><translate translate-context="*/*/*/Noun">Tags</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<tags-selector v-model="tags" />
|
2020-01-27 15:10:43 +00:00
|
|
|
</div>
|
2019-02-13 07:46:38 +00:00
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="album-ordering"><translate translate-context="Content/Search/Dropdown.Label/Noun">Ordering</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="album-ordering"
|
|
|
|
v-model="ordering"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
v-for="(option, key) in orderingOptions"
|
|
|
|
:key="key"
|
|
|
|
:value="option[0]"
|
|
|
|
>
|
2019-02-13 07:46:38 +00:00
|
|
|
{{ sharedLabels.filters[option[1]] }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="album-ordering-direction"><translate translate-context="Content/Search/Dropdown.Label/Noun">Ordering direction</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="album-ordering-direction"
|
|
|
|
v-model="orderingDirection"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
|
|
|
<option value="+">
|
|
|
|
<translate translate-context="Content/Search/Dropdown">
|
|
|
|
Ascending
|
|
|
|
</translate>
|
|
|
|
</option>
|
|
|
|
<option value="-">
|
|
|
|
<translate translate-context="Content/Search/Dropdown">
|
|
|
|
Descending
|
|
|
|
</translate>
|
|
|
|
</option>
|
2019-02-13 07:46:38 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-08-01 09:11:51 +00:00
|
|
|
<label for="album-results"><translate translate-context="Content/Search/Dropdown.Label/Noun">Results per page</translate></label>
|
2021-12-06 10:35:20 +00:00
|
|
|
<select
|
|
|
|
id="album-results"
|
|
|
|
v-model="paginateBy"
|
|
|
|
class="ui dropdown"
|
|
|
|
>
|
2022-05-08 23:52:44 +00:00
|
|
|
<option :value="12">
|
2021-12-06 10:35:20 +00:00
|
|
|
12
|
|
|
|
</option>
|
2022-05-08 23:52:44 +00:00
|
|
|
<option :value="25">
|
2021-12-06 10:35:20 +00:00
|
|
|
25
|
|
|
|
</option>
|
2022-05-08 23:52:44 +00:00
|
|
|
<option :value="50">
|
2021-12-06 10:35:20 +00:00
|
|
|
50
|
|
|
|
</option>
|
2019-02-13 07:46:38 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-06 11:21:07 +00:00
|
|
|
</form>
|
2021-12-06 10:35:20 +00:00
|
|
|
<div class="ui hidden divider" />
|
2019-02-13 07:46:38 +00:00
|
|
|
<div
|
|
|
|
v-if="result"
|
|
|
|
transition-duration="0"
|
|
|
|
item-selector=".column"
|
|
|
|
percent-position="true"
|
|
|
|
stagger="0"
|
2021-12-06 10:35:20 +00:00
|
|
|
class=""
|
|
|
|
>
|
2019-02-13 07:46:38 +00:00
|
|
|
<div
|
|
|
|
v-if="result.results.length > 0"
|
2021-12-06 10:35:20 +00:00
|
|
|
class="ui app-cards cards"
|
|
|
|
>
|
2019-02-13 07:46:38 +00:00
|
|
|
<album-card
|
|
|
|
v-for="album in result.results"
|
|
|
|
:key="album.id"
|
2021-12-06 10:35:20 +00:00
|
|
|
:album="album"
|
|
|
|
/>
|
2019-02-13 07:46:38 +00:00
|
|
|
</div>
|
2021-12-06 10:35:20 +00:00
|
|
|
<div
|
|
|
|
v-else
|
|
|
|
class="ui placeholder segment sixteen wide column"
|
|
|
|
style="text-align: center; display: flex; align-items: center"
|
|
|
|
>
|
2019-10-17 12:15:33 +00:00
|
|
|
<div class="ui icon header">
|
2021-12-06 10:35:20 +00:00
|
|
|
<i class="compact disc icon" />
|
2019-10-17 12:15:33 +00:00
|
|
|
<translate translate-context="Content/Albums/Placeholder">
|
|
|
|
No results matching your query
|
|
|
|
</translate>
|
|
|
|
</div>
|
|
|
|
<router-link
|
2021-12-06 10:35:20 +00:00
|
|
|
v-if="$store.state.auth.authenticated"
|
|
|
|
:to="{name: 'content.index'}"
|
|
|
|
class="ui success button labeled icon"
|
|
|
|
>
|
|
|
|
<i class="upload icon" />
|
2019-10-17 12:15:33 +00:00
|
|
|
<translate translate-context="Content/*/Verb">
|
|
|
|
Add some music
|
|
|
|
</translate>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2019-02-13 07:46:38 +00:00
|
|
|
</div>
|
|
|
|
<div class="ui center aligned basic segment">
|
|
|
|
<pagination
|
|
|
|
v-if="result && result.count > paginateBy"
|
2022-05-08 23:52:44 +00:00
|
|
|
v-model:current="page"
|
2019-02-13 07:46:38 +00:00
|
|
|
:paginate-by="paginateBy"
|
|
|
|
:total="result.count"
|
2021-12-06 10:35:20 +00:00
|
|
|
/>
|
2019-02-13 07:46:38 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</template>
|