Skip to content
Snippets Groups Projects
Commit 5206ae3e authored by ale's avatar ale
Browse files

add a button to automatically add suggestions based on the current playlist

parent 4fa17267
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,19 @@ djr.Backend.prototype.search = function(query, callback, ctx) {
});
};
// More like these.
djr.Backend.prototype.moreLikeThese = function(uuids, callback, ctx) {
$.ajax({url: '/json/morelikethese',
data: {'h': uuids.join(',')},
dataType: 'json',
type: 'POST',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
// Get information about a specific song.
// Read a playlist, calls callback(Playlist).
......@@ -457,6 +470,36 @@ djr.Player.prototype.streamCurrentPlaylist = function(enable) {
// Nothing for now.
};
// Extend the current playlist with suggestions.
djr.Player.prototype.extendCurrentPlaylist = function() {
var player = this;
var cur_songs = this.allSongs();
this.backend.moreLikeThese(cur_songs, function(results) {
var new_chunk = player.playlist.createUniqueChunk(results, 'suggestions');
if (!new_chunk) {
djr.debug('All the results are already in the playlist.');
return;
}
// Ok, now, if we have more than 1 chunk in the playlist, we
// merge them.
if (player.playlist.chunks.length > 1) {
player.mergePlaylistChunks();
}
// Add the new chunk with the suggestions.
var chunk_id = player.playlist.addChunk(new_chunk);
player.savePlaylist();
player.backend.getHtmlForSongs(songs, function(songs_html) {
var chunk_div = 'chunk_' + chunk_id;
player.hideAllChunks();
player.setChunkHtml(new_chunk, chunk_id, songs_html);
});
});
};
djr.state = {
backend: null,
......@@ -474,6 +517,9 @@ djr.init = function () {
$('#playlistStreamBtn').click(function() {
djr.state.player.streamCurrentPlaylist();
});
$('#playlistExtendBtn').click(function() {
djr.state.player.extendCurrentPlaylist();
});
// Set the album art image to auto-fullscreen on load.
$('#albumart_fs').load(function() {
......
......@@ -89,7 +89,8 @@ DJ:Random
</div>
<div id="playlistControls">
<a id="playlistClearBtn">Clear</a>
<a id="playlistExtendBtn">Extend</a>
| <a id="playlistClearBtn">Clear</a>
| <a id="playlistStreamBtn">Stream</a>
<span id="playlistStreamUrl"></span>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment