Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Unavailable Albums feature #53

Merged
merged 2 commits into from
Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion rdio-enhancer.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,39 @@
}

.section_header .exportToCSV {
padding: 0 8px;
padding: 0 12px;
font-size: 12px;
color: #008fd5;
float:right;
margin-right:5px;
}

.Dialog.unavailable_dialog .album {
margin: 0;
padding: 10px 0;
line-height: 18px;
border-bottom: 1px solid #e1e4e6;
position: relative;
}
.Dialog.unavailable_dialog .album:last-child {
border: 0;
}
.Dialog.unavailable_dialog .album_name,
.Dialog.unavailable_dialog .album_artist {
max-width: 400px;
}
.Dialog.unavailable_dialog .album_artist a {
color: #94999c;
}
.Dialog.unavailable_dialog .badge {
position: absolute;
right: 0;
top: 50%;
margin: 0;
color: #fff;
cursor: default;
background: rgba(55, 70, 79, 0.6);
border-radius: 3px;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
99 changes: 97 additions & 2 deletions rdio-enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ function injectedJs() {

}

if (a == "Profile.Favorites") {
if(a == "Profile.Favorites") {
b.orig_onRendered = b.onRendered;
b.onRendered = function() {
b.orig_onRendered.call(this);
Expand Down Expand Up @@ -594,7 +594,78 @@ function injectedJs() {
}
}

if (a== "InfiniteScroll") {
if(a == "Menu") {
b.orig_onRendered = b.onRendered;
b.onRendered = function() {
b.orig_onRendered.call(this);
var menu = this;

if(menu.$('li:first-child').text().trim() == 'Name') {

// private scope for this menu component
(function() {

var item = $('<li class="option truncated_line">Unavailable Albums</li>'),
spinner = new R.Components.Spinner();
template = _.template(''
+ '<div class="album">'
+ '<div class="album_name"><a href="<%= albumUrl %>"><%= name %></a></div>'
+ '<div class="album_artist"><a href="<%= artistUrl %>"><%= artist %></a></div>'
+ '<div class="badge colored">Unavailable</div>'
+ '</div>'
);

menu.$('ul').append(item);
item.on('click', function(event) {

R.loader.load(["Dialog"], function() {

var dialog = new R.Components.Dialog({
title: 'Unavailable Albums',
width: 550,
extraClassName: 'unavailable_dialog',
closeButton: 'Close'
});

dialog.onOpen = function() {

if(R.enhancer.cache['unavailable_albums']) {
dialog.onLoaded(R.enhancer.cache['unavailable_albums']);
} else {
this.$('.body .container').append(spinner.el);
spinner.spin();
R.enhancer.getUnavilableAlbums(function(results) {
// caching results of this call as it's unlikely that:
// 1) someone will add an unavailable album to their favorites
// 2) a previously saved album will change to unavailable during their session
R.enhancer.cache['unavailable_albums'] = results;
dialog.onLoaded(results);
});
}
};

dialog.onLoaded = function(data) {
var albums = [];
for(var i = 0, length = data.length, album; i < length; i++) {
// console.debug(data[i]);
albums.push(template(data[i]));
}
spinner.stop();
this.$('.body .container').html('<ul>' + albums.join('') + '</ul>');
this.onResize();
};

menu.close();
dialog.open();
});
});

})();
}
}
}

if(a == "InfiniteScroll") {
b.orig_ensureItemsLoaded = b.ensureItemsLoaded;
b.ensureItemsLoaded = function() {
// When manually filtered (by tagging system)
Expand Down Expand Up @@ -762,6 +833,27 @@ function injectedJs() {
};
},

getUnavilableAlbums: function(callback) {
R.Api.request({
method: "getAlbumsInCollection",
content: {},
success: function(response) {
if(response.status != 'ok') {
R.enhancer.show_message('There was an error getting unavailable albums.', true);
return;
}
var unavailables = [];
$.each(response.result.items, function(index, album) {
if(!album.canStream) unavailables.push(album);
});
callback(unavailables);
},
error: function() {
R.enhancer.show_message('There was an error getting unavailable albums.', true);
}
});
},

getTracks: function(callback) {
R.enhancer.getModels(
callback,
Expand Down Expand Up @@ -1101,6 +1193,9 @@ function injectedJs() {
}
};

// cache for storing results of API calls as needed
R.enhancer.cache = {};

// Call all of the overwrite functions to hook into Rdio
R.enhancer.overwrite_playlist();
R.enhancer.overwrite_create();
Expand Down