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

208 wiersze
6.4 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">
<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">
<translate :translate-context="'Content/Radio/Title'">Instance radios</translate>
2018-07-17 11:09:13 +00:00
</h3>
<div class="ui cards">
<radio-card :type="'favorites'"></radio-card>
<radio-card :type="'random'"></radio-card>
<radio-card :type="'less-listened'"></radio-card>
</div>
</div>
<div class="ui hidden divider"></div>
<h3 class="ui header">
<translate :translate-context="'Content/Radio/Title'">User radios</translate>
2018-07-17 11:09:13 +00:00
</h3>
2018-04-15 10:45:56 +00:00
<router-link class="ui green basic 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>
2018-01-07 21:13:44 +00:00
<div class="ui hidden divider"></div>
<div :class="['ui', {'loading': isLoading}, 'form']">
<div class="fields">
<div class="field">
<label><translate :translate-context="'Content/Search/Input.Label/Verb'">Search</translate></label>
<input name="search" type="text" v-model="query" :placeholder="labels.searchPlaceholder"/>
2018-01-07 21:13:44 +00:00
</div>
<div class="field">
<label><translate :translate-context="'Content/Search/Dropdown.Label'">Ordering</translate></label>
2018-01-07 21:13:44 +00:00
<select class="ui dropdown" v-model="ordering">
<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">
<label><translate :translate-context="'Content/Search/Dropdown.Label'">Order</translate></label>
2018-01-07 21:13:44 +00:00
<select class="ui dropdown" v-model="orderingDirection">
2018-06-30 13:28:47 +00:00
<option value="+">
<translate :translate-context="'Content/Search/Dropdown'">Ascending</translate>
2018-06-30 13:28:47 +00:00
</option>
<option value="-">
<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">
<label><translate :translate-context="'Content/Search/Dropdown.Label'">Results per page</translate></label>
2018-01-07 21:13:44 +00:00
<select class="ui dropdown" v-model="paginateBy">
<option :value="parseInt(12)">12</option>
<option :value="parseInt(25)">25</option>
<option :value="parseInt(50)">50</option>
</select>
</div>
</div>
</div>
<div class="ui hidden divider"></div>
2018-02-26 19:10:35 +00:00
<div
v-if="result"
v-masonry
transition-duration="0"
item-selector=".card"
2018-02-26 19:10:35 +00:00
percent-position="true"
stagger="0">
2018-01-07 21:13:44 +00:00
<div
v-if="result.results.length > 0"
class="ui cards">
<radio-card
type="custom"
v-masonry-tile
v-for="radio in result.results"
:key="radio.id"
:custom-radio="radio"></radio-card>
2018-01-07 21:13:44 +00:00
</div>
</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: "" }
2018-01-07 21:13:44 +00:00
},
components: {
RadioCard,
Pagination
},
data() {
let defaultOrdering = this.getOrderingFromString(
this.defaultOrdering || "-creation_date"
)
2018-01-07 21:13:44 +00:00
return {
isLoading: true,
result: null,
page: parseInt(this.defaultPage),
query: this.defaultQuery,
paginateBy: parseInt(this.defaultPaginateBy || 12),
orderingDirection: defaultOrdering.direction || "+",
2018-01-07 21:13:44 +00:00
ordering: defaultOrdering.field,
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('Head/Radio/Title', "Radios")
2018-07-01 19:50:50 +00:00
return {
searchPlaceholder,
title
}
}
},
2018-01-07 21:13:44 +00:00
methods: {
updateQueryString: _.debounce(function() {
2018-01-07 21:13:44 +00:00
this.$router.replace({
query: {
query: this.query,
page: this.page,
paginateBy: this.paginateBy,
ordering: this.getOrderingAsString()
}
})
}, 500),
fetchData: _.debounce(function() {
2018-01-07 21:13:44 +00:00
var self = this
this.isLoading = true
let url = FETCH_URL
let params = {
page: this.page,
page_size: this.paginateBy,
name__icontains: this.query,
ordering: this.getOrderingAsString()
}
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
})
}, 500),
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()
},
paginateBy() {
2018-01-07 21:13:44 +00:00
this.updateQueryString()
this.fetchData()
},
ordering() {
2018-01-07 21:13:44 +00:00
this.updateQueryString()
this.fetchData()
},
orderingDirection() {
2018-01-07 21:13:44 +00:00
this.updateQueryString()
this.fetchData()
},
query() {
2018-01-07 21:13:44 +00:00
this.updateQueryString()
this.fetchData()
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>