Skip to content

Commit

Permalink
Context menu adding to library
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedb committed Sep 7, 2015
1 parent aea4c2e commit ba0e150
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/common/contextmenu/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ angular.module('spotmop.common.contextmenu', [
$element.hide();
}

$scope.addToLibrary = function(){
$rootScope.$broadcast('spotmop:tracklist:addSelectedTracksToLibrary');
$element.hide();
}

$scope.selectAll = function(){
$rootScope.$broadcast('spotmop:tracklist:selectAll');
$element.hide();
Expand Down
1 change: 1 addition & 0 deletions app/common/contextmenu/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<span class="menu-item" ng-show="context == 'track'" ng-click="playNext()">Play next</span>
<span class="menu-item" ng-show="context == 'track'" ng-click="enqueue()">Add to queue</span>
<span class="menu-item" ng-click="addToPlaylist()">Add to playlist</span>
<span class="menu-item" ng-click="addToLibrary()">Add to library</span>
<span class="menu-item" ng-show="context == 'tltrack'" ng-click="unqueue()">Delete</span>
<span class="menu-item" ng-show="context == 'track'" ng-click="removeFromPlaylist()">Delete</span>
</div>
4 changes: 4 additions & 0 deletions app/common/contextmenu/tltracklist.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<i class="fa fa-plus"></i>
<span class="text">Playlist</span>
</span>
<span class="menu-item" ng-click="addToLibrary()">
<i class="fa fa-plus"></i>
<span class="text">Library</span>
</span>
<span class="menu-item" ng-click="selectAll()">
<i class="fa fa-check-square-o"></i>
<span class="text">Select all</span>
Expand Down
4 changes: 4 additions & 0 deletions app/common/contextmenu/tracklist.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<i class="fa fa-plus"></i>
<span class="text">Playlist</span>
</span>
<span class="menu-item" ng-click="addToLibrary()">
<i class="fa fa-plus"></i>
<span class="text">Library</span>
</span>
<span class="menu-item" ng-click="removeFromPlaylist()">
<i class="fa fa-trash-o"></i>
<span class="text">Delete</span>
Expand Down
35 changes: 34 additions & 1 deletion app/common/tracklist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ angular.module('spotmop.common.tracklist', [
MopidyService.playTrack( [ firstSelectedTrack.uri ], 0 ).then( function(){

// no other tracks to add
if( selectedTracksUris.length <= 1 ){
if( selectedTracks.length <= 1 ){
$rootScope.$broadcast('spotmop:notifyUserRemoval', {id: 'playing-from-tracklist'});
}else{
// add the following tracks to the tracklist
Expand Down Expand Up @@ -371,6 +371,39 @@ angular.module('spotmop.common.tracklist', [
});


/**
* Selected Tracks >> Add to library
**/
$scope.$on('spotmop:tracklist:addSelectedTracksToLibrary', function(event){

$scope.$broadcast('spotmop:notifyUser', {type: 'loading', id: 'adding-to-library', message: 'Adding to library'});

var selectedTracks = $filter('filter')( $scope.tracklist.tracks, {selected: true} );
var selectedTracksUris = [];

angular.forEach( selectedTracks, function(track){

// if we have a nested track object (ie TlTrack objects)
if( typeof(track.track) !== 'undefined' )
selectedTracksUris.push( SpotifyService.getFromUri('trackid', track.track.uri) );

// nope, so let's use a non-nested version
else
selectedTracksUris.push( SpotifyService.getFromUri('trackid', track.uri) );
});

// tell spotify to go'on get
SpotifyService.addTracksToLibrary( selectedTracksUris )
.success( function(response){
$scope.$broadcast('spotmop:notifyUserRemoval', {id: 'adding-to-library'});
})
.error( function(response){
$scope.$broadcast('spotmop:notifyUserRemoval', {id: 'adding-to-library'});
$scope.$broadcast('spotmop:notifyUser', {type: 'error', id: 'adding-to-library-error', message: response.error.message, autoremove: true});
});
});


/**
* Manipulate selected tracks
**/
Expand Down

0 comments on commit ba0e150

Please sign in to comment.