From 9de1d53cd72763ea9b377726ba55fde5ee44513d Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sun, 28 Aug 2016 02:59:10 +0100 Subject: [PATCH] Track classification queue and directified track list --- app/Http/Controllers/AdminController.php | 5 ++ .../Controllers/Api/Web/TracksController.php | 30 +++++++- app/Http/routes.php | 2 + public/templates/admin/_layout.html | 1 + public/templates/admin/classifier.html | 1 + public/templates/admin/tracks.html | 21 +---- .../directives/paged-tracks-list.html | 22 ++++++ resources/assets/scripts/app/app.coffee | 5 ++ .../app/controllers/admin-classifier.coffee | 32 ++++++++ .../app/controllers/admin-tracks.coffee | 44 ----------- .../app/directives/paged-tracks-list.coffee | 76 +++++++++++++++++++ .../assets/scripts/app/services/tracks.coffee | 12 ++- 12 files changed, 181 insertions(+), 70 deletions(-) create mode 100644 public/templates/admin/classifier.html create mode 100644 public/templates/directives/paged-tracks-list.html create mode 100644 resources/assets/scripts/app/controllers/admin-classifier.coffee create mode 100644 resources/assets/scripts/app/directives/paged-tracks-list.coffee diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 450da761..821cfef4 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -48,4 +48,9 @@ class AdminController extends Controller { return View::make('shared.null'); } + + public function getClassifierQueue() + { + return View::make('shared.null'); + } } diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index d0bfdb5e..ee24c2bb 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -27,9 +27,12 @@ use Poniverse\Ponyfm\Commands\EditTrackCommand; use Poniverse\Ponyfm\Commands\UploadTrackCommand; use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase; use Poniverse\Ponyfm\Jobs\EncodeTrackFile; +use Poniverse\Ponyfm\Models\Genre; use Poniverse\Ponyfm\Models\ResourceLogItem; use Poniverse\Ponyfm\Models\TrackFile; use Poniverse\Ponyfm\Models\Track; +use Poniverse\Ponyfm\Models\TrackType; +use Poniverse\Ponyfm\Models\TrackTypes; use Auth; use Input; use Poniverse\Ponyfm\Models\User; @@ -131,7 +134,7 @@ class TracksController extends ApiControllerBase return Response::json(['url' => $url], 200); } - public function getIndex($all = false) + public function getIndex($all = false, $unknown = false) { $page = 1; $perPage = 45; @@ -155,7 +158,7 @@ class TracksController extends ApiControllerBase ->with('user', 'genre', 'cover', 'album', 'album.user'); } - $this->applyFilters($query); + $this->applyFilters($query, $unknown); $totalCount = $query->count(); $this->applyOrdering($query); @@ -182,6 +185,12 @@ class TracksController extends ApiControllerBase return $this->getIndex(true); } + public function getClassifierQueue() + { + $this->authorize('access-admin-area'); + return $this->getIndex(true, true); + } + public function getOwned(User $user) { $query = Track::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc'); @@ -231,7 +240,7 @@ class TracksController extends ApiControllerBase * @param $query * @return mixed */ - private function applyFilters($query) + private function applyFilters($query, $unknown = false) { if (Input::has('is_vocal')) { $isVocal = \Input::get('is_vocal'); @@ -254,10 +263,23 @@ class TracksController extends ApiControllerBase $query->whereIn('genre_id', Input::get('genres')); } - if (Input::has('types')) { + if (Input::has('types') && !$unknown) { $query->whereIn('track_type_id', Input::get('types')); } + if ($unknown) { + $query->where(function($q) { + $unknownGenre = Genre::where('name', 'Unknown')->first(); + + $q->where('track_type_id', TrackType::UNCLASSIFIED_TRACK); + + if ($unknownGenre) { + $q->orWhere('genre_id', $unknownGenre->id); + } + }); + + } + if (Input::has('songs')) { // DISTINCT is needed here to avoid duplicate results // when a track is associated with multiple show songs. diff --git a/app/Http/routes.php b/app/Http/routes.php index 88fa844e..4539cae2 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -177,6 +177,7 @@ Route::group(['prefix' => 'api/web'], function() { Route::delete('/showsongs/{id}', 'Api\Web\ShowSongsController@deleteSong')->where('id', '\d+'); Route::get('/tracks', 'Api\Web\TracksController@getAllTracks'); + Route::get('/tracks/unclassified', 'Api\Web\TracksController@getClassifierQueue'); }); Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); @@ -186,6 +187,7 @@ Route::group(['prefix' => 'api/web'], function() { Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-area']], function() { Route::get('/genres', 'AdminController@getGenres'); Route::get('/tracks', 'AdminController@getTracks'); + Route::get('/tracks/unclassified', 'AdminController@getClassifierQueue'); Route::get('/show-songs', 'AdminController@getShowSongs'); Route::get('/users', 'AdminController@getUsers'); Route::get('/', 'AdminController@getIndex'); diff --git a/public/templates/admin/_layout.html b/public/templates/admin/_layout.html index 5d1a4700..f94c5b84 100644 --- a/public/templates/admin/_layout.html +++ b/public/templates/admin/_layout.html @@ -1,5 +1,6 @@