From 45152101625473d6c74a3eb91b382a4efa221a8f Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 12 Dec 2017 22:58:17 +0100 Subject: [PATCH] better pagination on favorites --- api/funkwhale_api/music/fake_data.py | 22 +++++++++ api/funkwhale_api/music/tests/factories.py | 6 +-- front/package.json | 1 + front/src/components/Pagination.vue | 52 ++++++++++++++++++++++ front/src/components/favorites/List.vue | 27 ++++++++--- 5 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 api/funkwhale_api/music/fake_data.py create mode 100644 front/src/components/Pagination.vue diff --git a/api/funkwhale_api/music/fake_data.py b/api/funkwhale_api/music/fake_data.py new file mode 100644 index 000000000..ef5eaf4be --- /dev/null +++ b/api/funkwhale_api/music/fake_data.py @@ -0,0 +1,22 @@ +""" +Populates the database with fake data +""" +import random + +from funkwhale_api.music import models +from funkwhale_api.music.tests import factories + + +def create_data(count=25): + artists = factories.ArtistFactory.create_batch(size=count) + for artist in artists: + print('Creating data for', artist) + albums = factories.AlbumFactory.create_batch( + artist=artist, size=random.randint(1, 5)) + for album in albums: + factories.TrackFileFactory.create_batch( + track__album=album, size=random.randint(3, 18)) + + +if __name__ == '__main__': + main() diff --git a/api/funkwhale_api/music/tests/factories.py b/api/funkwhale_api/music/tests/factories.py index d4ec04810..ea680b3bd 100644 --- a/api/funkwhale_api/music/tests/factories.py +++ b/api/funkwhale_api/music/tests/factories.py @@ -5,7 +5,7 @@ SAMPLES_PATH = os.path.dirname(os.path.abspath(__file__)) class ArtistFactory(factory.django.DjangoModelFactory): - name = factory.Sequence(lambda n: 'artist-{0}'.format(n)) + name = factory.Faker('name') mbid = factory.Faker('uuid4') class Meta: @@ -13,7 +13,7 @@ class ArtistFactory(factory.django.DjangoModelFactory): class AlbumFactory(factory.django.DjangoModelFactory): - title = factory.Sequence(lambda n: 'album-{0}'.format(n)) + title = factory.Faker('sentence', nb_words=3) mbid = factory.Faker('uuid4') release_date = factory.Faker('date') cover = factory.django.ImageField() @@ -24,7 +24,7 @@ class AlbumFactory(factory.django.DjangoModelFactory): class TrackFactory(factory.django.DjangoModelFactory): - title = factory.Sequence(lambda n: 'track-{0}'.format(n)) + title = factory.Faker('sentence', nb_words=3) mbid = factory.Faker('uuid4') album = factory.SubFactory(AlbumFactory) artist = factory.SelfAttribute('album.artist') diff --git a/front/package.json b/front/package.json index 7cec50319..cc6869267 100644 --- a/front/package.json +++ b/front/package.json @@ -16,6 +16,7 @@ "dependencies": { "dateformat": "^2.0.0", "js-logger": "^1.3.0", + "lodash": "^4.17.4", "semantic-ui-css": "^2.2.10", "vue": "^2.3.3", "vue-resource": "^1.3.4", diff --git a/front/src/components/Pagination.vue b/front/src/components/Pagination.vue new file mode 100644 index 000000000..3ac7c59af --- /dev/null +++ b/front/src/components/Pagination.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/front/src/components/favorites/List.vue b/front/src/components/favorites/List.vue index f7972a07c..053f62bc6 100644 --- a/front/src/components/favorites/List.vue +++ b/front/src/components/favorites/List.vue @@ -12,11 +12,14 @@
- - - - +
+ +
@@ -28,13 +31,15 @@ import config from '@/config' import favoriteTracks from '@/favorites/tracks' import TrackTable from '@/components/audio/track/Table' import RadioButton from '@/components/radios/Button' +import Pagination from '@/components/Pagination' const FAVORITES_URL = config.API_URL + 'tracks/' export default { components: { TrackTable, - RadioButton + RadioButton, + Pagination }, data () { return { @@ -42,6 +47,7 @@ export default { isLoading: false, nextLink: null, previousLink: null, + page: 1, favoriteTracks } }, @@ -53,7 +59,8 @@ export default { var self = this this.isLoading = true let params = { - favorites: 'true' + favorites: 'true', + page: this.page } logger.default.time('Loading user favorites') this.$http.get(url, {params: params}).then((response) => { @@ -68,6 +75,14 @@ export default { logger.default.timeEnd('Loading user favorites') self.isLoading = false }) + }, + selectPage: function (page) { + this.page = page + } + }, + watch: { + page: function () { + this.fetchFavorites(FAVORITES_URL) } } }