From e3eddf2e288d343ed0fe51f18bd619ee616f5bbd Mon Sep 17 00:00:00 2001 From: jcass Date: Sat, 18 Feb 2017 09:04:11 +0200 Subject: [PATCH 1/4] Ignore calls to locationHashChanged untill page has finished loading. Fixes #230. --- README.rst | 1 + mopidy_musicbox_webclient/static/index.html | 8 +++---- .../static/js/functionsvars.js | 2 +- mopidy_musicbox_webclient/static/js/gui.js | 23 ++++++++++++------- .../static/js/library.js | 8 +++---- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index 7bb0b8b..60736f2 100644 --- a/README.rst +++ b/README.rst @@ -130,6 +130,7 @@ v2.4.0 (UNRELEASED) - The last scroll position is now always saved when navigating between pages or browsing the library. (Fixes: `#73 `_, `#93 `_). - Playlists will now list tracks even if they are no longer available in the library. (Fixes: `#226 `_). +- Refreshing album or artist info pages no longer raises an exception. (Fixes: `#230 `_). v2.3.0 (2016-05-15) ------------------- diff --git a/mopidy_musicbox_webclient/static/index.html b/mopidy_musicbox_webclient/static/index.html index 2928022..f7b1eed 100644 --- a/mopidy_musicbox_webclient/static/index.html +++ b/mopidy_musicbox_webclient/static/index.html @@ -140,10 +140,10 @@ Add All to Bottom of Queue
  • - Show Album + Show Album
  • - Show Artist + Show Artist
  • @@ -170,10 +170,10 @@ Remove from Queue
  • - Show Album + Show Album
  • - Show Artist + Show Artist
  • diff --git a/mopidy_musicbox_webclient/static/js/functionsvars.js b/mopidy_musicbox_webclient/static/js/functionsvars.js index b976340..24b467b 100644 --- a/mopidy_musicbox_webclient/static/js/functionsvars.js +++ b/mopidy_musicbox_webclient/static/js/functionsvars.js @@ -305,7 +305,7 @@ function renderSongLiDivider (previousTrack, track, nextTrack, target) { if (!hasSameAlbum(previousTrack, track) && hasSameAlbum(track, nextTrack)) { // Large divider with album cover. html += - '
  • ' + + '
  • ' + '' + '

    ' + track.album.name + '

    ' + renderSongLiTrackArtists(track) + '

  • ' diff --git a/mopidy_musicbox_webclient/static/js/gui.js b/mopidy_musicbox_webclient/static/js/gui.js index 1525dd0..1439f4b 100644 --- a/mopidy_musicbox_webclient/static/js/gui.js +++ b/mopidy_musicbox_webclient/static/js/gui.js @@ -78,7 +78,7 @@ function setSongInfo (data) { if (data.track.artists) { for (var j = 0; j < data.track.artists.length; j++) { - artistshtml += '' + data.track.artists[j].name + '' + artistshtml += '' + data.track.artists[j].name + '' artiststext += data.track.artists[j].name if (j !== data.track.artists.length - 1) { artistshtml += ', ' @@ -88,7 +88,7 @@ function setSongInfo (data) { arttmp = artistshtml } if (data.track.album && data.track.album.name) { - $('#modalalbum').html('' + data.track.album.name + '') + $('#modalalbum').html('' + data.track.album.name + '') } else { $('#modalalbum').html('') } @@ -132,9 +132,9 @@ function popupTracks (e, listuri, trackuri, tlid) { $('.popupArtistsDiv').hide() if (popupData[trackuri].artists) { if (popupData[trackuri].artists.length === 1 && popupData[trackuri].artists[0].uri) { - child = 'Show Artist' + child = 'Show Artist' $('.popupArtistName').html(popupData[trackuri].artists[0].name) - $('.popupArtistHref').attr('onclick', 'library.showArtist("' + popupData[trackuri].artists[0].uri + '");') + $('.popupArtistHref').attr('onclick', 'library.showArtist(\'' + popupData[trackuri].artists[0].uri + '\', mopidy);') $('.popupArtistsDiv').hide() $('.popupArtistsLi').show() } else { @@ -142,7 +142,7 @@ function popupTracks (e, listuri, trackuri, tlid) { for (var j = 0; j < popupData[trackuri].artists.length; j++) { if (popupData[trackuri].artists[j].uri) { isValidArtistURI = true - child += '
  • ' + popupData[trackuri].artists[j].name + '
  • ' + child += '
  • ' + popupData[trackuri].artists[j].name + '
  • ' } } if (isValidArtistURI) { @@ -186,7 +186,7 @@ function popupTracks (e, listuri, trackuri, tlid) { function showAlbumPopup (popupId) { uri = $(popupId).data('track') - library.showAlbum(popupData[uri].album.uri) + library.showAlbum(popupData[uri].album.uri, mopidy) } /** ******************** @@ -364,6 +364,13 @@ function updateStatusOfAll () { } function locationHashChanged () { + if (!mopidy) { + // Mopidy connection not yet established. User probably clicked 'Refresh' in their + // browser and the page is still loading. We can safely ignore this call as it will + // be invoked again later when the page has finished loading and $(document).ready() + // is triggered. + return false + } var hash = document.location.hash.split('?') // remove # var divid = hash[0].substr(1) @@ -399,12 +406,12 @@ function locationHashChanged () { break case 'artists': if (uri !== '') { - library.showArtist(uri) + library.showArtist(uri, mopidy) } break case 'albums': if (uri !== '') { - library.showAlbum(uri) + library.showAlbum(uri, mopidy) } break default: // Default footer diff --git a/mopidy_musicbox_webclient/static/js/library.js b/mopidy_musicbox_webclient/static/js/library.js index 6a90367..9ca8d92 100644 --- a/mopidy_musicbox_webclient/static/js/library.js +++ b/mopidy_musicbox_webclient/static/js/library.js @@ -131,7 +131,7 @@ // Artist results var child = '' - var template = '
  • {name}
  • ' + var template = '
  • {name}
  • ' var tokens for (i = 0; i < results.artists.length; i++) { @@ -155,7 +155,7 @@ // Album results child = '' - template = '
  • ' + template = '
  • ' template += '
    {albumName}
    ' template += '

    {artistName}

    ' template += '
  • ' @@ -269,7 +269,7 @@ return false }, - showArtist: function (nwuri) { + showArtist: function (nwuri, mopidy) { $('#popupQueue').popup('close') $('#popupTracks').popup('close') $('#controlsmodal').popup('close') @@ -288,7 +288,7 @@ return false }, - showAlbum: function (uri) { + showAlbum: function (uri, mopidy) { $('#popupQueue').popup('close') $('#popupTracks').popup('close') $('#controlsmodal').popup('close') From 3e678a32842b1890efa20194dd05f18ad36901a0 Mon Sep 17 00:00:00 2001 From: jcass Date: Sat, 18 Feb 2017 14:25:31 +0200 Subject: [PATCH 2/4] Fix merge conflicts. --- mopidy_musicbox_webclient/static/mb.appcache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy_musicbox_webclient/static/mb.appcache b/mopidy_musicbox_webclient/static/mb.appcache index d32dd12..6495c83 100644 --- a/mopidy_musicbox_webclient/static/mb.appcache +++ b/mopidy_musicbox_webclient/static/mb.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# 2017-02-18:v1 +# 2017-02-18:v2 NETWORK: * From 9384e69dd428189edd8c97ebe396f463a1c00d2b Mon Sep 17 00:00:00 2001 From: jcass Date: Sun, 19 Feb 2017 19:42:40 +0200 Subject: [PATCH 3/4] Show offline message until page refresh is completed. --- mopidy_musicbox_webclient/static/js/gui.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mopidy_musicbox_webclient/static/js/gui.js b/mopidy_musicbox_webclient/static/js/gui.js index df0cbe5..d897f80 100644 --- a/mopidy_musicbox_webclient/static/js/gui.js +++ b/mopidy_musicbox_webclient/static/js/gui.js @@ -366,13 +366,6 @@ function updateStatusOfAll () { } function locationHashChanged () { - if (!mopidy) { - // Mopidy connection not yet established. User probably clicked 'Refresh' in their - // browser and the page is still loading. We can safely ignore this call as it will - // be invoked again later when the page has finished loading and $(document).ready() - // is triggered. - return false - } var hash = document.location.hash.split('?') // remove # var divid = hash[0].substr(1) @@ -404,12 +397,20 @@ function locationHashChanged () { break case 'artists': if (uri !== '') { - library.showArtist(uri, mopidy) + if (mopidy) { + library.showArtist(uri, mopidy) + } else { + showOffline(true) // Page refreshed - wait for mopidy object to be initialized. + } } break case 'albums': if (uri !== '') { - library.showAlbum(uri, mopidy) + if (mopidy) { + library.showAlbum(uri, mopidy) + } else { + showOffline(true) // Page refreshed - wait for mopidy object to be initialized. + } } break default: // Default footer From 65b58a935219f27c501befc71b996f2e5bfcaf3e Mon Sep 17 00:00:00 2001 From: jcass Date: Sun, 26 Feb 2017 20:06:57 +0200 Subject: [PATCH 4/4] Touch application cache signature. --- mopidy_musicbox_webclient/static/mb.appcache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy_musicbox_webclient/static/mb.appcache b/mopidy_musicbox_webclient/static/mb.appcache index 3c6f198..52a48d8 100644 --- a/mopidy_musicbox_webclient/static/mb.appcache +++ b/mopidy_musicbox_webclient/static/mb.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# 2017-02-24:v1 +# 2017-02-26:v1 NETWORK: *