FEATURE: add quick actions to static page overview

This commit is contained in:
Michal Kváček
2016-01-28 13:38:30 +01:00
parent 0f4ad90cd8
commit 1b2d7db8f3
5 changed files with 133 additions and 15 deletions
@@ -1,10 +1,94 @@
<?php
namespace Modules\StaticPages\Http\Controllers\Admin;
use App\Enumerations\ContentStatuses;
use App\Models\Content;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EditStaticPage extends Controller
{
public function getEdit($id)
{
return view('staticpages::index');
}
/**
* Method for changing page status
*
* This method is called in static page overview from quick actions. It checks if status is valid, if page exists
* and updates status.
*
* @param $id
* @param $status
*
* @return \Illuminate\Http\RedirectResponse
*/
public function changeStatus($id, $status)
{
// get possible statuses
$statuses = ContentStatuses::getWithTranslations();
unset($statuses[Content::STATUS_DELETED]);
// check if given status is valid
if (!isset($statuses[$status])) {
return redirect()
->route('staticpage.overview')
->with('error', trans('staticpages::admin.invalidStatus'));
}
try {
// try to find this page
$page = Content::where('module_handler', config('staticpages.handler'))
->findOrFail($id);
// page found, save status
$page->status = $status;
$page->save();
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.statusChanged'));
} catch (NotFoundHttpException $e) {
// page not found
return redirect()
->route('staticpage.overview')
->with('error', trans('staticpages::admin.invalidPage'));
}
}
/**
* Delete page
*
* @param $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deletePage($id)
{
try {
// try to find this page
$page = Content::where('module_handler', config('staticpages.handler'))
->findOrFail($id);
// page found, save status
$page->status = Content::STATUS_DELETED;
$page->save();
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.pageDeleted', [
'name' => $page->title,
'url' => $page->url
]));
} catch (NotFoundHttpException $e) {
// page not found
return redirect()
->route('staticpage.overview')
->with('error', trans('staticpages::admin.invalidPage'));
}
}
}
+17 -1
View File
@@ -8,7 +8,6 @@ Route::group([
Route::get('/{url}', 'StaticPagesController@index');
});
// routes group for admin area
Route::group([
'middleware' => ['web', 'auth'],
@@ -31,4 +30,21 @@ Route::group([
// post method for creating new static page
Route::post('new', 'CreateNewStaticPage@postNew')
->name('staticpage.newPost');
// routes for quick actions
// change status of page (protected, public or draft)
Route::get('status/{id}/{status}', 'EditStaticPage@changeStatus')
->name('staticpage.changeStatus');
// delete page
Route::get('delete/{id}', 'EditStaticPage@deletePage')
->name('staticpage.delete');
// display change history of given page
// Route::get('history/{id}', 'StaticPageHistory@getHistory')->name('staticpage.history');
// Route::get('', '')->name('staticpage.');
});