FEATURE: add quick actions to static page overview
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.');
|
||||
});
|
||||
@@ -18,6 +18,12 @@ return [
|
||||
'viewPage' => 'View page on web',
|
||||
'edit' => 'Edit page',
|
||||
'deletePage' => 'Delete page (ireversible!)',
|
||||
'makePublic' => 'Publish page',
|
||||
'makeDraft' => 'Disable page and make it draft'
|
||||
'makePublic' => 'Publish page',
|
||||
'makeProtected' => 'Publish page only for logged users',
|
||||
'makeDraft' => 'Disable page and make it draft',
|
||||
'invalidStatus' => 'Cannot change status to something undefined.',
|
||||
'statusChanged' => 'Status successfully changed.',
|
||||
'invalidPage' => 'Specified page does not exist.',
|
||||
'pageDeleted' => 'Page :name (:url) successfully deleted.'
|
||||
|
||||
];
|
||||
@@ -3,6 +3,18 @@
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<h1>@lang('staticpages::admin.overview')</h1>
|
||||
|
||||
@if (session('success'))
|
||||
<div data-alert class="callout success">
|
||||
<strong>{{ session('success') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (session('error'))
|
||||
<div data-alert class="callout alert">
|
||||
<strong>{{ session('error') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="row" id="static-page-overview" data-equalizer>
|
||||
@@ -19,15 +31,15 @@
|
||||
{{--</div>--}}
|
||||
|
||||
<h4>{{$page->title}}</h4>
|
||||
<span class="date">{{$page->created_at}}</span>
|
||||
<span class="date">{{date('d.m.Y', strtotime($page->created_at))}}</span>
|
||||
<span class="author">{{$page->author_name}}</span>
|
||||
|
||||
<p class="perex">
|
||||
@if (trim($page->meta_description))
|
||||
{{str_limit($page->meta_description)}}
|
||||
@else
|
||||
{{str_limit(strip_tags($page->content))}}
|
||||
@endif
|
||||
@if (trim($page->meta_description))
|
||||
{{str_limit($page->meta_description)}}
|
||||
@else
|
||||
{{str_limit(strip_tags($page->content))}}
|
||||
@endif
|
||||
</p>
|
||||
|
||||
@if ($page->meta_keywords)
|
||||
@@ -36,18 +48,19 @@
|
||||
|
||||
<p class="controls row text-center">
|
||||
|
||||
<a href="#" class="button tiny secondary has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.viewPage')"><i class="fa fa-desktop"></i></a>
|
||||
<a href="#" class="button tiny success has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.edit')"><i class="fa fa-edit"></i></a>
|
||||
{{--<a href="#" class="button tiny secondary has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.viewPage')"><i class="fa fa-desktop"></i></a>--}}
|
||||
<a href="{{route('staticpage.edit', ['id' => $page->id])}}" class="button tiny success has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.edit')"><i class="fa fa-edit"></i></a>
|
||||
|
||||
@if($page->status == \App\Models\Content::STATUS_DRAFT)
|
||||
<a href="#" class="button tiny success confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makePublic')"><i class="fa fa-eye"></i></a>
|
||||
<a href="{{route('staticpage.changeStatus', ['id' => $page->id, 'status' => \App\Models\Content::STATUS_PUBLIC])}}" class="button tiny success confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makePublic')"><i class="fa fa-eye"></i></a>
|
||||
<a href="{{route('staticpage.changeStatus', ['id' => $page->id, 'status' => \App\Models\Content::STATUS_PROTECTED])}}" class="button tiny warning confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makeProtected')"><i class="fa fa-lock"></i></a>
|
||||
@endif
|
||||
|
||||
@if(in_array($page->status, [\App\Models\Content::STATUS_PROTECTED, \App\Models\Content::STATUS_PUBLIC]))
|
||||
<a href="#" class="button tiny warning confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makeDraft')"><i class="fa fa-eye-slash"></i></a>
|
||||
<a href="{{route('staticpage.changeStatus', ['id' => $page->id, 'status' => \App\Models\Content::STATUS_DRAFT])}}" class="button tiny warning confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makeDraft')"><i class="fa fa-eye-slash"></i></a>
|
||||
@endif
|
||||
|
||||
<a href="#" class="button tiny alert confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.deletePage')"><i class="fa fa-remove"></i></a>
|
||||
<a href="{{route('staticpage.delete', ['id' => $page->id])}}" class="button tiny alert confirm has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.deletePage')"><i class="fa fa-remove"></i></a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
Vendored
-1
@@ -60,7 +60,6 @@
|
||||
#static-page-overview .keywords {
|
||||
margin-bottom: 0;
|
||||
font-size: 80%;
|
||||
background:red;
|
||||
}
|
||||
|
||||
.red {
|
||||
|
||||
Reference in New Issue
Block a user