Volume control from the web interface.

This commit is contained in:
Jim Driessen
2017-01-30 16:39:25 +01:00
parent e0ac7cf4ce
commit a5c2331bcf
9 changed files with 97 additions and 6 deletions

View File

@ -14,4 +14,6 @@ urlpatterns = [
url(r'^movedown', views.move_down),
url(r'^cancel', views.cancel),
url(r'^upload', views.upload),
url(r'^volumedown', views.volume_down),
url(r'^volumeup', views.volume_up),
]

View File

@ -11,7 +11,7 @@ from django.views.decorators.http import require_http_methods
from marietje.utils import song_to_dict, playlist_song_to_dict, send_to_bertha
from songs.models import Song
from queues.models import PlaylistSong
from queues.models import PlaylistSong, Queue, QueueCommand
from .forms import UploadForm
@ -185,3 +185,23 @@ def upload(request):
return JsonResponse({
'success': True
})
@require_http_methods(["POST"])
@login_required
def volume_down(request):
if not request.user.has_perm('queues.can_control_volume'):
return HttpResponseForbidden()
command = QueueCommand(queue=request.user.queue, command='volume_down')
command.save()
return JsonResponse({})
@require_http_methods(["POST"])
@login_required
def volume_up(request):
if not request.user.has_perm('queues.can_control_volume'):
return HttpResponseForbidden()
command = QueueCommand(queue=request.user.queue, command='volume_up')
command.save()
return JsonResponse({})

View File

@ -73,6 +73,14 @@ $(function () {
getSongs();
});
$('#volume-down').click(function(){
$.post('/api/volumedown', {csrfmiddlewaretoken: csrf_token});
});
$('#volume-up').click(function(){
$.post('/api/volumeup', {csrfmiddlewaretoken: csrf_token});
});
getSongs();
});

View File

@ -15,9 +15,15 @@ from .decorators import token_required
def queue(request):
queue = get_object_or_404(Queue, id=request.POST.get('queue'))
commands = queue.queuecommand_set.filter(executed=False)
for command in commands:
command.executed = True
command.save()
return JsonResponse({
'current_song': playlist_song_to_dict(queue.current_song(), True),
'queue': [playlist_song_to_dict(playlist_song, True) for playlist_song in queue.queue()[:1]]
'queue': [playlist_song_to_dict(playlist_song, True) for playlist_song in queue.queue()[:1]],
'commands': [command.command for command in commands]
})

View File

@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Queue, Playlist, PlaylistSong
from .models import Queue, Playlist, PlaylistSong, QueueCommand
admin.site.register(Playlist)
@ -9,3 +9,6 @@ admin.site.register(PlaylistSong)
@admin.register(Queue)
class OrderAdmin(admin.ModelAdmin):
list_display = ('name', 'playlist', 'random_playlist')
admin.site.register(QueueCommand)

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-30 13:48
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('queues', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='queue',
options={'permissions': (('can_skip', 'Can skip the currently playing song'), ('can_move', 'Can move all songs in the queue'), ('can_cancel', 'Can cancel all songs in the queue'), ('can_control_volume', 'Can control the volume of Marietje'))},
),
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-30 14:56
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('queues', '0002_auto_20170130_1348'),
]
operations = [
migrations.CreateModel(
name='QueueCommand',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('command', models.TextField()),
('executed', models.BooleanField(default=False)),
('queue', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='queues.Queue')),
],
),
]

View File

@ -63,6 +63,7 @@ class Queue(models.Model):
('can_skip', 'Can skip the currently playing song'),
('can_move', 'Can move all songs in the queue'),
('can_cancel', 'Can cancel all songs in the queue'),
('can_control_volume', 'Can control the volume of Marietje'),
)
name = models.TextField()
@ -138,5 +139,10 @@ class Queue(models.Model):
return self.name
class QueueCommand(models.Model):
queue = models.ForeignKey(
Queue,
on_delete=models.CASCADE,
)
command = models.TextField()
executed = models.BooleanField(default=False)

View File

@ -65,7 +65,9 @@
<td class="title"></td>
<td class="requestedby"></td>
<td class="timeleft"></td>
<td><a id="skip" href="#"></a></td>
<td>
<a id="skip" href="#"></a>{% if perms.queues.can_control_volume %}&nbsp;&nbsp;&nbsp;&nbsp;<a id="volume-down" class="glyphicon glyphicon-volume-down" href="#"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a id="volume-up" class="glyphicon glyphicon-volume-up" href="#"></a>{% endif %}
</td>
</tr>
</tbody>
</table>