From ca95d1d595d195da17e91666c700177bb5db9263 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 15:27:11 +0530 Subject: [PATCH 1/6] Variable names conflicts in body of datagrid causing view action to producce exception is fixed --- packages/Webkul/Ui/src/DataGrid/AbsGrid.php | 1 + .../Webkul/Ui/src/Resources/views/testgrid/body.blade.php | 6 +++--- .../Webkul/Ui/src/Resources/views/testgrid/table.blade.php | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Ui/src/DataGrid/AbsGrid.php b/packages/Webkul/Ui/src/DataGrid/AbsGrid.php index 03afd8b51..163d08212 100644 --- a/packages/Webkul/Ui/src/DataGrid/AbsGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/AbsGrid.php @@ -20,6 +20,7 @@ abstract class AbsGrid protected $massActions = []; protected $request; protected $parse; + // protected $enableMassAction = false; // protected $gridName = null; abstract public function prepareMassActions(); diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php index b58078251..1269c11a0 100644 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php @@ -3,7 +3,7 @@ - + @@ -11,9 +11,9 @@ @foreach($columns as $column) @php - $index = explode('.', $column['index']); + $indexName = explode('.', $column['index']); - $index = end($index); + $indexName = end($indexName); @endphp @if(isset($column['wrapper'])) diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php index c33c4900d..222cb405d 100644 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php @@ -583,8 +583,6 @@ //triggered when any select box is clicked in the datagrid select() { - console.log(this.dataIds); - this.allSelected = false; this.massActionsToggle = true; From 9b85622533aea1f6f6151ad3363a06c1b626c96c Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 15:42:34 +0530 Subject: [PATCH 2/6] unnecessary code is removed --- .../Admin/src/DataGrids/AttributeDataGrid.php | 4 +- .../src/DataGrids/AttributeFamilyDataGrid.php | 4 +- .../Admin/src/DataGrids/CategoryDataGrid.php | 4 +- .../Admin/src/DataGrids/ChannelDataGrid.php | 4 +- .../Admin/src/DataGrids/CountryDataGrid.php | 113 -- .../Admin/src/DataGrids/CurrencyDataGrid.php | 4 +- .../Admin/src/DataGrids/CustomerDataGrid.php | 4 +- .../src/DataGrids/CustomerGroupDataGrid.php | 4 +- .../src/DataGrids/CustomerReviewDataGrid.php | 4 +- .../src/DataGrids/ExchangeRatesDataGrid.php | 4 +- .../DataGrids/InventorySourcesDataGrid.php | 4 +- .../Admin/src/DataGrids/LocalesDataGrid.php | 4 +- .../src/DataGrids/NewsLetterDataGrid.php | 4 +- .../Admin/src/DataGrids/OrderDataGrid.php | 4 +- .../src/DataGrids/OrderInvoicesDataGrid.php | 4 +- .../src/DataGrids/OrderShipmentsDataGrid.php | 4 +- .../Admin/src/DataGrids/ProductDataGrid.php | 308 +++--- .../Admin/src/DataGrids/RolesDataGrid.php | 4 +- .../Admin/src/DataGrids/SliderDataGrid.php | 4 +- .../src/DataGrids/TaxCategoryDataGrid.php | 4 +- .../Admin/src/DataGrids/TaxRateDataGrid.php | 4 +- .../Admin/src/DataGrids/TestDataGrid.php | 147 --- .../Admin/src/DataGrids/UserDataGrid.php | 4 +- .../views/catalog/products/index.blade.php | 2 +- packages/Webkul/Ui/src/DataGrid/AbsGrid.php | 197 ---- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 975 +++--------------- .../{testgrid => datagrid}/body.blade.php | 10 +- .../views/datagrid/filters.blade.php | 132 --- .../{testgrid => datagrid}/head.blade.php | 0 .../Resources/views/datagrid/index.blade.php | 532 ---------- .../views/datagrid/notused/column.blade.php | 18 - .../views/datagrid/pagination.blade.php | 0 .../Resources/views/datagrid/table.blade.php | 644 +++++++++++- .../views/datagrid/table/body.blade.php | 50 - .../views/datagrid/table/head.blade.php | 79 -- .../views/testgrid/filters.blade.php | 3 - .../views/testgrid/pagination.blade.php | 3 - .../Resources/views/testgrid/table.blade.php | 637 ------------ 38 files changed, 941 insertions(+), 2989 deletions(-) delete mode 100755 packages/Webkul/Admin/src/DataGrids/CountryDataGrid.php mode change 100755 => 100644 packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php delete mode 100644 packages/Webkul/Admin/src/DataGrids/TestDataGrid.php delete mode 100644 packages/Webkul/Ui/src/DataGrid/AbsGrid.php mode change 100755 => 100644 packages/Webkul/Ui/src/DataGrid/DataGrid.php rename packages/Webkul/Ui/src/Resources/views/{testgrid => datagrid}/body.blade.php (75%) delete mode 100755 packages/Webkul/Ui/src/Resources/views/datagrid/filters.blade.php rename packages/Webkul/Ui/src/Resources/views/{testgrid => datagrid}/head.blade.php (100%) delete mode 100755 packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php delete mode 100755 packages/Webkul/Ui/src/Resources/views/datagrid/notused/column.blade.php mode change 100755 => 100644 packages/Webkul/Ui/src/Resources/views/datagrid/pagination.blade.php mode change 100755 => 100644 packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php delete mode 100755 packages/Webkul/Ui/src/Resources/views/datagrid/table/body.blade.php delete mode 100755 packages/Webkul/Ui/src/Resources/views/datagrid/table/head.blade.php delete mode 100644 packages/Webkul/Ui/src/Resources/views/testgrid/filters.blade.php delete mode 100644 packages/Webkul/Ui/src/Resources/views/testgrid/pagination.blade.php delete mode 100644 packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index fa7a936c3..51d1238c8 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class AttributeDataGrid extends AbsGrid +class AttributeDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php index 2c8adeff9..251df7e87 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class AttributeFamilyDataGrid extends AbsGrid +class AttributeFamilyDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php index 8665cab42..bbee7ef83 100755 --- a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CategoryDataGrid extends AbsGrid +class CategoryDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php index a3ba4f12c..31de86a10 100755 --- a/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class ChannelDataGrid extends AbsGrid +class ChannelDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/CountryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CountryDataGrid.php deleted file mode 100755 index 32679093a..000000000 --- a/packages/Webkul/Admin/src/DataGrids/CountryDataGrid.php +++ /dev/null @@ -1,113 +0,0 @@ - @prashant-webkul - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -class CountryDataGrid extends AbsGrid -{ - public $allColumns = []; - - public function prepareQueryBuilder() - { - $queryBuilder = DB::table('countries')->select('id')->addSelect($this->columns); - - $this->setQueryBuilder($queryBuilder); - } - - public function addColumns() - { - $this->addColumn([ - 'column' => 'id', - 'alias' => 'countryId', - 'label' => 'ID', - 'type' => 'number', - 'searchable' => false, - 'sortable' => true, - 'width' => '40px' - ]); - - $this->addColumn([ - 'column' => 'code', - 'alias' => 'countryCode', - 'label' => 'Code', - 'type' => 'string', - 'searchable' => true, - 'sortable' => true, - 'width' => '100px' - ]); - - $this->addColumn([ - 'column' => 'name', - 'alias' => 'countryName', - 'label' => 'Name', - 'type' => 'string', - 'searchable' => true, - 'sortable' => true, - 'width' => '100px' - ]); - - $this->addColumn([ - 'column' => 'status', - 'alias' => 'countryStatus', - 'label' => 'Status', - 'type' => 'number', - 'sortable' => true, - 'searchable' => true, - 'width' => '100px' - ]); - } - - public function prepareActions() { - $this->prepareAction([ - 'type' => 'Edit', - 'route' => 'admin.catalog.products.edit', - 'icon' => 'icon pencil-lg-icon' - ]); - - $this->prepareAction([ - 'type' => 'Delete', - 'route' => 'admin.catalog.products.delete', - 'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']), - 'icon' => 'icon trash-icon' - ]); - } - - public function prepareMassActions() { - // $this->prepareMassAction([ - // 'type' => 'delete', - // 'action' => route('admin.catalog.products.massdelete'), - // 'method' => 'DELETE' - // ]); - - // $this->prepareMassAction([ - // 'type' => 'update', - // 'action' => route('admin.catalog.products.massupdate'), - // 'method' => 'PUT', - // 'options' => [ - // 0 => true, - // 1 => false, - // ] - // ]); - } - - public function render() - { - $this->addColumns(); - - $this->prepareActions(); - - $this->prepareMassActions(); - - $this->prepareQueryBuilder(); - - return view('ui::testgrid.table')->with('results', ['records' => $this->getCollection(), 'columns' => $this->allColumns, 'actions' => $this->actions, 'massactions' => $this->massActions]); - } -} \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php index c1a9e11d7..ba915e36b 100755 --- a/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CurrencyDataGrid extends AbsGrid +class CurrencyDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php index 463534b67..9a7f09dd6 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CustomerDataGrid extends AbsGrid +class CustomerDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php index 64891c0d3..6ffcee5ea 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CustomerGroupDataGrid extends AbsGrid +class CustomerGroupDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php index 015f0783e..821f5d050 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CustomerReviewDataGrid extends AbsGrid +class CustomerReviewDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php index 2b45a8497..2b3adc95b 100755 --- a/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class ExchangeRatesDataGrid extends AbsGrid +class ExchangeRatesDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php index 668fe3bc3..22828b670 100755 --- a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class InventorySourcesDataGrid extends AbsGrid +class InventorySourcesDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php index 044321232..762e13fe4 100755 --- a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class LocalesDataGrid extends AbsGrid +class LocalesDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php index 84d7e2dad..c68456f28 100755 --- a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class NewsLetterDataGrid extends AbsGrid +class NewsLetterDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php index b2913d2dc..f455b1fb6 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderDataGrid extends AbsGrid +class OrderDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php index b21410693..3aebaed56 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderInvoicesDataGrid extends AbsGrid +class OrderInvoicesDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php index 46d26af23..9666227a6 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderShipmentsDataGrid extends AbsGrid +class OrderShipmentsDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php old mode 100755 new mode 100644 index 1bd3dbc1f..bbee2310d --- a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php @@ -2,208 +2,146 @@ namespace Webkul\Admin\DataGrids; -use Illuminate\View\View; -use Webkul\Ui\DataGrid\Facades\DataGrid; -use Webkul\Channel\Repositories\ChannelRepository; -use Webkul\Product\Repositories\ProductRepository; +use Webkul\Ui\DataGrid\DataGrid; +use DB; /** - * Product DataGrid + * Product Data Grid class * - * @author Prashant Singh @prashant-webkul + * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class ProductDataGrid +class ProductDataGrid extends DataGrid { + public $allColumns = []; - /** - * The Data Grid implementation for Products - */ - public function createProductDataGrid() + public function prepareQueryBuilder() { - return DataGrid::make([ - 'name' => 'Products', - 'table' => 'products_grid as prods', - 'select' => 'prods.product_id', - 'perpage' => 10, - 'aliased' => false, //use this with false as default and true in case of joins + $queryBuilder = DB::table('products_grid')->addSelect('products_grid.product_id', 'products_grid.sku', 'products_grid.name', 'products.type', 'products_grid.status', 'products_grid.price', 'products_grid.quantity')->leftJoin('products', 'products_grid.product_id', '=', 'products.id'); - 'massoperations' => [ - 0 => [ - 'type' => 'delete', //all lower case will be shifted in the configuration file for better control and increased fault tolerance - 'action' => route('admin.catalog.products.massdelete'), - 'method' => 'DELETE' - ], + $this->setQueryBuilder($queryBuilder); + } - 1 => [ - 'type' => 'update', //all lower case will be shifted in the configuration file for better control and increased fault tolerance - 'action' => route('admin.catalog.products.massupdate'), - 'method' => 'PUT', - 'options' => [ - 0 => 'In Active', - 1 => 'Active', - ] - ] - ], + public function setIndex() { + $this->index = 'product_id'; //the column that needs to be treated as index column + } - 'actions' => [ - [ - 'type' => 'Edit', - 'route' => 'admin.catalog.products.edit', - // 'confirm_text' => trans('ui::app.datagrid.massaction.edit', ['resource' => 'product']), - 'icon' => 'icon pencil-lg-icon' - ], [ - 'type' => 'Delete', - 'route' => 'admin.catalog.products.delete', - 'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']), - 'icon' => 'icon trash-icon' - ] - ], + // public function setGridName() { + // $this->gridName = 'products_grid'; // should be the table name for getting proper index + // } - 'join' => [ - ], - - //use aliasing on secodary columns if join is performed - 'columns' => [ - //name, alias, type, label, sortable - [ - 'name' => 'prods.product_id', - 'alias' => 'id', - 'type' => 'string', - 'label' => 'ID', - 'sortable' => true, - ], [ - 'name' => 'prods.sku', - 'alias' => 'productSku', - 'type' => 'string', - 'label' => 'SKU', - 'sortable' => true, - ], [ - 'name' => 'prods.name', - 'alias' => 'ProductName', - 'type' => 'string', - 'label' => 'Name', - 'sortable' => true, - ], [ - 'name' => 'prods.type', - 'alias' => 'ProductType', - 'type' => 'string', - 'label' => 'Type', - 'sortable' => true, - ], [ - 'name' => 'prods.status', - 'alias' => 'ProductStatus', - 'type' => 'boolean', - 'label' => 'Status', - 'sortable' => true, - 'wrapper' => function ($value) { - if($value == 1) - return 'Active'; - else - return 'Inactive'; - }, - ], [ - 'name' => 'prods.price', - 'alias' => 'ProductPrice', - 'type' => 'string', - 'label' => 'Price', - 'sortable' => true, - 'wrapper' => function ($value) { - return core()->formatBasePrice($value); - }, - ], [ - 'name' => 'prods.attribute_family_name', - 'alias' => 'productattributefamilyname', - 'type' => 'string', - 'label' => 'Attribute Family', - 'sortable' => true, - ], [ - 'name' => 'prods.quantity', - 'alias' => 'ProductQuantity', - 'type' => 'string', - 'label' => 'Product Quantity', - 'sortable' => true, - ] - ], - - 'filterable' => [ - //column, alias, type, and label - [ - 'column' => 'prods.product_id', - 'alias' => 'productID', - 'type' => 'number', - 'label' => 'ID', - ], [ - 'column' => 'prods.sku', - 'alias' => 'productSku', - 'type' => 'string', - 'label' => 'SKU', - ], [ - 'column' => 'prods.name', - 'alias' => 'ProductName', - 'type' => 'string', - 'label' => 'Product Name', - ], [ - 'column' => 'prods.type', - 'alias' => 'ProductType', - 'type' => 'string', - 'label' => 'Product Type', - ], [ - 'column' => 'prods.status', - 'alias' => 'ProductStatus', - 'type' => 'boolean', - 'label' => 'Status' - ] - ], - //don't use aliasing in case of searchables - - 'searchable' => [ - //column, type and label - [ - 'column' => 'prods.product_id', - 'type' => 'number', - 'label' => 'ID', - ], [ - 'column' => 'prods.sku', - 'type' => 'string', - 'label' => 'SKU', - ], [ - 'column' => 'prods.name', - 'type' => 'string', - 'label' => 'Product Name', - ], [ - 'column' => 'prods.type', - 'type' => 'string', - 'label' => 'Product Type', - ] - ], - - //list of viable operators that will be used - 'operators' => [ - 'eq' => "=", - 'lt' => "<", - 'gt' => ">", - 'lte' => "<=", - 'gte' => ">=", - 'neqs' => "<>", - 'neqn' => "!=", - 'like' => "like", - 'nlike' => "not like", - ], - // 'css' => [] + public function addColumns() + { + $this->addColumn([ + 'index' => 'products_grid.product_id', + 'alias' => 'productid', + 'label' => 'ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '40px' ]); + $this->addColumn([ + 'index' => 'products_grid.sku', + 'alias' => 'productsku', + 'label' => 'SKU', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px' + ]); + + $this->addColumn([ + 'index' => 'products_grid.name', + 'alias' => 'productname', + 'label' => 'Name', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px' + ]); + + $this->addColumn([ + 'index' => 'products.type', + 'alias' => 'producttype', + 'label' => 'Type', + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'width' => '100px' + ]); + + $this->addColumn([ + 'index' => 'products_grid.status', + 'alias' => 'productstatus', + 'label' => 'Status', + 'type' => 'boolean', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px', + 'wrapper' => function($value) { + if($value == 1) + return 'Active'; + else + return 'Inactive'; + } + ]); + + $this->addColumn([ + 'index' => 'products_grid.price', + 'alias' => 'productprice', + 'label' => 'Price', + 'type' => 'number', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px', + 'wrapper' => function($value) { + return core()->formatBasePrice($value); + } + ]); + + $this->addColumn([ + 'index' => 'products_grid.quantity', + 'alias' => 'productqty', + 'label' => 'Quantity', + 'type' => 'number', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px' + ]); } - public function render() - { - return $this->createProductDataGrid()->render(); + public function prepareActions() { + $this->addAction([ + 'type' => 'Edit', + 'route' => 'admin.catalog.products.edit', + 'icon' => 'icon pencil-lg-icon' + ]); + + $this->addAction([ + 'type' => 'Delete', + 'route' => 'admin.catalog.products.delete', + 'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']), + 'icon' => 'icon trash-icon' + ]); } - public function export() - { - $paginate = false; - return $this->createProductDataGrid()->render($paginate); - } + public function prepareMassActions() { + $this->addMassAction([ + 'type' => 'delete', + 'action' => route('admin.catalog.products.massdelete'), + 'method' => 'DELETE' + ]); + $this->addMassAction([ + 'type' => 'update', + 'action' => route('admin.catalog.products.massupdate'), + 'method' => 'PUT', + 'options' => [ + 0 => true, + 1 => false, + ] + ]); + } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php index bc285dae5..4aaa1f1ff 100755 --- a/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class RolesDataGrid extends AbsGrid +class RolesDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php index a79da325f..079c546ac 100755 --- a/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class SliderDataGrid extends AbsGrid +class SliderDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php index b71bd21eb..920d0b05c 100755 --- a/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class TaxCategoryDataGrid extends AbsGrid +class TaxCategoryDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php index 1598965b0..5b99fddf2 100755 --- a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class TaxRateDataGrid extends AbsGrid +class TaxRateDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php deleted file mode 100644 index 441d3c646..000000000 --- a/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php +++ /dev/null @@ -1,147 +0,0 @@ - @prashant-webkul - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -class TestDataGrid extends AbsGrid -{ - public $allColumns = []; - - public function prepareQueryBuilder() - { - $queryBuilder = DB::table('products_grid')->addSelect('products_grid.product_id', 'products_grid.sku', 'products_grid.name', 'products.type', 'products_grid.status', 'products_grid.price', 'products_grid.quantity')->leftJoin('products', 'products_grid.product_id', '=', 'products.id'); - - $this->setQueryBuilder($queryBuilder); - } - - public function setIndex() { - $this->index = 'product_id'; //the column that needs to be treated as index column - } - - // public function setGridName() { - // $this->gridName = 'products_grid'; // should be the table name for getting proper index - // } - - public function addColumns() - { - $this->addColumn([ - 'index' => 'products_grid.product_id', - 'alias' => 'productid', - 'label' => 'ID', - 'type' => 'number', - 'searchable' => false, - 'sortable' => true, - 'width' => '40px' - ]); - - $this->addColumn([ - 'index' => 'products_grid.sku', - 'alias' => 'productsku', - 'label' => 'SKU', - 'type' => 'string', - 'searchable' => true, - 'sortable' => true, - 'width' => '100px' - ]); - - $this->addColumn([ - 'index' => 'products_grid.name', - 'alias' => 'productname', - 'label' => 'Name', - 'type' => 'string', - 'searchable' => true, - 'sortable' => true, - 'width' => '100px' - ]); - - $this->addColumn([ - 'index' => 'products.type', - 'alias' => 'producttype', - 'label' => 'Type', - 'type' => 'string', - 'sortable' => true, - 'searchable' => true, - 'width' => '100px' - ]); - - $this->addColumn([ - 'index' => 'products_grid.status', - 'alias' => 'productstatus', - 'label' => 'Status', - 'type' => 'boolean', - 'sortable' => true, - 'searchable' => false, - 'width' => '100px', - 'wrapper' => function($value) { - if($value == 1) - return 'Active'; - else - return 'Inactive'; - } - ]); - - $this->addColumn([ - 'index' => 'products_grid.price', - 'alias' => 'productprice', - 'label' => 'Price', - 'type' => 'number', - 'sortable' => true, - 'searchable' => false, - 'width' => '100px', - 'wrapper' => function($value) { - return core()->formatBasePrice($value); - } - ]); - - $this->addColumn([ - 'index' => 'products_grid.quantity', - 'alias' => 'productqty', - 'label' => 'Quantity', - 'type' => 'number', - 'sortable' => true, - 'searchable' => false, - 'width' => '100px' - ]); - } - - public function prepareActions() { - $this->addAction([ - 'type' => 'Edit', - 'route' => 'admin.catalog.products.edit', - 'icon' => 'icon pencil-lg-icon' - ]); - - $this->addAction([ - 'type' => 'Delete', - 'route' => 'admin.catalog.products.delete', - 'confirm_text' => trans('ui::app.datagrid.massaction.delete', ['resource' => 'product']), - 'icon' => 'icon trash-icon' - ]); - } - - public function prepareMassActions() { - $this->addMassAction([ - 'type' => 'delete', - 'action' => route('admin.catalog.products.massdelete'), - 'method' => 'DELETE' - ]); - - $this->addMassAction([ - 'type' => 'update', - 'action' => route('admin.catalog.products.massupdate'), - 'method' => 'PUT', - 'options' => [ - 0 => true, - 1 => false, - ] - ]); - } -} \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php index fe40caafd..a7f8579d0 100755 --- a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\AbsGrid; +use Webkul\Ui\DataGrid\DataGrid; use DB; /** @@ -11,7 +11,7 @@ use DB; * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class UserDataGrid extends AbsGrid +class UserDataGrid extends DataGrid { public $allColumns = []; diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php index 5d75b7260..639eb9ccd 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/index.blade.php @@ -22,7 +22,7 @@ {{-- @inject('product','Webkul\Admin\DataGrids\ProductDataGrid') {!! $product->render() !!} --}} - @inject('products', 'Webkul\Admin\DataGrids\TestDataGrid') + @inject('products', 'Webkul\Admin\DataGrids\ProductDataGrid') {!! $products->render() !!} diff --git a/packages/Webkul/Ui/src/DataGrid/AbsGrid.php b/packages/Webkul/Ui/src/DataGrid/AbsGrid.php deleted file mode 100644 index 163d08212..000000000 --- a/packages/Webkul/Ui/src/DataGrid/AbsGrid.php +++ /dev/null @@ -1,197 +0,0 @@ - - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -abstract class AbsGrid -{ - protected $index = null; - protected $columns = []; - protected $allColumns = []; - protected $queryBuilder = []; - protected $collection = []; - protected $actions = []; - protected $massActions = []; - protected $request; - protected $parse; - // protected $enableMassAction = false; - // protected $gridName = null; - - abstract public function prepareMassActions(); - abstract public function prepareActions(); - abstract public function prepareQueryBuilder(); - abstract public function addColumns(); - abstract public function setIndex(); - - /** - * Parse the URL and get it ready to be used. - */ - private function parse() - { - $parsed = []; - $unparsed = url()->full(); - - if (count(explode('?', $unparsed)) > 1) { - $to_be_parsed = explode('?', $unparsed)[1]; - - parse_str($to_be_parsed, $parsed); - unset($parsed['page']); - } - - return $parsed; - } - - public function addColumn($column) - { - array_push($this->columns, $column); - - $this->setAllColumnDetails($column); - } - - public function setAllColumnDetails($column) - { - array_push($this->allColumns, $column); - } - - public function setQueryBuilder($queryBuilder) - { - $this->queryBuilder = $queryBuilder; - } - - public function addAction($action) - { - array_push($this->actions, $action); - } - - public function addMassAction($massAction) - { - array_push($this->massActions, $massAction); - } - - public function getCollection() - { - $p = $this->parse(); - - if(count($p)) { - $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $p); - - // return $filteredOrSortedCollection->get(); - - if (config()->has('datagrid.pagination')) { - return $filteredOrSortedCollection->paginate(config('datagrid.pagination')); - } else { - return $filteredOrSortedCollection->get(); - } - } - - if (config()->has('datagrid.pagination')) { - $this->collection = $this->queryBuilder->paginate(config('datagrid.pagination')); - } else { - $this->collection = $this->queryBuilder->get(); - } - - if ($this->collection) { - return $this->collection; - } else { - dd('no records found'); - } - } - - /** - * To find the alias of the column and by taking the column name. - * - * @return string - */ - public function findColumnType($columnAlias) { - foreach($this->allColumns as $column) { - if($column['alias'] == $columnAlias) { - return [$column['type'], $column['index']]; - } - } - } - - public function sortOrFilterCollection($collection, $parseInfo) { - - foreach($parseInfo as $key => $info) { - $columnType = $this->findColumnType($key)[0]; - $columnName = $this->findColumnType($key)[1]; - - if($key == "sort") { - $count_keys = count(array_keys($info)); - - if ($count_keys > 1) { - throw new \Exception('Fatal Error! Multiple Sort keys Found, Please Resolve the URL Manually'); - } - - $columnName = $this->findColumnType(array_keys($info)[0]); - - return $collection->orderBy( - $columnName[1], - array_values($info)[0] - ); - } else if($key == "search") { - $count_keys = count(array_keys($info)); - - if($count_keys > 1) { - throw new \Exception('Multiple Search keys Found, Please Resolve the URL Manually'); - } - - if($count_keys == 1) { - return $collection->where(function() use($collection, $info) { - foreach ($this->allColumns as $column) { - if($column['searchable'] == true) - $collection->orWhere($column['index'], 'like', '%'.$info['all'].'%'); - } - }); - } - } else { - if (array_keys($info)[0] == "like" || array_keys($info)[0] == "nlike") { - foreach ($info as $condition => $filter_value) { - return $collection->where( - $columnName, - config("datagrid.operators.{$condition}"), - '%'.$filter_value.'%' - ); - } - } else { - foreach ($info as $condition => $filter_value) { - if($columnType == 'datetime') { - return $collection->whereDate( - $columnName, - config("datagrid.operators.{$condition}"), - $filter_value - ); - } else { - return $collection->where( - $columnName, - config("datagrid.operators.{$condition}"), - $filter_value - ); - } - } - } - } - } - } - - public function render() - { - $this->addColumns(); - - $this->setIndex(); - - $this->prepareActions(); - - $this->prepareMassActions(); - - $this->prepareQueryBuilder(); - - return view('ui::testgrid.table')->with('results', ['records' => $this->getCollection(), 'columns' => $this->allColumns, 'actions' => $this->actions, 'massactions' => $this->massActions, 'index' => $this->index]); - } -} \ No newline at end of file diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php old mode 100755 new mode 100644 index 650c0559f..feaeab4e5 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -3,525 +3,31 @@ namespace Webkul\Ui\DataGrid; use Illuminate\Http\Request; -use Illuminate\Support\Collection; -use Illuminate\Support\Validate; -use Illuminate\Pagination\Paginator; -use Illuminate\Support\Facades\DB; -use Webkul\Ui\DataGrid\Helpers\Column; -use Webkul\Ui\DataGrid\Helpers\Pagination; -use Webkul\Ui\DataGrid\Helpers\Css; -use URL; - /** - * DataGrid controller - * - * @author Nikhil Malik @ysmnikhil - * & - * @author Prashant Singh @prashant-webkul + * Product Data Grid class * + * @author Jitendra Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class DataGrid +abstract class DataGrid { + protected $index = null; + protected $columns = []; + protected $allColumns = []; + protected $queryBuilder = []; + protected $collection = []; + protected $actions = []; + protected $massActions = []; + protected $request; + protected $parse; + protected $enableMassAction = false; + // protected $gridName = null; - /** - * Name of DataGrid - * - * @var string - */ - protected $name; - - - /** - * select from table(s) - * - * @var string - */ - protected $select; - - - /** - * Table - * @var Boolean for aliasing - */ - protected $aliased; - - - /** - * Pagination variable - * @var String - */ - protected $perpage; - - /** - * Table - * - * @var String Classs name $table - */ - protected $table; - - /** - * Join - * - * @var Array name $join - * - * [ - * 'join' => 'left', - * 'table' => 'posts', - * 'primaryKey' => 'user.id', - * 'condition' => '=', - * 'secondryKey' => 'posts.user_id', - * 'callback' => 'not supported yet' - * ] - */ - protected $join; - - /** - * Collection Object of Column $columns - * - * @var Collection - */ - protected $columns; - - /** - * array of columns to be filtered - * - * @var Array - */ - protected $filterable; - - /** - * array of columns to be searched - * - * @var Array - */ - protected $searchable; - - /** - * mass operations - * - * @var Array - */ - protected $massoperations; - - /** - * Pagination $pagination - * - * @var Pagination - */ - protected $pagination; - - /** - * Css $css - * - * @var Css - */ - protected $css; - - /** - * Actions $action - * - * @var action - */ - protected $actions; - - /** - * URL parse $parsed - * - * @var parse - */ - protected $parsed; - - /* - public function __construct ( - $name = null , - $table = null , - array $join = [], - Collection $columns = null, - Pagination $pagination = null - ) { - $this->make( - $name, - $table, - $join, - $columns, - $pagination - ); - return $this; - - Separates the bags in the array of make attributes - } - */ - - //Prepares the input parameters passed as the configuration for datagrid. - public function make($args) - { - // list($name, $select, $table, $join, $columns) = array_values($args); - $name = $select = $aliased = $table = false; - $join = $columns = $filterable = $searchable = - $massoperations = $css = $actions = []; - - extract($args); - - return $this->build($name, $select, $filterable, $searchable, $massoperations, $aliased, $perpage, $table, $join, $columns, $css, $actions); - } - - //This assigns the private and public properties of the datagrid classes from make functions - public function build ( - string $name = null, - string $select = null, - array $filterable = [], - array $searchable = [], - array $massoperations = [], - bool $aliased = false, - int $perpage = 0, - string $table = null, - array $join = [], - array $columns = null, - array $css = [], - array $actions = [], - Pagination $pagination = null - ) { - $this->request = Request::capture(); - $this->setName($name); - $this->setAlias($aliased); - $this->setTable($table); - $this->setSelect($select); - $this->setFilterable($filterable); - $this->setSearchable($filterable); - $this->setMassOperations($massoperations); - $this->setPerPage($perpage); - $this->setJoin($join); - $this->addColumns($columns, true); - $this->setCss($css); - $this->setOperators(); - $this->setActions($actions); - // $this->addPagination($pagination); - - return $this; - } - - /** - * Set Name. - * - * @return $this - */ - public function setName(string $name) - { - $this->name = $name ? : 'Default' . time(); - return $this; - } - - /** - * Set Select. - * - * @return $this - */ - public function setSelect($select) - { - if (!$select) { - $select = config('datagrid.select'); - - if ($this->aliased) { - $alias = $this->findTableAlias(); - - $select = $alias.'.'.$select; - } - } - - $this->select = $select; - - return $this; - } - - /** - * Set Filterable - * - * @return $this - */ - public function setFilterable(array $filterable) - { - $this->filterable = $filterable ? : []; - return $this; - } - - /** - * Set Searchable columns - * - * @return $this - */ - public function setSearchable($searchable) - { - $this->searchable = $searchable ? : []; - return $this; - } - - /** - * Set mass operations - * - * @return $this - */ - public function setMassOperations($massops) - { - $this->massoperations = $massops ? : []; - return $this; - } - - /** - * Set alias parameter to know whether aliasing is true or not. - * - * @return $this. - */ - public function setAlias(bool $aliased) - { - $this->aliased = $aliased ? : false; - return $this; - } - - /** - * Set the default pagination for data grid. - * - * @return $this - */ - public function setPerPage($perpage) - { - $this->perpage = $perpage ? : 5; - return $this; - } - - /** - * Set table name in front of query scope. - * - * @return $this - */ - public function setTable(string $table) - { - $this->table = $table ?: false; - return $this; - } - - /** - * Set join bag if present. - * - * @return $this - */ - public function setJoin(array $join) - { - $this->join = $join ?: []; - return $this; - } - - /** - * Adds the custom css rules - * - * @return $this - */ - private function setCss($css = []) - { - $this->css = new Css($css); - return $this->css; - } - - - /** - * Adds operands to be used for query condition - * - * @return $this - */ - public function setOperators() - { - $operands = [ - 'eq' => "=", - 'lt' => "<", - 'gt' => ">", - 'lte' => "<=", - 'gte' => ">=", - 'neqs' => "<>", - 'neqn' => "!=", - 'like' => "like", - 'nlike' => "not like", - ]; - - $this->operators = $operands; - - return $this; - } - - /** - * setFilterableColumns - * - * @return $this - */ - // public function setFilterableColumns($filterable_columns = []) - // { - // $this->join = $filterable_columns ?: []; - // return $this; - // } - - /** - * get alias of the leftmost table - * - * @return null|string - */ - public function findTableAlias() { - if($this->aliased) { - $alias = trim(explode('as', $this->table)[1]); - } else { - $alias = null; - } - - return $alias; - } - - /** - * Section actions bag here. - * - * @return $this - */ - public function setActions($actions = []) { - $this->actions = $actions ?: []; - return $this; - } - - /** - * Add Columns. - * - * @return $this - */ - public function addColumns($columns = [], $reCreate = false) - { - if ($reCreate) { - $this->columns = new Collection(); - } - - if ($columns) { - foreach ($columns as $column) { - $this->addColumn($column); - } - } - - return $this; - } - - /** - * Add Column. - * - * @return $this - */ - public function addColumn($column = []) - { - if ($column instanceof Column) { - $this->columns->push($column); - } elseif (gettype($column) == 'array' && $column) { - $this->columns->push(new Column($column, $this->request)); - } else { - throw new \Exception("DataGrid: Add Column argument is not valid!"); - } - - return $this; - } - - /** - * Add multiple columns, not being used currently - * - * @return $this - */ - private function addColumnMultiple($column = [], $multiple = false) - { - if ($column instanceof Column) { - if ($multiple) { - if ($this->columns->offsetExists($column->getName())) { - $this->columns->offsetSet($column->getName(). time(), $column); - } else { - $this->columns->offsetSet($column->getName(), $column); - } - } else { - $this->columns->offsetSet($column->getName(), $column); - } - } elseif (gettype($column) == 'array' && $column) { - $columnObj = new Column($column); - if ($multiple) { - if ($this->columns->offsetExists($columnObj->getName())) { - $this->columns->offsetSet($columnObj->getName(). time(), $columnObj); - } else { - $this->columns->offsetSet($columnObj->getName(), $columnObj); - } - } else { - $this->columns->offsetSet($columnObj->getName(), $columnObj); - } - } else { - throw new \Exception("DataGrid: Add Column argument is not valid!"); - } - return $this; - } - - /** - * Add Pagination. - * - * @return $this - */ - public function addPagination($pagination = []) - { - if ($pagination instanceof Pagination) { - $this->pagination = $pagination; - } elseif (gettype($pagination) == 'array' && $pagination) { - $this->pagination = new Pagination($pagination); - } else { - throw new \Exception("DataGrid: Pagination argument is not valid!"); - } - - return $this; - } - - /** - * Used for selecting the columns got in make from controller. - * - * @return $this - */ - private function getSelect() - { - $select = []; - - if ($this->select) { - $this->query->addselect($this->select); - } - - foreach ($this->columns as $column) { - $this->query->addselect(DB::raw($column->name.' as '.$column->alias)); - } - - // $this->query->select(...$select); - } - - /** - * To find the alias - * of the column and - * by taking the column - * name. - * @return string - */ - public function findColumnAlias($column_alias) { - foreach($this->columns as $column) { - if($column->alias == $column_alias) { - return $column->name; - } - } - } - - /** - * To find the alias - * of the column and - * by taking the column - * name. - * @return string - */ - public function findColumnType($column_alias) { - foreach($this->columns as $column) { - if($column->alias == $column_alias) { - return $column->type; - } - } - } + abstract public function prepareMassActions(); + abstract public function prepareActions(); + abstract public function prepareQueryBuilder(); + abstract public function addColumns(); + abstract public function setIndex(); /** * Parse the URL and get it ready to be used. @@ -536,363 +42,156 @@ class DataGrid parse_str($to_be_parsed, $parsed); unset($parsed['page']); + } - return $parsed; + return $parsed; + } + + public function addColumn($column) + { + array_push($this->columns, $column); + + $this->setAllColumnDetails($column); + } + + public function setAllColumnDetails($column) + { + array_push($this->allColumns, $column); + } + + public function setQueryBuilder($queryBuilder) + { + $this->queryBuilder = $queryBuilder; + } + + public function addAction($action) + { + array_push($this->actions, $action); + } + + public function addMassAction($massAction) + { + array_push($this->massActions, $massAction); + } + + public function getCollection() + { + $p = $this->parse(); + + if(count($p)) { + $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $p); + + // return $filteredOrSortedCollection->get(); + + if (config()->has('datagrid.pagination')) { + return $filteredOrSortedCollection->paginate(config('datagrid.pagination')); + } else { + return $filteredOrSortedCollection->get(); + } + } + + if (config()->has('datagrid.pagination')) { + $this->collection = $this->queryBuilder->paginate(config('datagrid.pagination')); } else { - return $parsed; + $this->collection = $this->queryBuilder->get(); + } + + if ($this->collection) { + return $this->collection; + } else { + dd('no records found'); } } /** - * ->join('contacts', 'users.id', '=', 'contacts.user_id') + * To find the alias of the column and by taking the column name. * - * @return $this->query + * @return string */ - private function getQueryWithJoin() - { - foreach ($this->join as $join) { - $this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey']); - - if(isset($join['conditions'])) { - // dd($join['conditions']['condition'][0], $join['conditions']['condition'][1]); - $this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey'])->where($join['conditions']['condition'][0], $join['conditions']['condition'][1]); + public function findColumnType($columnAlias) { + foreach($this->allColumns as $column) { + if($column['alias'] == $columnAlias) { + return [$column['type'], $column['index']]; } } } - private function getQueryWithColumnFilters() - { - // config()->set('key', $value); - foreach ($this->columns as $column) { - if ($column->filter) { // if the filter bag in array exists then these will be applied. - // if (count($column->filter['condition']) == count($column->filter['condition'], COUNT_RECURSIVE)) { - if (count($column->filter['condition']) == 2) { - $this->query->{$column->filter['function']}(...$column->filter['condition']); - } else { - if (count($column->filter['condition']) == 3) { - $this->query->{$column->filter['function']}( - extract( - array_combine( - // ['key', 'condition', 'value'], - array_fill( //will work with all kind of where conditions - 0, - (count($column->filter['condition']) - 1), - 'array_fill_nikhil'.time() - ), - $column->filter['condition'] - ) - ) - ); - } + public function sortOrFilterCollection($collection, $parseInfo) { + + foreach($parseInfo as $key => $info) { + $columnType = $this->findColumnType($key)[0]; + $columnName = $this->findColumnType($key)[1]; + + if($key == "sort") { + $count_keys = count(array_keys($info)); + + if ($count_keys > 1) { + throw new \Exception('Fatal Error! Multiple Sort keys Found, Please Resolve the URL Manually'); } - } - } - } - /** - * Function runs when filters, sort, search any of it is applied - * - * @return QueryBuilder object - */ - private function getQueryWithFilters() - { - $parsed = $this->parse(); + $columnName = $this->findColumnType(array_keys($info)[0]); - if ($this->aliased) { //aliasing is expected in this case or it will be changed to presence of join bag - foreach ($parsed as $key=>$value) { - $column_name = $this->findColumnAlias($key); - $column_type = $this->findColumnType($key); + return $collection->orderBy( + $columnName[1], + array_values($info)[0] + ); + } else if($key == "search") { + $count_keys = count(array_keys($info)); - if ($key == "sort") { - //resolve the case with the column helper class - if(substr_count($key,'_') >= 1) - $column_name = $this->findColumnAlias($key); + if($count_keys > 1) { + throw new \Exception('Multiple Search keys Found, Please Resolve the URL Manually'); + } - //case that don't need any resolving - $count_keys = count(array_keys($value)); - if ($count_keys == 1) { - $this->query->orderBy( - str_replace('_', '.', array_keys($value)[0]), - array_values($value)[0] - ); - } else { - throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually'); - } - } elseif ($key == "search") { - - $count_keys = count(array_keys($value)); - if($count_keys==1) - $this->query->where(function ($query) use ($parsed) { - foreach ($this->searchable as $search) { - if (strpos($search['column'], 'CONCAT') !== false) { - $query->orWhere(DB::raw($search['column']), 'like', '%'.$parsed['search']['all'].'%'); - } else { - $query->orWhere($search['column'], 'like', '%'.$parsed['search']['all'].'%'); - } + if($count_keys == 1) { + return $collection->where(function() use($collection, $info) { + foreach ($this->allColumns as $column) { + if($column['searchable'] == true) + $collection->orWhere($column['index'], 'like', '%'.$info['all'].'%'); } }); - } else { - $column_name = $this->findColumnAlias($key); - if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") { - foreach ($value as $condition => $filter_value) { - if (strpos($column_name, 'CONCAT') !== false) { - $this->query->orWhere(DB::raw($column_name), $this->operators[$condition], - '%'.$filter_value.'%'); - } else { - $this->query->where( - $column_name, - $this->operators[$condition], - '%'.$filter_value.'%' - ); - } - } - } else { - foreach ($value as $condition => $filter_value) { - if($column_type == 'datetime') { - $this->query->whereDate( - $column_name, - $this->operators[$condition], - $filter_value - ); - } else { - if (strpos($column_name, 'CONCAT') !== false) { - $this->query->orWhere(DB::raw($column_name), $this->operators[$condition], - $filter_value); - } else { - $this->query->where( - $column_name, - $this->operators[$condition], - $filter_value - ); - } - } - } - } } - } - } else { - //this is the case for the non aliasing. - foreach ($parsed as $key => $value) { - if ($key=="sort") { - - //case that don't need any resolving - $count_keys = count(array_keys($value)); - if ($count_keys==1) { - - $this->query->orderBy( - array_keys($value)[0], - array_values($value)[0] + } else { + if (array_keys($info)[0] == "like" || array_keys($info)[0] == "nlike") { + foreach ($info as $condition => $filter_value) { + return $collection->where( + $columnName, + config("datagrid.operators.{$condition}"), + '%'.$filter_value.'%' ); - - } else { - throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.'); } - } elseif ($key=="search") { - $count_keys = count(array_keys($value)); - if($count_keys==1) - $this->query->where(function ($query) use ($parsed) { - foreach ($this->searchable as $search) { - if (strpos($search['column'], 'CONCAT') !== false) { - $query->orWhere(DB::raw($search['column']), 'like', '%'.$parsed['search']['all'].'%'); - } else { - $query->orWhere($search['column'], 'like', '%'.$parsed['search']['all'].'%'); - } - } - }); - else - throw new \Exception('Multiple Search keys Found, Please Resolve the URL Manually.'); - } else { - // $column_name = $key; - $column_name = $this->findColumnAlias($key); - $column_type = $this->findColumnType($key); - - if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") { - foreach ($value as $condition => $filter_value) { - if (strpos($column_name, 'CONCAT') !== false) { - $this->query->orWhere(DB::raw($column_name), $this->operators[$condition], - '%'.$filter_value.'%'); - } else { - $this->query->where( - $column_name, - $this->operators[$condition], - '%'.$filter_value.'%' - ); - } - } - } else { - foreach ($value as $condition => $filter_value) { - if($column_type == 'datetime') { - $this->query->whereDate( - $column_name, - $this->operators[$condition], - $filter_value - ); - } else { - if (strpos($column_name, 'CONCAT') !== false) { - $this->query->orWhere(DB::raw($column_name), $this->operators[$condition], - $filter_value); - } else { - $this->query->where( - $column_name, - $this->operators[$condition], - $filter_value - ); - } - } - } - } - } - } - } - } - - private function getDbQueryResults($pagination = true) - { - $parsed = $this->parse(); - - if ($this->aliased==true) { - //flags - $table_alias = false; - $join_table_alias = false; - $allowed_joins = false; - $other_joins = false; - $join_good = false; - - //prepare query object - $this->query = DB::table($this->table); - - //explode if alias is available - if (strpos('.', $this->table)) { - throw new \Exception("dot/s cannot be used in table names in mysql"); - } else { - $exploded = explode('as', $this->table); - } - - //check whether exploded string still has same table name - if ($exploded[0]==$this->table) { - $table_alias = false; - } else { - $table_alias = true; - $table_name = trim($exploded[0]); - $table_alias = trim($exploded[1]); - } - - //Run this if there are any selects priorly. - if (!empty($this->select)) { - $this->getSelect(); - } - - //Run this if there are joins - if (!empty($this->join)) { - - foreach ($this->join as $index => $join) { - - $name = strtolower($join['join']); - - //Allow joins i.e left or right - if ($name=='leftjoin' || $name=='rightjoin') { - - //check if the aliasing on the primary table and primaryKey in join is also the same - $primary_key_alias = trim(explode('.', $join['primaryKey'])[0]); - - if ($primary_key_alias == $table_alias) { - - $join_table_alias = explode('as', $join['table']); - - if (isset($join_table_alias)) { - - $alias1 = trim($join_table_alias[1]); //important!!!!! - - //check if the secondary table match column is not having '.' and has proper alias - $secondary_join_column = $join['secondaryKey']; - if (isset($secondary_join_column)) { - - $exploded_secondary = explode('.', $secondary_join_column); - $alias2 = trim($exploded_secondary[0]); - - if ($alias1 == $alias2) { - if($index==count($this->join)-1) - $this->getQueryWithJoin(); - $alias_proper_secondary = true; - } else { - throw new \Exception('Aliases of Join table and the secondary key columns do not match'); - } - } else { - throw new \Exception('Improper aliasing on secondary/join column for join'); - } - - } else { - throw new \Exception('Join/Secondary table alias is not found for join'); - } + foreach ($info as $condition => $filter_value) { + if($columnType == 'datetime') { + return $collection->whereDate( + $columnName, + config("datagrid.operators.{$condition}"), + $filter_value + ); } else { - throw new \Exception('Primary key and primary table aliases do not match for join'); + return $collection->where( + $columnName, + config("datagrid.operators.{$condition}"), + $filter_value + ); } - } else { - $other_joins = true; - throw new \Exception('Please check if there is some fault in your aliasing and do not use as in column names or you might have been using a join that is not allowed i.e cross, inner, etc use left and right join only'); } } } - - //Check for column filter bags and resolve aliasing - $this->getQueryWithColumnFilters(); - - if (!empty($parsed)) { - $this->getQueryWithFilters(); - } - - if ($pagination == 'true' && config('datagrid.distinct')) { - $this->results = $this->query->orderBy($this->select, 'desc')->distinct()->paginate($this->perpage)->appends(request()->except('page')); - } else if($pagination == 'true' && !config('datagrid.distinct')) { - $this->results = $this->query->orderBy($this->select, 'desc')->paginate($this->perpage)->appends(request()->except('page')); - }else { - $this->results = $this->query->orderBy($this->select, 'desc')->get(); - } - - return $this->results; - - } else { - - $this->query = DB::table($this->table); - - $this->getSelect(); - - $this->getQueryWithColumnFilters(); - - if (!empty($parsed)) { - $this->getQueryWithFilters(); - } - - if ($pagination == 'true') { - $this->results = $this->query->orderBy($this->select, 'desc')->paginate($this->perpage)->appends(request()->except('page')); - } else { - $this->results = $this->query->orderBy($this->select, 'desc')->get(); - } - - return $this->results; } } - /** - * Main Render Function, it renders views responsible for loading datagrid. - * - * @return view - */ - public function render($pagination = true) + public function render() { - $this->getDbQueryResults($pagination); + $this->addColumns(); - return view('ui::datagrid.index', [ - 'css' => $this->css, - 'table' => $this->table, - 'name' => $this->name, - 'results' => $this->results, - 'columns' => $this->columns, - 'filterable' =>$this->filterable, - 'operators' => $this->operators, - 'massoperations' => $this->massoperations, - 'actions' => $this->actions, - ]); + $this->setIndex(); + + $this->prepareActions(); + + $this->prepareMassActions(); + + $this->prepareQueryBuilder(); + + return view('ui::datagrid.table')->with('results', ['records' => $this->getCollection(), 'columns' => $this->allColumns, 'actions' => $this->actions, 'massactions' => $this->massActions, 'index' => $this->index]); } } \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php similarity index 75% rename from packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php rename to packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php index 1269c11a0..c21495022 100644 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php @@ -11,19 +11,19 @@ @foreach($columns as $column) @php - $indexName = explode('.', $column['index']); + $tableIndex = explode('.', $column['index']); - $indexName = end($indexName); + $tableIndex = end($tableIndex); @endphp @if(isset($column['wrapper'])) @if(isset($column['closure']) && $column['closure'] == true) - {!! $column['wrapper']($record->{$index}) !!} + {!! $column['wrapper']($record->{$tableIndex}) !!} @else - {{ $column['wrapper']($record->{$index}) }} + {{ $column['wrapper']($record->{$tableIndex}) }} @endif @else - {{ $record->{$index} }} + {{ $record->{$tableIndex} }} @endif @endforeach diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/filters.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/filters.blade.php deleted file mode 100755 index 1e349aa7d..000000000 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/filters.blade.php +++ /dev/null @@ -1,132 +0,0 @@ -
-
-
- - -
- -
-
- -
-
- {{-- - - Stock - - - Available - - - --}} -
-
diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/head.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/head.blade.php similarity index 100% rename from packages/Webkul/Ui/src/Resources/views/testgrid/head.blade.php rename to packages/Webkul/Ui/src/Resources/views/datagrid/head.blade.php diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php deleted file mode 100755 index 12a8fc5aa..000000000 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php +++ /dev/null @@ -1,532 +0,0 @@ -
- {{-- For loading the filters from includes directory file --}} - @include('ui::datagrid.filters') - - {{-- for generating the table and its content --}} - @include('ui::datagrid.table') - - {{-- Section for datagrid javascript --}} - @push('scripts') - - @endpush -
diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/notused/column.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/notused/column.blade.php deleted file mode 100755 index 57f066df9..000000000 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/notused/column.blade.php +++ /dev/null @@ -1,18 +0,0 @@ -{{--
- - - - @foreach ($columns as $column) - - @endforeach - - - - - @foreach ($results as $result) - - @endforeach - - -
{{ $column->lable }}
{{ $result->{$columns[$loop->index]->name} }}
-
--}} diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/pagination.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/pagination.blade.php old mode 100755 new mode 100644 diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php old mode 100755 new mode 100644 index 01dd17288..987904c93 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -1,11 +1,637 @@
- {{-- @foreach($massoperations as $key => $value) - {{ $value['type'] }} - @endforeach - {{ dd($massoperations) }} --}} - - @include('ui::datagrid.table.head') - @include('ui::datagrid.table.body') -
- @include('ui::datagrid.pagination') + + + @if(config('datagrid.pagination')) + @include('ui::testgrid.pagination', ['results' => $results['records']]) + @endif + + @push('scripts') + + + + @endpush
\ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table/body.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table/body.blade.php deleted file mode 100755 index adef7629b..000000000 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table/body.blade.php +++ /dev/null @@ -1,50 +0,0 @@ - - @if(count($results) == 0) - - - {{ __('ui::app.datagrid.no-records') }} - - - @endif - @foreach ($results as $result) - - @if(count($massoperations)) - - - - - - - @endif - @foreach ($columns as $column) - @if(isset($column->closure)) - @if($column->closure == true) - {!! $column->render($result) !!} - @endif - @else - {{ $column->render($result) }} - @endif - @endforeach - @if(count($actions)) - - @foreach($actions as $action) - - - - @endforeach - - @endif - - @endforeach - \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table/head.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table/head.blade.php deleted file mode 100755 index b6edace13..000000000 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table/head.blade.php +++ /dev/null @@ -1,79 +0,0 @@ - - @if(count($massoperations)) - - -
- - - - -
- @csrf() - - -
- -
- - @foreach($massoperations as $key => $value) - @if($value['type'] == 'update') - - @endif - @endforeach - - -
-
- - - @endif - - @if(count($massoperations)) - - - - - - - @endif - @foreach ($columns as $column) - @if($column->sortable == "true") - alias, ' as ')) - name); ?> - data-column-name="{{ $exploded_name[0] }}" - @else - data-column-name="{{ $column->alias }}" - @endif - - data-column-label="{{ $column->label }}" - data-column-sort="asc"> - {!! $column->sorting() !!} - - @else - - {!! $column->sorting() !!} - - @endif - @endforeach - @if(count($actions)) - - {{ __('ui::app.datagrid.actions') }} - - @endif - - \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/filters.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/filters.blade.php deleted file mode 100644 index b31ca660f..000000000 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/filters.blade.php +++ /dev/null @@ -1,3 +0,0 @@ -
- -
diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/pagination.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/pagination.blade.php deleted file mode 100644 index 90116cf07..000000000 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/pagination.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php deleted file mode 100644 index 222cb405d..000000000 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/table.blade.php +++ /dev/null @@ -1,637 +0,0 @@ -
- - - @if(config('datagrid.pagination')) - @include('ui::testgrid.pagination', ['results' => $results['records']]) - @endif - - @push('scripts') - - - - @endpush -
\ No newline at end of file From 128e31626521168ce7447778b0524b3971af0cff Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 16:55:10 +0530 Subject: [PATCH 3/6] pagination fixes --- config/datagrid.php | 7 +-- .../Admin/src/DataGrids/AttributeDataGrid.php | 7 ++- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 46 +++++++++---------- .../Webkul/Ui/src/Resources/lang/en/app.php | 2 + .../Resources/views/datagrid/body.blade.php | 24 +++++----- .../Resources/views/datagrid/table.blade.php | 18 ++++---- 6 files changed, 57 insertions(+), 47 deletions(-) diff --git a/config/datagrid.php b/config/datagrid.php index c9b1ddc6c..d47cd7540 100644 --- a/config/datagrid.php +++ b/config/datagrid.php @@ -13,8 +13,9 @@ return [ * * Accepted Values = Array */ 'order' => [ - 'column' => 'id', - 'direction' => 'desc' + 'default' => 'descending', + 'descending' => 'desc', + 'ascending' => 'asc' ], /** @@ -84,6 +85,6 @@ return [ 7 => "orders", 8 => "limit", 9 => "offset", - 10 => "lock", + 10 => "lock" ] ]; \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index 51d1238c8..287197ecf 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -15,6 +15,10 @@ class AttributeDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('attributes')->select('id')->addSelect('id', 'code', 'admin_name', 'type', 'is_required', 'is_unique', 'value_per_locale', 'value_per_channel'); @@ -22,7 +26,8 @@ class AttributeDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } - public function setIndex() { + public function setIndex() + { $this->index = 'id'; //the column that needs to be treated as index column } diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index feaeab4e5..1145f6821 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -3,6 +3,7 @@ namespace Webkul\Ui\DataGrid; use Illuminate\Http\Request; + /** * Product Data Grid class * @@ -21,7 +22,7 @@ abstract class DataGrid protected $request; protected $parse; protected $enableMassAction = false; - // protected $gridName = null; + protected $itemsPerPage = 0; abstract public function prepareMassActions(); abstract public function prepareActions(); @@ -32,19 +33,19 @@ abstract class DataGrid /** * Parse the URL and get it ready to be used. */ - private function parse() + private function parseUrl() { - $parsed = []; + $parsedUrl = []; $unparsed = url()->full(); if (count(explode('?', $unparsed)) > 1) { $to_be_parsed = explode('?', $unparsed)[1]; - parse_str($to_be_parsed, $parsed); - unset($parsed['page']); + parse_str($to_be_parsed, $parsedUrl); + unset($parsedUrl['page']); } - return $parsed; + return $parsedUrl; } public function addColumn($column) @@ -72,35 +73,31 @@ abstract class DataGrid public function addMassAction($massAction) { array_push($this->massActions, $massAction); + + $this->enableMassAction = true; } public function getCollection() { - $p = $this->parse(); + $parsedUrl = $this->parseUrl(); - if(count($p)) { - $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $p); + if(count($parsedUrl)) { + $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $parsedUrl); - // return $filteredOrSortedCollection->get(); - - if (config()->has('datagrid.pagination')) { - return $filteredOrSortedCollection->paginate(config('datagrid.pagination')); + if($this->itemsPerPage > 0) { + return $filteredOrSortedCollection->paginate($this->itemsPerPage); } else { return $filteredOrSortedCollection->get(); } } - if (config()->has('datagrid.pagination')) { - $this->collection = $this->queryBuilder->paginate(config('datagrid.pagination')); + if ($this->itemsPerPage > 0) { + $this->collection = $this->queryBuilder->paginate($this->itemsPerPage); } else { $this->collection = $this->queryBuilder->get(); } - if ($this->collection) { - return $this->collection; - } else { - dd('no records found'); - } + return $this->collection; } /** @@ -108,7 +105,8 @@ abstract class DataGrid * * @return string */ - public function findColumnType($columnAlias) { + public function findColumnType($columnAlias) + { foreach($this->allColumns as $column) { if($column['alias'] == $columnAlias) { return [$column['type'], $column['index']]; @@ -116,8 +114,8 @@ abstract class DataGrid } } - public function sortOrFilterCollection($collection, $parseInfo) { - + public function sortOrFilterCollection($collection, $parseInfo) + { foreach($parseInfo as $key => $info) { $columnType = $this->findColumnType($key)[0]; $columnName = $this->findColumnType($key)[1]; @@ -192,6 +190,6 @@ abstract class DataGrid $this->prepareQueryBuilder(); - return view('ui::datagrid.table')->with('results', ['records' => $this->getCollection(), 'columns' => $this->allColumns, 'actions' => $this->actions, 'massactions' => $this->massActions, 'index' => $this->index]); + return view('ui::datagrid.table')->with('results', ['records' => $this->getCollection(), 'columns' => $this->allColumns, 'actions' => $this->actions, 'massactions' => $this->massActions, 'index' => $this->index, 'enableMassActions' => $this->enableMassAction, 'norecords' => trans('ui::datagrid.no-records')]); } } \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/lang/en/app.php b/packages/Webkul/Ui/src/Resources/lang/en/app.php index a0c6a07fc..bbd4c7b89 100755 --- a/packages/Webkul/Ui/src/Resources/lang/en/app.php +++ b/packages/Webkul/Ui/src/Resources/lang/en/app.php @@ -2,12 +2,14 @@ return [ 'datagrid' => [ 'actions' => 'Actions', + 'massaction' => [ 'mass-delete-confirm' => 'Do you really want to delete these selected :resource?', 'mass-update-status' => 'Do you really want to update status of these selected :resource?', 'delete' => 'Do you really want to delete this :resource?', 'edit' => 'Do you really want to edit this :resource?', ], + 'no-records' => 'No Records Found', 'filter-fields-missing' => 'Some of the required field is null, please check column, condition and value properly' ] diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php index c21495022..7c20ee2be 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php @@ -1,29 +1,31 @@ @foreach($records as $key => $record) - - - + @if($enableMassAction) + + + - - - + + + + @endif @foreach($columns as $column) @php - $tableIndex = explode('.', $column['index']); + $columnIndex = explode('.', $column['index']); - $tableIndex = end($tableIndex); + $columnIndex = end($columnIndex); @endphp @if(isset($column['wrapper'])) @if(isset($column['closure']) && $column['closure'] == true) - {!! $column['wrapper']($record->{$tableIndex}) !!} + {!! $column['wrapper']($record->{$columnIndex}) !!} @else - {{ $column['wrapper']($record->{$tableIndex}) }} + {{ $column['wrapper']($record->{$columnIndex}) }} @endif @else - {{ $record->{$tableIndex} }} + {{ $record->{$columnIndex} }} @endif @endforeach diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index 987904c93..07f7c2e1d 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -2,7 +2,7 @@ @if(config('datagrid.pagination')) - @include('ui::testgrid.pagination', ['results' => $results['records']]) + @include('ui::datagrid.pagination', ['results' => $results['records']]) @endif @push('scripts') @@ -185,13 +185,15 @@ - - - + @if($results['enableMassActions']) + + + - - - + + + + @endif @foreach($results['columns'] as $key => $column) @@ -205,7 +207,7 @@ - @include('ui::datagrid.body', ['records' => $results['records'], 'actions' => $results['actions'], 'index' => $results['index'], 'columns' => $results['columns']]) + @include('ui::datagrid.body', ['records' => $results['records'], 'actions' => $results['actions'], 'index' => $results['index'], 'columns' => $results['columns'],'enableMassAction' => $results['enableMassActions']]) From 7785475eb9c734821cab07d5e82c6afeb8445eb8 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 17:23:36 +0530 Subject: [PATCH 4/6] mass actions enhanced and one bug remvoed causing value havoc --- .../src/DataGrids/CustomerReviewDataGrid.php | 8 ++++---- .../src/Http/Controllers/ReviewController.php | 18 ++++++++++-------- .../Resources/views/datagrid/table.blade.php | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php index 821f5d050..1a020969e 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php @@ -103,17 +103,17 @@ class CustomerReviewDataGrid extends DataGrid public function prepareMassActions() { $this->addMassAction([ 'type' => 'delete', - 'action' => route('admin.catalog.products.massdelete'), + 'action' => route('admin.customer.review.massdelete'), 'method' => 'DELETE' ]); $this->addMassAction([ 'type' => 'update', - 'action' => route('admin.catalog.products.massupdate'), + 'action' => route('admin.customer.review.massupdate'), 'method' => 'PUT', 'options' => [ - 0 => true, - 1 => false, + 'Disapprove' => 0, + 'Approve' => 1 ] ]); } diff --git a/packages/Webkul/Product/src/Http/Controllers/ReviewController.php b/packages/Webkul/Product/src/Http/Controllers/ReviewController.php index 6f57dabae..147dac40f 100755 --- a/packages/Webkul/Product/src/Http/Controllers/ReviewController.php +++ b/packages/Webkul/Product/src/Http/Controllers/ReviewController.php @@ -174,16 +174,18 @@ class ReviewController extends Controller $review = $this->productReview->findOneByField('id', $value); try { - if($data['massaction-type'] == 1 && $data['update-options'] == 1 && $data['selected-option-text'] == 'Approve') { - Event::fire('customer.review.update.before', $value); + if($data['massaction-type'] == 'update') { + if($data['update-options'] == 1) { + Event::fire('customer.review.update.before', $value); - $review->update(['status' => 'approved']); + $review->update(['status' => 'approved']); - Event::fire('customer.review.update.after', $review); - } else if($data['massaction-type'] == 1 && $data['update-options'] == 0 && $data['selected-option-text'] == 'Disapprove') { - $review->update(['status' => 'pending']); - } else { - continue; + Event::fire('customer.review.update.after', $review); + } else if($data['update-options'] == 0) { + $review->update(['status' => 'pending']); + } else { + continue; + } } } catch(\Exception $e) { $suppressFlash = true; diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index 07f7c2e1d..a3143ade8 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -12,6 +12,7 @@
+
@@ -171,7 +172,7 @@
From 11fd8adfff42c89938aaf6091e8955710f89df53 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 18:35:25 +0530 Subject: [PATCH 5/6] pagination fixes in newly refactored datagrid --- config/datagrid.php | 2 +- packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php | 8 ++++---- .../Admin/src/DataGrids/AttributeFamilyDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php | 4 ++++ .../Admin/src/DataGrids/InventorySourcesDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php | 8 ++++++-- packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php | 4 ++++ .../Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php | 4 ++++ packages/Webkul/Admin/src/DataGrids/UserDataGrid.php | 4 ++++ packages/Webkul/Ui/src/DataGrid/DataGrid.php | 4 ++-- .../Ui/src/Resources/views/datagrid/table.blade.php | 1 - 24 files changed, 89 insertions(+), 10 deletions(-) diff --git a/config/datagrid.php b/config/datagrid.php index d47cd7540..6d9b1da1b 100644 --- a/config/datagrid.php +++ b/config/datagrid.php @@ -30,7 +30,7 @@ return [ * * Accepted Value = integer */ - // 'pagination' => 10, + 'pagination' => 10, 'operators' => [ 'eq' => "=", diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index 287197ecf..5ea8ef294 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -81,7 +81,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'width' => '100px', - 'wrapper' => function($value){ + 'wrapper' => function($value) { if($value == 1) return 'True'; else @@ -97,7 +97,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'width' => '100px', - 'wrapper' => function($value){ + 'wrapper' => function($value) { if($value == 1) return 'True'; else @@ -113,7 +113,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'width' => '100px', - 'wrapper' => function($value){ + 'wrapper' => function($value) { if($value == 1) return 'True'; else @@ -129,7 +129,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'width' => '100px', - 'wrapper' => function($value){ + 'wrapper' => function($value) { if($value == 1) return 'True'; else diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php index 251df7e87..a00ae77c7 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php @@ -15,6 +15,10 @@ class AttributeFamilyDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('attribute_families')->select('id')->addSelect('id', 'code', 'name'); diff --git a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php index bbee7ef83..2c89e327a 100755 --- a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php @@ -15,6 +15,10 @@ class CategoryDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('categories as cat')->select('cat.id', 'ct.name', 'cat.position', 'cat.status', 'ct.locale')->leftJoin('category_translations as ct', 'cat.id', '=', 'ct.category_id'); diff --git a/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php index 31de86a10..c85bcae9c 100755 --- a/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php @@ -15,6 +15,10 @@ class ChannelDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('channels')->addSelect('id', 'code', 'name', 'hostname'); diff --git a/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php index ba915e36b..3ee28fd74 100755 --- a/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php @@ -15,6 +15,10 @@ class CurrencyDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('currencies')->addSelect('id', 'name', 'code'); diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php index 9a7f09dd6..c3035a24c 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php @@ -15,6 +15,10 @@ class CustomerDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('customers as cus')->addSelect('cus.id', 'cus.first_name', 'cus.email', 'cg.name')->leftJoin('customer_groups as cg', 'cus.customer_group_id', '=', 'cg.id'); diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php index 6ffcee5ea..0d5c1a0c7 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php @@ -15,6 +15,10 @@ class CustomerGroupDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('customer_groups')->addSelect('id', 'name'); diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php index 1a020969e..edbdea5ed 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php @@ -15,6 +15,10 @@ class CustomerReviewDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('product_reviews as pr')->addSelect('pr.id', 'pr.title', 'pr.comment', 'pg.name', 'pr.status')->leftjoin('products_grid as pg', 'pr.product_id', '=', 'pg.id'); diff --git a/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php index 2b3adc95b..36eeff15c 100755 --- a/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ExchangeRatesDataGrid.php @@ -15,6 +15,10 @@ class ExchangeRatesDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('currency_exchange_rates as cer')->addSelect('cer.id', 'curr.name', 'cer.rate')->leftJoin('currencies as curr', 'cer.target_currency', '=', 'curr.id'); diff --git a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php index 22828b670..5ebc39d7a 100755 --- a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php @@ -15,6 +15,10 @@ class InventorySourcesDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('inventory_sources')->addSelect('id', 'code', 'name', 'priority', 'status'); diff --git a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php index 762e13fe4..6e88189f4 100755 --- a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php @@ -15,6 +15,10 @@ class LocalesDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('locales')->addSelect('id', 'code', 'name'); diff --git a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php index c68456f28..8fd3b64f2 100755 --- a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php @@ -15,6 +15,10 @@ class NewsLetterDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('subscribers_list')->addSelect('id', 'is_subscribed', 'email'); diff --git a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php index f455b1fb6..4204c9029 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php @@ -15,6 +15,10 @@ class OrderDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('orders')->select('id', 'base_grand_total', 'grand_total', 'created_at', 'channel_name', 'status')->addSelect(DB::raw('CONCAT(customer_first_name, " ", customer_last_name) as fullname')); diff --git a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php index 3aebaed56..be79faa11 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php @@ -15,6 +15,10 @@ class OrderInvoicesDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('invoices')->select('id', 'order_id', 'state', 'grand_total', 'created_at'); diff --git a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php index 9666227a6..5ded9d48b 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php @@ -15,6 +15,10 @@ class OrderShipmentsDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('shipments as ship')->select('ship.id', 'ship.order_id', 'ship.total_qty', 'is.name', 'ors.created_at as orderdate', 'ship.created_at')->addSelect(DB::raw('CONCAT(ors.customer_first_name, " ", ors.customer_last_name) as custname'))->leftJoin('orders as ors', 'ship.order_id', '=', 'ors.id')->leftJoin('inventory_sources as is', 'ship.inventory_source_id', '=', 'is.id'); diff --git a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php index bbee2310d..eaa6182e3 100644 --- a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php @@ -15,6 +15,10 @@ class ProductDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('products_grid')->addSelect('products_grid.product_id', 'products_grid.sku', 'products_grid.name', 'products.type', 'products_grid.status', 'products_grid.price', 'products_grid.quantity')->leftJoin('products', 'products_grid.product_id', '=', 'products.id'); @@ -139,8 +143,8 @@ class ProductDataGrid extends DataGrid 'action' => route('admin.catalog.products.massupdate'), 'method' => 'PUT', 'options' => [ - 0 => true, - 1 => false, + 'Active' => 1, + 'Inactive' => 0 ] ]); } diff --git a/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php index 4aaa1f1ff..9bbf0a1bc 100755 --- a/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/RolesDataGrid.php @@ -15,6 +15,10 @@ class RolesDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('roles')->addSelect('id', 'name', 'permission_type'); diff --git a/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php index 079c546ac..2068badf0 100755 --- a/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/SliderDataGrid.php @@ -15,6 +15,10 @@ class SliderDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('sliders as sl')->addSelect('sl.id', 'sl.title', 'ch.name')->leftJoin('channels as ch', 'sl.channel_id', '=', 'ch.id'); diff --git a/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php index 920d0b05c..f22dda005 100755 --- a/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TaxCategoryDataGrid.php @@ -15,6 +15,10 @@ class TaxCategoryDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('tax_categories')->addSelect('id', 'name', 'code'); diff --git a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php index 5b99fddf2..da1c16c1a 100755 --- a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php @@ -15,6 +15,10 @@ class TaxRateDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('tax_rates')->addSelect('id', 'identifier', 'state', 'country', 'tax_rate'); diff --git a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php index a7f8579d0..49c69bd24 100755 --- a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php @@ -15,6 +15,10 @@ class UserDataGrid extends DataGrid { public $allColumns = []; + public function __construct() { + $this->itemsPerPage = 5; + } + public function prepareQueryBuilder() { $queryBuilder = DB::table('admins as u')->addSelect('u.id', 'u.name', 'u.status', 'u.email', 'ro.name')->leftJoin('roles as ro', 'u.role_id', '=', 'ro.id'); diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 1145f6821..b002af5b0 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -85,14 +85,14 @@ abstract class DataGrid $filteredOrSortedCollection = $this->sortOrFilterCollection($this->collection = $this->queryBuilder, $parsedUrl); if($this->itemsPerPage > 0) { - return $filteredOrSortedCollection->paginate($this->itemsPerPage); + return $filteredOrSortedCollection->paginate($this->itemsPerPage)->appends(request()->except('page')); } else { return $filteredOrSortedCollection->get(); } } if ($this->itemsPerPage > 0) { - $this->collection = $this->queryBuilder->paginate($this->itemsPerPage); + $this->collection = $this->queryBuilder->paginate($this->itemsPerPage)->appends(request()->except('page')); } else { $this->collection = $this->queryBuilder->get(); } diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index a3143ade8..e1963a62b 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -144,7 +144,6 @@ @{{ filter.val }} -
From a2c02817f8f5a9b2a6007c7d50fccd1efc0798ec Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 19:55:44 +0530 Subject: [PATCH 6/6] added labels to the filter tags --- .../Admin/src/DataGrids/AttributeDataGrid.php | 9 +- .../Resources/views/datagrid/table.blade.php | 90 +++++++++++++++---- 2 files changed, 77 insertions(+), 22 deletions(-) diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index 5ea8ef294..6386c47c3 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -15,7 +15,8 @@ class AttributeDataGrid extends DataGrid { public $allColumns = []; - public function __construct() { + public function __construct() + { $this->itemsPerPage = 5; } @@ -138,7 +139,8 @@ class AttributeDataGrid extends DataGrid ]); } - public function prepareActions() { + public function prepareActions() + { $this->addAction([ 'type' => 'Edit', 'route' => 'admin.catalog.attributes.edit', @@ -152,7 +154,8 @@ class AttributeDataGrid extends DataGrid ]); } - public function prepareMassActions() { + public function prepareMassActions() + { $this->addMassAction([ 'type' => 'delete', 'action' => route('admin.catalog.attributes.massdelete'), diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php index e1963a62b..a3ba2831f 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table.blade.php @@ -136,9 +136,9 @@
- @{{ filter.cond }} + @{{ filter.label }} Search - @{{ filter.column }} + @{{ filter.label }} @{{ filter.val }} @@ -309,23 +309,47 @@ }, getResponse() { + label = ''; + + for(colIndex in this.columns) { + if(this.columns[colIndex].alias == this.columnOrAlias) { + label = this.columns[colIndex].label; + } + } + if(this.type == 'string') { - this.formURL(this.columnOrAlias, this.stringCondition, this.stringValue) + this.formURL(this.columnOrAlias, this.stringCondition, this.stringValue, label) } else if(this.type == 'number') { - this.formURL(this.columnOrAlias, this.numberCondition, this.numberValue); + this.formURL(this.columnOrAlias, this.numberCondition, this.numberValue, label); } else if(this.type == 'boolean') { - this.formURL(this.columnOrAlias, this.booleanCondition, this.booleanValue); + this.formURL(this.columnOrAlias, this.booleanCondition, this.booleanValue, label); } else if(this.type == 'datetime') { - this.formURL(this.columnOrAlias, this.datetimeCondition, this.datetimeValue); + this.formURL(this.columnOrAlias, this.datetimeCondition, this.datetimeValue, label); } }, sortCollection(alias) { - this.formURL("sort", alias, this.sortAsc); + label = ''; + + for(colIndex in this.columns) { + if(this.columns[colIndex].alias == this.columnOrAlias) { + label = this.columns[colIndex].label; + } + } + + this.formURL("sort", alias, this.sortAsc, label); }, searchCollection(searchValue) { - this.formURL("search", 'all', searchValue); + label = ''; + + for(colIndex in this.columns) { + if(this.columns[colIndex].alias == this.columnOrAlias) { + label = this.columns[colIndex].label; + } + } + + this.formURL("search", 'all', searchValue, label); }, // function triggered to check whether the query exists or not and then call the make filters from the url @@ -391,7 +415,7 @@ }, //make array of filters, sort and search - formURL(column, condition, response) { + formURL(column, condition, response, label) { var obj = {}; if(column == "" || condition == "" || response == "" || column == null || condition == null || response == null) { @@ -406,15 +430,10 @@ for(j = 0; j < this.filters.length; j++) { if(this.filters[j].column == column) { if(this.filters[j].cond == condition && this.filters[j].val == response) { + filterRepeated = 1; + return false; } - - filterRepeated = 1; - - this.filters[j].cond = condition; - this.filters[j].val = response; - - this.makeURL(); } } @@ -422,7 +441,7 @@ obj.column = column; obj.cond = condition; obj.val = response; - + obj.label = label; this.filters.push(obj); obj = {}; @@ -456,6 +475,7 @@ this.filters[j].column = column; this.filters[j].cond = condition; this.filters[j].val = response; + this.filters[j].label = label; this.makeURL(); } @@ -471,6 +491,7 @@ obj.column = column; obj.cond = condition; obj.val = this.currentSort; + obj.label = label; this.filters.push(obj); @@ -483,11 +504,12 @@ if(column == "search") { search_found = 0; - for(j = 0;j < this.filters.length;j++) { + for(j = 0; j < this.filters.length; j++) { if(this.filters[j].column == "search") { this.filters[j].column = column; this.filters[j].cond = condition; this.filters[j].val = response; + this.filters[j].label = label; this.makeURL(); } @@ -503,6 +525,7 @@ obj.column = column; obj.cond = condition; obj.val = response; + obj.label = label; this.filters.push(obj); @@ -515,6 +538,7 @@ obj.column = column; obj.cond = condition; obj.val = response; + obj.label = label; this.filters.push(obj); @@ -562,10 +586,38 @@ cond = moreSplitted[i][0].replace(']','').split('[')[1] val = moreSplitted[i][1]; + label = 'cannotfindthislabel'; + + // for(colIndex in this.columns) { + // if(this.columns[colIndex].alias == this.columnOrAlias) { + // label = this.columns[colIndex].label; + // } + // } + obj.column = col; obj.cond = cond; obj.val = val; + if(col == "sort") { + label = ''; + + for(colIndex in this.columns) { + if(this.columns[colIndex].alias == obj.cond) { + obj.label = this.columns[colIndex].label; + } + } + } else if(col == "search") { + obj.label = 'Search'; + } else { + obj.label = ''; + + for(colIndex in this.columns) { + if(this.columns[colIndex].alias == obj.column) { + obj.label = this.columns[colIndex].label; + } + } + } + if(col != undefined && cond != undefined && val != undefined) this.filters.push(obj); @@ -622,7 +674,7 @@ } } - console.log(this.dataIds); + // console.log(this.dataIds); }, removeMassActions() {