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

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