Merge branch 'feature/50-browsing' into 'develop'
Feature/50 browsing Closes #50 See merge request funkwhale/funkwhale!32
This commit is contained in:
commit
e1817cc5c2
|
@ -10,6 +10,8 @@ Changelog
|
||||||
- Shortcuts: avoid collisions between shortcuts by using the exact modifier (#53)
|
- Shortcuts: avoid collisions between shortcuts by using the exact modifier (#53)
|
||||||
- Player: Added looping controls and shortcuts (#52)
|
- Player: Added looping controls and shortcuts (#52)
|
||||||
- Player: Added shuffling controls and shortcuts (#52)
|
- Player: Added shuffling controls and shortcuts (#52)
|
||||||
|
- Favorites: can now modify the ordering of track list (#50)
|
||||||
|
- Library: can now search/reorder results on artist browsing view (#50)
|
||||||
|
|
||||||
|
|
||||||
0.2.6 (2017-12-15)
|
0.2.6 (2017-12-15)
|
||||||
|
|
|
@ -31,3 +31,9 @@ if settings.DEBUG:
|
||||||
url(r'^404/$', default_views.page_not_found),
|
url(r'^404/$', default_views.page_not_found),
|
||||||
url(r'^500/$', default_views.server_error),
|
url(r'^500/$', default_views.server_error),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
|
if 'debug_toolbar' in settings.INSTALLED_APPS:
|
||||||
|
import debug_toolbar
|
||||||
|
urlpatterns += [
|
||||||
|
url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||||
|
]
|
||||||
|
|
|
@ -8,5 +8,5 @@ class ArtistFilter(django_filters.FilterSet):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Artist
|
model = models.Artist
|
||||||
fields = {
|
fields = {
|
||||||
'name': ['exact', 'iexact', 'startswith']
|
'name': ['exact', 'iexact', 'startswith', 'icontains']
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,14 @@ class TagSerializer(serializers.ModelSerializer):
|
||||||
class SimpleArtistSerializer(serializers.ModelSerializer):
|
class SimpleArtistSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Artist
|
model = models.Artist
|
||||||
fields = ('id', 'mbid', 'name')
|
fields = ('id', 'mbid', 'name', 'creation_date')
|
||||||
|
|
||||||
|
|
||||||
class ArtistSerializer(serializers.ModelSerializer):
|
class ArtistSerializer(serializers.ModelSerializer):
|
||||||
tags = TagSerializer(many=True, read_only=True)
|
tags = TagSerializer(many=True, read_only=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Artist
|
model = models.Artist
|
||||||
fields = ('id', 'mbid', 'name', 'tags')
|
fields = ('id', 'mbid', 'name', 'tags', 'creation_date')
|
||||||
|
|
||||||
|
|
||||||
class TrackFileSerializer(serializers.ModelSerializer):
|
class TrackFileSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -47,16 +47,15 @@ class TagViewSetMixin(object):
|
||||||
class ArtistViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
|
class ArtistViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = (
|
queryset = (
|
||||||
models.Artist.objects.all()
|
models.Artist.objects.all()
|
||||||
.order_by('name')
|
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
'albums__tracks__files',
|
'albums__tracks__files',
|
||||||
|
'albums__tracks__artist',
|
||||||
'albums__tracks__tags'))
|
'albums__tracks__tags'))
|
||||||
serializer_class = serializers.ArtistSerializerNested
|
serializer_class = serializers.ArtistSerializerNested
|
||||||
permission_classes = [ConditionalAuthentication]
|
permission_classes = [ConditionalAuthentication]
|
||||||
search_fields = ['name']
|
search_fields = ['name']
|
||||||
ordering_fields = ('creation_date', 'name')
|
|
||||||
filter_class = filters.ArtistFilter
|
filter_class = filters.ArtistFilter
|
||||||
|
ordering_fields = ('id', 'name', 'creation_date')
|
||||||
|
|
||||||
class AlbumViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
|
class AlbumViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = (
|
queryset = (
|
||||||
|
@ -96,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()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<sidebar></sidebar>
|
<sidebar></sidebar>
|
||||||
<router-view></router-view>
|
<router-view :key="$route.fullPath"></router-view>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div id="footer" class="ui vertical footer segment">
|
<div id="footer" class="ui vertical footer segment">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,40 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div v-if="isLoading" class="ui vertical segment">
|
<div class="ui vertical stripe segment">
|
||||||
<div :class="['ui', 'centered', 'active', 'inline', 'loader']"></div>
|
|
||||||
</div>
|
|
||||||
<div v-if="result" class="ui vertical stripe segment">
|
|
||||||
<h2 class="ui header">Browsing artists</h2>
|
<h2 class="ui header">Browsing artists</h2>
|
||||||
<div class="ui stackable three column grid">
|
<div :class="['ui', {'loading': isLoading}, 'form']">
|
||||||
|
<div class="fields">
|
||||||
|
<div class="field">
|
||||||
|
<label>Search</label>
|
||||||
|
<input type="text" v-model="query" placeholder="Enter an artist name..."/>
|
||||||
|
</div>
|
||||||
|
<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>
|
||||||
|
<div class="ui hidden divider"></div>
|
||||||
|
<div v-if="result" class="ui stackable three column grid">
|
||||||
<div
|
<div
|
||||||
v-if="result.results.length > 0"
|
v-if="result.results.length > 0"
|
||||||
v-for="artist in result.results"
|
v-for="artist in result.results"
|
||||||
|
@ -28,41 +57,71 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import _ from 'lodash'
|
||||||
|
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: {
|
||||||
|
defaultQuery: {type: String, required: false, default: ''}
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
ArtistCard,
|
ArtistCard,
|
||||||
Pagination
|
Pagination
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
let defaultOrdering = this.getOrderingFromString(this.defaultOrdering || '-creation_date')
|
||||||
return {
|
return {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
result: null,
|
result: null,
|
||||||
page: 1,
|
page: parseInt(this.defaultPage),
|
||||||
orderBy: 'name',
|
query: this.defaultQuery,
|
||||||
paginateBy: 12
|
paginateBy: parseInt(this.defaultPaginateBy || 12),
|
||||||
|
orderingDirection: defaultOrdering.direction,
|
||||||
|
ordering: defaultOrdering.field,
|
||||||
|
orderingOptions: [
|
||||||
|
['creation_date', 'Creation date'],
|
||||||
|
['name', 'Name']
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.fetchData()
|
this.fetchData()
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
$('.ui.dropdown').dropdown()
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchData () {
|
updateQueryString: function () {
|
||||||
|
this.$router.replace({
|
||||||
|
query: {
|
||||||
|
query: this.query,
|
||||||
|
page: this.page,
|
||||||
|
paginateBy: this.paginateBy,
|
||||||
|
ordering: this.getOrderingAsString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fetchData: _.debounce(function () {
|
||||||
var self = this
|
var self = this
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
let url = FETCH_URL
|
let url = FETCH_URL
|
||||||
let params = {
|
let params = {
|
||||||
page: this.page,
|
page: this.page,
|
||||||
page_size: this.paginateBy,
|
page_size: this.paginateBy,
|
||||||
order_by: 'name'
|
name__icontains: this.query,
|
||||||
|
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) => {
|
||||||
|
@ -76,13 +135,30 @@ export default {
|
||||||
})
|
})
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
})
|
})
|
||||||
},
|
}, 500),
|
||||||
selectPage: function (page) {
|
selectPage: function (page) {
|
||||||
this.page = page
|
this.page = page
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
page () {
|
page () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
paginateBy () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
ordering () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
orderingDirection () {
|
||||||
|
this.updateQueryString()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
query () {
|
||||||
|
this.updateQueryString()
|
||||||
this.fetchData()
|
this.fetchData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<router-link v-if="auth.user.availablePermissions['import.launch']" class="ui item" to="/library/import/batches">Import batches</router-link>
|
<router-link v-if="auth.user.availablePermissions['import.launch']" class="ui item" to="/library/import/batches">Import batches</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<router-view></router-view>
|
<router-view :key="$route.fullPath"></router-view>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -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,14 +47,28 @@ 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',
|
||||||
component: Library,
|
component: Library,
|
||||||
children: [
|
children: [
|
||||||
{ path: '', component: LibraryHome },
|
{ path: '', component: LibraryHome },
|
||||||
{ path: 'artists/', name: 'library.artists.browse', component: LibraryArtists },
|
{
|
||||||
|
path: 'artists/',
|
||||||
|
name: 'library.artists.browse',
|
||||||
|
component: LibraryArtists,
|
||||||
|
props: (route) => ({
|
||||||
|
defaultOrdering: route.query.ordering,
|
||||||
|
defaultQuery: route.query.query,
|
||||||
|
defaultPaginateBy: route.query.paginateBy,
|
||||||
|
defaultPage: route.query.page
|
||||||
|
})
|
||||||
|
},
|
||||||
{ path: 'artists/:id', name: 'library.artists.detail', component: LibraryArtist, props: true },
|
{ path: 'artists/:id', name: 'library.artists.detail', component: LibraryArtist, props: true },
|
||||||
{ path: 'albums/:id', name: 'library.albums.detail', component: LibraryAlbum, props: true },
|
{ path: 'albums/:id', name: 'library.albums.detail', component: LibraryAlbum, props: true },
|
||||||
{ path: 'tracks/:id', name: 'library.tracks.detail', component: LibraryTrack, props: true },
|
{ path: 'tracks/:id', name: 'library.tracks.detail', component: LibraryTrack, props: true },
|
||||||
|
|
Loading…
Reference in New Issue