menus start
This commit is contained in:
parent
975a68f988
commit
7bb73ebef5
|
|
@ -19,7 +19,14 @@ return [
|
|||
'key' => 'catalog.scrap.products',
|
||||
'name' => 'sarga::app.layouts.scrap-products',
|
||||
'route' => 'admin.scrap-products.index',
|
||||
'sort' => 1,
|
||||
'sort' => 2,
|
||||
'icon-class' => '',
|
||||
],
|
||||
[
|
||||
'key' => 'catalog.menu',
|
||||
'name' => 'sarga::app.layouts.menu',
|
||||
'route' => 'admin.menu.index',
|
||||
'sort' => 7,
|
||||
'icon-class' => '',
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\Admin\src\DataGrids;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Webkul\Core\Models\Locale;
|
||||
use Webkul\Ui\DataGrid\DataGrid;
|
||||
|
||||
class MenuDataGrid extends DataGrid
|
||||
{
|
||||
/**
|
||||
* Index.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $index = 'menu_id';
|
||||
|
||||
/**
|
||||
* Sort order.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
/**
|
||||
* Locale.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $locale = 'all';
|
||||
|
||||
/**
|
||||
* Contains the keys for which extra filters to show.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $extraFilters = [
|
||||
'locales',
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new datagrid instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->locale = core()->getRequestedLocaleCode();
|
||||
}
|
||||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
if ($this->locale === 'all') {
|
||||
$whereInLocales = Locale::query()->pluck('code')->toArray();
|
||||
} else {
|
||||
$whereInLocales = [$this->locale];
|
||||
}
|
||||
|
||||
$queryBuilder = DB::table('menus as m')
|
||||
->select(
|
||||
'm.id as menu_id',
|
||||
'mt.name',
|
||||
'm.position',
|
||||
'm.status',
|
||||
'm.locale'
|
||||
)
|
||||
->leftJoin('menu_translations as mt', function ($leftJoin) use ($whereInLocales) {
|
||||
$leftJoin->on('m.id', '=', 'mt.cmenu_id')
|
||||
->whereIn('mt.locale', $whereInLocales);
|
||||
})
|
||||
|
||||
->groupBy('m.id', 'mt.locale',);
|
||||
|
||||
|
||||
$this->addFilter('status', 'm.status');
|
||||
$this->addFilter('menu_id', 'm.id');
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
public function addColumns()
|
||||
{
|
||||
$this->addColumn([
|
||||
'index' => 'menu_id',
|
||||
'label' => trans('admin::app.datagrid.id'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'name',
|
||||
'label' => trans('admin::app.datagrid.name'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'position',
|
||||
'label' => trans('admin::app.datagrid.position'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'status',
|
||||
'label' => trans('admin::app.datagrid.status'),
|
||||
'type' => 'boolean',
|
||||
'sortable' => true,
|
||||
'searchable' => true,
|
||||
'filterable' => true,
|
||||
'closure' => function ($value) {
|
||||
if ($value->status) {
|
||||
return trans('admin::app.datagrid.active');
|
||||
} else {
|
||||
return trans('admin::app.datagrid.inactive');
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
}
|
||||
/**
|
||||
* Prepare actions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareActions()
|
||||
{
|
||||
$this->addAction([
|
||||
'title' => trans('admin::app.datagrid.edit'),
|
||||
'method' => 'GET',
|
||||
'route' => 'admin.catalog.menus.edit',
|
||||
'icon' => 'icon pencil-lg-icon',
|
||||
]);
|
||||
|
||||
$this->addAction([
|
||||
'title' => trans('admin::app.datagrid.delete'),
|
||||
'method' => 'POST',
|
||||
'route' => 'admin.catalog.menus.delete',
|
||||
'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'menu']),
|
||||
'icon' => 'icon trash-icon',
|
||||
]);
|
||||
|
||||
$this->addMassAction([
|
||||
'type' => 'delete',
|
||||
'label' => trans('admin::app.datagrid.delete'),
|
||||
'action' => route('admin.catalog.menus.massdelete'),
|
||||
'method' => 'POST',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Sarga\Admin\src\Http\Controllers;
|
||||
use Sarga\Admin\src\DataGrids\MenuDataGrid;
|
||||
use Sarga\Shop\Repositories\MenuRepository;
|
||||
use Webkul\Admin\Http\Controllers\Controller;
|
||||
|
||||
class Menus extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
public function __construct(
|
||||
protected MenuRepository $attributeRepository
|
||||
)
|
||||
{
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
public function index(){
|
||||
if (request()->ajax()) {
|
||||
return app(MenuDataGrid::class)->toJson();
|
||||
}
|
||||
|
||||
return view($this->_config['view']);
|
||||
}
|
||||
|
||||
public function create(){
|
||||
|
||||
}
|
||||
|
||||
public function store(){
|
||||
|
||||
}
|
||||
|
||||
public function edit(){
|
||||
|
||||
}
|
||||
|
||||
public function update(){}
|
||||
}
|
||||
|
|
@ -181,4 +181,19 @@ return [
|
|||
],
|
||||
],
|
||||
],
|
||||
'catalog' => [
|
||||
'menus' => [
|
||||
'title' => 'Menus',
|
||||
'add-title' => 'Add Menu',
|
||||
'edit-title' => 'Edit Menu',
|
||||
'save-btn-title' => 'Save Menu',
|
||||
'general' => 'General',
|
||||
'name' => 'Name',
|
||||
'visible-in-menu' => 'Visible In Menu',
|
||||
'yes' => 'Yes',
|
||||
'no' => 'No',
|
||||
'position' => 'Position',
|
||||
'description' => 'Description',
|
||||
],
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
@php
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
@endphp
|
||||
|
||||
@extends('admin::layouts.content')
|
||||
|
||||
@section('page_title')
|
||||
{{ __('admin::app.catalog.menus.title') }}
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
<div class="content">
|
||||
<div class="page-header">
|
||||
<div class="page-title">
|
||||
<h1>{{ __('admin::app.catalog.menus.title') }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="page-action">
|
||||
<a
|
||||
href="{{ route('admin.catalog.menus.create') }}"
|
||||
class="btn btn-lg btn-primary"
|
||||
>
|
||||
{{ __('admin::app.catalog.menus.add-title') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-content">
|
||||
<datagrid-plus src="{{ route('admin.catalog.menus.index') }}"></datagrid-plus>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@stop
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("input[type='checkbox']").change(deleteCategory);
|
||||
});
|
||||
|
||||
/**
|
||||
* Delete category function. This function name is present in category datagrid.
|
||||
* So outside scope function should be loaded `onclick` rather than `v-on`.
|
||||
*/
|
||||
let deleteCategory = function(e, type) {
|
||||
let indexes;
|
||||
|
||||
if (type == 'delete') {
|
||||
indexes = $(e.target).parent().attr('id');
|
||||
} else {
|
||||
$("input[type='checkbox']").attr('disabled', true);
|
||||
|
||||
let formData = {};
|
||||
$.each($('form').serializeArray(), function(i, field) {
|
||||
formData[field.name] = field.value;
|
||||
});
|
||||
|
||||
indexes = formData.indexes;
|
||||
}
|
||||
|
||||
if (indexes) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{{ route('admin.catalog.menus.product.count') }}',
|
||||
data: {
|
||||
_token: '{{ csrf_token() }}',
|
||||
indexes: indexes
|
||||
},
|
||||
success: function(data) {
|
||||
$("input[type='checkbox']").attr('disabled', false);
|
||||
if (data.product_count > 0) {
|
||||
let message = "{{ trans('ui::app.datagrid.massaction.delete-category-product') }}";
|
||||
|
||||
if (type == 'delete') {
|
||||
doAction(e, message);
|
||||
} else {
|
||||
$('form').attr('onsubmit', 'return confirm("' + message + '")');
|
||||
}
|
||||
} else {
|
||||
let message = "{{ __('ui::app.datagrid.click_on_action') }}";
|
||||
|
||||
if (type == 'delete') {
|
||||
doAction(e, message);
|
||||
} else {
|
||||
$('form').attr('onsubmit', 'return confirm("' + message + '")');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("input[type='checkbox']").attr('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload page.
|
||||
*/
|
||||
function reloadPage(getVar, getVal) {
|
||||
let url = new URL(window.location.href);
|
||||
|
||||
url.searchParams.set(getVar, getVal);
|
||||
|
||||
window.location.href = url.href;
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Sarga\Admin\src\Http\Controllers\Menus;
|
||||
|
||||
/**
|
||||
* Catalog routes.
|
||||
*/
|
||||
Route::group(['middleware' => ['web', 'admin'], 'prefix' => config('app.admin_url')], function () {
|
||||
Route::prefix('catalog')->group(function () {
|
||||
/**
|
||||
* Categories routes.
|
||||
*/
|
||||
Route::get('/menus', [Menus::class, 'index'])->defaults('_config', [
|
||||
'view' => 'admin::catalog.menus.index',
|
||||
])->name('admin.catalog.menus.index');
|
||||
|
||||
Route::get('/menus/create', [Menus::class, 'create'])->defaults('_config', [
|
||||
'view' => 'admin::catalog.menus.create',
|
||||
])->name('admin.catalog.menus.create');
|
||||
|
||||
Route::post('/menus/create', [Menus::class, 'store'])->defaults('_config', [
|
||||
'redirect' => 'admin.catalog.menus.index',
|
||||
])->name('admin.catalog.menus.store');
|
||||
|
||||
Route::get('/menus/edit/{id}', [Menus::class, 'edit'])->defaults('_config', [
|
||||
'view' => 'admin::catalog.menus.edit',
|
||||
])->name('admin.catalog.menus.edit');
|
||||
|
||||
Route::put('/menus/edit/{id}', [Menus::class, 'update'])->defaults('_config', [
|
||||
'redirect' => 'admin.catalog.menus.index',
|
||||
])->name('admin.catalog.menus.update');
|
||||
|
||||
Route::post('/menus/delete/{id}', [Menus::class, 'destroy'])->name('admin.catalog.menus.delete');
|
||||
|
||||
Route::post('menus/massdelete', [Menus::class, 'massDestroy'])->defaults('_config', [
|
||||
'redirect' => 'admin.catalog.menus.index',
|
||||
])->name('admin.catalog.menus.massdelete');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue