Fixed #50: ordering for favorites
This commit is contained in:
parent
04c70116c3
commit
6ad8b212cf
|
@ -95,7 +95,12 @@ class TrackViewSet(TagViewSetMixin, SearchMixin, viewsets.ReadOnlyModelViewSet):
|
||||||
serializer_class = serializers.TrackSerializerNested
|
serializer_class = serializers.TrackSerializerNested
|
||||||
permission_classes = [ConditionalAuthentication]
|
permission_classes = [ConditionalAuthentication]
|
||||||
search_fields = ['title', 'artist__name']
|
search_fields = ['title', 'artist__name']
|
||||||
ordering_fields = ('creation_date',)
|
ordering_fields = (
|
||||||
|
'creation_date',
|
||||||
|
'title',
|
||||||
|
'album__title',
|
||||||
|
'artist__name',
|
||||||
|
)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = super().get_queryset()
|
queryset = super().get_queryset()
|
||||||
|
|
|
@ -9,9 +9,36 @@
|
||||||
{{ favoriteTracks.count }} favorites
|
{{ favoriteTracks.count }} favorites
|
||||||
</h2>
|
</h2>
|
||||||
<radio-button type="favorites"></radio-button>
|
<radio-button type="favorites"></radio-button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="ui vertical stripe segment">
|
<div class="ui vertical stripe segment">
|
||||||
|
<div :class="['ui', {'loading': isLoading}, 'form']">
|
||||||
|
<div class="fields">
|
||||||
|
<div class="field">
|
||||||
|
<label>Ordering</label>
|
||||||
|
<select class="ui dropdown" v-model="ordering">
|
||||||
|
<option v-for="option in orderingOptions" :value="option[0]">
|
||||||
|
{{ option[1] }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Ordering direction</label>
|
||||||
|
<select class="ui dropdown" v-model="orderingDirection">
|
||||||
|
<option value="">Ascending</option>
|
||||||
|
<option value="-">Descending</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Results per page</label>
|
||||||
|
<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>
|
||||||
|
|
||||||
<track-table v-if="results" :tracks="results.results"></track-table>
|
<track-table v-if="results" :tracks="results.results"></track-table>
|
||||||
<div class="ui center aligned basic segment">
|
<div class="ui center aligned basic segment">
|
||||||
<pagination
|
<pagination
|
||||||
|
@ -27,6 +54,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import $ from 'jquery'
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import logger from '@/logging'
|
import logger from '@/logging'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
|
@ -34,37 +62,60 @@ import favoriteTracks from '@/favorites/tracks'
|
||||||
import TrackTable from '@/components/audio/track/Table'
|
import TrackTable from '@/components/audio/track/Table'
|
||||||
import RadioButton from '@/components/radios/Button'
|
import RadioButton from '@/components/radios/Button'
|
||||||
import Pagination from '@/components/Pagination'
|
import Pagination from '@/components/Pagination'
|
||||||
|
import OrderingMixin from '@/components/mixins/Ordering'
|
||||||
|
import PaginationMixin from '@/components/mixins/Pagination'
|
||||||
const FAVORITES_URL = config.API_URL + 'tracks/'
|
const FAVORITES_URL = config.API_URL + 'tracks/'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
mixins: [OrderingMixin, PaginationMixin],
|
||||||
components: {
|
components: {
|
||||||
TrackTable,
|
TrackTable,
|
||||||
RadioButton,
|
RadioButton,
|
||||||
Pagination
|
Pagination
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
let defaultOrdering = this.getOrderingFromString(this.defaultOrdering || 'artist__name')
|
||||||
return {
|
return {
|
||||||
results: null,
|
results: null,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
nextLink: null,
|
nextLink: null,
|
||||||
previousLink: null,
|
previousLink: null,
|
||||||
page: 1,
|
favoriteTracks,
|
||||||
paginateBy: 25,
|
page: parseInt(this.defaultPage),
|
||||||
favoriteTracks
|
paginateBy: parseInt(this.defaultPaginateBy || 25),
|
||||||
|
orderingDirection: defaultOrdering.direction,
|
||||||
|
ordering: defaultOrdering.field,
|
||||||
|
orderingOptions: [
|
||||||
|
['title', 'Track name'],
|
||||||
|
['album__title', 'Album name'],
|
||||||
|
['artist__name', 'Artist name']
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.fetchFavorites(FAVORITES_URL)
|
this.fetchFavorites(FAVORITES_URL)
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
$('.ui.dropdown').dropdown()
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
updateQueryString: function () {
|
||||||
|
this.$router.replace({
|
||||||
|
query: {
|
||||||
|
page: this.page,
|
||||||
|
paginateBy: this.paginateBy,
|
||||||
|
ordering: this.getOrderingAsString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
fetchFavorites (url) {
|
fetchFavorites (url) {
|
||||||
var self = this
|
var self = this
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
let params = {
|
let params = {
|
||||||
favorites: 'true',
|
favorites: 'true',
|
||||||
page: this.page,
|
page: this.page,
|
||||||
page_size: this.paginateBy
|
page_size: this.paginateBy,
|
||||||
|
ordering: this.getOrderingAsString()
|
||||||
}
|
}
|
||||||
logger.default.time('Loading user favorites')
|
logger.default.time('Loading user favorites')
|
||||||
this.$http.get(url, {params: params}).then((response) => {
|
this.$http.get(url, {params: params}).then((response) => {
|
||||||
|
@ -86,6 +137,19 @@ export default {
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
page: function () {
|
page: function () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchFavorites(FAVORITES_URL)
|
||||||
|
},
|
||||||
|
paginateBy: function () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchFavorites(FAVORITES_URL)
|
||||||
|
},
|
||||||
|
orderingDirection: function () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchFavorites(FAVORITES_URL)
|
||||||
|
},
|
||||||
|
ordering: function () {
|
||||||
|
this.updateQueryString()
|
||||||
this.fetchFavorites(FAVORITES_URL)
|
this.fetchFavorites(FAVORITES_URL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,30 +63,31 @@ import $ from 'jquery'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import backend from '@/audio/backend'
|
import backend from '@/audio/backend'
|
||||||
import logger from '@/logging'
|
import logger from '@/logging'
|
||||||
|
|
||||||
|
import OrderingMixin from '@/components/mixins/Ordering'
|
||||||
|
import PaginationMixin from '@/components/mixins/Pagination'
|
||||||
import ArtistCard from '@/components/audio/artist/Card'
|
import ArtistCard from '@/components/audio/artist/Card'
|
||||||
import Pagination from '@/components/Pagination'
|
import Pagination from '@/components/Pagination'
|
||||||
|
|
||||||
const FETCH_URL = config.API_URL + 'artists/'
|
const FETCH_URL = config.API_URL + 'artists/'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
mixins: [OrderingMixin, PaginationMixin],
|
||||||
props: {
|
props: {
|
||||||
defaultOrdering: {type: String, required: false, default: '-creation_date'},
|
defaultQuery: {type: String, required: false, default: ''}
|
||||||
defaultQuery: {type: String, required: false, default: ''},
|
|
||||||
defaultPage: {required: false, default: 1},
|
|
||||||
defaultPaginateBy: {required: false, default: 12}
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
ArtistCard,
|
ArtistCard,
|
||||||
Pagination
|
Pagination
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
let defaultOrdering = this.getOrderingFromString(this.defaultOrdering)
|
let defaultOrdering = this.getOrderingFromString(this.defaultOrdering || '-creation_date')
|
||||||
return {
|
return {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
result: null,
|
result: null,
|
||||||
page: parseInt(this.defaultPage),
|
page: parseInt(this.defaultPage),
|
||||||
query: this.defaultQuery,
|
query: this.defaultQuery,
|
||||||
paginateBy: parseInt(this.defaultPaginateBy),
|
paginateBy: parseInt(this.defaultPaginateBy || 12),
|
||||||
orderingDirection: defaultOrdering.direction,
|
orderingDirection: defaultOrdering.direction,
|
||||||
ordering: defaultOrdering.field,
|
ordering: defaultOrdering.field,
|
||||||
orderingOptions: [
|
orderingOptions: [
|
||||||
|
@ -102,27 +103,13 @@ export default {
|
||||||
$('.ui.dropdown').dropdown()
|
$('.ui.dropdown').dropdown()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getOrderingFromString (s) {
|
|
||||||
let parts = s.split('-')
|
|
||||||
if (parts.length > 1) {
|
|
||||||
return {
|
|
||||||
direction: '-',
|
|
||||||
field: parts.slice(1).join('-')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
direction: '',
|
|
||||||
field: s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateQueryString: function () {
|
updateQueryString: function () {
|
||||||
this.$router.replace({
|
this.$router.replace({
|
||||||
query: {
|
query: {
|
||||||
query: this.query,
|
query: this.query,
|
||||||
page: this.page,
|
page: this.page,
|
||||||
paginateBy: this.paginateBy,
|
paginateBy: this.paginateBy,
|
||||||
ordering: [this.orderingDirection, this.ordering].join('')
|
ordering: this.getOrderingAsString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -134,7 +121,7 @@ export default {
|
||||||
page: this.page,
|
page: this.page,
|
||||||
page_size: this.paginateBy,
|
page_size: this.paginateBy,
|
||||||
name__icontains: this.query,
|
name__icontains: this.query,
|
||||||
ordering: [this.orderingDirection, this.ordering].join('')
|
ordering: this.getOrderingAsString()
|
||||||
}
|
}
|
||||||
logger.default.debug('Fetching artists')
|
logger.default.debug('Fetching artists')
|
||||||
this.$http.get(url, {params: params}).then((response) => {
|
this.$http.get(url, {params: params}).then((response) => {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
defaultOrdering: {type: String, required: false}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getOrderingFromString (s) {
|
||||||
|
let parts = s.split('-')
|
||||||
|
if (parts.length > 1) {
|
||||||
|
return {
|
||||||
|
direction: '-',
|
||||||
|
field: parts.slice(1).join('-')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
direction: '',
|
||||||
|
field: s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getOrderingAsString () {
|
||||||
|
return [this.orderingDirection, this.ordering].join('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
defaultPage: {required: false, default: 1},
|
||||||
|
defaultPaginateBy: {required: false}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -47,7 +47,11 @@ export default new Router({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/favorites',
|
path: '/favorites',
|
||||||
component: Favorites
|
component: Favorites,
|
||||||
|
props: (route) => ({
|
||||||
|
defaultOrdering: route.query.ordering,
|
||||||
|
defaultPage: route.query.page
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/library',
|
path: '/library',
|
||||||
|
|
Loading…
Reference in New Issue