mass operations and datagrid operations normalization

This commit is contained in:
prashant-webkul 2018-11-30 20:37:41 +05:30
parent 1ba21f281d
commit 7fb67dc161
21 changed files with 4812 additions and 225 deletions

View File

@ -32,23 +32,23 @@ class AttributeDataGrid
'aliased' => true,
'massoperations' => [
// [
// 'route' => route('admin.datagrid.delete'),
// 'method' => 'DELETE',
// 'label' => 'Delete',
// 'type' => 'button',
// ],
[
'route' => route('admin.catalog.attributes.massdelete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
]
],
'actions' => [
[
'type' => 'Edit',
'route' => route('admin.datagrid.delete'),
'route' => 'admin.catalog.attributes.edit',
'confirm_text' => 'Do you really want to edit this record?',
'icon' => 'icon pencil-lg-icon',
], [
'type' => 'Delete',
'route' => route('admin.datagrid.delete'),
'route' => 'admin.catalog.attributes.edit',
'confirm_text' => 'Do you really want to delete this record?',
'icon' => 'icon trash-icon',
],
@ -57,7 +57,6 @@ class AttributeDataGrid
'join' => [],
//use aliasing on secodary columns if join is performed
'columns' => [
[
'name' => 'id',

View File

@ -24,7 +24,7 @@ class CurrencyDataGrid
public function createCurrencyDataGrid()
{
return DataGrid::make([
return DataGrid::make([
'name' => 'Currencies',
'table' => 'currencies',
'select' => 'id',
@ -32,12 +32,12 @@ class CurrencyDataGrid
'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',
// ],
[
'route' => route('admin.currencies.massdelete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
]
],
'actions' => [
@ -65,9 +65,7 @@ class CurrencyDataGrid
],
//use aliasing on secodary columns if join is performed
'columns' => [
[
'name' => 'id',
'alias' => 'currencyId',

View File

@ -31,12 +31,12 @@ class CustomerDataGrid
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button', //select || button only
],
// [
// 'route' => route('admin.datagrid.delete'),
// 'method' => 'DELETE',
// 'label' => 'Delete',
// 'type' => 'button', //select || button only
// ],
],
'actions' => [

View File

@ -11,172 +11,16 @@ use Webkul\Ui\DataGrid\Facades\DataGrid;
* DataGrid controller
*
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class DataGridController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
DataGrid::make([
'name' => 'Admin Datagrid',
'table' => 'admins as u',
'select' => 'u.id',
'aliased' => true , //boolean to validate aliasing on the basis of this.
'perpage' => 2,
'filterable' => [
[
'column' => 'u.id',
'type' => 'integer',
'label' => 'Admin ID'
], [
'column' => 'u.email',
'type' => 'string',
'label' => 'Admin Email',
], [
'column' => 'u.name',
'type' => 'string',
'label' => 'Admin Name',
]
],
'searchables' =>[
[
'name' => 'u.id',
'label' => 'ID',
'label' => 'Admin ID',
],
[
'name' => 'u.name',
'label' => 'Name',
'label' => 'Admin Name',
]
],
'join' => [
[
'join' => 'leftjoin',
'table' => 'roles as r',
'primaryKey' => 'u.role_id',
'condition' => '=',
'secondaryKey' => 'r.id',
]
],
'columns' => [
[
'name' => 'u.id',
'type' => 'string',
'label' => 'Admin ID',
'sortable' => true,
'filterable' => true
],
[
'name' => 'u.email',
'type' => 'string',
'label' => 'Admin Email',
'sortable' => true,
'filterable' => true
],
[
'name' => 'u.name',
'type' => 'string',
'label' => 'Admin Name',
'sortable' => true,
'filterable' => true,
// will create on run time query
// 'filter' => [
// 'function' => 'orwhere', // orwhere
// 'condition' => ['name', 'like', 'u'] // multiarray
// ],
'attributes' => [
'class' => 'class-a class-b',
'data-attr' => 'whatever you want',
'onclick' => "window.alert('alert from datagrid column')"
],
'wrapper' => function ($value, $object) {
return '<a href="'.$value.'">' . $object->name . '</a>';
},
],
[
'name' => 'r.name as x',
'type' => 'string',
'label' => 'Admin\'s Role',
'sortable' => true,
'filterable' => true,
],
[
'name' => 'r.id as xx',
'type' => 'integer',
'label' => 'Role ID',
'sortable' => false,
'filterable' => false
],
],
'operators' => [
'eq' => "=",
'lt' => "<",
'gt' => ">",
'lte' => "<=",
'gte' => ">=",
'neqn' => "!=",
'ceq' => "<=>",
'like' => "like",
'nlike' => "not like",
],
'mass_operations' =>[
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
]
],
// 'css' => []
]);
$result = DataGrid::render();
return $result;
public function massDelete() {
dd(request()->all());
}
//for performing mass actions
public function massAction()
{
$make = [
'operations' =>[
// [
// 'route' => 'datagrid/update',
// 'method' => 'post',
// 'label' => 'Update',
// 'type' => 'select',
// 'name' => 'status',
// 'values' => [
// [
// 'label' => 'Enable',
// 'value' => 1
// ], [
// 'label' => 'Disable',
// 'value' => 0
// ]
// ],
// ],
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button'
]
]
];
$result = DataGrid::makeMassAction($make);
}
public function massDelete(Request $r)
{
return $r;
public function massUpdate() {
dd(request()->all());
}
}

View File

@ -7,11 +7,11 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'admin::users.sessions.create'
])->name('admin.session.create');
//login post route to admin auth controller
Route::post('/login', 'Webkul\User\Http\Controllers\SessionController@store')->defaults('_config', [
'redirect' => 'admin.dashboard.index'
])->name('admin.session.store');
// Forget Password Routes
Route::get('/forget-password', 'Webkul\User\Http\Controllers\ForgetPasswordController@create')->defaults('_config', [
'view' => 'admin::users.forget-password.create'
@ -19,7 +19,6 @@ Route::group(['middleware' => ['web']], function () {
Route::post('/forget-password', 'Webkul\User\Http\Controllers\ForgetPasswordController@store')->name('admin.forget-password.store');
// Reset Password Routes
Route::get('/reset-password/{token}', 'Webkul\User\Http\Controllers\ResetPasswordController@create')->defaults('_config', [
'view' => 'admin::users.reset-password.create'
@ -36,13 +35,11 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.session.create'
])->name('admin.session.destroy');
// Dashboard Route
Route::get('dashboard', 'Webkul\Admin\Http\Controllers\DashboardController@index')->defaults('_config', [
'view' => 'admin::dashboard.index'
])->name('admin.dashboard.index');
//Customers Management Routes
Route::get('customers', 'Webkul\Admin\Http\Controllers\Customer\CustomerController@index')->defaults('_config', [
'view' => 'admin::customers.index'
@ -248,8 +245,9 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.catalog.attributes.index'
])->name('admin.catalog.attributes.update');
Route::get('/attributes/delete/{id}', 'Webkul\Attribute\Http\Controllers\AttributeController@destroy')->name('admin.catalog.attributes.delete');
Route::get('/attributes/delete/{id}', 'Webkul\Attribute\Http\Controllers\AttributeController@destroy')->name('admin.catalog.attributes.edit');
Route::delete('/attributes/massdelete', 'Webkul\Attribute\Http\Controllers\AttributeController@massDestroy')->name('admin.catalog.attributes.massdelete');
// Catalog Family Routes
Route::get('/families', 'Webkul\Attribute\Http\Controllers\AttributeFamilyController@index')->defaults('_config', [
@ -283,7 +281,7 @@ Route::group(['middleware' => ['web']], function () {
Route::any('datagrid/massaction/delete', 'Webkul\Admin\Http\Controllers\DataGridController@massDelete')->name('admin.datagrid.delete');
Route::any('datagrid/massaction/edit','Webkul\Admin\Http\Controllers\DataGridController@massUpdate')->name('admin.datagrid.edit');
Route::any('datagrid/massaction/update','Webkul\Admin\Http\Controllers\DataGridController@massUpdate')->name('admin.datagrid.update');
// User Routes
@ -379,6 +377,8 @@ Route::group(['middleware' => ['web']], function () {
Route::get('/currencies/delete/{id}', 'Webkul\Core\Http\Controllers\CurrencyController@destroy')->name('admin.currencies.delete');
Route::any('/currencies/massdelete', 'Webkul\Core\Http\Controllers\CurrencyController@massDestroy')->name('admin.currencies.massdelete');
// Exchange Rates Routes
Route::get('/exchange_rates', 'Webkul\Core\Http\Controllers\ExchangeRateController@index')->defaults('_config', [

View File

@ -2,7 +2,7 @@
return [
'common' => [
'no-result-found' => 'We couldn\'t find any records.',
'no-result-found' => 'We could not find any records.',
'country' => 'Country',
'state' => 'State'
],
@ -27,6 +27,15 @@ return [
'stock-threshold' => 'Stock Threshold',
'qty-left' => ':qty Left',
],
'datagrid' => [
'mass-ops' => [
'method-error' => 'Error! Wrong method detected, please check mass action configuration',
'delete-success' => 'Selected index of :resource were successfully deleted',
'partial-action' => 'Some actions were not performed due restricted system constraints on :resource'
]
],
'account' => [
'title' => 'My Account',
'save-btn-title' => 'Save',

View File

@ -42,6 +42,8 @@
window.flashMessages = [{'type': 'alert-warning', 'message': "{{ $warning }}" }];
@elseif($error = session('error'))
window.flashMessages = [{'type': 'alert-error', 'message': "{{ $error }}" }];
@elseif($info = session('info'))
window.flashMessages = [{'type': 'alert-error', 'message': "{{ $info }}" }];
@endif
window.serverErrors = [];

View File

@ -128,7 +128,7 @@ class AttributeController extends Controller
public function destroy($id)
{
$attribute = $this->attribute->findOrFail($id);
if(!$attribute->is_user_defined) {
session()->flash('error', 'Can not delete system attribute.');
} else {
@ -143,4 +143,38 @@ class AttributeController extends Controller
return redirect()->back();
}
/**
* Remove the specified resources from database
*
* @return response \Illuminate\Http\Response
*/
public function massDestroy() {
$suppressFlash = false;
if(request()->isMethod('delete')) {
$indexes = explode(',', request()->input('indexes'));
foreach($indexes as $key => $value) {
try {
$this->attribute->delete($value);
} catch(\Exception $e) {
$suppressFlash = true;
continue;
}
}
if(!$suppressFlash)
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success'));
else
session()->flash('info', trans('admin::app.datagrid.mass-ops.partial-action', ['resource' => 'attributes']));
return redirect()->back();
} else {
session()->flash('error', trans('admin::app.datagrid.mass-ops.method-error'));
return redirect()->back();
}
}
}

View File

@ -149,4 +149,38 @@ class AttributeFamilyController extends Controller
return redirect()->back();
}
/**
* Remove the specified resources from database
*
* @return response \Illuminate\Http\Response
*/
public function massDestroy() {
$suppressFlash = false;
if(request()->isMethod('delete')) {
$indexes = explode(',', request()->input('indexes'));
foreach($indexes as $key => $value) {
try {
$this->attributeFamily->delete($value);
} catch(\Exception $e) {
$suppressFlash = true;
continue;
}
}
if(!$suppressFlash)
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success'));
else
session()->flash('info', trans('admin::app.datagrid.mass-ops.partial-action', ['resource' => 'Attribute Family']));
return redirect()->back();
} else {
session()->flash('error', trans('admin::app.datagrid.mass-ops.method-error'));
return redirect()->back();
}
}
}

View File

@ -139,4 +139,38 @@ class CategoryController extends Controller
return redirect()->back();
}
/**
* Remove the specified resources from database
*
* @return response \Illuminate\Http\Response
*/
public function massDestroy() {
$suppressFlash = false;
if(request()->isMethod('delete')) {
$indexes = explode(',', request()->input('indexes'));
foreach($indexes as $key => $value) {
try {
$this->category->delete($value);
} catch(\Exception $e) {
$suppressFlash = true;
continue;
}
}
if(!$suppressFlash)
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success'));
else
session()->flash('info', trans('admin::app.datagrid.mass-ops.partial-action', ['resource' => 'Attribute Family']));
return redirect()->back();
} else {
session()->flash('error', trans('admin::app.datagrid.mass-ops.method-error'));
return redirect()->back();
}
}
}

View File

@ -125,14 +125,47 @@ class CurrencyController extends Controller
*/
public function destroy($id)
{
if($this->currency->count() == 1) {
session()->flash('error', 'At least one currency is required.');
} else {
$this->currency->delete($id);
$result = $this->currency->delete($id);
if($result)
session()->flash('success', 'Currency deleted successfully.');
}
else
session()->flash('error', 'At least one currency is required.');
return redirect()->back();
}
/**
* Remove the specified resources from database
*
* @return response \Illuminate\Http\Response
*/
public function massDestroy() {
$suppressFlash = false;
if(request()->isMethod('delete')) {
$indexes = explode(',', request()->input('indexes'));
foreach($indexes as $key => $value) {
try {
$this->currency->delete($value);
} catch(\Exception $e) {
$suppressFlash = true;
continue;
}
}
if(!$suppressFlash)
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', ['resource' => 'currencies']));
else
session()->flash('info', trans('admin::app.datagrid.mass-ops.partial-action', ['resource' => 'currencies']));
return redirect()->back();
} else {
session()->flash('error', trans('admin::app.datagrid.mass-ops.method-error'));
return redirect()->back();
}
}
}

View File

@ -1,7 +1,7 @@
<?php
<?php
namespace Webkul\Core\Repositories;
use Webkul\Core\Eloquent\Repository;
/**
@ -21,4 +21,12 @@ class CurrencyRepository extends Repository
{
return 'Webkul\Core\Models\Currency';
}
public function delete($id) {
if($this->model->count() == 1) {
return false;
} else {
$this->currency->delete($id);
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/ui.js": "/js/ui.js?id=b25a07d206dd0b89048f",
"/css/ui.css": "/css/ui.css?id=856413ffffbe95f7b91d"
"/js/ui.js": "/js/ui.js",
"/css/ui.css": "/css/ui.css"
}

View File

@ -749,8 +749,6 @@ class DataGrid
$this->getQueryWithFilters();
}
$this->results = $this->query->get();
$this->results = $this->query->paginate($this->perpage)->appends(request()->except('page'));
return $this->results;
@ -767,8 +765,6 @@ class DataGrid
$this->getQueryWithFilters();
}
$this->results = $this->query->get();
$this->results = $this->query->paginate($this->perpage)->appends(request()->except('page'));
return $this->results;
@ -782,13 +778,14 @@ class DataGrid
*
* @return view
*/
public function render()
{
$this->getDbQueryResults();
return view('ui::datagrid.index', [
'css' => $this->css,
'table' => $this->table,
'name' => $this->name,
'results' => $this->results,
'columns' => $this->columns,
'filterable' =>$this->filterable,

View File

@ -353,6 +353,8 @@ h2 {
opacity: 0;
position: absolute;
top: 0;
height: 24px;
width: 24px;
z-index: 100;
}

View File

@ -209,14 +209,10 @@
align-items: center;
.massaction-remove {
margin-top: 10px;
margin-top: 4px;
margin-right: 10px;
}
form {
margin-top: 8px;
}
.selected-items {
margin-right: 15px;
}

View File

@ -8,12 +8,12 @@
@endif
@foreach ($results as $result)
<tr>
{{-- <td class="">
<td class="">
<span class="checkbox">
<input type="checkbox" class="indexers" id="{{ $result->id }}" name="checkbox[]">
<label class="checkbox-view" for="checkbox1"></label>
</span>
</td> --}}
</td>
@foreach ($columns as $column)
@if(isset($column->closure))
@if($column->closure == true)

View File

@ -1,6 +1,6 @@
<thead>
{{-- <tr class="mass-action" style="display: none; height:63px;">
<th colspan="{{ count($columns)+1 }}">
<tr class="mass-action" style="display: none; height:63px;">
<th colspan="{{ count($columns)+1 }}" style="width: 100%;">
<div class="mass-action-wrapper">
<span class="massaction-remove">
@ -11,8 +11,8 @@
@if($massoperation['type'] == "button")
<form onsubmit="return confirm('Are You Sure?');"
@if(strtoupper($massoperation[ 'method'])=="GET" || strtoupper($massoperation['method'])=="POST" )
method="{{ strtoupper($massoperation['method']) }}"
@if(strtoupper($massoperation['method']) == "GET")
method="GET"
@else
method="POST"
@endif
@ -27,6 +27,8 @@
@endif
<input type="hidden" value="{{ $table }}" name="table_name">
<input type="hidden" id="indexes" name="indexes" value="">
<input class="btn btn-primary btn-sm" type="submit" value="Delete">
@ -67,14 +69,14 @@
@endforeach
</div>
</th>
</tr> --}}
</tr>
<tr class="table-grid-header">
{{-- <th>
<th>
<span class="checkbox">
<input type="checkbox" id="mastercheckbox">
<label class="checkbox-view" for="checkbox"></label>
</span>
</th> --}}
</th>
@foreach ($columns as $column)
@if($column->sortable == "true")
<th class="grid_head sortable"

View File

@ -1,8 +1,8 @@
const { mix } = require("laravel-mix");
require("laravel-mix-merge-manifest");
var publicPath = 'publishable/assets';
// var publicPath = "../../../public/vendor/webkul/ui/assets";
// var publicPath = 'publishable/assets';
var publicPath = "../../../public/vendor/webkul/ui/assets";
mix.setPublicPath(publicPath).mergeManifest();
mix.disableNotifications();