mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-21 20:48:00 +01:00
Start of announcements admin panel
This commit is contained in:
parent
b356cfaea1
commit
d9dc582c08
10 changed files with 163 additions and 0 deletions
70
app/Commands/CreateAnnouncementCommand.php
Normal file
70
app/Commands/CreateAnnouncementCommand.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
namespace Poniverse\Ponyfm\Commands;
|
||||
|
||||
use Gate;
|
||||
use Poniverse\Ponyfm\Models\Announcement;
|
||||
use Validator;
|
||||
|
||||
class CreateAnnouncementCommand extends CommandBase
|
||||
{
|
||||
/** @var Announcement */
|
||||
private $_announcementName;
|
||||
|
||||
public function __construct($announcementName)
|
||||
{
|
||||
$this->_announcementName = $announcementName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Gate::allows('create-announcement');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @return CommandResponse
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
|
||||
$rules = [
|
||||
'name' => 'required|max:50',
|
||||
];
|
||||
|
||||
$validator = Validator::make([
|
||||
'name' => $this->_announcementName,
|
||||
], $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return CommandResponse::fail($validator);
|
||||
}
|
||||
|
||||
Announcement::create([
|
||||
'title' => $this->_announcementName,
|
||||
]);
|
||||
|
||||
return CommandResponse::succeed(['message' => 'Announcement created!']);
|
||||
}
|
||||
}
|
|
@ -53,4 +53,9 @@ class AdminController extends Controller
|
|||
{
|
||||
return View::make('shared.null');
|
||||
}
|
||||
|
||||
public function getAnnouncements()
|
||||
{
|
||||
return View::make('shared.null');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
namespace Poniverse\Ponyfm\Http\Controllers\Api\Web;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Poniverse\Ponyfm\Commands\CreateAnnouncementCommand;
|
||||
use Poniverse\Ponyfm\Http\Controllers\Controller;
|
||||
use Poniverse\Ponyfm\Models\Announcement;
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
class AnnouncementsController extends Controller {
|
||||
|
@ -42,4 +44,34 @@ class AnnouncementsController extends Controller {
|
|||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function getAdminIndex() {
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
$announcements = Announcement::orderBy('start_time', 'desc')
|
||||
->get();
|
||||
|
||||
return Response::json([
|
||||
'announcements' => $announcements->toArray()
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getItemById($genreId) {
|
||||
$this->authorize('access-admin-area');
|
||||
|
||||
$query = Announcement::where('id', '=', $genreId)
|
||||
->orderBy('start_time', 'desc');
|
||||
|
||||
$announcement = $query->first();
|
||||
|
||||
return Response::json(
|
||||
["announcement" => $announcement],
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function postCreate() {
|
||||
$command = new CreateAnnouncementCommand(Request::get('name'));
|
||||
return $this->execute($command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,10 @@ class AuthServiceProvider extends ServiceProvider
|
|||
return $user->hasRole('admin');
|
||||
});
|
||||
|
||||
Gate::define('create-announcement', function (User $user) {
|
||||
return $user->hasRole('admin');
|
||||
});
|
||||
|
||||
$this->registerPolicies();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<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>
|
||||
<li ui-sref-active="active"><a ui-sref=".announcements">Announcements</a></li>
|
||||
</ul>
|
||||
|
||||
<ui-view></ui-view>
|
||||
|
|
5
public/templates/admin/announcements.html
Normal file
5
public/templates/admin/announcements.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<div>
|
||||
<div class="admin-announcement" ng-repeat="item in announcements">
|
||||
<a href="/admin/announcements/{{ item.id }}">{{ item.id }}: {{ item.title }}</a>
|
||||
</div>
|
||||
</div>
|
|
@ -293,6 +293,16 @@ ponyfm.config [
|
|||
controller: 'admin-users'
|
||||
templateUrl: '/templates/admin/users.html'
|
||||
|
||||
state.state 'admin.announcements',
|
||||
url: '/announcements'
|
||||
controller: 'admin-announcements'
|
||||
templateUrl: '/templates/admin/announcements.html'
|
||||
|
||||
state.state 'admin.announcement',
|
||||
url: '/announcements/{id:[^\-]+}-{slug}'
|
||||
templateUrl: '/templates/admin/announcement-show.html'
|
||||
controller: 'admin-announcement-edit'
|
||||
|
||||
# Homepage
|
||||
|
||||
if window.pfm.auth.isLogged
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# 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').controller "admin-announcements", [
|
||||
'$scope', 'announcements'
|
||||
($scope, announcements) ->
|
||||
announcements.getAdminList().done (ann) ->
|
||||
$scope.announcements = ann
|
||||
console.log $scope.announcements
|
||||
]
|
|
@ -28,5 +28,11 @@ module.exports = angular.module('ponyfm').factory('announcements', [
|
|||
def.resolve(announcementResponse.announcement)
|
||||
def.promise()
|
||||
|
||||
getAdminList: () ->
|
||||
def = new $.Deferred()
|
||||
$http.get('/api/web/admin/announcements').success (announcementResponse) ->
|
||||
def.resolve(announcementResponse.announcements)
|
||||
def.promise()
|
||||
|
||||
self
|
||||
])
|
||||
|
|
|
@ -193,6 +193,12 @@ Route::group(['prefix' => 'api/web'], function () {
|
|||
|
||||
Route::get('/tracks', 'Api\Web\TracksController@getAllTracks');
|
||||
Route::get('/tracks/unclassified', 'Api\Web\TracksController@getClassifierQueue');
|
||||
|
||||
Route::get('/announcements', 'Api\Web\AnnouncementsController@getAdminIndex');
|
||||
Route::get('/announcements/{id}', 'Api\Web\AnnouncementsController@getItemById')->where('id', '\d+');
|
||||
Route::post('/announcements', 'Api\Web\AnnouncementsController@postCreate');
|
||||
Route::put('/announcements/{id}', 'Api\Web\AnnouncementsController@putUpdate')->where('id', '\d+');
|
||||
Route::delete('/announcements/{id}', 'Api\Web\AnnouncementsController@deleteItem')->where('id', '\d+');
|
||||
});
|
||||
|
||||
Route::post('/auth/logout', 'Api\Web\AuthController@postLogout');
|
||||
|
@ -205,6 +211,7 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-ar
|
|||
Route::get('/tracks/unclassified', 'AdminController@getClassifierQueue');
|
||||
Route::get('/show-songs', 'AdminController@getShowSongs');
|
||||
Route::get('/users', 'AdminController@getUsers');
|
||||
Route::get('/announcements', 'AdminController@getAnnouncements');
|
||||
Route::get('/', 'AdminController@getIndex');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue