Track classification queue and directified track list

This commit is contained in:
Josef Citrine 2016-08-28 02:59:10 +01:00
parent d0b356be2c
commit 9de1d53cd7
12 changed files with 181 additions and 70 deletions

View file

@ -48,4 +48,9 @@ class AdminController extends Controller
{ {
return View::make('shared.null'); return View::make('shared.null');
} }
public function getClassifierQueue()
{
return View::make('shared.null');
}
} }

View file

@ -27,9 +27,12 @@ use Poniverse\Ponyfm\Commands\EditTrackCommand;
use Poniverse\Ponyfm\Commands\UploadTrackCommand; use Poniverse\Ponyfm\Commands\UploadTrackCommand;
use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase; use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase;
use Poniverse\Ponyfm\Jobs\EncodeTrackFile; use Poniverse\Ponyfm\Jobs\EncodeTrackFile;
use Poniverse\Ponyfm\Models\Genre;
use Poniverse\Ponyfm\Models\ResourceLogItem; use Poniverse\Ponyfm\Models\ResourceLogItem;
use Poniverse\Ponyfm\Models\TrackFile; use Poniverse\Ponyfm\Models\TrackFile;
use Poniverse\Ponyfm\Models\Track; use Poniverse\Ponyfm\Models\Track;
use Poniverse\Ponyfm\Models\TrackType;
use Poniverse\Ponyfm\Models\TrackTypes;
use Auth; use Auth;
use Input; use Input;
use Poniverse\Ponyfm\Models\User; use Poniverse\Ponyfm\Models\User;
@ -131,7 +134,7 @@ class TracksController extends ApiControllerBase
return Response::json(['url' => $url], 200); return Response::json(['url' => $url], 200);
} }
public function getIndex($all = false) public function getIndex($all = false, $unknown = false)
{ {
$page = 1; $page = 1;
$perPage = 45; $perPage = 45;
@ -155,7 +158,7 @@ class TracksController extends ApiControllerBase
->with('user', 'genre', 'cover', 'album', 'album.user'); ->with('user', 'genre', 'cover', 'album', 'album.user');
} }
$this->applyFilters($query); $this->applyFilters($query, $unknown);
$totalCount = $query->count(); $totalCount = $query->count();
$this->applyOrdering($query); $this->applyOrdering($query);
@ -182,6 +185,12 @@ class TracksController extends ApiControllerBase
return $this->getIndex(true); return $this->getIndex(true);
} }
public function getClassifierQueue()
{
$this->authorize('access-admin-area');
return $this->getIndex(true, true);
}
public function getOwned(User $user) public function getOwned(User $user)
{ {
$query = Track::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc'); $query = Track::summary()->where('user_id', $user->id)->orderBy('created_at', 'desc');
@ -231,7 +240,7 @@ class TracksController extends ApiControllerBase
* @param $query * @param $query
* @return mixed * @return mixed
*/ */
private function applyFilters($query) private function applyFilters($query, $unknown = false)
{ {
if (Input::has('is_vocal')) { if (Input::has('is_vocal')) {
$isVocal = \Input::get('is_vocal'); $isVocal = \Input::get('is_vocal');
@ -254,10 +263,23 @@ class TracksController extends ApiControllerBase
$query->whereIn('genre_id', Input::get('genres')); $query->whereIn('genre_id', Input::get('genres'));
} }
if (Input::has('types')) { if (Input::has('types') && !$unknown) {
$query->whereIn('track_type_id', Input::get('types')); $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')) { if (Input::has('songs')) {
// DISTINCT is needed here to avoid duplicate results // DISTINCT is needed here to avoid duplicate results
// when a track is associated with multiple show songs. // when a track is associated with multiple show songs.

View file

@ -177,6 +177,7 @@ Route::group(['prefix' => 'api/web'], function() {
Route::delete('/showsongs/{id}', 'Api\Web\ShowSongsController@deleteSong')->where('id', '\d+'); Route::delete('/showsongs/{id}', 'Api\Web\ShowSongsController@deleteSong')->where('id', '\d+');
Route::get('/tracks', 'Api\Web\TracksController@getAllTracks'); Route::get('/tracks', 'Api\Web\TracksController@getAllTracks');
Route::get('/tracks/unclassified', 'Api\Web\TracksController@getClassifierQueue');
}); });
Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); 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::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-area']], function() {
Route::get('/genres', 'AdminController@getGenres'); Route::get('/genres', 'AdminController@getGenres');
Route::get('/tracks', 'AdminController@getTracks'); Route::get('/tracks', 'AdminController@getTracks');
Route::get('/tracks/unclassified', 'AdminController@getClassifierQueue');
Route::get('/show-songs', 'AdminController@getShowSongs'); Route::get('/show-songs', 'AdminController@getShowSongs');
Route::get('/users', 'AdminController@getUsers'); Route::get('/users', 'AdminController@getUsers');
Route::get('/', 'AdminController@getIndex'); Route::get('/', 'AdminController@getIndex');

View file

@ -1,5 +1,6 @@
<ul class="tabs"> <ul class="tabs">
<li ui-sref-active="active"><a ui-sref=".tracks">All Tracks</a></li> <li ui-sref-active="active"><a ui-sref=".tracks">All Tracks</a></li>
<li ui-sref-active="active"><a ui-sref=".classifier">Unclassified Tracks</a></li>
<li ui-sref-active="active"><a ui-sref=".genres">Genres</a></li> <li ui-sref-active="active"><a ui-sref=".genres">Genres</a></li>
<li ui-sref-active="active"><a ui-sref=".showsongs">Show Songs</a></li> <li ui-sref-active="active"><a ui-sref=".showsongs">Show Songs</a></li>
<li ui-sref-active="active"><a ui-sref=".users">Users</a></li> <li ui-sref-active="active"><a ui-sref=".users">Users</a></li>

View file

@ -0,0 +1 @@
<pfm-paged-tracks-list type="unclassified"></pfm-paged-tracks-list>

View file

@ -1,20 +1 @@
<div class="pagination" ng-if="totalPages > 1"> <pfm-paged-tracks-list type="all"></pfm-paged-tracks-list>
<ul>
<li ng-class="{disabled: !prevPage}"><a href="#" ng-click="gotoPage(prevPage);" pfm-eat-click>Prev</a></li>
<li ng-repeat="page in pages track by page" ng-class="{active: page == currentPage}">
<a href="#" ng-click="gotoPage(page);" pfm-eat-click>{{page}}</a>
</li>
<li ng-class="{disabled: !nextPage}"><a href="#" ng-click="gotoPage(nextPage);" pfm-eat-click>Next</a></li>
<li class="pagination-jump">
<a href="#" ng-click="showPageSelector();" ng-hide="pageSelectorShown" pfm-eat-click>Jump&hellip;</a>
<form ng-submit="jumpToPage(inputPageNumber)" ng-show="pageSelectorShown">
<input type="number" id="pagination-jump-destination" ng-model="inputPageNumber" ng-blur="hidePageSelector()" />
<input type="submit" />
</form>
</li>
</ul>
</div>
<div class="stretch-to-bottom">
<pfm-tracks-list tracks="tracks" class="three-columns"></pfm-tracks-list>
</div>

View file

@ -0,0 +1,22 @@
<div class="paged-tracks-list">
<div class="pagination" ng-if="totalPages > 1">
<ul>
<li ng-class="{disabled: !prevPage}"><a href="#" ng-click="gotoPage(prevPage);" pfm-eat-click>Prev</a></li>
<li ng-repeat="page in pages track by page" ng-class="{active: page == currentPage}">
<a href="#" ng-click="gotoPage(page);" pfm-eat-click>{{page}}</a>
</li>
<li ng-class="{disabled: !nextPage}"><a href="#" ng-click="gotoPage(nextPage);" pfm-eat-click>Next</a></li>
<li class="pagination-jump">
<a href="#" ng-click="showPageSelector();" ng-hide="pageSelectorShown" pfm-eat-click>Jump&hellip;</a>
<form ng-submit="jumpToPage(inputPageNumber)" ng-show="pageSelectorShown">
<input type="number" id="pagination-jump-destination" ng-model="inputPageNumber" ng-blur="hidePageSelector()" />
<input type="submit" />
</form>
</li>
</ul>
</div>
<div class="stretch-to-bottom">
<pfm-tracks-list tracks="tracks" class="three-columns"></pfm-tracks-list>
</div>
</div>

View file

@ -283,6 +283,11 @@ ponyfm.config [
controller: 'admin-tracks' controller: 'admin-tracks'
templateUrl: '/templates/admin/tracks.html' templateUrl: '/templates/admin/tracks.html'
state.state 'admin.classifier',
url: '/tracks/unclassified'
controller: 'admin-classifier'
templateUrl: '/templates/admin/classifier.html'
state.state 'admin.users', state.state 'admin.users',
url: '/users' url: '/users'
controller: 'admin-users' controller: 'admin-users'

View file

@ -0,0 +1,32 @@
# Pony.fm - A community for pony fan music.
# Copyright (C) 2016 Josef Citrine
#
# 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/>.
window.pfm.preloaders['admin-classifier'] = [
'tracks', '$state'
(tracks, $state) ->
tracks.loadFilters().then(->
tracks.mainQuery.fromFilterString($state.params.filter)
tracks.mainQuery.setPage $state.params.page || 1
tracks.mainQuery.setAdmin true
)
]
module.exports = angular.module('ponyfm').controller "admin-classifier", [
'$scope', 'tracks', '$state',
($scope, tracks, $state) ->
]

View file

@ -21,56 +21,12 @@ window.pfm.preloaders['admin-tracks'] = [
tracks.mainQuery.fromFilterString($state.params.filter) tracks.mainQuery.fromFilterString($state.params.filter)
tracks.mainQuery.setPage $state.params.page || 1 tracks.mainQuery.setPage $state.params.page || 1
tracks.mainQuery.setAdmin true tracks.mainQuery.setAdmin true
tracks.mainQuery.fetch()
) )
] ]
module.exports = angular.module('ponyfm').controller "admin-tracks", [ module.exports = angular.module('ponyfm').controller "admin-tracks", [
'$scope', 'tracks', '$state', '$scope', 'tracks', '$state',
($scope, tracks, $state) -> ($scope, tracks, $state) ->
tracks.mainQuery.fetch().done (searchResults) ->
$scope.tracks = searchResults.tracks
$scope.currentPage = parseInt(searchResults.current_page)
$scope.totalPages = parseInt(searchResults.total_pages)
delete $scope.nextPage
delete $scope.prevPage
$scope.nextPage = $scope.currentPage + 1 if $scope.currentPage < $scope.totalPages
$scope.prevPage = $scope.currentPage - 1 if $scope.currentPage > 1
$scope.allPages = [1..$scope.totalPages]
# TODO: turn this into a directive
# The actual first page will always be in the paginator.
$scope.pages = [1]
# This logic determines how many pages to add prior to the current page, if any.
firstPage = Math.max(2, $scope.currentPage-3)
$scope.pages = $scope.pages.concat [firstPage..$scope.currentPage] unless $scope.currentPage == 1
pagesLeftToAdd = 8-$scope.pages.length
lastPage = Math.min($scope.totalPages - 1, $scope.currentPage+1+pagesLeftToAdd)
$scope.pages = $scope.pages.concat([$scope.currentPage+1..lastPage]) unless $scope.currentPage >= lastPage
# The actual last page will always be in the paginator.
$scope.pages.push($scope.totalPages) unless $scope.totalPages in $scope.pages
$scope.pageSelectorShown = false
$scope.gotoPage = (page) ->
$state.transitionTo 'content.tracks.list', {filter: $state.params.filter, page: page}
$scope.showPageSelector = () ->
$scope.pageSelectorShown = true
focus('#pagination-jump-destination')
$scope.hidePageSelector = () ->
$scope.pageSelectorShown = false
$scope.jumpToPage = (inputPageNumber) ->
$scope.gotoPage(inputPageNumber)
] ]

View file

@ -0,0 +1,76 @@
# Pony.fm - A community for pony fan music.
# Copyright (C) 2016 Josef Citrine
#
# 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/>.
module.exports = angular.module('ponyfm').directive 'pfmPagedTracksList', () ->
restrict: 'E'
templateUrl: '/templates/directives/paged-tracks-list.html'
replace: true
scope:
type: '@'
class: '@class'
controller: [
'$scope', 'tracks', '$state',
($scope, tracks, $state) ->
typeEnum = switch
when $scope.type == 'normal' then tracks.FetchType.NORMAL
when $scope.type == 'all' then tracks.FetchType.ALL
when $scope.type == 'unclassified' then tracks.FetchType.UNCLASSIFIED
else tracks.FetchType.NORMAL
tracks.mainQuery.fetch(typeEnum).done (searchResults) ->
$scope.tracks = searchResults.tracks
$scope.currentPage = parseInt(searchResults.current_page)
$scope.totalPages = parseInt(searchResults.total_pages)
delete $scope.nextPage
delete $scope.prevPage
$scope.nextPage = $scope.currentPage + 1 if $scope.currentPage < $scope.totalPages
$scope.prevPage = $scope.currentPage - 1 if $scope.currentPage > 1
$scope.allPages = [1..$scope.totalPages]
# The actual first page will always be in the paginator.
$scope.pages = [1]
# This logic determines how many pages to add prior to the current page, if any.
firstPage = Math.max(2, $scope.currentPage-3)
$scope.pages = $scope.pages.concat [firstPage..$scope.currentPage] unless $scope.currentPage == 1
pagesLeftToAdd = 8-$scope.pages.length
lastPage = Math.min($scope.totalPages - 1, $scope.currentPage+1+pagesLeftToAdd)
$scope.pages = $scope.pages.concat([$scope.currentPage+1..lastPage]) unless $scope.currentPage >= lastPage
# The actual last page will always be in the paginator.
$scope.pages.push($scope.totalPages) unless $scope.totalPages in $scope.pages
$scope.pageSelectorShown = false
$scope.gotoPage = (page) ->
$state.transitionTo 'content.tracks.list', {filter: $state.params.filter, page: page}
$scope.showPageSelector = () ->
$scope.pageSelectorShown = true
focus('#pagination-jump-destination')
$scope.hidePageSelector = () ->
$scope.pageSelectorShown = false
$scope.jumpToPage = (inputPageNumber) ->
$scope.gotoPage(inputPageNumber)
]

View file

@ -144,16 +144,19 @@ module.exports = angular.module('ponyfm').factory('tracks', [
else else
@toggleListFilter filterName, id for id in _.rest parts, 1 @toggleListFilter filterName, id for id in _.rest parts, 1
fetch: () -> fetch: (type) ->
return @cachedDef if @cachedDef return @cachedDef if @cachedDef
@cachedDef = new $.Deferred() @cachedDef = new $.Deferred()
trackDef = @cachedDef trackDef = @cachedDef
query = '/api/web/tracks?' query = '/api/web/tracks?'
if @admin if type == self.FetchType.ALL && @admin
query = '/api/web/admin/tracks?' query = '/api/web/admin/tracks?'
if type == self.FetchType.UNCLASSIFIED && @admin
query = '/api/web/admin/tracks/unclassified?'
parts = ['page=' + @page] parts = ['page=' + @page]
_.each @availableFilters, (filter, name) => _.each @availableFilters, (filter, name) =>
@ -178,6 +181,11 @@ module.exports = angular.module('ponyfm').factory('tracks', [
self = self =
filters: {} filters: {}
FetchType:
NORMAL: 0
ALL: 1
UNCLASSIFIED: 2
fetch: (id, force) -> fetch: (id, force) ->
force = force || false force = force || false
return trackCache[id] if !force && trackCache[id] return trackCache[id] if !force && trackCache[id]