Merge branch 'feature/refresh_queue' into 'master'

Update time only instead of rendering the whole queue every second.

See merge request !10
This commit is contained in:
Jim Driessen
2017-09-04 15:35:42 +02:00

View File

@ -158,7 +158,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); refreshSeconds(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
@ -173,7 +173,6 @@ function renderQueue(playNextAt, now)
{ {
$('.queuebody').empty(); $('.queuebody').empty();
var timeToPlay = playNextAt - now; var timeToPlay = playNextAt - now;
var firstSongInQueue = true;
$.each(queue, function (id, song) { $.each(queue, function (id, song) {
var requestedBy = song.requested_by; var requestedBy = song.requested_by;
var canDelete = song.can_move_down || canMoveSongs; var canDelete = song.can_move_down || canMoveSongs;
@ -238,6 +237,19 @@ function refreshQueue()
}); });
} }
function refreshSeconds(playNextAt, now)
{
if(!showTimeToPlay) {
return;
}
var timeToPlay = playNextAt - now;
times = $('.plays-at');
$.each(queue, function (id, song) {
$(times[id]).text(timeToPlay < 0 ? '' : timeToPlay.secondsToHHMMSS());
timeToPlay += parseInt(song.song.duration);
});
}
function getSongs() function getSongs()
{ {
var all = $('#search-all').val(); var all = $('#search-all').val();