Permalink
Browse files

Add managable Banners Order

  • Loading branch information...
bpocallaghan committed Jan 16, 2018
1 parent 6f86514 commit 315fc9fff08cc4289dc84ea12628549e38f2e773
@@ -1,7 +1,9 @@
##Admin Starter - TODO
- ~~Add cropper for Gallery photos~~
- Update bootstrap 4 to latest beta version
- Add cropper for Images (Banners)
- ~~Update bootstrap 4 to latest beta version~~
- ~~Make Banners Order Dynamic (specify their order)~~
- Move components to seperate packages for more mudular structure
- ~~[Locations](https://github.com/bpocallaghan/locations)~~
- ~~[Subscriptions](https://github.com/bpocallaghan/subscriptions)~~
@@ -116,6 +116,9 @@ public function update(Banner $banner, Request $request)
*/
public function destroy(Banner $banner, Request $request)
{
// update list order
$banner->update(['list_order' => 999]);
$this->deleteEntry($banner, $request);
return redirect_to_resource();
@@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Banner;
use App\Http\Requests;
use Illuminate\Http\Request;
class BannersOrderController extends AdminController
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$items = Banner::active()->orderBy('list_order')->get();
return $this->view('banners.order')->with('items', $items);
}
/**
* Update the order
* @param Request $request
* @return array
*/
public function update(Request $request)
{
$items = json_decode($request->get('list'), true);
foreach ($items as $key => $item) {
Banner::find($item['id'])->update(['list_order' => ($key + 1)]);
}
return ['result' => 'success'];
}
}
@@ -66,7 +66,10 @@ protected function getBanners()
// if no banners linked to page - get default
if ($items->count() <= 0) {
$items = Banner::active()->where('is_website', 1)->orderBy('created_at', 'DESC')->get();
$items = Banner::active()
->where('is_website', 1)
->orderBy('list_order')
->get();
}
return $items;
@@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Titan\Models\TitanCMSModel;
@@ -48,4 +49,26 @@ public function pages()
{
return $this->belongsToMany(Page::class);
}
/**
* Get the is active label attribute
* @return string
*/
public function getIsActiveLabelAttribute()
{
$title = 'Not Active';
$class = 'danger';
$from = Carbon::parse($this->active_from);
$to = Carbon::parse($this->active_to);
if (!$this->active_to || Carbon::now()->diffInMinutes($to, false) > 0) {
if (Carbon::now()->diffInMinutes($from, false) < 0) {
$title = 'Active';
$class = 'success';
}
}
return "<span class='label label-{$class}'>{$title}</span>";
}
}
@@ -23,6 +23,7 @@ public function up()
$table->timestamp('active_to')->nullable();
$table->boolean('is_website')->default(0); // if for a page or website
$table->boolean('hide_name')->default(0); // to hide the banner name
$table->integer('list_order')->default(1); // default first banner
$table->timestamps();
$table->softDeletes();
$table->integer('created_by')->unsigned();
@@ -15,7 +15,7 @@
@include('admin.partials.info')
@include('admin.partials.toolbar')
@include('admin.partials.toolbar', ['order' => true])
<table id="tbl-list" data-server="false" class="dt-table table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
@@ -27,7 +27,7 @@
<th>Active To</th>
<th>Image</th>
<th>Website</th>
<th>Action</th>
<th style="min-width: 70px;">Action</th>
</tr>
</thead>
<tbody>
@@ -0,0 +1,56 @@
@extends('layouts.admin')
@section('content')
<div class="row">
<div class="col-xs-12">
<div class="box box-primary box-solid">
<div class="box-header with-border">
<h3 class="box-title">
<span><i class="fa fa-align-center"></i></span>
<span>Update {{ ucfirst($resource) }} List Order</span>
</h3>
</div>
<div class="box-body">
<div class="well well-sm well-toolbar" id="nestable-menu">
<a href="javascript:window.history.back();" class="btn btn-labeled btn-default">
<span class="btn-label"><i class="fa fa-fw fa-chevron-left"></i></span>Back
</a>
</div>
<div class="row">
<div class="col-xs-12">
<div class="dd" id="dd-navigation" style="max-width: 100%">
<ol class="dd-list">
@foreach($items as $item)
<li class="dd-item" data-id="{{ $item->id }}">
<div class="dd-handle" style="overflow: auto;">
<p style="float: left">
{{ $item->name }} (Visibility: <strong>{{ $item->is_website? 'All Pages':'Page Specific' }}</strong>) (Expire: <strong>{{ $item->active_to? $item->active_to : 'Never' }}</strong>)
<br/>{{ $item->summary }}
</p>
<img src="{{ uploaded_images_url($item->image) }}" style="height: 50px; float: right;">
</div>
</li>
@endforeach
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@include('admin.partials.nestable')
@endsection
@section('scripts')
@parent
<script type="text/javascript" charset="utf-8">
$(function ()
{
initNestableMenu(1, "{{ request()->url() }}");
})
</script>
@endsection
@@ -13,11 +13,11 @@
<div class="col-sm-3">
<div class="card h-100">
<div class="card-header">
<h4 class="card-title"><i class="fa fa-fw fa-check"></i> Laravel v5.5.19</h4>
<h4 class="card-title"><i class="fa fa-fw fa-check"></i> Laravel v5.5.28</h4>
</div>
<div class="card-body">
<ul>
<li><strong>Laravel v5.5.19+</strong></li>
<li><strong>Laravel v5.5.28+</strong></li>
<li><strong>AdminLTE v2.4.2</strong></li>
<li><strong>Bootstrap v4.0.0</strong></li>
<li><strong>jQuery v3.2.1</strong></li>
@@ -126,6 +126,8 @@ function () {
Route::group(['prefix' => 'general'], function () {
Route::resource('tags', 'TagsController');
Route::get('/banners/order', 'BannersOrderController@index');
Route::post('/banners/order', 'BannersOrderController@update');
Route::resource('banners', 'BannersController');
Route::resource('clients', 'ClientsController');

0 comments on commit 315fc9f

Please sign in to comment.