Permalink
Browse files

Distinguish synched and subscribed playlists

* Show progress spinner while syncing
* Fix persistance bugs with unplayed status
* Don't fetch playlists from couch until after Playdar is fully set up.
  • Loading branch information...
1 parent 94ae8cd commit fb810909125a877a8743ba7221aa9d0581f78c3f @jwheare committed Dec 21, 2009
View
@@ -45,6 +45,11 @@ <h1 id="albumsTitle">Your favourite albums</h1>
<ul class="playlists" id="albums"></ul>
</div>
+ <h1 id="synchedTitle">Your synched playlists</h1>
+ <div class="sidebar_list">
+ <ul class="playlists" id="synched"></ul>
+ </div>
+
<h1 id="subscriptionsTitle">Your subscriptions</h1>
<div class="sidebar_list">
<ul class="playlists" id="subscriptions"></ul>
View
@@ -133,9 +133,14 @@ h1#title small {
margin: 15px 0;
}
/* Playlists */
-h1#albumsTitle {
+h1#albumsTitle,
+h1#subscriptionsTitle,
+h1#synchedTitle {
display: none;
}
+#sidebar h1.progress {
+ background: url('track_scanning.gif') no-repeat 100% 50%;
+}
p#loading_playlists {
margin: 0;
padding: 5px 10px;
@@ -8,6 +8,8 @@ function Playlist () {
this.albumsSidebarList = $('#albums');
this.subscriptionsSidebarTitleElem = $('h1#subscriptionsTitle');
this.subscriptionsSidebarList = $('#subscriptions');
+ this.synchedSidebarTitleElem = $('h1#synchedTitle');
+ this.synchedSidebarList = $('#synched');
this.loadingPlaylistsElem = $('#loading_playlists');
this.createTitleElem = $('#createPlaylist');
this.headerElem = $('#playlistHeader');
@@ -91,6 +93,9 @@ Playlist.prototype = {
if (playlist.isAlbum()) {
this.albumsSidebarList.append(playlist.element);
this.albumsSidebarTitleElem.show();
+ } else if (playlist.isSynched()) {
+ this.synchedSidebarList.append(playlist.element);
+ this.synchedSidebarTitleElem.show();
} else if (playlist.isSubscription()) {
this.subscriptionsSidebarList.append(playlist.element);
this.subscriptionsSidebarTitleElem.show();
@@ -107,13 +112,16 @@ Playlist.prototype = {
} else {
var playlistElements = [];
var albumElements = [];
+ var synchedElements = [];
var subscriptionElements = [];
var that = this;
var playlists = MODELS.Playlist.fetchAll(function callback (playlist) {
that.checkSubscription(playlist);
var element = playlist.element.get()[0];
if (playlist.isAlbum()) {
albumElements.push(element);
+ } else if (playlist.isSynched()) {
+ synchedElements.push(element);
} else if (playlist.isSubscription()) {
subscriptionElements.push(element);
} else {
@@ -127,6 +135,10 @@ Playlist.prototype = {
this.subscriptionsSidebarTitleElem.show();
this.subscriptionsSidebarList.append(subscriptionElements);
}
+ if (synchedElements.length) {
+ this.synchedSidebarTitleElem.show();
+ this.synchedSidebarList.append(synchedElements);
+ }
if (albumElements.length) {
this.albumsSidebarTitleElem.show();
this.albumsSidebarList.append(albumElements);
@@ -474,6 +486,30 @@ Playlist.prototype = {
},
/* SUBSCRIPTIONS */
+ subscriptionQueue: 0,
+ synchedQueue: 0,
+ queueSync: function (playlist) {
+ if (playlist.isSynched()) {
+ this.synchedQueue++;
+ this.synchedSidebarTitleElem.addClass('progress');
+ } else {
+ this.subscriptionQueue++;
+ this.subscriptionsSidebarTitleElem.addClass('progress');
+ }
+ },
+ consumeSyncQueue: function (playlist) {
+ if (playlist.isSynched()) {
+ this.synchedQueue--;
+ if (!this.synchedQueue) {
+ this.synchedSidebarTitleElem.removeClass('progress');
+ }
+ } else {
+ this.subscriptionQueue--;
+ if (!this.subscriptionQueue) {
+ this.subscriptionsSidebarTitleElem.removeClass('progress');
+ }
+ }
+ },
checkSubscription: function (playlist) {
if (!playlist.isSubscription()) {
// Not a subscription
@@ -483,6 +519,7 @@ Playlist.prototype = {
// Make a copy of the args so we don't modify the original
var args = sub.arguments.slice();
// Add callback and exception handler to the arguments
+ var that = this;
args.push(function callback (newPlaylist) {
// compare with saved playlist and update/warn for conflicts?
var diff = playlist.diffTracks(newPlaylist);
@@ -493,30 +530,35 @@ Playlist.prototype = {
}
}
if (added.length) {
- // console.log(playlist.toString());
- if (playlist.isIncrementalSubscription()) {
+ playlist.setLastSyncDate();
+ if (playlist.isSynched()) {
+ playlist.reset_tracks(newPlaylist.tracks);
+ playlist.reload();
+ } else {
// Prepend the new tracks
UTIL.sortByMethod(added, 'get_position', true);
$.each(added, function (i, playlist_track) {
- // console.info(playlist_track.toString());
playlist.add_track(playlist_track.track, {
unplayed: true
}, true);
});
playlist.save();
- } else {
- // console.dir(newPlaylist.tracks);
- playlist.reset_tracks(newPlaylist.tracks);
- playlist.reload();
}
+ playlist.element.find('.playlist').effect('highlight', {
+ color: '#6ea31e'
+ }, 100);
// TODO message that shit
}
+ that.consumeSyncQueue(playlist);
});
args.push(function exceptionHandler (exception) {
// show a warning icon and message?
- // console.log(playlist.toString());
+ // console.warn(exception);
exception.diagnose();
+ that.consumeSyncQueue(playlist);
});
+ this.queueSync(playlist);
+ // console.log(playlist.toString(), playlist.lastSync ? playlist.lastSync.toLocaleString() : '');
IMPORTERS[sub.namespace][sub.method].apply(this, args);
},
@@ -545,6 +587,10 @@ Playlist.prototype = {
if (!this.albumsSidebarList.find('li').size()) {
this.albumsSidebarTitleElem.hide();
}
+ } else if (playlist.isSynched()) {
+ if (!this.synchedSidebarList.find('li').size()) {
+ this.synchedSidebarTitleElem.hide();
+ }
} else if (playlist.isSubscription()) {
if (!this.subscriptionsSidebarList.find('li').size()) {
this.subscriptionsSidebarTitleElem.hide();
@@ -100,7 +100,7 @@ LastFm.getUserPlaylist = function (data, callback, exceptionHandler) {
namespace: 'LastFm',
method: 'getUserPlaylist',
arguments: [data],
- incremental: false
+ synched: true
}
};
var image = $.grep(data.image, function (value, i) {
@@ -177,7 +177,7 @@ LastFm.lovedTracks = function (user, callback, exceptionHandler) {
namespace: 'LastFm',
method: 'lovedTracks',
arguments: [user],
- incremental: false
+ synched: true
}
});
// Load tracks
View
@@ -68,7 +68,7 @@ Url.url = function (source, callback, exceptionHandler) {
namespace: 'Url',
method: 'url',
arguments: [source],
- incremental: true
+ synched: false
}
};
if (jspf) {
View
@@ -9,8 +9,6 @@ var PLAYLICK = {
init: function () {
// Start a new playlist
CONTROLLERS.Playlist.create();
- // Load playlists
- CONTROLLERS.Playlist.fetchAll();
// Create appLauncher iframe
PLAYLICK.createAppLauncherFrame();
},
View
@@ -7,6 +7,8 @@ var PLAYDAR = {
Playdar.client.go();
// Check URL hash
PLAYLICK.checkUrlHash();
+ // Load playlists
+ CONTROLLERS.Playlist.fetchAll();
} else {
PLAYDAR.update_status(STRINGS.loading_flash_error_text);
}
@@ -6,7 +6,6 @@ function Playlist (options) {
this.saved = false;
this.persisted = false;
this.tracks = [];
- this.unplayed = false;
this.options = options || {};
@@ -27,7 +26,9 @@ function Playlist (options) {
}
}
this.date = this.options.date ? new Date(this.options.date) : new Date();
+ this.lastSync = this.options.lastSync ? new Date(this.options.lastSync) : '';
this.setOption('type', 'playlist');
+ this.setOption('unplayed', false);
this.setOption('artist');
this.setOption('album');
this.setOption('title');
@@ -90,8 +91,11 @@ Playlist.prototype = {
isSubscription: function () {
return this.type == 'subscription' && this.subscription;
},
- isIncrementalSubscription: function () {
- return this.isSubscription() && this.subscription.incremental === true;
+ isSynched: function () {
+ return this.isSubscription() && this.subscription.synched === true;
+ },
+ setLastSyncDate: function () {
+ this.lastSync = new Date();
},
isEditable: function () {
return !this.isAlbum() && !this.isSubscription();
@@ -124,7 +128,9 @@ Playlist.prototype = {
var playlist = this;
// TODO this is view layer stuff
var elements = $.map(value.tracks, function (track_data, i) {
- var playlist_track = playlist.add_track(new MODELS.Track(track_data.track));
+ var playlist_track = playlist.add_track(new MODELS.Track(track_data.track), {
+ unplayed: track_data.unplayed
+ });
// Build DOM element
return playlist_track.element.get();
});
@@ -353,6 +359,7 @@ Playlist.prototype = {
copyright: this.copyright,
source: this.source,
subscription: this.subscription,
+ lastSync: this.lastSync ? this.lastSync.getTime() : '',
tracks: $.map(this.tracks, function (playlist_track, i) {
if (playlist_track.unplayed) {
unplayed = true;

0 comments on commit fb81090

Please sign in to comment.