mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-02-24 13:44:33 +01:00
Merge pull request #71 from Poniverse/feature/track-removals
Feature/track removals
This commit is contained in:
commit
547a8dc883
7 changed files with 99 additions and 4 deletions
62
app/Commands/RemoveTrackFromPlaylistCommand.php
Normal file
62
app/Commands/RemoveTrackFromPlaylistCommand.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2015 Peter Deltchev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Poniverse\Ponyfm\Commands;
|
||||
|
||||
use Poniverse\Ponyfm\Models\Playlist;
|
||||
use Poniverse\Ponyfm\Models\Track;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RemoveTrackFromPlaylistCommand extends CommandBase
|
||||
{
|
||||
private $_track;
|
||||
private $_playlist;
|
||||
|
||||
public function __construct($playlistId, $trackId)
|
||||
{
|
||||
$this->_playlist = Playlist::find($playlistId);
|
||||
$this->_track = Track::find($trackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return $user != null && $this->_playlist && $this->_track && $this->_playlist->user_id == $user->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @return CommandResponse
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->_playlist->tracks()->detach($this->_track);
|
||||
Playlist::whereId($this->_playlist->id)->update([
|
||||
'track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = ' . $this->_playlist->id . ')')
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Track removed!']);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ use Poniverse\Ponyfm\Commands\AddTrackToPlaylistCommand;
|
|||
use Poniverse\Ponyfm\Commands\CreatePlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\DeletePlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\EditPlaylistCommand;
|
||||
use Poniverse\Ponyfm\Commands\RemoveTrackFromPlaylistCommand;
|
||||
use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase;
|
||||
use Poniverse\Ponyfm\Models\Image;
|
||||
use Poniverse\Ponyfm\Models\Playlist;
|
||||
|
@ -56,6 +57,11 @@ class PlaylistsController extends ApiControllerBase
|
|||
return $this->execute(new AddTrackToPlaylistCommand($id, Input::get('track_id')));
|
||||
}
|
||||
|
||||
public function postRemoveTrack($id)
|
||||
{
|
||||
return $this->execute(new RemoveTrackFromPlaylistCommand($id, Input::get('track_id')));
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
$page = 1;
|
||||
|
|
|
@ -117,6 +117,7 @@ Route::group(['prefix' => 'api/web'], function() {
|
|||
Route::post('/playlists/delete/{id}', 'Api\Web\PlaylistsController@postDelete');
|
||||
Route::post('/playlists/edit/{id}', 'Api\Web\PlaylistsController@postEdit');
|
||||
Route::post('/playlists/{id}/add-track', 'Api\Web\PlaylistsController@postAddTrack');
|
||||
Route::post('/playlists/{id}/remove-track', 'Api\Web\PlaylistsController@postRemoveTrack');
|
||||
|
||||
Route::post('/comments/{type}/{id}', 'Api\Web\CommentsController@postCreate')->where('id', '\d+');
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
<a pfm-eat-click class="icon-favourite" href="#" ng-click="toggleFavourite(track)" ng-if="::auth.isLogged">
|
||||
<i class="icon-star-empty"></i>
|
||||
</a>
|
||||
<a pfm-eat-click href="#" ng-click="removeFromPlaylist(track)" ng-if="::canModifyPlaylist()">
|
||||
<i class="icon-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<a class="info" ng-href="{{::track.url}}">
|
||||
<span class="title">{{::track.title}}</span>
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
</div>
|
||||
|
||||
<h2>Tracks</h2>
|
||||
<pfm-tracks-list tracks="::playlist.tracks"></pfm-tracks-list>
|
||||
<pfm-tracks-list tracks="::playlist.tracks" playlist="::playlist"></pfm-tracks-list>
|
||||
|
||||
<pfm-comments type="playlist" resource="::playlist"></pfm-comments>
|
||||
</div>
|
||||
|
|
|
@ -19,14 +19,30 @@ module.exports = angular.module('ponyfm').directive 'pfmTracksList', () ->
|
|||
templateUrl: '/templates/directives/tracks-list.html'
|
||||
replace: true
|
||||
scope:
|
||||
tracks: '=tracks',
|
||||
playlist: '='
|
||||
tracks: '=tracks'
|
||||
class: '@class'
|
||||
|
||||
controller: [
|
||||
'$scope', 'favourites', 'player', 'auth'
|
||||
($scope, favourites, player, auth) ->
|
||||
'$dialog', '$scope', 'favourites', 'player', 'playlists', 'auth'
|
||||
($dialog, $scope, favourites, player, playlists, auth) ->
|
||||
$scope.auth = auth.data
|
||||
|
||||
$scope.canModifyPlaylist = ->
|
||||
$scope.playlist and $scope.auth.isLogged and $scope.playlist.user.id == $scope.auth.user.id
|
||||
|
||||
$scope.removeFromPlaylist = (track) ->
|
||||
$dialog.messageBox "Remove #{track.title} from playlist",
|
||||
"Are you sure you want to delete \"#{track.title}\"?", [
|
||||
{ result: 'ok', label: 'Yes', cssClass: 'btn-danger' },
|
||||
{ result: 'cancel', label: 'No', cssClass: 'btn-primary' }
|
||||
]
|
||||
.open().then (res) ->
|
||||
return if res is 'cancel'
|
||||
playlists.removeTrackFromPlaylist $scope.playlist?.id, track.id
|
||||
.done ->
|
||||
$scope.tracks = _.reject $scope.tracks, (t) -> t.id == track.id
|
||||
|
||||
$scope.toggleFavourite = (track) ->
|
||||
favourites.toggle('track', track.id).done (res) ->
|
||||
track.user_data.is_favourited = res.is_favourited
|
||||
|
|
|
@ -68,6 +68,13 @@ module.exports = angular.module('ponyfm').factory('playlists', [
|
|||
|
||||
def
|
||||
|
||||
removeTrackFromPlaylist: (playlistId, trackId) ->
|
||||
def = new $.Deferred()
|
||||
$http.post('/api/web/playlists/' + playlistId + '/remove-track', {track_id: trackId}).success (res) ->
|
||||
def.resolve(res)
|
||||
|
||||
def
|
||||
|
||||
refresh: () ->
|
||||
if auth.data.isLogged
|
||||
$.getJSON('/api/web/playlists/pinned')
|
||||
|
|
Loading…
Reference in a new issue