From 3da39943f110f1277994a5abdc9f4035552e0002 Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Thu, 16 Aug 2018 13:37:37 +0530 Subject: [PATCH] Datagrid bug fixes --- .../src/DataGrids/AttributeFamilyDataGrid.php | 155 ++++++++++++++++++ ...annelsDataGrid.php => ChannelDataGrid.php} | 2 +- ...nciesDataGrid.php => CurrencyDataGrid.php} | 2 +- .../views/catalog/families/index.blade.php | 3 +- .../views/settings/channels/index.blade.php | 2 +- .../views/settings/currencies/index.blade.php | 2 +- .../Seeders/AttributeFamilyTableSeeder.php | 12 +- .../AttributeFamilyRepository.php | 8 +- 8 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php rename packages/Webkul/Admin/src/DataGrids/{ChannelsDataGrid.php => ChannelDataGrid.php} (99%) rename packages/Webkul/Admin/src/DataGrids/{CurrenciesDataGrid.php => CurrencyDataGrid.php} (99%) diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php new file mode 100644 index 000000000..2fdc93ddd --- /dev/null +++ b/packages/Webkul/Admin/src/DataGrids/AttributeFamilyDataGrid.php @@ -0,0 +1,155 @@ + @prashant-webkul + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class AttributeFamilyDataGrid +{ + /** + * The Data Grid implementation. + * + * @var CountryComposer + * for countries + */ + + public function createAttributeFamilyDataGrid() + { + + return DataGrid::make([ + 'name' => 'Attribute Family', + 'table' => 'attribute_families', + 'select' => 'id', + 'perpage' => 10, + 'aliased' => false, //use this with false as default and true in case of joins + + 'massoperations' =>[ + [ + 'route' => route('admin.datagrid.delete'), + 'method' => 'DELETE', + 'label' => 'Delete', + 'type' => 'button', + ], + ], + + 'actions' => [ + [ + 'type' => 'Edit', + 'route' => route('admin.datagrid.delete'), + 'confirm_text' => 'Do you really want to do this?', + 'icon' => 'icon pencil-lg-icon', + ], [ + 'type' => 'Delete', + 'route' => route('admin.datagrid.delete'), + 'confirm_text' => 'Do you really want to do this?', + 'icon' => 'icon trash-icon', + ], + ], + + 'join' => [ + // [ + // 'join' => 'leftjoin', + // 'table' => 'roles as r', + // 'primaryKey' => 'u.role_id', + // 'condition' => '=', + // 'secondaryKey' => 'r.id', + // ] + ], + + //use aliasing on secodary columns if join is performed + + 'columns' => [ + + [ + 'name' => 'id', + 'alias' => 'attribute_family_id', + 'type' => 'number', + 'label' => 'ID', + 'sortable' => true, + ], + [ + 'name' => 'code', + 'alias' => 'attribute_family_code', + 'type' => 'string', + 'label' => 'Code', + 'sortable' => true, + ], + [ + 'name' => 'name', + 'alias' => 'attribute_family_name', + 'type' => 'string', + 'label' => 'Code', + 'sortable' => true, + ], + ], + + 'filterable' => [ + [ + 'column' => 'id', + 'alias' => 'attribute_family_id', + 'type' => 'number', + 'label' => 'ID', + ], + [ + 'column' => 'code', + 'alias' => 'attribute_family_code', + 'type' => 'string', + 'label' => 'Code', + ], + [ + 'column' => 'name', + 'alias' => 'attribute_family_name', + 'type' => 'string', + 'label' => 'Name', + ], + ], + + //don't use aliasing in case of searchables + + 'searchable' => [ + [ + 'column' => 'name', + 'type' => 'string', + 'label' => 'Name', + ], + [ + 'column' => 'code', + 'type' => 'string', + 'label' => 'Code', + ], + ], + + //list of viable operators that will be used + 'operators' => [ + 'eq' => "=", + 'lt' => "<", + 'gt' => ">", + 'lte' => "<=", + 'gte' => ">=", + 'neqs' => "<>", + 'neqn' => "!=", + 'like' => "like", + 'nlike' => "not like", + ], + // 'css' => [] + + ]); + + } + + public function render() + { + + return $this->createAttributeFamilyDataGrid()->render(); + + } +} \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/ChannelsDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php similarity index 99% rename from packages/Webkul/Admin/src/DataGrids/ChannelsDataGrid.php rename to packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php index 2efa69aeb..b2ef60053 100644 --- a/packages/Webkul/Admin/src/DataGrids/ChannelsDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ChannelDataGrid.php @@ -13,7 +13,7 @@ use Webkul\Ui\DataGrid\Facades\DataGrid; * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class ChannelsDataGrid +class ChannelDataGrid { /** * The Data Grid implementation. diff --git a/packages/Webkul/Admin/src/DataGrids/CurrenciesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php similarity index 99% rename from packages/Webkul/Admin/src/DataGrids/CurrenciesDataGrid.php rename to packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php index ec58fad13..d23fba390 100644 --- a/packages/Webkul/Admin/src/DataGrids/CurrenciesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CurrencyDataGrid.php @@ -12,7 +12,7 @@ use Webkul\Ui\DataGrid\Facades\DataGrid; * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CurrenciesDataGrid +class CurrencyDataGrid { /** * The Data Grid implementation. diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/families/index.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/families/index.blade.php index e9a0ec81e..504bf291b 100644 --- a/packages/Webkul/Admin/src/Resources/views/catalog/families/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/families/index.blade.php @@ -15,7 +15,8 @@
- + @inject('attributefamily','Webkul\Admin\DataGrids\AttributeFamilyDataGrid') + {!! $attributefamily->render() !!}
@stop \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Resources/views/settings/channels/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/channels/index.blade.php index ccf50f298..1efc98711 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/channels/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/channels/index.blade.php @@ -15,7 +15,7 @@
- @inject('channels','Webkul\Admin\DataGrids\ChannelsDataGrid') + @inject('channels','Webkul\Admin\DataGrids\ChannelDataGrid') {!! $channels->render() !!}
diff --git a/packages/Webkul/Admin/src/Resources/views/settings/currencies/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/currencies/index.blade.php index f34017be7..f3f1c44f9 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/currencies/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/currencies/index.blade.php @@ -15,7 +15,7 @@
- @inject('currencies','Webkul\Admin\DataGrids\CurrenciesDataGrid') + @inject('currencies','Webkul\Admin\DataGrids\CurrencyDataGrid') {!! $currencies->render() !!}
diff --git a/packages/Webkul/Attribute/src/Database/Seeders/AttributeFamilyTableSeeder.php b/packages/Webkul/Attribute/src/Database/Seeders/AttributeFamilyTableSeeder.php index 9e5e7d21f..be13b1fd1 100644 --- a/packages/Webkul/Attribute/src/Database/Seeders/AttributeFamilyTableSeeder.php +++ b/packages/Webkul/Attribute/src/Database/Seeders/AttributeFamilyTableSeeder.php @@ -20,7 +20,7 @@ class AttributeFamilyTableSeeder extends Seeder "name" => "General", "is_user_defined" => 0, "position" => 1, - "attributes" => [ + "custom_attributes" => [ [ 'code' => 'sku', 'position' => 1 @@ -48,7 +48,7 @@ class AttributeFamilyTableSeeder extends Seeder "name" => "Description", "is_user_defined" => 0, "position" => 2, - "attributes" => [ + "custom_attributes" => [ [ 'code' => 'short_description', 'position' => 1 @@ -61,7 +61,7 @@ class AttributeFamilyTableSeeder extends Seeder "name" => "Meta Description", "is_user_defined" => 0, "position" => 3, - "attributes" => [ + "custom_attributes" => [ [ 'code' => 'meta_title', 'position' => 1 @@ -77,7 +77,7 @@ class AttributeFamilyTableSeeder extends Seeder "name" => "Price", "is_user_defined" => 0, "position" => 4, - "attributes" => [ + "custom_attributes" => [ [ 'code' => 'price', 'position' => 1 @@ -99,7 +99,7 @@ class AttributeFamilyTableSeeder extends Seeder "name" => "Shipping", "is_user_defined" => 0, "position" => 5, - "attributes" => [ + "custom_attributes" => [ [ 'code' => 'width', 'position' => 1 @@ -136,7 +136,7 @@ class AttributeFamilyTableSeeder extends Seeder { $this->attributeFamily = $attributeFamily; } - + public function run() { foreach($this->rawData as $row) { diff --git a/packages/Webkul/Attribute/src/Repositories/AttributeFamilyRepository.php b/packages/Webkul/Attribute/src/Repositories/AttributeFamilyRepository.php index 365065e38..29e69cec6 100644 --- a/packages/Webkul/Attribute/src/Repositories/AttributeFamilyRepository.php +++ b/packages/Webkul/Attribute/src/Repositories/AttributeFamilyRepository.php @@ -1,7 +1,7 @@ -update($data); $previousAttributeGroupIds = $family->attribute_groups()->pluck('id'); - + if(isset($data['attribute_groups'])) { foreach ($data['attribute_groups'] as $attributeGroupId => $attributeGroupInputs) { if (str_contains($attributeGroupId, 'group_')) { @@ -114,7 +114,7 @@ class AttributeFamilyRepository extends Repository $attributeGroup = $this->attributeGroup->findOrFail($attributeGroupId); $attributeGroup->update($attributeGroupInputs); - + $attributeIds = $attributeGroup->custom_attributes()->get()->pluck('id'); if(isset($attributeGroupInputs['custom_attributes'])) {