2018-01-07 21:13:44 +00:00
|
|
|
<template>
|
2018-11-19 22:33:22 +00:00
|
|
|
<main v-title="labels.title">
|
|
|
|
<section class="ui vertical stripe segment">
|
2018-06-30 13:28:47 +00:00
|
|
|
<h2 class="ui header">
|
2019-02-14 09:40:20 +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-02-14 09:40: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">
|
|
|
|
<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">
|
2019-02-14 09:40:20 +00:00
|
|
|
<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>
|
2019-02-14 09:40:20 +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>
|
|
|
|
<div :class="['ui', {'loading': isLoading}, 'form']">
|
|
|
|
<div class="fields">
|
|
|
|
<div class="field">
|
2019-02-14 09:40:20 +00:00
|
|
|
<label><translate :translate-context="'Content/Search/Input.Label/Verb'">Search</translate></label>
|
2019-01-26 17:06:19 +00:00
|
|
|
<input name="search" type="text" v-model="query" :placeholder="labels.searchPlaceholder"/>
|
2018-01-07 21:13:44 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-02-14 09:40:20 +00:00
|
|
|
<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]">
|
2018-10-05 17:31:30 +00:00
|
|
|
{{ sharedLabels.filters[option[1]] }}
|
2018-01-07 21:13:44 +00:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-02-14 09:40:20 +00:00
|
|
|
<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="+">
|
2019-02-14 09:40:20 +00:00
|
|
|
<translate :translate-context="'Content/Search/Dropdown'">Ascending</translate>
|
2018-06-30 13:28:47 +00:00
|
|
|
</option>
|
|
|
|
<option value="-">
|
2019-02-14 09:40: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">
|
2019-02-14 09:40:20 +00:00
|
|
|
<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"
|
2019-02-13 08:04:49 +00:00
|
|
|
item-selector=".card"
|
2018-02-26 19:10:35 +00:00
|
|
|
percent-position="true"
|
2019-02-13 08:04:49 +00:00
|
|
|
stagger="0">
|
2018-01-07 21:13:44 +00:00
|
|
|
<div
|
|
|
|
v-if="result.results.length > 0"
|
2019-02-13 08:04:49 +00:00
|
|
|
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
|
2018-07-11 17:15:03 +00:00
|
|
|
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>
|
2018-11-19 22:33:22 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
2018-01-07 21:13:44 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-11-19 22:33:22 +00:00
|
|
|
import axios from "axios"
|
2018-12-20 10:21:15 +00:00
|
|
|
import _ from "@/lodash"
|
2018-11-19 22:33:22 +00:00
|
|
|
import $ from "jquery"
|
2018-01-07 21:13:44 +00:00
|
|
|
|
2018-11-19 22:33:22 +00:00
|
|
|
import logger from "@/logging"
|
2018-01-07 21:13:44 +00:00
|
|
|
|
2018-11-19 22:33:22 +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
|
|
|
|
2018-11-19 22:33:22 +00:00
|
|
|
const FETCH_URL = "radios/radios/"
|
2018-01-07 21:13:44 +00:00
|
|
|
|
|
|
|
export default {
|
2018-10-05 17:31:30 +00:00
|
|
|
mixins: [OrderingMixin, PaginationMixin, TranslationsMixin],
|
2018-01-07 21:13:44 +00:00
|
|
|
props: {
|
2018-11-19 22:33:22 +00:00
|
|
|
defaultQuery: { type: String, required: false, default: "" }
|
2018-01-07 21:13:44 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
RadioCard,
|
|
|
|
Pagination
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
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),
|
2018-11-19 22:33:22 +00:00
|
|
|
orderingDirection: defaultOrdering.direction || "+",
|
2018-01-07 21:13:44 +00:00
|
|
|
ordering: defaultOrdering.field,
|
2018-11-19 22:33:22 +00:00
|
|
|
orderingOptions: [["creation_date", "creation_date"], ["name", "name"]]
|
2018-01-07 21:13:44 +00:00
|
|
|
}
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
created() {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.fetchData()
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
mounted() {
|
|
|
|
$(".ui.dropdown").dropdown()
|
2018-01-07 21:13:44 +00:00
|
|
|
},
|
2018-07-01 19:50:50 +00:00
|
|
|
computed: {
|
2018-11-19 22:33:22 +00:00
|
|
|
labels() {
|
2019-02-14 09:40:20 +00:00
|
|
|
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: {
|
2018-11-19 22:33:22 +00:00
|
|
|
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),
|
2018-11-19 22:33:22 +00:00
|
|
|
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()
|
|
|
|
}
|
2018-11-19 22:33:22 +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
|
|
|
|
})
|
|
|
|
}, 500),
|
2018-11-19 22:33:22 +00:00
|
|
|
selectPage: function(page) {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.page = page
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2018-11-19 22:33:22 +00:00
|
|
|
page() {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.updateQueryString()
|
|
|
|
this.fetchData()
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
paginateBy() {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.updateQueryString()
|
|
|
|
this.fetchData()
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
ordering() {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.updateQueryString()
|
|
|
|
this.fetchData()
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
orderingDirection() {
|
2018-01-07 21:13:44 +00:00
|
|
|
this.updateQueryString()
|
|
|
|
this.fetchData()
|
|
|
|
},
|
2018-11-19 22:33:22 +00:00
|
|
|
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>
|