diff --git a/app/Http/Controllers/Admin/Contents/EditContent.php b/app/Http/Controllers/Admin/Contents/EditContent.php index 294b987e..9fe2da1d 100644 --- a/app/Http/Controllers/Admin/Contents/EditContent.php +++ b/app/Http/Controllers/Admin/Contents/EditContent.php @@ -117,4 +117,24 @@ class EditContent extends Controller ->route('content.overview') ->with('success', trans('admin/contents.successfullyEdited')); } + + public function order() { + $pages = $this->content->getOverview()->get(); + + return view('admin.content.order', compact('pages')); + } + + public function setOrder(Request $request) { + + $data = $request->get('page'); + + foreach ($data as $id => $order) { + Content::where('id', $id)->update(['order' => $order]); + } + + // something was changed, inform user + return redirect() + ->route('content.overview') + ->with('success', trans('admin/contents.orderSuccessfullySet')); + } } \ No newline at end of file diff --git a/app/Models/Content/Content.php b/app/Models/Content/Content.php index 6901c023..052ff9d3 100644 --- a/app/Models/Content/Content.php +++ b/app/Models/Content/Content.php @@ -7,6 +7,7 @@ use App\CMS\Helpers\Traits\Nullable; use App\CMS\Observers\Content as ContentObserver; use App\Models\FileManager\File; use App\Models\Module; +use App\Models\Templates\Template; use App\Models\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -33,6 +34,7 @@ class Content extends Model 'isHomepage', 'title', 'url', + 'order', 'metaKeywords', 'metaDescription', 'pageContent', @@ -63,6 +65,10 @@ class Content extends Model return $this->hasMany(ContentHistory::class); } + public function templateModel() { + return $this->belongsTo(Template::class, 'template', 'template_name'); + } + /** * Mark relationship with users table * @return \Illuminate\Database\Eloquent\Relations\BelongsTo @@ -100,7 +106,7 @@ class Content extends Model */ public function subpages() { - return $this->hasMany(Content::class, 'parentId'); + return $this->hasMany(Content::class, 'parentId')->orderBy('order')->orderBy('created_at', 'DESC'); } /** @@ -109,7 +115,7 @@ class Content extends Model */ public function publishedSubpages() { - $query = $this->hasMany(Content::class, 'parentId'); + $query = $this->subpages(); if (\Auth::check()) { $query = $query->where('status', '!=', ContentContract::STATUS_DRAFT); diff --git a/database/migrations/2017_09_13_105949_add_order_to_content.php b/database/migrations/2017_09_13_105949_add_order_to_content.php new file mode 100644 index 00000000..f6db114a --- /dev/null +++ b/database/migrations/2017_09_13_105949_add_order_to_content.php @@ -0,0 +1,32 @@ +integer('order') + ->after('viewed') + ->default(0); + }); + } + + /** + * Reverse the migrations. + * @return void + */ + public function down() + { + Schema::table('contents', function (Blueprint $table) { + $table->dropColumn('order'); + }); + } +} diff --git a/resources/assets/admin/css/custom.css b/resources/assets/admin/css/custom.css index f09877a4..b56038bb 100644 --- a/resources/assets/admin/css/custom.css +++ b/resources/assets/admin/css/custom.css @@ -340,79 +340,11 @@ img { width: 100%; } -/*.tag {*/ - /*display: inline-block;*/ - /*padding: 0.25em 0.4em;*/ - /*font-size: 75%;*/ - /*font-weight: bold;*/ - /*line-height: 1;*/ - /*color: #FFF;*/ - /*text-align: center;*/ - /*white-space: nowrap;*/ - /*vertical-align: baseline;*/ - /*border-radius: 0.25rem;*/ -/*}*/ - -/*.tag:empty {*/ - /*display: none;*/ -/*}*/ - -/*.btn .tag {*/ - /*position: relative;*/ - /*top: -1px;*/ -/*}*/ - -/*a.tag:focus, a.tag:hover {*/ - /*color: #FFF;*/ - /*text-decoration: none;*/ - /*cursor: pointer;*/ -/*}*/ - -/*.tag-pill {*/ - /*padding-right: 0.6em;*/ - /*padding-left: 0.6em;*/ - /*border-radius: 10rem;*/ -/*}*/ - -/*.tag-default {*/ - /*background-color: #818A91;*/ -/*}*/ - -/*.tag-default[href]:focus, .tag-default[href]:hover {*/ - /*background-color: #687077;*/ -/*}*/ - -/*.tag-success {*/ - /*background-color: #5CB85C;*/ -/*}*/ - -/*.tag-success[href]:focus, .tag-success[href]:hover {*/ - /*background-color: #449D44;*/ -/*}*/ - -/*.tag-info {*/ - /*background-color: #5BC0DE;*/ -/*}*/ - -/*.tag-info[href]:focus, .tag-info[href]:hover {*/ - /*background-color: #31B0D5;*/ -/*}*/ - -/*.tag-warning {*/ - /*background-color: #F0AD4E;*/ -/*}*/ - -/*.tag-warning[href]:focus, .tag-warning[href]:hover {*/ - /*background-color: #EC971F;*/ -/*}*/ - -/*.tag-danger {*/ - /*background-color: #D9534F;*/ -/*}*/ - -/*.tag-danger[href]:focus, .tag-danger[href]:hover {*/ - /*background-color: #C9302C;*/ -/*}*/ - +.has-subpages:hover { + cursor: pointer; +} +#orderSetup .subpage td:first-child { + padding-left: 35px; +} diff --git a/resources/assets/admin/js/app.js b/resources/assets/admin/js/app.js index 5c2dc532..4c48a5cc 100644 --- a/resources/assets/admin/js/app.js +++ b/resources/assets/admin/js/app.js @@ -386,9 +386,9 @@ $ (document).ready (function () { $ ('#confirm-button').attr ('href', href); } else if (tag === 'BUTTON') { - var form = $(this).closest('form'); + var form = $ (this).closest ('form'); $ ('#confirm-button').click (function () { - form.submit(); + form.submit (); }) } @@ -461,4 +461,12 @@ $ ('.checkbox').change (function () { var parent = e.data ('parent'); $ ('#checkbox-parent-' + parent).prop ('checked', true); } -}); \ No newline at end of file +}); + +$ ('.has-subpages').click (function (e) { + if (!$ (e.target).is ("div")) + return; + + var id = $ (this).data ('id'); + $ ('.parent-page-' + id).toggleClass ('hidden-xs-up'); +}) \ No newline at end of file diff --git a/resources/assets/sass/admin/_common/items-list.scss b/resources/assets/sass/admin/_common/items-list.scss index 239d417d..f0c3bd4a 100644 --- a/resources/assets/sass/admin/_common/items-list.scss +++ b/resources/assets/sass/admin/_common/items-list.scss @@ -49,6 +49,19 @@ ********************************************** */ .item-list { + + .subpage { + padding-left: 35px; + } + + .thumbnail { + width: 100%; + height: 80px; + background-size: cover; + background-repeat: no-repeat; + background-position: center center; + } + .item { display: flex; flex-direction: column; diff --git a/resources/lang/cs/admin/contents.php b/resources/lang/cs/admin/contents.php index a48dd961..1e84ba2a 100644 --- a/resources/lang/cs/admin/contents.php +++ b/resources/lang/cs/admin/contents.php @@ -56,4 +56,6 @@ return [ "title" => "Titulek", "uploadTitleImage" => "Nahrát titulní obrázek", "viewPage" => "Zobrazit", + 'setOrder' => 'Nastavení pořadí stránek', + 'orderSuccessfullySet' => 'Pořadí stránek úspěšně nastaveno', ]; diff --git a/resources/lang/cs/admin/mainMenu.php b/resources/lang/cs/admin/mainMenu.php index cc18fea7..595883d3 100644 --- a/resources/lang/cs/admin/mainMenu.php +++ b/resources/lang/cs/admin/mainMenu.php @@ -27,5 +27,6 @@ return [ "widgetAreas" => "Plochy pro widgety", "widgets" => "Widgety", "widgetsOverview" => "Všechny widgety", - 'permissions' => 'Přístupová práva' + 'permissions' => 'Přístupová práva', + 'contentOrder' => 'Pořadí stránek' ]; diff --git a/resources/views/admin/content/_partials/orderSetupRow.blade.php b/resources/views/admin/content/_partials/orderSetupRow.blade.php new file mode 100644 index 00000000..db691d26 --- /dev/null +++ b/resources/views/admin/content/_partials/orderSetupRow.blade.php @@ -0,0 +1,16 @@ +