Merge branch '6-toggle-column-plays-at-with-plays-in' into 'master'

Toggle column plays at with plays in.

Closes #6

See merge request !3
This commit is contained in:
Jim Driessen
2017-05-02 12:42:19 +02:00
2 changed files with 52 additions and 26 deletions

View File

@ -8,9 +8,14 @@ var songs = [];
var refreshing = false; var refreshing = false;
var iteration = 0; var iteration = 0;
var requestViewOpen = false; var requestViewOpen = false;
var showTimeToPlay = true;
var noRemove = false;
$(function () { $(function () {
$('.pagesize').val(Cookies.get('pagesize')); $('.pagesize').val(Cookies.get('pagesize'));
showTimeToPlay = (Cookies.get('showtimetoplay') || '1') === '1' ? true : false;
$('#queue-time-header').text(showTimeToPlay ? 'Plays In' : 'Plays At');
refreshQueue(); refreshQueue();
setInterval(updateTime, 1000); setInterval(updateTime, 1000);
@ -107,6 +112,12 @@ $(function () {
} }
}); });
$('#queue-time-header').click(function(){
showTimeToPlay = !showTimeToPlay;
$('#queue-time-header').text(showTimeToPlay ? 'Plays In' : 'Plays At');
Cookies.set('showtimetoplay', showTimeToPlay ? '1' : '0');
});
getSongs(); getSongs();
}); });
@ -142,6 +153,7 @@ function updateTime()
if (secondsLeft >= 0) if (secondsLeft >= 0)
{ {
$('.currentsong .time-left').text(secondsLeft.secondsToHHMMSS()); $('.currentsong .time-left').text(secondsLeft.secondsToHHMMSS());
renderQueue(secondsLeft + timestamp, timestamp);
} }
// Refresh every ten seconds, or if the song has ended in the last ten // Refresh every ten seconds, or if the song has ended in the last ten
@ -152,6 +164,43 @@ function updateTime()
} }
} }
function renderQueue(playNextAt, now)
{
$('.queuebody').empty();
var timeToPlay = playNextAt - now;
var firstSongInQueue = true;
$.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 artist = song.song.artist.trim() === '' ? '?' : song.song.artist;
var title = song.song.title.trim() === '' ? '?' : song.song.title;
if (firstSongInQueue === true) {
firstSongInQueue = false;
} else {
timeToPlay += song.song.duration;
}
showTime = showTimeToPlay ? (timeToPlay < 0 ? '' : timeToPlay.secondsToHHMMSS()) : (playNextAt < now ? '' : playNextAt.timestampToHHMMSS())
$('.queuebody:last-child').append('<tr><td class="artist">' + artist
+ '</td><td class="title">' + title + '</td><td class="hidden-xs requested-by">' + requestedBy
+ '</td><td class="hidden-xs plays-at">' + showTime
+ '</td><td>' + '<a href="#" class="glyphicon glyphicon-arrow-up'
+ (canMoveSongs && id !== 0 ? '' : ' invisible')
+ '" onclick="return moveUp(' + song.id
+ ')"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="glyphicon glyphicon-arrow-down'
+ (canMoveDown ? '' : ' invisible') + '" onclick="return moveDown('
+ song.id + ')"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="glyphicon glyphicon-trash'
+ (canDelete ? '' : ' invisible') + '" onclick="return cancelSong('
+ song.id + ')"></a></td></tr>');
if(playNextAt >= now)
{
playNextAt += parseInt(song.song.duration);
}
});
}
function refreshQueue() function refreshQueue()
{ {
refreshing = true; refreshing = true;
@ -181,30 +230,7 @@ function refreshQueue()
$('#skip').removeClass('glyphicon glyphicon-fast-forward'); $('#skip').removeClass('glyphicon glyphicon-fast-forward');
} }
$('.queuebody').empty(); renderQueue(playNextAt, now);
$.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 artist = song.song.artist.trim() === '' ? '?' : song.song.artist;
var title = song.song.title.trim() === '' ? '?' : song.song.title;
$('.queuebody:last-child').append('<tr><td class="artist">' + artist
+ '</td><td class="title">' + title + '</td><td class="hidden-xs requested-by">' + requestedBy
+ '</td><td class="hidden-xs plays-at">' + (playNextAt < now ? '' : playNextAt.timestampToHHMMSS())
+ '</td><td>' + '<a href="#" class="glyphicon glyphicon-arrow-up'
+ (canMoveSongs && id !== 0 ? '' : ' invisible')
+ '" onclick="return moveUp(' + song.id
+ ')"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="glyphicon glyphicon-arrow-down'
+ (canMoveDown ? '' : ' invisible') + '" onclick="return moveDown('
+ song.id + ')"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="glyphicon glyphicon-trash'
+ (canDelete ? '' : ' invisible') + '" onclick="return cancelSong('
+ song.id + ')"></a></td></tr>');
if(playNextAt >= now)
{
playNextAt += parseInt(song.song.duration);
}
});
updateTime(); updateTime();
refreshing = false; refreshing = false;
@ -271,7 +297,7 @@ Number.prototype.secondsToHHMMSS = function () {
var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60); var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) { if (hours < 10 && hours >= 0) {
hours = '0' + hours; hours = '0' + hours;
} }
if (minutes < 10) { if (minutes < 10) {

View File

@ -75,7 +75,7 @@
<th class="col-md-4">Artist</th> <th class="col-md-4">Artist</th>
<th class="col-md-4">Title</th> <th class="col-md-4">Title</th>
<th class="col-md-2 hidden-xs">Requested By</th> <th class="col-md-2 hidden-xs">Requested By</th>
<th class="col-md-1 hidden-xs">Plays At</th> <th id="queue-time-header" class="col-md-1 hidden-xs">Plays At</th>
<th class="col-md-1 control-icons">Control</th> <th class="col-md-1 control-icons">Control</th>
</tr> </tr>
</thead> </thead>