Creation and deletion of playlists

This commit is contained in:
James Barnsley
2016-11-14 11:20:02 +13:00
parent 57311f1b6a
commit 1de58afa44
12 changed files with 338 additions and 86 deletions

View File

@ -125,6 +125,13 @@ export function setTimePosition( time_position ){
* Asset-oriented actions
**/
export function deletePlaylist( uri ){
return {
type: 'MOPIDY_DELETE_PLAYLIST',
uri: uri
}
}
export function getPlaylists(){
return { type: 'MOPIDY_PLAYLISTS' }
}

View File

@ -85,18 +85,30 @@ const MopidyMiddleware = (function(){
var callParts = call.split('.');
var model = callParts[0];
var method = callParts[1];
if( method ){
var mopidyObject = ws[model][method]
var property = method;
}else{
var mopidyObject = ws[model]
var property = model;
}
property = property.replace('get','');
property = property.replace('set','');
return new Promise( (resolve, reject) => {
if( model in ws ){
if( method in ws[model] ){
var mopidyObject = ws[model][method]
var property = method;
}else{
var mopidyObject = ws[model]
var property = model;
}
}else{
var error = {
message: 'Call to an invalid object. Check your are calling a valid Mopidy endpoint.',
call: call,
value: value
}
console.error(error)
reject(error)
}
property = property.replace('get','');
property = property.replace('set','');
mopidyObject( value )
.then(
response => {
@ -219,32 +231,39 @@ const MopidyMiddleware = (function(){
uris.push( playlist.tracks[i].uri );
}
instruct( socket, store, 'library.lookup', { uris: uris } )
.then( response => {
// no tracks
if( uris.length <= 0 ){
store.dispatch({ type: 'MOPIDY_PLAYLIST_LOADED', data: playlist });
for(var uri in response){
if (response.hasOwnProperty(uri)) {
// tracks? let's flesh them out with full track objects, rather than just reference objects
}else{
instruct( socket, store, 'library.lookup', { uris: uris } )
.then( response => {
var track = response[uri][0];
if( track ){
// find the track reference, and drop in the full track data
function getByURI( trackReference ){
return track.uri == trackReference.uri
}
var trackReferences = playlist.tracks.filter(getByURI);
// there could be multiple instances of this track, so accommodate this
for( var j = 0; j < trackReferences.length; j++){
var key = playlist.tracks.indexOf( trackReferences[j] );
playlist.tracks[ key ] = track;
for(var uri in response){
if (response.hasOwnProperty(uri)) {
var track = response[uri][0];
if( track ){
// find the track reference, and drop in the full track data
function getByURI( trackReference ){
return track.uri == trackReference.uri
}
var trackReferences = playlist.tracks.filter(getByURI);
// there could be multiple instances of this track, so accommodate this
for( var j = 0; j < trackReferences.length; j++){
var key = playlist.tracks.indexOf( trackReferences[j] );
playlist.tracks[ key ] = track;
}
}
}
}
}
store.dispatch({ type: 'MOPIDY_PLAYLIST_LOADED', data: playlist });
})
store.dispatch({ type: 'MOPIDY_PLAYLIST_LOADED', data: playlist });
})
}
})
break;
@ -292,6 +311,24 @@ const MopidyMiddleware = (function(){
});
break
case 'MOPIDY_CREATE_PLAYLIST':
instruct( socket, store, 'playlists.create', { name: action.name, uri_scheme: action.scheme })
.then( response => {
// re-load our global playlists
store.dispatch({ type: 'MOPIDY_PLAYLISTS' });
});
break
case 'MOPIDY_DELETE_PLAYLIST':
instruct( socket, store, 'playlists.delete', { uri: action.uri })
.then( response => {
// re-load our global playlists
store.dispatch({ type: 'MOPIDY_PLAYLISTS' });
});
break
case 'MOPIDY_ALBUM':
//store.dispatch({ type: 'MOPIDY_ALBUM_LOADED', data: false });
instruct( socket, store, 'library.lookup', action.data )