Slider layers now working, datagrid on slider working

This commit is contained in:
prashant-webkul 2018-08-08 19:17:40 +05:30
parent 3fa134ca16
commit 8406da969d
9 changed files with 234 additions and 26 deletions

View File

@ -0,0 +1,146 @@
<?php
namespace Webkul\Admin\Http\ViewComposers\DataGrids;
use Illuminate\View\View;
use Webkul\Ui\DataGrid\Facades\DataGrid;
// use App\Repositories\UserRepository;
class SliderComposer
{
/**
* The Data Grid implementation.
*
* @var CountryComposer
* for countries
*/
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
$datagrid = DataGrid::make([
'name' => 'Sliders',
'table' => 'sliders',
'select' => 'id',
'perpage' => 5,
'aliased' => false, //use this with false as default and true in case of joins
'massoperations' =>[
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
],
],
'actions' => [
[
'type' => 'Edit',
'route' => route('admin.datagrid.delete'),
'confirm_text' => 'Do you really edit this record?',
'icon' => 'icon pencil-lg-icon',
], [
'type' => 'Delete',
'route' => route('admin.datagrid.delete'),
'confirm_text' => 'Do you really want to delete this record?',
'icon' => 'icon trash-icon',
],
],
'join' => [
// [
// 'join' => 'leftjoin',
// 'table' => 'roles as r',
// 'primaryKey' => 'u.role_id',
// 'condition' => '=',
// 'secondaryKey' => 'r.id',
// ]
],
//use aliasing on secodary columns if join is performed
'columns' => [
[
'name' => 'id',
'alias' => 'slider_id',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'title',
'alias' => 'slider_title',
'type' => 'string',
'label' => 'title',
'sortable' => true,
],
],
//don't use aliasing in case of filters
'filterable' => [
// [
// 'column' => 'id',
// 'alias' => 'locale_id',
// 'type' => 'number',
// 'label' => 'ID',
// ],
// [
// 'column' => 'code',
// 'alias' => 'locale_code',
// 'type' => 'string',
// 'label' => 'Code',
// ],
// [
// 'column' => 'name',
// 'alias' => 'locale_name',
// 'type' => 'string',
// 'label' => 'Name',
// ],
],
//don't use aliasing in case of searchables
'searchable' => [
// [
// 'column' => 'name',
// 'type' => 'string',
// 'label' => 'Name',
// ],
// [
// 'column' => 'code',
// 'type' => 'string',
// 'label' => 'Code',
// ],
],
//list of viable operators that will be used
'operators' => [
'eq' => "=",
'lt' => "<",
'gt' => ">",
'lte' => "<=",
'gte' => ">=",
'neqs' => "<>",
'neqn' => "!=",
'like' => "like",
'nlike' => "not like",
],
// 'css' => []
]);
$view->with('datagrid', $datagrid);
// $view->with('count', $this->users->count());
}
}

View File

@ -301,13 +301,18 @@ Route::group(['middleware' => ['web']], function () {
Route::put('/account', 'Webkul\User\Http\Controllers\AccountController@update')->name('admin.account.update');
// Admin Store Front Settings Route
Route::get('/slider/create','Webkul\Shop\Http\Controllers\SliderController@index')->defaults('_config',[
'view' => 'admin::sliders.create'
Route::get('/slider','Webkul\Shop\Http\Controllers\SliderController@index')->defaults('_config',[
'view' => 'admin::settings.sliders.index'
])->name('admin.sliders.index');
Route::post('/slider/create','Webkul\Shop\Http\Controllers\SliderController@create')->defaults('_config',[
'redirect' => 'admin::sliders.create'
// Admin Store Front Settings Route
Route::get('/slider/create','Webkul\Shop\Http\Controllers\SliderController@create')->defaults('_config',[
'view' => 'admin::settings.sliders.create'
])->name('admin.sliders.create');
Route::post('/slider/create','Webkul\Shop\Http\Controllers\SliderController@store')->defaults('_config',[
'redirect' => 'admin::sliders.index'
])->name('admin.sliders.store');
});
});
});

View File

@ -41,6 +41,9 @@ class ComposerServiceProvider extends ServiceProvider
//for channels in admin dashboard
View::composer('admin::settings.channels.index', 'Webkul\Admin\Http\ViewComposers\DataGrids\ChannelsComposer');
//for sliders in admin dashboard
View::composer('admin::settings.sliders.index', 'Webkul\Admin\Http\ViewComposers\DataGrids\SliderComposer');
}
/**

View File

@ -243,7 +243,7 @@ return [
],
'sliders' => [
'title' => 'Title',
'title' => 'Sliders',
'add-title' => 'Create Slider',
'save-btn-title' => 'Save Slider',
'general' => 'General',

View File

@ -31,14 +31,14 @@
<span class="control-error" v-if="errors.has('title')">@{{ errors.first('title') }}</span>
</div>
<div class="control-group" :class="[errors.has('channel') ? 'has-error' : '']">
<label for="channel">{{ __('admin::app.settings.sliders.channels') }}</label>
<select class="control" id="channel" name="channel" value="" v-validate="'required'">
<div class="control-group" :class="[errors.has('channel_id') ? 'has-error' : '']">
<label for="channel_id">{{ __('admin::app.settings.sliders.channels') }}</label>
<select class="control" id="channel_id" name="channel_id" value="" v-validate="'required'">
@foreach($channels[0] as $channel)
<option value="{{ $channel->id }}">{{ __($channel->name) }}</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('channel')">@{{ errors.first('channel') }}</span>
<span class="control-error" v-if="errors.has('channel_id')">@{{ errors.first('channel_id') }}</span>
</div>
<div class="control-group" :class="[errors.has('image') ? 'has-error' : '']">

View File

@ -0,0 +1,21 @@
@extends('admin::layouts.content')
@section('content')
<div class="content">
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.settings.sliders.title') }}</h1>
</div>
<div class="page-action">
<a href="{{ route('admin.sliders.store') }}" class="btn btn-lg btn-primary">
{{ __('admin::app.settings.sliders.add-title') }}
</a>
</div>
</div>
<div class="page-content">
{!! $datagrid->render() !!}
</div>
</div>
@stop

View File

@ -11,7 +11,10 @@ class Slider extends Model
*
* @var array
*/
protected $table = 'sliders';
protected $fillable = [
'tile', 'path','content','channel_id'
'title', 'path','content','channel_id'
];
}

View File

@ -21,4 +21,22 @@ class SliderRepository extends Repository
{
return 'Webkul\Core\Models\Slider';
}
/**
* @param array $data
* @return mixed
*/
public function create(array $data)
{
$image = request()->file('image');
$image_name = trim($data['title']).'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/vendor/webkul/shop/assets/images/slider');
$path = $image->move($destinationPath, $image_name);
$path= $path->getrealPath();
$data['path'] = $path;
$this->model->create($data);
}
}

View File

@ -18,32 +18,44 @@ use Webkul\Core\Repositories\SliderRepository as Slider;
class SliderController extends controller
{
protected $_config;
protected $slider;
protected $channels;
public function __construct()
public function __construct(Slider $slider)
{
$this->slider = $slider;
$this->_config = request('_config');
}
public function index(){
/**
* Loads the index
* for the sliders
* settings.
*/
public function index() {
return view($this->_config['view']);
}
/**
* Loads the form
* for creating
* slider.
*/
public function create() {
$call = new Channel();
$channels = $call->getChannelWithLocales();
return view($this->_config['view'])->with('channels',[$channels]);
}
public function create(Request $request) {
$this->validate($request,[
'title' => 'string|required|max:100',
'image' => 'required|image|mimes:png,jpg',
// |dimensions:ratio=12/5
'content' => 'string'
]);
$image = $request->file('image');
$input['imagename'] = time().'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$image->move($destinationPath, $input['imagename']);
/**
* Creates the new
* sider item
*/
public function store() {
// dd($request->title,$full_path->getrealPath(),$request->content,$request->channel);
$this->slider->create(request()->all());
return redirect()->back();
}
}