diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 3ee791fe..6e12222d 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -34,4 +34,9 @@ class AdminController extends Controller { return View::make('shared.null'); } + + public function getTracks() + { + return View::make('shared.null'); + } } diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index 29ac29ff..7cbe9d70 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -128,7 +128,7 @@ class TracksController extends ApiControllerBase return Response::json(['url' => $url], 200); } - public function getIndex() + public function getIndex($all = false) { $page = 1; $perPage = 45; @@ -137,12 +137,22 @@ class TracksController extends ApiControllerBase $page = Input::get('page'); } - $query = Track::summary() - ->userDetails() - ->listed() - ->explicitFilter() - ->published() - ->with('user', 'genre', 'cover', 'album', 'album.user'); + $query = null; + + if ($all) { + $query = Track::summary() + ->userDetails() + ->listed() + ->explicitFilter() + ->with('user', 'genre', 'cover', 'album', 'album.user'); + } else { + $query = Track::summary() + ->userDetails() + ->listed() + ->explicitFilter() + ->published() + ->with('user', 'genre', 'cover', 'album', 'album.user'); + } $this->applyFilters($query); @@ -164,6 +174,12 @@ class TracksController extends ApiControllerBase ], 200); } + public function getAllTracks() + { + $this->authorize('access-admin-area'); + return $this->getIndex(true); + } + public function getOwned() { $query = Track::summary()->where('user_id', \Auth::user()->id)->orderBy('created_at', 'desc'); diff --git a/app/Http/routes.php b/app/Http/routes.php index 52cd0cf2..62dceb63 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -156,6 +156,8 @@ Route::group(['prefix' => 'api/web'], function() { Route::post('/genres', 'Api\Web\GenresController@postCreate'); Route::put('/genres/{id}', 'Api\Web\GenresController@putRename')->where('id', '\d+'); Route::delete('/genres/{id}', 'Api\Web\GenresController@deleteGenre')->where('id', '\d+'); + + Route::get('/tracks', 'Api\Web\TracksController@getAllTracks'); }); Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); @@ -164,6 +166,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('/', 'AdminController@getIndex'); }); diff --git a/app/Models/Track.php b/app/Models/Track.php index cbfd510d..9d05cb9e 100644 --- a/app/Models/Track.php +++ b/app/Models/Track.php @@ -556,7 +556,7 @@ class Track extends Model implements Searchable public function canView($user) { - if ($this->isPublished()) { + if ($this->isPublished() || $user->hasRole('admin')) { return true; } diff --git a/public/templates/admin/_layout.html b/public/templates/admin/_layout.html index 75f5dfa4..bf04aabd 100644 --- a/public/templates/admin/_layout.html +++ b/public/templates/admin/_layout.html @@ -1,4 +1,5 @@ diff --git a/public/templates/admin/tracks.html b/public/templates/admin/tracks.html new file mode 100644 index 00000000..6f12f17a --- /dev/null +++ b/public/templates/admin/tracks.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/resources/assets/scripts/app/app.coffee b/resources/assets/scripts/app/app.coffee index 607aaf8d..c59c9b37 100644 --- a/resources/assets/scripts/app/app.coffee +++ b/resources/assets/scripts/app/app.coffee @@ -271,6 +271,11 @@ ponyfm.config [ controller: 'admin-genres' templateUrl: '/templates/admin/genres.html' + state.state 'admin.tracks', + url: '/tracks' + controller: 'admin-tracks' + templateUrl: '/templates/admin/tracks.html' + # Homepage if window.pfm.auth.isLogged diff --git a/resources/assets/scripts/app/controllers/admin-tracks.coffee b/resources/assets/scripts/app/controllers/admin-tracks.coffee new file mode 100644 index 00000000..64262ba0 --- /dev/null +++ b/resources/assets/scripts/app/controllers/admin-tracks.coffee @@ -0,0 +1,34 @@ +# 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 . + +window.pfm.preloaders['admin-tracks'] = [ + 'tracks', '$state' + (tracks, $state) -> + tracks.loadFilters().then(-> + 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 +] diff --git a/resources/assets/scripts/app/services/tracks.coffee b/resources/assets/scripts/app/services/tracks.coffee index 2d19333f..286c0ca2 100644 --- a/resources/assets/scripts/app/services/tracks.coffee +++ b/resources/assets/scripts/app/services/tracks.coffee @@ -23,6 +23,7 @@ module.exports = angular.module('ponyfm').factory('tracks', [ class Query cachedDef: null page: 1 + admin: false listeners: [] constructor: (@availableFilters) -> @@ -94,6 +95,10 @@ module.exports = angular.module('ponyfm').factory('tracks', [ @page = page @cachedDef = null + setAdmin: (value) -> + @cachedDef = null + @admin = value + setFilter: (type, value) -> @cachedDef = null @page = 1 @@ -145,6 +150,11 @@ module.exports = angular.module('ponyfm').factory('tracks', [ trackDef = @cachedDef query = '/api/web/tracks?' + + if @admin + query = '/api/web/admin/tracks?' + + parts = ['page=' + @page] _.each @availableFilters, (filter, name) => if filter.type == 'single'