Skip to content

Commit

Permalink
Updated settings view for nicer ui wrt alwayson.
Browse files Browse the repository at this point in the history
  • Loading branch information
chepazzo committed Sep 10, 2016
1 parent 3b0ab78 commit 6210856
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions config/jukeberry.example.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[GLOBAL]
DEBUG=True
THREADED=True
THREADED=False
SSL=False
PLAYER=omxplayer
#PLAYER=mpg123
LIB=/var/media/music/
LIB=/var/media/music/Tomahawk/

[SSL]
SSL_CRT=/path/to/crt.crt
Expand Down
8 changes: 5 additions & 3 deletions jukeberry/jukebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Jukebox(object):
Dict Structure:
status (bool): Is the Jukebox always on? If so, then a random song will play
if the queue is empty.
filter (Dict[str,str]): This will filter the list of songs available to be
filters (List[Dict[str,str]]): This will filter the list of songs available to be
randomly selected to play (if the filter is on), where the ``key`` is an
attribute of ``catalog.Song``.
Expand All @@ -84,7 +84,7 @@ def __init__(self,player=None,medialib=None):
self.playlist = []
self.alwayson = {
"status":False,
"filter":{}
"filters":[]
}
self.currsong = None
self.proc = None
Expand Down Expand Up @@ -146,7 +146,9 @@ def play_next_song(self):
if song is None:
if self.alwayson['status']:
print("No next song ... finding random.")
song = self.songlist.get_random_song(**self.alwayson['filter'])
kwargs = {self.alwayson['filters'][0]['attr']:self.alwayson['filters'][0]['value']}
print("kwargs = ", kwargs)
song = self.songlist.get_random_song(**kwargs)
filename = None
if type(song) == catalog.Song:
filename = song.filename
Expand Down
4 changes: 2 additions & 2 deletions jukeberry/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def set_alwayson():
else:
if 'status' in content.keys():
JUKE.alwayson['status'] = content['status']
if 'filter' in content.keys():
JUKE.alwayson['filter'] = content['filter']
if 'filters' in content.keys():
JUKE.alwayson['filters'] = content['filters']
return jsonify(succ(value=JUKE.alwayson))

@app.route('/add', methods = ['POST'])
Expand Down
30 changes: 26 additions & 4 deletions jukeberry/templates/JukeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ jukeApp.config(['$interpolateProvider', function ($interpolateProvider) {

jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
// data
$scope.alwayson = false;
$scope.alwayson = {
"status":false,
"filters":[]
};
$scope.tiles="#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$scope.songs = [];
$scope.artists = [];
Expand Down Expand Up @@ -41,6 +44,7 @@ jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
if (angular.isDefined(auto)) { return; }
console.log('turning on auto refresh.');
auto = $interval(function() {
$scope.get_alwayson();
$scope.get_playlist();
$scope.get_currsong();
},10000);
Expand All @@ -60,7 +64,7 @@ jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
//$location.replace();
window.open(url);
};
$scope.setalwayson = function(action) {
$scope.set_alwayson = function(action) {
// The problem with this is that turning the feature off
// resets the filter to the current attr:value.
// This means that to put it back, you have to navigate first
Expand All @@ -71,10 +75,12 @@ jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
var filter = {};
var data = {
"status":action,
"filter":filter
"filters":[filter]
};
$scope.alwayson = data;
if (attr != '' && value != '') {
filter[attr] = value;
filter['attr'] = attr;
filter['value'] = value;
}
var url = '{{url_for('set_alwayson')}}';
var method = 'POST';
Expand All @@ -89,6 +95,21 @@ jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
console.log(status);
});
};
$scope.get_alwayson = function() {
var url = '{{url_for('get_alwayson')}}';
var method = 'GET';
$http(
{method: method, url: url}
).success(function(data, status) {
$scope.alwayson = data.data;
console.log(data.data);
console.log(status);
}).error(function(data, status) {
console.log('ERROR');
console.log(data);
console.log(status);
});
};
$scope.play = function(artist,title) {
var data = {'artist':artist,'title':title};
var url = '{{url_for('add')}}';
Expand Down Expand Up @@ -222,6 +243,7 @@ jukeApp.controller('JukeCtrl', function ($scope,$http,$interval,$location) {
$scope.get_playlist();
$scope.get_currsong();
$scope.get_songs();
$scope.get_alwayson();
});

jukeApp.filter('secs2hms', function() {
Expand Down
24 changes: 17 additions & 7 deletions jukeberry/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,33 @@
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='jukeberry.css')}}" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="/JukeCtrl.js"></script>

<style>
#alwayson .active { color:red; }
#alwayson .button {
margin:2px;
}
</style>

</head>
<body>
<div id='head'>
<div id='title'>Jukeberry Settings</div>
</div><!-- id='head' -->
<div id='body' class='raspi' ng-controller="JukeCtrl">
<div id='alwayson'>
<div id='seton' class='clickable button'
ng-click='setalwayson(true);'>
on</div>
<div id='setoff' class='clickable button'
ng-click='setalwayson(false);'>
off</div>
<span id='seton' class='clickable button'
ng-click='set_alwayson(true);'
ng-class='{"active":alwayson.status}'
>on</span>
<span id='setoff' class='clickable button'
ng-click='set_alwayson(false);'
ng-class='{"active":!alwayson.status}'
>off</span>
</div>

<div>
{[currattr]}:{[currvalue]}
{[alwayson.filters.length > 0 ? alwayson.filters : "Everything"]}
</div>

<select ng-model="currattr">
Expand Down

0 comments on commit 6210856

Please sign in to comment.