diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index 382944d1c..461382ddc 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -28,6 +28,8 @@ class AttributeDataGrid extends DataGrid public function addColumns() { + $this->setInvoker($this); + $this->addColumn([ 'index' => 'id', 'label' => trans('admin::app.datagrid.id'), @@ -64,19 +66,19 @@ class AttributeDataGrid extends DataGrid 'filterable' => true ]); - $this->addColumn([ - 'index' => 'is_required', - 'label' => trans('admin::app.datagrid.required'), - 'type' => 'boolean', - 'sortable' => true, - 'searchable' => false, - 'wrapper' => function($value) { - if ($value->is_required == 1) - return 'True'; - else - return 'False'; - } - ]); + // $this->addColumn([ + // 'index' => 'is_required', + // 'label' => trans('admin::app.datagrid.required'), + // 'type' => 'boolean', + // 'sortable' => true, + // 'searchable' => false, + // 'wrapper' => function($value) { + // if ($value->is_required == 1) + // return 'True'; + // else + // return 'False'; + // } + // ]); $this->addColumn([ 'index' => 'is_unique', diff --git a/packages/Webkul/Product/src/Commands/DemoProducts.php b/packages/Webkul/Product/src/Commands/DemoProducts.php new file mode 100644 index 000000000..b2087a6bf --- /dev/null +++ b/packages/Webkul/Product/src/Commands/DemoProducts.php @@ -0,0 +1,28 @@ +product = $product; + } + + /** + * To call the seeder and provide the demo data generators parameters + */ + public function callGenerator() + { + + $result = $this->productSeeder(); + } +} \ No newline at end of file diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index d1ed77667..63671aa15 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -2,7 +2,7 @@ namespace Webkul\Ui\DataGrid; -use Illuminate\Http\Request; +use Event; /** * DataGrid class @@ -12,22 +12,87 @@ use Illuminate\Http\Request; */ abstract class DataGrid { + /** + * set index columns, ex: id. + */ protected $index = null; + + /** + * To know the class of datagrid calling parent methods, to be set by the extending class. + */ + protected $invoker = null; + + /** + * Default sort order of datagrid + */ protected $sortOrder = 'asc'; + + /** + * Situation handling property when working with custom columns in datagrid, helps abstaining + * aliases on custom column. + */ protected $enableFilterMap = false; + + /** + * This is array where aliases and custom column's name are passed + */ protected $filterMap = []; + + /** + * array to hold all the columns which will be displayed on frontend. + */ protected $columns = []; + protected $completeColumnDetails = []; + + /** + * Hold query builder instance of the query prepared by executing datagrid + * class method setQueryBuilder + */ protected $queryBuilder = []; + + /** + * Final result of the datagrid program that is collection object. + */ protected $collection = []; + + /** + * Set of handly click tools which you could be using for various operations. + * ex: dyanmic and static redirects, deleting, etc. + */ protected $actions = []; + + /** + * Works on selection of values index column as comma separated list as response + * to your endpoint set as route. + */ protected $massActions = []; - protected $request; + + /** + * Parsed value of the url parameters + */ protected $parse; + + /** + * To show mass action or not. + */ protected $enableMassAction = false; + + /** + * To enable actions or not. + */ protected $enableAction = false; + + /** + * paginate the collection or not + */ protected $paginate = true; + + /** + * If paginated then value of pagination. + */ protected $itemsPerPage = 15; + protected $operators = [ 'eq' => "=", 'lt' => "<", @@ -105,9 +170,13 @@ abstract class DataGrid public function addColumn($column) { + $this->fireEvent('before.add.column.'.$column['index']); + array_push($this->columns, $column); $this->setCompleteColumnDetails($column); + + $this->fireEvent('after.add.column.'.$column['index']); } public function setCompleteColumnDetails($column) @@ -306,12 +375,34 @@ abstract class DataGrid return $collection; } + protected function fireEvent($name) + { + $className = get_class($this->invoker); + + $className = last(explode("\\", $className)); + + $className = strtolower($className); + + $eventName = $className.'.'.$name; + + Event::fire($eventName, $this->invoker); + } + public function prepareMassActions() { } public function prepareActions() { } + public function setInvoker($class) + { + $this->invoker = $class; + + // $this->invoker = last(explode("\\", $class)); + + // $this->invoker = strtolower($this->invoker); + } + public function render() { $this->addColumns(); diff --git a/packages/Webkul/Ui/src/DataGrid/notes.md b/packages/Webkul/Ui/src/DataGrid/notes.md new file mode 100644 index 000000000..86d7829a0 --- /dev/null +++ b/packages/Webkul/Ui/src/DataGrid/notes.md @@ -0,0 +1,17 @@ +Event::listen('attributedatagrid.before.add.column.id', function($dataGridInstance) { + $data = [ + 'index' => 'is_required', + 'label' => 'trans', + 'type' => 'boolean', + 'sortable' => true, + 'searchable' => false, + 'wrapper' => function ($value) { + if ($value->is_required == 1) + return 'True'; + else + return 'False'; + } + ]; + + $dataGridInstance->addColumn($data); +}); \ No newline at end of file