funkwhale/front/src/components/library/Radios.vue

274 wiersze
7.9 KiB
Vue
Czysty Zwykły widok Historia

2018-01-07 21:13:44 +00:00
<template>
<main v-title="labels.title">
<section class="ui vertical stripe segment">
2018-06-30 13:28:47 +00:00
<h2 class="ui header">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Radio/Title">
Browsing radios
</translate>
2018-06-30 13:28:47 +00:00
</h2>
2021-12-06 10:35:20 +00:00
<div class="ui hidden divider" />
2018-07-17 11:09:13 +00:00
<div class="ui row">
<h3 class="ui header">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Radio/Title">
Instance radios
</translate>
2018-07-17 11:09:13 +00:00
</h3>
<div class="ui cards">
2021-12-06 10:35:20 +00:00
<radio-card
v-if="isAuthenticated"
:type="'actor-content'"
:object-id="$store.state.auth.fullUsername"
/>
<radio-card
v-if="isAuthenticated && hasFavorites"
:type="'favorites'"
/>
<radio-card :type="'random'" />
<radio-card :type="'recently-added'" />
<radio-card
v-if="$store.state.auth.authenticated"
:type="'less-listened'"
/>
2018-07-17 11:09:13 +00:00
</div>
</div>
2021-12-06 10:35:20 +00:00
<div class="ui hidden divider" />
2018-07-17 11:09:13 +00:00
<h3 class="ui header">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Radio/Title">
User radios
</translate>
2018-07-17 11:09:13 +00:00
</h3>
2021-12-06 10:35:20 +00:00
<router-link
class="ui success button"
to="/library/radios/build"
exact
>
<translate translate-context="Content/Radio/Button.Label/Verb">
Create your own radio
</translate>
2018-04-15 10:45:56 +00:00
</router-link>
2021-12-06 10:35:20 +00:00
<div class="ui hidden divider" />
<form
:class="['ui', {'loading': isLoading}, 'form']"
@submit.prevent="updateQueryString();fetchData()"
>
2018-01-07 21:13:44 +00:00
<div class="fields">
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="radios-search"><translate translate-context="Content/Search/Input.Label/Noun">Search</translate></label>
<div class="ui action input">
2021-12-06 10:35:20 +00:00
<input
id="radios-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" />
</button>
</div>
2018-01-07 21:13:44 +00:00
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="radios-ordering"><translate translate-context="Content/Search/Dropdown.Label/Noun">Ordering</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="radios-ordering"
v-model="ordering"
class="ui dropdown"
>
<option
v-for="(option, key) in orderingOptions"
:key="key"
:value="option[0]"
>
{{ sharedLabels.filters[option[1]] }}
2018-01-07 21:13:44 +00:00
</option>
</select>
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="radios-ordering-direction"><translate translate-context="Content/Search/Dropdown.Label/Noun">Order</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="radios-ordering-direction"
v-model="orderingDirection"
class="ui dropdown"
>
2018-06-30 13:28:47 +00:00
<option value="+">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Search/Dropdown">
Ascending
</translate>
2018-06-30 13:28:47 +00:00
</option>
<option value="-">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Search/Dropdown">
Descending
</translate>
2018-06-30 13:28:47 +00:00
</option>
2018-01-07 21:13:44 +00:00
</select>
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="radios-results"><translate translate-context="Content/Search/Dropdown.Label/Noun">Results per page</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="radios-results"
v-model="paginateBy"
class="ui dropdown"
>
<option :value="parseInt(12)">
12
</option>
<option :value="parseInt(25)">
25
</option>
<option :value="parseInt(50)">
50
</option>
2018-01-07 21:13:44 +00:00
</select>
</div>
</div>
</form>
2021-12-06 10:35:20 +00:00
<div class="ui hidden divider" />
<div
v-if="result && !result.results.length > 0"
class="ui placeholder segment"
>
<div class="ui icon header">
2021-12-06 10:35:20 +00:00
<i class="feed icon" />
<translate translate-context="Content/Radios/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: 'library.radios.build'}"
class="ui success button labeled icon"
>
<i class="rss icon" />
<translate translate-context="Content/*/Verb">
Create a radio
</translate>
</router-link>
</div>
2018-02-26 19:10:35 +00:00
<div
v-if="result && result.results.length > 0"
2021-12-06 10:35:20 +00:00
class="ui cards"
>
<radio-card
v-for="radio in result.results"
:key="radio.id"
2021-12-06 10:35:20 +00:00
type="custom"
:custom-radio="radio"
/>
2018-01-07 21:13:44 +00:00
</div>
<div class="ui center aligned basic segment">
<pagination
v-if="result && result.count > paginateBy"
2018-01-07 21:13:44 +00:00
:current="page"
:paginate-by="paginateBy"
:total="result.count"
2021-12-06 10:35:20 +00:00
@page-changed="selectPage"
/>
2018-01-07 21:13:44 +00:00
</div>
</section>
</main>
2018-01-07 21:13:44 +00:00
</template>
<script>
2021-12-06 10:35:20 +00:00
import axios from 'axios'
import $ from 'jquery'
2018-01-07 21:13:44 +00:00
2022-02-21 16:27:00 +00:00
import logger from '@/logging.js'
2018-01-07 21:13:44 +00:00
2022-02-21 14:07:07 +00:00
import OrderingMixin from '@/components/mixins/Ordering.vue'
import PaginationMixin from '@/components/mixins/Pagination.vue'
import TranslationsMixin from '@/components/mixins/Translations.vue'
import RadioCard from '@/components/radios/Card.vue'
import Pagination from '@/components/Pagination.vue'
2018-01-07 21:13:44 +00:00
2021-12-06 10:35:20 +00:00
const FETCH_URL = 'radios/radios/'
2018-01-07 21:13:44 +00:00
export default {
components: {
RadioCard,
Pagination
},
2021-12-06 10:35:20 +00:00
mixins: [OrderingMixin, PaginationMixin, TranslationsMixin],
props: {
defaultQuery: { type: String, required: false, default: '' },
scope: { type: String, required: false, default: 'all' }
},
data () {
2018-01-07 21:13:44 +00:00
return {
isLoading: true,
result: null,
page: parseInt(this.defaultPage),
query: this.defaultQuery,
2021-12-06 10:35:20 +00:00
orderingOptions: [['creation_date', 'creation_date'], ['name', 'name']]
2018-01-07 21:13:44 +00:00
}
},
2018-07-01 19:50:50 +00:00
computed: {
2021-12-06 10:35:20 +00:00
labels () {
const searchPlaceholder = this.$pgettext('Content/Search/Input.Placeholder', 'Enter a radio name…')
const title = this.$pgettext('*/*/*', 'Radios')
2018-07-01 19:50:50 +00:00
return {
searchPlaceholder,
title
}
},
isAuthenticated () {
return this.$store.state.auth.authenticated
},
hasFavorites () {
return this.$store.state.favorites.count > 0
2021-12-06 10:35:20 +00:00
}
},
watch: {
page () {
this.updateQueryString()
this.fetchData()
}
},
created () {
this.fetchData()
},
mounted () {
$('.ui.dropdown').dropdown()
2018-07-01 19:50:50 +00:00
},
2018-01-07 21:13:44 +00:00
methods: {
2021-12-06 10:35:20 +00:00
updateQueryString: function () {
history.pushState(
{},
null,
this.$route.path + '?' + new URLSearchParams(
{
2021-12-06 10:35:20 +00:00
query: this.query,
page: this.page,
paginateBy: this.paginateBy,
ordering: this.getOrderingAsString()
}).toString()
)
},
2021-12-06 10:35:20 +00:00
fetchData: function () {
const self = this
2018-01-07 21:13:44 +00:00
this.isLoading = true
2021-12-06 10:35:20 +00:00
const url = FETCH_URL
const params = {
scope: this.scope,
2018-01-07 21:13:44 +00:00
page: this.page,
page_size: this.paginateBy,
name__icontains: this.query,
2021-12-06 10:35:20 +00:00
ordering: this.getOrderingAsString()
2018-01-07 21:13:44 +00:00
}
2021-12-06 10:35:20 +00:00
logger.default.debug('Fetching radios')
axios.get(url, { params: params }).then(response => {
2018-01-07 21:13:44 +00:00
self.result = response.data
self.isLoading = false
})
},
2021-12-06 10:35:20 +00:00
selectPage: function (page) {
2018-01-07 21:13:44 +00:00
this.page = page
}
}
}
</script>