mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-21 20:48:00 +01:00
Track classification queue and directified track list
This commit is contained in:
parent
d0b356be2c
commit
9de1d53cd7
12 changed files with 181 additions and 70 deletions
|
@ -48,4 +48,9 @@ class AdminController extends Controller
|
|||
{
|
||||
return View::make('shared.null');
|
||||
}
|
||||
|
||||
public function getClassifierQueue()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<ul class="tabs">
|
||||
<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=".showsongs">Show Songs</a></li>
|
||||
<li ui-sref-active="active"><a ui-sref=".users">Users</a></li>
|
||||
|
|
1
public/templates/admin/classifier.html
Normal file
1
public/templates/admin/classifier.html
Normal file
|
@ -0,0 +1 @@
|
|||
<pfm-paged-tracks-list type="unclassified"></pfm-paged-tracks-list>
|
|
@ -1,20 +1 @@
|
|||
<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…</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>
|
||||
<pfm-paged-tracks-list type="all"></pfm-paged-tracks-list>
|
||||
|
|
22
public/templates/directives/paged-tracks-list.html
Normal file
22
public/templates/directives/paged-tracks-list.html
Normal 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…</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>
|
|
@ -283,6 +283,11 @@ ponyfm.config [
|
|||
controller: 'admin-tracks'
|
||||
templateUrl: '/templates/admin/tracks.html'
|
||||
|
||||
state.state 'admin.classifier',
|
||||
url: '/tracks/unclassified'
|
||||
controller: 'admin-classifier'
|
||||
templateUrl: '/templates/admin/classifier.html'
|
||||
|
||||
state.state 'admin.users',
|
||||
url: '/users'
|
||||
controller: 'admin-users'
|
||||
|
|
|
@ -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) ->
|
||||
|
||||
|
||||
]
|
|
@ -21,56 +21,12 @@ window.pfm.preloaders['admin-tracks'] = [
|
|||
tracks.mainQuery.fromFilterString($state.params.filter)
|
||||
tracks.mainQuery.setPage $state.params.page || 1
|
||||
tracks.mainQuery.setAdmin true
|
||||
|
||||
tracks.mainQuery.fetch()
|
||||
)
|
||||
]
|
||||
|
||||
module.exports = angular.module('ponyfm').controller "admin-tracks", [
|
||||
'$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)
|
||||
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
]
|
|
@ -144,16 +144,19 @@ module.exports = angular.module('ponyfm').factory('tracks', [
|
|||
else
|
||||
@toggleListFilter filterName, id for id in _.rest parts, 1
|
||||
|
||||
fetch: () ->
|
||||
fetch: (type) ->
|
||||
return @cachedDef if @cachedDef
|
||||
@cachedDef = new $.Deferred()
|
||||
trackDef = @cachedDef
|
||||
|
||||
query = '/api/web/tracks?'
|
||||
|
||||
if @admin
|
||||
if type == self.FetchType.ALL && @admin
|
||||
query = '/api/web/admin/tracks?'
|
||||
|
||||
if type == self.FetchType.UNCLASSIFIED && @admin
|
||||
query = '/api/web/admin/tracks/unclassified?'
|
||||
|
||||
|
||||
parts = ['page=' + @page]
|
||||
_.each @availableFilters, (filter, name) =>
|
||||
|
@ -178,6 +181,11 @@ module.exports = angular.module('ponyfm').factory('tracks', [
|
|||
self =
|
||||
filters: {}
|
||||
|
||||
FetchType:
|
||||
NORMAL: 0
|
||||
ALL: 1
|
||||
UNCLASSIFIED: 2
|
||||
|
||||
fetch: (id, force) ->
|
||||
force = force || false
|
||||
return trackCache[id] if !force && trackCache[id]
|
||||
|
|
Loading…
Reference in a new issue