FEATURE: add overview to all static pages
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Content
|
* Class Content
|
||||||
@@ -29,4 +30,38 @@ class Content extends Model
|
|||||||
const STATUS_DRAFT = 'draft';
|
const STATUS_DRAFT = 'draft';
|
||||||
const STATUS_PROTECTED = 'protected';
|
const STATUS_PROTECTED = 'protected';
|
||||||
const STATUS_PUBLIC = 'public';
|
const STATUS_PUBLIC = 'public';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for overview of all content pages of given handler (module type)
|
||||||
|
*
|
||||||
|
* @param $handler
|
||||||
|
* @param bool $joinAuthor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getByType($handler, $joinAuthor = false)
|
||||||
|
{
|
||||||
|
$query = DB::table('contents')
|
||||||
|
->select('contents.*')
|
||||||
|
->where('contents.status', '<>', self::STATUS_DELETED)
|
||||||
|
->where('module_handler', $handler)
|
||||||
|
->orderBy('created_at');
|
||||||
|
|
||||||
|
// join user email and user name to results when needed
|
||||||
|
if ($joinAuthor) {
|
||||||
|
$query = $query->join('users', 'users.id', '=', 'contents.user_id')
|
||||||
|
->select('contents.*', 'users.name AS author_name', 'users.email AS author_email');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark relationship with users table
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function author()
|
||||||
|
{
|
||||||
|
return $this->belongsTo('App\Models\User', 'user_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Enumerations\ContentStatuses;
|
||||||
|
use App\Models\Content;
|
||||||
|
|
||||||
class StaticPageOverview extends Controller
|
class StaticPageOverview extends Controller
|
||||||
{
|
{
|
||||||
public function getOverview()
|
public function getOverview($perPage = 20, $status = null)
|
||||||
{
|
{
|
||||||
return view('staticpages::admin.overview');
|
$model = new Content();
|
||||||
|
$pages = $model->getByType(config('staticpages.handler'), true);
|
||||||
|
|
||||||
|
// add filtering by status
|
||||||
|
if (!is_null($status) && in_array($status, ContentStatuses::getSimple())) {
|
||||||
|
$pages = $pages->where('status', $status);
|
||||||
|
}
|
||||||
|
$pages = $pages->paginate($perPage);
|
||||||
|
|
||||||
|
return view('staticpages::admin.overview', ['pages' => $pages]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,5 +13,11 @@ return [
|
|||||||
'field_meta_description' => 'Page description',
|
'field_meta_description' => 'Page description',
|
||||||
'field_published_from' => 'Published from',
|
'field_published_from' => 'Published from',
|
||||||
'field_published_to' => 'Published to',
|
'field_published_to' => 'Published to',
|
||||||
'successfullyCreated' => 'Page successfully created'
|
'successfullyCreated' => 'Page successfully created',
|
||||||
|
'noPagesAvailable' => 'No static pages available. Try to create one first.',
|
||||||
|
'viewPage' => 'View page on web',
|
||||||
|
'edit' => 'Edit page',
|
||||||
|
'deletePage' => 'Delete page (ireversible!)',
|
||||||
|
'makePublic' => 'Publish page',
|
||||||
|
'makeDraft' => 'Disable page and make it draft'
|
||||||
];
|
];
|
||||||
@@ -4,4 +4,56 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<h1>@lang('staticpages::admin.overview')</h1>
|
<h1>@lang('staticpages::admin.overview')</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row" id="static-page-overview" data-equalizer>
|
||||||
|
@forelse($pages as $page)
|
||||||
|
<div class="columns large-3">
|
||||||
|
<div class="callout" data-equalizer-watch>
|
||||||
|
|
||||||
|
<div class="controls pull-right">
|
||||||
|
<button class="button tiny secondary" data-toggle="static-page-{{$page->id}}actions"><i class="fa fa-caret-down"></i></button>
|
||||||
|
|
||||||
|
<div class="dropdown-pane" id="static-page-{{$page->id}}actions" data-dropdown>
|
||||||
|
<div class="row text-center">
|
||||||
|
|
||||||
|
<a href="#" class="button secondary has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.viewPage')"><i class="fa fa-desktop"></i></a>
|
||||||
|
<a href="#" class="button 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 success has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.makePublic')"><i class="fa fa-eye"></i></a>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if(in_array($page->status, [\App\Models\Content::STATUS_PROTECTED, \App\Models\Content::STATUS_PUBLIC]))
|
||||||
|
<a href="#" class="button warning 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 alert confirm pull-right has-tip" data-tooltip aria-haspopup="true" title="@lang('staticpages::admin.deletePage')"><i class="fa fa-remove"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>{{$page->title}}</h3>
|
||||||
|
<span class="date">{{$page->created_at}}</span>
|
||||||
|
<span class="author">{{$page->author_name}}</span>
|
||||||
|
|
||||||
|
@if ($page->meta_description)
|
||||||
|
<p>{{str_limit($page->meta_description)}}</p>
|
||||||
|
@else
|
||||||
|
<p>{{str_limit(strip_tags($page->content))}}</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($page->meta_keywords)
|
||||||
|
<p class="keywords">{{$page->meta_keywords}}</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<em>@lang('staticpages::admin.noPagesAvailable')</em>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
{{$pages->render()}}
|
||||||
|
</div>
|
||||||
@stop
|
@stop
|
||||||
Reference in New Issue
Block a user