From 549fe25b7f97abf2f7625c4526af9e24ce9e40e7 Mon Sep 17 00:00:00 2001 From: Trevor Squillario Date: Sun, 30 Sep 2012 20:02:04 -0400 Subject: [PATCH] 2.1 Moved ratings to stars --- index.html | 10 ++- js/app.js | 2 +- js/libs/api.js | 144 ++++++++++++++++++++++++++++++++++++------ js/libs/generators.js | 17 +++-- js/libs/player.js | 17 +++++ js/ui-ready.js | 20 ++++-- manifest.json | 2 +- 7 files changed, 173 insertions(+), 39 deletions(-) diff --git a/index.html b/index.html index 0e64a51..4d2105a 100755 --- a/index.html +++ b/index.html @@ -79,11 +79,12 @@ @@ -261,12 +262,15 @@ --> +
  • 9/30/2012 - 2.1 + Moved ratings to stars (5 star ratings will reappear eventually) +
  • 9/30/2012 - 2.0.9 Added Dark Theme Fixed issue with track duration display
  • 9/30/2012 - 2.0.8 - Removed "http://*/" from manifest.json + Removed "http://*/" permission from manifest.json (This was what caused the permissions alert, more info here)
  • 9/29/2012 - 2.0.7 Updated to SoundManager2 v297a-20120916 diff --git a/js/app.js b/js/app.js index 73903c6..74003ef 100755 --- a/js/app.js +++ b/js/app.js @@ -86,7 +86,7 @@ function loadTabContent(tab) { if (debug) { console.log("TAG PLAYLIST"); } loadPlaylists(); loadFolders(); - loadGenres(); + loadAutoPlaylists(); break; case '#tabPodcasts': if (debug) { console.log("TAG PODCAST"); } diff --git a/js/libs/api.js b/js/libs/api.js index 576c357..888a489 100755 --- a/js/libs/api.js +++ b/js/libs/api.js @@ -151,8 +151,8 @@ function getGenres() { }); $('#Genres').html(options.join('')); } -function loadGenres(refresh) { - if (debug) { console.log("LOAD GENRES"); } +function loadAutoPlaylists(refresh) { + if (debug) { console.log("LOAD AUTO PLAYLISTS"); } if (refresh) { $('#AutoPlaylistContainer').empty(); } @@ -163,7 +163,9 @@ function loadGenres(refresh) { if (genres) { genresArr = genres.split(','); genresArr.unshift('Random'); + genresArr.unshift('Starred'); } else { + genresArr.push('Starred'); genresArr.push('Random'); } $.each(genresArr, function (i, genre) { @@ -264,9 +266,10 @@ function getAlbumListBy(id) { rowcolor = 'odd'; } // Only show albums, not songs (Rated songs will also be returned in API call, trying to display them will break Back button, disabled for now) - var albumhtml; + var albumhtml, starred; + if (album.starred !== undefined) { starred = true; } else { starred = false; } if (album.isDir === true) { - albumhtml = generateAlbumHTML(rowcolor, album.id, album.parent, album.coverArt, album.title, album.artist, album.userRating); + albumhtml = generateAlbumHTML(rowcolor, album.id, album.parent, album.coverArt, album.title, album.artist, album.userRating, starred); } $(albumhtml).appendTo("#AlbumRows"); }); @@ -292,14 +295,77 @@ function getRandomSongList(action, appendto, genre, folder) { } if (folder !== undefined) { gstring = '&musicFolderId=' + folder; - } + } + if (genre == 'Starred') { + getStarred(action, appendto, 'song'); + } else { + $.ajax({ + url: baseURL + '/getRandomSongs.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp&size=' + size + gstring, + method: 'GET', + dataType: 'jsonp', + timeout: 10000, + success: function (data) { + if (data["subsonic-response"].randomSongs.song !== undefined) { + if (appendto === '#TrackContainer') { + $("#TrackContainer").empty(); + } + if (action === 'autoplay') { + $("#TrackContainer").empty(); + $(appendto).empty(); + } + // There is a bug in the API that doesn't return a JSON array for one artist + var items = []; + if (data["subsonic-response"].randomSongs.song.length > 0) { + items = data["subsonic-response"].randomSongs.song; + } else { + items[0] = data["subsonic-response"].randomSongs.song; + } + + var rowcolor; + var html; + $.each(items, function (i, item) { + if (i % 2 === 0) { + rowcolor = 'even'; + } else { + rowcolor = 'odd'; + } + var track, starred; + if (item.starred !== undefined) { starred = true; } else { starred = false; } + if (item.track === undefined) { track = " "; } else { track = item.track; } + var time = secondsToTime(item.duration); + html = generateSongHTML(rowcolor, item.id, item.parent, track, item.title, item.artist, item.album, item.coverArt, item.userRating, starred, time); + $(html).appendTo(appendto); + }); + if (appendto === '#TrackContainer') { + updateMessage(items.length + ' Song(s)'); + } + if (appendto === '#CurrentPlaylistContainer') { + updateMessage(items.length + ' Song(s) Added'); + } + if (action === 'autoplay') { + autoPlay(); + } + } else { + $(appendto).empty(); + } + } + }); + } +} +function getStarred(action, appendto, type) { + var size; + if ($.cookie('AutoPlaylistSize') === null) { + size = 25; + } else { + size = $.cookie('AutoPlaylistSize'); + } $.ajax({ - url: baseURL + '/getRandomSongs.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp&size=' + size + gstring, + url: baseURL + '/getStarred.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp&size=' + size, method: 'GET', dataType: 'jsonp', timeout: 10000, success: function (data) { - if (data["subsonic-response"].randomSongs.song !== undefined) { + if (data["subsonic-response"].starred !== undefined) { if (appendto === '#TrackContainer') { $("#TrackContainer").empty(); } @@ -309,10 +375,36 @@ function getRandomSongList(action, appendto, genre, folder) { } // There is a bug in the API that doesn't return a JSON array for one artist var items = []; - if (data["subsonic-response"].randomSongs.song.length > 0) { - items = data["subsonic-response"].randomSongs.song; - } else { - items[0] = data["subsonic-response"].randomSongs.song; + switch (type) { + case 'artist': + if (data["subsonic-response"].starred.artist !== undefined) { + if (data["subsonic-response"].starred.artist.length > 0) { + items = data["subsonic-response"].starred.artist; + } else { + items[0] = data["subsonic-response"].starred.artist; + } + } + break; + case 'album': + if (data["subsonic-response"].starred.album !== undefined) { + if (data["subsonic-response"].starred.album.length > 0) { + items = data["subsonic-response"].starred.album; + } else { + items[0] = data["subsonic-response"].starred.album; + } + } + break; + case 'song': + if (data["subsonic-response"].starred.song !== undefined) { + if (data["subsonic-response"].starred.song.length > 0) { + items = data["subsonic-response"].starred.song; + } else { + items[0] = data["subsonic-response"].starred.song; + } + } + break; + default: + break; } var rowcolor; @@ -323,10 +415,22 @@ function getRandomSongList(action, appendto, genre, folder) { } else { rowcolor = 'odd'; } - var track; + var track, starred; + if (item.starred !== undefined) { starred = true; } else { starred = false; } if (item.track === undefined) { track = " "; } else { track = item.track; } var time = secondsToTime(item.duration); - html = generateSongHTML(rowcolor, item.id, item.parent, track, item.title, item.artist, item.album, item.coverArt, item.userRating, time); + switch (type) { + case 'artist': + break; + case 'album': + html = generateRowHTML(item, appendto, rowcolor); + break; + case 'song': + html = generateRowHTML(item, appendto, rowcolor); + break; + default: + break; + } $(html).appendTo(appendto); }); if (appendto === '#TrackContainer') { @@ -444,14 +548,17 @@ function search(type, query) { } else { rowcolor = 'odd'; } + var starred; + if (child.starred !== undefined) { starred = true; } else { starred = false; } isDir = child.isDir; if (isDir === true) { - albumhtml = generateAlbumHTML(rowcolor, child.id, child.parent, child.coverArt, child.title, child.artist, child.userRating); + albumhtml = generateAlbumHTML(rowcolor, child.id, child.parent, child.coverArt, child.title, child.artist, child.userRating, starred); } else { - var track; + var track, starred; + if (child.starred !== undefined) { starred = true; } else { starred = false; } if (child.track === undefined) { track = " "; } else { track = child.track; } var time = secondsToTime(child.duration); - albumhtml = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, time); + albumhtml = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, starred, time); } $(albumhtml).appendTo("#AlbumRows"); }); @@ -777,10 +884,11 @@ function getPlaylist(id, action, appendto) { } else { rowcolor = 'odd'; } - var track; + var track, starred; + if (child.starred !== undefined) { starred = true; } else { starred = false; } if (child.track === undefined) { track = " "; } else { track = child.track; } var time = secondsToTime(child.duration); - html = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, time); + html = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, starred, time); $(html).appendTo(appendto); }); if (appendto === '#TrackContainer tbody') { diff --git a/js/libs/generators.js b/js/libs/generators.js index 03cf64d..4648bdb 100755 --- a/js/libs/generators.js +++ b/js/libs/generators.js @@ -1,15 +1,14 @@ function generateRowHTML(child, appendto, rowcolor) { - var albumhtml; - var isDir; - var i; + var albumhtml, isDir, starred, i; isDir = child.isDir; + if (child.starred !== undefined) { starred = true; } else { starred = false; } if (isDir === true) { - albumhtml = generateAlbumHTML(rowcolor, child.id, child.parent, child.coverArt, child.title, child.artist, child.userRating); + albumhtml = generateAlbumHTML(rowcolor, child.id, child.parent, child.coverArt, child.title, child.artist, child.userRating, starred); } else { var track; if (child.track === undefined) { track = " "; } else { track = child.track; } var time = secondsToTime(child.duration); - albumhtml = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, time); + albumhtml = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, starred, time); } return albumhtml; } @@ -18,13 +17,13 @@ function generateAlbumHeaderHTML() { html = 'AlbumArtist'; return html; } -function generateAlbumHTML(rowcolor, childid, parentid, coverart, title, artist, rating) { +function generateAlbumHTML(rowcolor, childid, parentid, coverart, title, artist, rating, starred) { var html; html = ''; html += ''; html += ''; html += ''; - if (rating === 5) { + if (starred) { html += ''; } else { html += ''; @@ -45,14 +44,14 @@ function generateSongHeaderHTML() { html = 'TrackTitleArtistAlbumTime'; return html; } -function generateSongHTML(rowcolor, childid, parentid, track, title, artist, album, coverart, rating, time) { +function generateSongHTML(rowcolor, childid, parentid, track, title, artist, album, coverart, rating, starred, time) { var html; html = ''; html += ''; html += ''; html += ''; html += ''; - if (rating === 5) { + if (starred) { html += ''; } else { html += ''; diff --git a/js/libs/player.js b/js/libs/player.js index ad46cfd..88ccc2b 100644 --- a/js/libs/player.js +++ b/js/libs/player.js @@ -167,6 +167,23 @@ function rateSong(songid, rating) { } }); } +function starItem(itemid, starred) { + var url; + if (starred) { + url = baseURL + '/star.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + itemid; + } else { + url = baseURL + '/unstar.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + itemid; + } + $.ajax({ + url: url, + method: 'GET', + dataType: 'jsonp', + timeout: 10000, + success: function () { + updateMessage('Favorite Updated!'); + } + }); +} function playPauseSong() { var el = '#PlayTrack'; if ($(el).hasClass('playing')) { diff --git a/js/ui-ready.js b/js/ui-ready.js index b1a6e90..c91884d 100755 --- a/js/ui-ready.js +++ b/js/ui-ready.js @@ -174,14 +174,16 @@ }); $('tr.album a.rate').live('click', function (event) { var itemid = $(this).parent().parent().attr('childid'); - rateSong(itemid, 5); + //rateSong(itemid, 5); + starItem(itemid, true); $(this).removeClass('rate'); $(this).addClass('favorite'); return false; }); $('tr.album a.favorite').live('click', function (event) { var itemid = $(this).parent().parent().attr('childid'); - rateSong(itemid, 0); + //rateSong(itemid, 0); + starItem(itemid, false); $(this).removeClass('favorite'); $(this).addClass('rate'); return false; @@ -273,14 +275,16 @@ }); $('table.songlist tr.song a.rate').live('click', function (event) { var songid = $(this).parent().parent().attr('childid'); - rateSong(songid, 5); + //rateSong(songid, 5); + starItem(songid, true); $(this).removeClass('rate'); $(this).addClass('favorite'); return false; }); $('table.songlist tr.song a.favorite').live('click', function (event) { var songid = $(this).parent().parent().attr('childid'); - rateSong(songid, 0); + //rateSong(songid, 0); + starItem(songid, false); $(this).removeClass('favorite'); $(this).addClass('rate'); return false; @@ -539,14 +543,16 @@ }); $('#songdetails a.rate').live('click', function (event) { var itemid = $('#songdetails_song').attr('childid'); - rateSong(itemid, 5); + //rateSong(itemid, 5); + starItem(itemid, true); $(this).removeClass('rate'); $(this).addClass('favorite'); return false; }); $('#songdetails a.favorite').live('click', function (event) { var itemid = $('#songdetails_song').attr('childid'); - rateSong(itemid, 0); + //rateSong(itemid, 0); + starItem(itemid, false); $(this).removeClass('favorite'); $(this).addClass('rate'); return false; @@ -713,5 +719,5 @@ } }).disableSelection(); -}); // End document.ready +}); // End document.ready diff --git a/manifest.json b/manifest.json index 872fd0c..3f9bef2 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 1, "name": "MiniSub", "description": "MiniSub - HTML5 Mini Player for Subsonic", - "version": "2.0.9", + "version": "2.1", "app": { "launch": { "local_path": "index.html"