Newer
Older
Eliot Berriot
committed
<template>
Eliot Berriot
committed
<div class="ui vertical center aligned stripe segment">
<div :class="['ui', {'active': isLoading}, 'inverted', 'dimmer']">
<div class="ui text loader"><i18next path="Loading your favorites..."/></div>
Eliot Berriot
committed
</div>
<h2 v-if="results" class="ui center aligned icon header">
<i class="circular inverted heart pink icon"></i>
<i18next path="{%0%} favorites">
{{ $store.state.favorites.count }}
</i18next>
Eliot Berriot
committed
</h2>
<radio-button type="favorites"></radio-button>
</div>
<div class="ui vertical stripe segment">
<div :class="['ui', {'loading': isLoading}, 'form']">
<div class="fields">
<div class="field">
<select class="ui dropdown" v-model="ordering">
<option v-for="option in orderingOptions" :value="option[0]">
{{ option[1] }}
</option>
</select>
</div>
<div class="field">
<i18next tag="label" path="Ordering direction"/>
<select class="ui dropdown" v-model="orderingDirection">
<option value="+"><i18next path="Ascending"/></option>
<option value="-"><i18next path="Descending"/></option>
</select>
</div>
<div class="field">
<i18next tag="label" path="Results per page"/>
<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>
Eliot Berriot
committed
<track-table v-if="results" :tracks="results.results"></track-table>
<div class="ui center aligned basic segment">
<pagination
@page-changed="selectPage"
:current="page"
:total="results.count"
></pagination>
</div>
Eliot Berriot
committed
</div>
</div>
</template>
<script>
Eliot Berriot
committed
import logger from '@/logging'
import TrackTable from '@/components/audio/track/Table'
import RadioButton from '@/components/radios/Button'
import Pagination from '@/components/Pagination'
import OrderingMixin from '@/components/mixins/Ordering'
import PaginationMixin from '@/components/mixins/Pagination'
Eliot Berriot
committed
export default {
mixins: [OrderingMixin, PaginationMixin],
Eliot Berriot
committed
components: {
TrackTable,
Eliot Berriot
committed
},
data () {
let defaultOrdering = this.getOrderingFromString(this.defaultOrdering || '-creation_date')
Eliot Berriot
committed
return {
results: null,
isLoading: false,
nextLink: null,
previousLink: null,
page: parseInt(this.defaultPage),
paginateBy: parseInt(this.defaultPaginateBy || 25),
orderingDirection: defaultOrdering.direction || '+',
ordering: defaultOrdering.field,
orderingOptions: [
['creation_date', 'Creation date'],
['title', 'Track name'],
['album__title', 'Album name'],
['artist__name', 'Artist name']
Eliot Berriot
committed
}
},
created () {
this.fetchFavorites(FAVORITES_URL)
},
mounted () {
$('.ui.dropdown').dropdown()
},
Eliot Berriot
committed
methods: {
updateQueryString: function () {
this.$router.replace({
query: {
page: this.page,
paginateBy: this.paginateBy,
ordering: this.getOrderingAsString()
}
})
},
Eliot Berriot
committed
fetchFavorites (url) {
var self = this
this.isLoading = true
let params = {
page_size: this.paginateBy,
ordering: this.getOrderingAsString()
Eliot Berriot
committed
}
logger.default.time('Loading user favorites')
axios.get(url, {params: params}).then((response) => {
Eliot Berriot
committed
self.results = response.data
self.nextLink = response.data.next
self.previousLink = response.data.previous
self.results.results.forEach((track) => {
self.$store.commit('favorites/track', {id: track.id, value: true})
Eliot Berriot
committed
})
logger.default.timeEnd('Loading user favorites')
self.isLoading = false
})
},
selectPage: function (page) {
this.page = page
}
},
watch: {
page: function () {
this.updateQueryString()
},
paginateBy: function () {
this.updateQueryString()
},
orderingDirection: function () {
this.updateQueryString()
},
ordering: function () {
this.updateQueryString()
Eliot Berriot
committed
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>