From 6cf1b4bef229e405f19d12d31877af59737c17f1 Mon Sep 17 00:00:00 2001 From: oslomp Date: Sun, 16 Dec 2018 21:39:11 +0100 Subject: [PATCH] Fixes on arrows in the main screen --- marietje/api/views.py | 7 +++++++ marietje/marietje/static/js/queue.js | 13 ++++++++++--- marietje/queues/models.py | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/marietje/api/views.py b/marietje/api/views.py index 30e9871..a2bbe7e 100644 --- a/marietje/api/views.py +++ b/marietje/api/views.py @@ -201,7 +201,14 @@ def move_up(request): @require_http_methods(["POST"]) @api_auth_required def move_down(request): +# print('') +# print(request) +# print('') + ide=(request.POST.get('id')) +# print('') playlist_song = get_object_or_404(PlaylistSong, id=request.POST.get('id')) +# print(playlist_song) +# print('') if playlist_song.user != request.user and not request.user.has_perm('queues.can_move'): return HttpResponseForbidden() playlist_song.move_down() diff --git a/marietje/marietje/static/js/queue.js b/marietje/marietje/static/js/queue.js index 9282852..7b847ac 100644 --- a/marietje/marietje/static/js/queue.js +++ b/marietje/marietje/static/js/queue.js @@ -194,12 +194,18 @@ function renderQueue(playNextAt, now) { $('.queuebody').empty(); var timeToPlay = playNextAt - now; + var canDeletePrevious = false; $.each(queue, function (id, song) { var requestedBy = song.requested_by; var canDelete = song.can_move_down || canMoveSongs; - var canMoveDown = canDelete && id < queue.length - 1; + var canMoveUp = canMoveSongs && id != queue.length -5 || canDeletePrevious && id < queue.length - 5; + var canMoveDown = canDelete && id < queue.length - 6 || canMoveSongs && id < queue.length - 1 && id != queue.length - 6; var artist = song.song.artist.trim() === '' ? '?' : song.song.artist; var title = song.song.title.trim() === '' ? '?' : song.song.title; + var prevId = song.id - 1; + console.log(song.id, id); + console.log(song); + console.log(queue); showTime = showTimeToPlay ? (timeToPlay < 0 ? '' : timeToPlay.secondsToMMSS()) : (playNextAt < now ? '' : playNextAt.timestampToHHMMSS()) @@ -207,14 +213,15 @@ function renderQueue(playNextAt, now) + '' + title + '' + requestedBy + '' + showTime + '' + '        '); timeToPlay += parseInt(song.song.duration); + canDeletePrevious = canDelete if(playNextAt >= now) { playNextAt += parseInt(song.song.duration); diff --git a/marietje/queues/models.py b/marietje/queues/models.py index 7f765eb..c027f5d 100644 --- a/marietje/queues/models.py +++ b/marietje/queues/models.py @@ -53,8 +53,12 @@ class PlaylistSong(models.Model): self.switch_order(other_song) def move_down(self): - other_song = PlaylistSong.objects.filter(playlist=self.playlist, id__gt=self.id).order_by('id').first() - self.switch_order(other_song) + other_song = PlaylistSong.objects.filter(playlist=self.playlist, id__gt=self.id).first() + old_id = self.id + self.id = other_song.id + other_song.id = old_id + self.save() + other_song.save() def switch_order(self, other_song): old_id = self.id