From 3d7168a1c8bdc09826d1eca43d6095471127dcf5 Mon Sep 17 00:00:00 2001 From: Wouter van Wijk Date: Sat, 22 Jun 2013 01:22:45 +0200 Subject: [PATCH] better queue popup, next track fix --- webclient/index.html | 16 +++--- webclient/js/controls.js | 30 +++++++---- webclient/js/gui.js | 103 +++++++++++++++++++------------------ webclient/js/process_ws.js | 6 --- 4 files changed, 81 insertions(+), 74 deletions(-) diff --git a/webclient/index.html b/webclient/index.html index a272942..b13b2d7 100755 --- a/webclient/index.html +++ b/webclient/index.html @@ -73,20 +73,20 @@
    -
  • +
  • + Play
  • -
  • +
  • Play Track Next
  • -
  • - Add track to bottom of queue +
  • + Add Track to Bottom of Queue
  • -
  • - Add all tracks to bottom of queue +
  • + Add all to Bottom of Queue
  • Show Album diff --git a/webclient/js/controls.js b/webclient/js/controls.js index 7f1bf11..d7d16fe 100755 --- a/webclient/js/controls.js +++ b/webclient/js/controls.js @@ -17,6 +17,7 @@ function playTrack(addtoqueue) { var trackslist = new Array(); var track, tracksbefore, tracksafter; var tracks = getTracksFromUri(playlisturi); + console.log(tracks); if (tracks) { if (!addtoqueue) { clearQueue(); @@ -39,20 +40,27 @@ function playTrack(addtoqueue) { } //find track that was selected - for (var i = 0; i < tracks.length; i++) { - if (tracks[i].uri == uri) { + for (var selected = 0; selected < tracks.length; selected++) { + if (tracks[selected].uri == uri) { break; } } -//options +//find track that is playing + for (var playing = 0; playing < currentplaylist.length; playing++) { + if (currentplaylist[playing].uri == songdata.uri) { + break; + } + } + +//switch popup options switch (addtoqueue) { case ADD_THIS_BOTTOM: - mopidy.tracklist.add(tracks.slice(i, i + 1)); + mopidy.tracklist.add(tracks.slice(selected, selected + 1)); showLoading(false); return false; case PLAY_NEXT: - mopidy.tracklist.add(tracks.slice(i, i + 1), 1); + mopidy.tracklist.add(tracks.slice(selected, selected + 1), playing + 1); showLoading(false); return false; case ADD_ALL_BOTTOM: @@ -62,15 +70,15 @@ function playTrack(addtoqueue) { } // play now: first add track to be played, then the other tracks - mopidy.tracklist.add(tracks.slice(i, i + 1) ); + mopidy.tracklist.add(tracks.slice(selected, selected + 1) ); mopidy.playback.play(); - //wait 2 seconds before adding the rest to give server the time to start playing + //wait 1 second before adding the rest to give server the time to start playing setTimeout(function() { - mopidy.tracklist.add(tracks.slice(0, i), 0); - if (i < tracks.length) { - mopidy.tracklist.add(tracks.slice(i + 1) ); + mopidy.tracklist.add(tracks.slice(0, selected), 0); + if (selected < tracks.length) { + mopidy.tracklist.add(tracks.slice(selected + 1) ); } - }, (2000)); + }, (1000)); showLoading(false); return false; } diff --git a/webclient/js/gui.js b/webclient/js/gui.js index 13eee84..1c5a457 100755 --- a/webclient/js/gui.js +++ b/webclient/js/gui.js @@ -76,48 +76,11 @@ function resizeMb() { } function setSongInfo(data) { - if (data) { - songdata = data; - } else { - data = songdata; - } - artistshtml = ''; - artiststext = ''; - - if ( !data.name || (data.name == '')) { + if (!data) { return; } + if (data.name == '') { return; }; - for (var j = 0; j < data.artists.length; j++) { - artistshtml += '' + data.artists[j].name + ''; - artiststext += data.artists[j].name; - if (j != data.artists.length - 1) { - artistshtml += ', '; - artiststext += ', '; - } - } - - - if (data.album) { - $("#modalalbum").html('Album: ' + data.album.name + ''); - } - $("#modalname").html(data.name); - - getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge'); - - var arttmp = 'Artist'; - - if (data.artists.length > 1) { - arttmp += 's'; - } - $("#modalartist").html(arttmp + ': ' + artistshtml); - - $("#trackslider").attr("min", 0); - songlength = data.length; - $("#trackslider").attr("max", data.length); - $("#songlength").html(timeFromSeconds(data.length / 1000)); - - resizeMb(); //update styles of listviews $('#currenttable li').each(function() { $(this).removeClass("currenttrack"); @@ -150,6 +113,46 @@ function setSongInfo(data) { $(this).addClass('currenttrack2'); } }); + + if (songdata.name == data.name) { + return; + } + if (data) { + songdata = data; + } else { + data = songdata; + } + artistshtml = ''; + artiststext = ''; + + for (var j = 0; j < data.artists.length; j++) { + artistshtml += '' + data.artists[j].name + ''; + artiststext += data.artists[j].name; + if (j != data.artists.length - 1) { + artistshtml += ', '; + artiststext += ', '; + } + } + + if (data.album) { + $("#modalalbum").html('Album: ' + data.album.name + ''); + } + $("#modalname").html(data.name); + getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge'); + + var arttmp = 'Artist'; + + if (data.artists.length > 1) { + arttmp += 's'; + } + $("#modalartist").html(arttmp + ': ' + artistshtml); + + $("#trackslider").attr("min", 0); + songlength = data.length; + $("#trackslider").attr("max", data.length); + $("#songlength").html(timeFromSeconds(data.length / 1000)); + + resizeMb(); } /*************** @@ -195,11 +198,12 @@ function popupTracks(e, listuri, trackuri) { // this makes the viewport of the window resize somehow $('#popupArtistsLv').listview("refresh"); } - var hash = getHash(); - if (hash == 'current') { - $("#liaddtobottom").hide(); + var hash = document.location.hash.split('?'); + var divid = hash[0].substr(1); + if (divid == 'current') { + $(".addqueue").hide(); } else { - $("#liaddtobottom").show(); + $(".addqueue").show(); } $('#popupTracks').data("list", listuri).data("track", trackuri).popup("open", { @@ -315,7 +319,7 @@ function initSocketevents() { $(document).ready(function() { //check for websockets if (!window.WebSocket) { - switchContent("current"); + switchContent("playlists"); $('#playlistspane').html('

    Old Browser

    Sorry. Your browser isn\'t modern enough for this webapp. Modern versions of Chrome, Firefox, Safari all will do. Maybe Opera and Internet Explorer 10 also work, but it\'s not tested.

    '); exit; } @@ -330,7 +334,7 @@ $(document).ready(function() { resetSong(); if (location.hash.length < 2) { - switchContent("current"); + switchContent("playlists"); } initgui = false; @@ -371,7 +375,7 @@ function switchContent(divid, uri) { } //update timer -function updateStatusOfAll() { +function updateTimer() { mopidy.playback.getCurrentTrack().then(processCurrenttrack, console.error); mopidy.playback.getTimePosition().then(processCurrentposition, console.error); //TODO check offline? @@ -391,15 +395,16 @@ function updateStatusOfAll() { function locationHashChanged() { var hash = document.location.hash.split('?'); + //remove # + var divid = hash[0].substr(1); var uri = hash[1]; - $('#navcurrent a').removeClass('ui-state-active ui-state-persist ui-btn-active'); $('#navplaylists a').removeClass('ui-state-active ui-state-persist ui-btn-active'); $('#navsearch a').removeClass('ui-state-active ui-state-persist ui-btn-active'); $('.pane').hide(); - $('#' + getHash() + 'pane').show(); + $('#' + divid + 'pane').show(); - switch(hash) { + switch(divid) { case 'current': $('#navcurrent a').addClass('ui-state-active ui-state-persist ui-btn-active'); break; diff --git a/webclient/js/process_ws.js b/webclient/js/process_ws.js index 7bcf8b9..4bf3578 100755 --- a/webclient/js/process_ws.js +++ b/webclient/js/process_ws.js @@ -72,13 +72,7 @@ function processGetPlaylists(resultArr) { }; $('#playlistslist').empty(); $('#playlistslist').html(tmp); - // $('#playlistslist').listview('refresh'); scrollToTracklist(); -/* if (isMobileWebkit) { - playlistslistScroll.refresh(); - } -*/ - console.log('pl'); showLoading(false); }