DataGrid improvements and fixed a validation bug in the product controller

This commit is contained in:
prashant-webkul 2018-08-16 19:09:51 +05:30
parent 3da39943f1
commit 608a74a0b8
19 changed files with 569 additions and 66 deletions

View File

@ -0,0 +1,191 @@
<?php
namespace Webkul\Admin\DataGrids;
use Illuminate\View\View;
use Webkul\Ui\DataGrid\Facades\DataGrid;
/**
* Attributes DataGrid
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AttributeDataGrid
{
/**
* The Data Grid implementation.
*
* @var AttributeDataGrid
* for countries
*/
public function createAttributeDataGrid()
{
return DataGrid::make([
'name' => 'Attributes',
'table' => 'attributes',
'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' => 'attributeId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'attributeCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'admin_name',
'alias' => 'attributeAdminName',
'type' => 'string',
'label' => 'AdminName',
'sortable' => true,
],
[
'name' => 'type',
'alias' => 'attributeType',
'type' => 'string',
'label' => 'Type',
'sortable' => true,
],
[
'name' => 'is_required',
'alias' => 'attributeIsRequired',
'type' => 'string',
'label' => 'Required',
'sortable' => true,
],
[
'name' => 'is_unique',
'alias' => 'attributeIsUnique',
'type' => 'string',
'label' => 'Unique',
'sortable' => true,
],
[
'name' => 'value_per_locale',
'alias' => 'attributeValuePerLocale',
'type' => 'string',
'label' => 'ValuePerLocale',
'sortable' => true,
],
[
'name' => 'value_per_channel',
'alias' => 'attributeValuePerChannel',
'type' => 'string',
'label' => 'ValuePerChannel',
'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->createAttributeDataGrid()->render();
}
}

View File

@ -7,7 +7,7 @@ use Webkul\Ui\DataGrid\Facades\DataGrid;
/**
* Countries DataGrid
* Attributes Family DataGrid
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
@ -71,21 +71,21 @@ class AttributeFamilyDataGrid
[
'name' => 'id',
'alias' => 'attribute_family_id',
'alias' => 'attributeFamilyId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'attribute_family_code',
'alias' => 'attributeFamilyCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'attribute_family_name',
'alias' => 'attributeFamilyName',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
@ -95,19 +95,19 @@ class AttributeFamilyDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'attribute_family_id',
'alias' => 'attributeFamilyId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'code',
'alias' => 'attribute_family_code',
'alias' => 'attributeFamilyCode',
'type' => 'string',
'label' => 'Code',
],
[
'column' => 'name',
'alias' => 'attribute_family_name',
'alias' => 'attributeFamilyName',
'type' => 'string',
'label' => 'Name',
],

View File

@ -0,0 +1,172 @@
<?php
namespace Webkul\Admin\DataGrids;
use Illuminate\View\View;
use Webkul\Ui\DataGrid\Facades\DataGrid;
/**
* Category DataGrid
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CategoryDataGrid
{
/**
* The Data Grid implementation.
*
* @var AttributeDataGrid
* for countries
*/
public function createCategoryDataGrid()
{
return DataGrid::make([
'name' => 'Categories',
'table' => 'categories as cat',
'select' => 'cat.id',
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
],
],
'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' => 'category_translations as ct',
'primaryKey' => 'cat.id',
'condition' => '=',
'secondaryKey' => 'ct.category_id',
], [
'join' => 'leftjoin',
'table' => 'category_translations as cta',
'primaryKey' => 'cat.parent_id',
'condition' => '=',
'secondaryKey' => 'cta.category_id',
],
],
//use aliasing on secodary columns if join is performed
'columns' => [
[
'name' => 'cat.id',
'alias' => 'catID',
'type' => 'number',
'label' => 'Category ID',
'sortable' => true,
], [
'name' => 'ct.name',
'alias' => 'catName',
'type' => 'string',
'label' => 'Category Name',
'sortable' => false,
], [
'name' => 'cat.position',
'alias' => 'catPosition',
'type' => 'string',
'label' => 'Category Position',
'sortable' => false,
], [
'name' => 'cta.name',
'alias' => 'parentName',
'type' => 'string',
'label' => 'Parent Name',
'sortable' => true,
], [
'name' => 'cat.status',
'alias' => 'catStatus',
'type' => 'string',
'label' => 'Visible in Menu',
'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->createCategoryDataGrid()->render();
}
}

View File

@ -98,19 +98,19 @@ class ChannelDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'channel_id',
'alias' => 'channelId',
'type' => 'number',
'label' => 'Channel ID',
],
[
'column' => 'code',
'alias' => 'channel_code',
'alias' => 'channelCode',
'type' => 'string',
'label' => 'Channel Code',
],
[
'column' => 'name',
'alias' => 'channel_name',
'alias' => 'channelName',
'type' => 'string',
'label' => 'Channel Name',
],

View File

@ -71,28 +71,28 @@ class CountryDataGrid
[
'name' => 'id',
'alias' => 'country_id',
'alias' => 'countryId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'country_code',
'alias' => 'countryCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'country_name',
'alias' => 'countryName',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
],
[
'name' => 'status',
'alias' => 'country_status',
'alias' => 'countryStatus',
'type' => 'number',
'label' => 'Code',
'sortable' => true,
@ -105,25 +105,25 @@ class CountryDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'country_id',
'alias' => 'countryId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'code',
'alias' => 'country_code',
'alias' => 'countryCode',
'type' => 'string',
'label' => 'Code',
],
[
'column' => 'name',
'alias' => 'country_name',
'alias' => 'countryName',
'type' => 'string',
'label' => 'Name',
],
[
'column' => 'status',
'alias' => 'country_status',
'alias' => 'countryStatus',
'type' => 'number',
'label' => 'Code',
],

View File

@ -70,21 +70,21 @@ class CurrencyDataGrid
[
'name' => 'id',
'alias' => 'currency_id',
'alias' => 'currencyId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'currency_code',
'alias' => 'currencyCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'currency_name',
'alias' => 'currencyName',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
@ -97,19 +97,19 @@ class CurrencyDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'currency_id',
'alias' => 'currencyId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'code',
'alias' => 'currency_code',
'alias' => 'currencyCode',
'type' => 'string',
'label' => 'Code',
],
[
'column' => 'name',
'alias' => 'currency_name',
'alias' => 'currencyName',
'type' => 'string',
'label' => 'Name',
],

View File

@ -71,28 +71,28 @@ class ExchangeRatesDataGrid
[
'name' => 'id',
'alias' => 'exch_id',
'alias' => 'exchID',
'type' => 'number',
'label' => 'Rate ID',
'sortable' => true,
],
[
'name' => 'source_currency',
'alias' => 'exch_source_currency',
'alias' => 'exchSourceCurrency',
'type' => 'string',
'label' => 'Source Currency',
'sortable' => true,
],
[
'name' => 'target_currency',
'alias' => 'exch_target_currency',
'alias' => 'exchTargetCurrency',
'type' => 'string',
'label' => 'Target Currency',
'sortable' => true,
],
[
'name' => 'ratio',
'alias' => 'exch_ratio',
'alias' => 'exchRatio',
'type' => 'string',
'label' => 'Exchange Ratio',
],
@ -104,20 +104,20 @@ class ExchangeRatesDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'exch_id',
'alias' => 'exchId',
'type' => 'number',
'label' => 'Rate ID',
],
[
'column' => 'source_currency',
'alias' => 'exch_source_currency',
'alias' => 'exchSourceCurrency',
'type' => 'string',
'label' => 'Source Currency',
'sortable' => true,
],
[
'column' => 'target_currency',
'alias' => 'exch_target_currency',
'alias' => 'exchTargetCurrency',
'type' => 'string',
'label' => 'Target Currency',
'sortable' => true,

View File

@ -69,35 +69,35 @@ class InventorySourcesDataGrid
[
'name' => 'id',
'alias' => 'inventory_id',
'alias' => 'inventoryID',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'inventory_code',
'alias' => 'inventoryCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'inventory_name',
'alias' => 'inventoryName',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
],
[
'name' => 'priority',
'alias' => 'inventory_priority',
'alias' => 'inventoryPriority',
'type' => 'string',
'label' => 'Priority',
'sortable' => true,
],
[
'name' => 'status',
'alias' => 'inventory_status',
'alias' => 'inventoryStatus',
'type' => 'string',
'label' => 'Status',
'sortable' => true,
@ -110,19 +110,19 @@ class InventorySourcesDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'inventory_id',
'alias' => 'inventoryId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'code',
'alias' => 'inventory_code',
'alias' => 'inventoryCode',
'type' => 'string',
'label' => 'Code',
],
[
'column' => 'name',
'alias' => 'inventory_name',
'alias' => 'inventoryName',
'type' => 'string',
'label' => 'Name',
],

View File

@ -70,21 +70,21 @@ class LocalesDataGrid
[
'name' => 'id',
'alias' => 'locale_id',
'alias' => 'localeId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'code',
'alias' => 'locale_code',
'alias' => 'localeCode',
'type' => 'string',
'label' => 'Code',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'locale_name',
'alias' => 'localeName',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
@ -97,19 +97,19 @@ class LocalesDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'locale_id',
'alias' => 'localeId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'code',
'alias' => 'locale_code',
'alias' => 'localeCode',
'type' => 'string',
'label' => 'Code',
],
[
'column' => 'name',
'alias' => 'locale_name',
'alias' => 'localeName',
'type' => 'string',
'label' => 'Name',
],

View File

@ -0,0 +1,129 @@
<?php
namespace Webkul\Admin\DataGrids;
use Illuminate\View\View;
use Webkul\Ui\DataGrid\Facades\DataGrid;
/**
* Product DataGrid
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductDataGrid
{
/**
* The Data Grid implementation.
*
* @var AttributProductDataGrideDataGrid
* for countries
*/
public function createProductDataGrid()
{
return DataGrid::make([
'name' => 'Products',
'table' => 'products as pr',
'select' => 'pr.id',
'perpage' => 10,
'aliased' => true, //use this with false as default and true in case of joins
'massoperations' =>[
[
'route' => route('admin.datagrid.delete'),
'method' => 'DELETE',
'label' => 'Delete',
'type' => 'button',
],
],
'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' => 'category_translations as ct',
// 'primaryKey' => 'cat.id',
// 'condition' => '=',
// 'secondaryKey' => 'ct.category_id',
// ], [
// 'join' => 'leftjoin',
// 'table' => 'category_translations as cta',
// 'primaryKey' => 'cat.parent_id',
// 'condition' => '=',
// 'secondaryKey' => 'cta.category_id',
// ],
],
//use aliasing on secodary columns if join is performed
'columns' => [
//name, alias, type, label, sortable
[
'name' => 'pr.id',
'alias' => 'productID',
'type' => 'number',
'label' => 'Product ID',
'sortable' => true,
],
[
'name' => 'pr.sku',
'alias' => 'productCode',
'type' => 'number',
'label' => 'Product Code',
'sortable' => true,
],
],
'filterable' => [
],
//don't use aliasing in case of searchables
'searchable' => [
//column, type and label
],
//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->createProductDataGrid()->render();
}
}

View File

@ -71,21 +71,21 @@ class RolesDataGrid
[
'name' => 'id',
'alias' => 'r_id',
'alias' => 'roleId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 'name',
'alias' => 'r_name',
'alias' => 'roleName',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
],
[
'name' => 'permission_type',
'alias' => 'r_permission_type',
'alias' => 'rolePermissionType',
'type' => 'string',
'label' => 'Permission Type',
'sortable' => true,
@ -98,19 +98,19 @@ class RolesDataGrid
'filterable' => [
[
'column' => 'id',
'alias' => 'r_id',
'alias' => 'roleId',
'type' => 'number',
'label' => 'ID',
],
[
'column' => 'name',
'alias' => 'r_name',
'alias' => 'roleName',
'type' => 'string',
'label' => 'Name',
],
[
'column' => 'permission_type',
'alias' => 'r_permission_type',
'alias' => 'rolePermissionType',
'type' => 'string',
'label' => 'Permission Type',
],

View File

@ -70,27 +70,27 @@ class SliderDataGrid
[
'name' => 's.id',
'alias' => 'slider_id',
'alias' => 'sliderId',
'type' => 'number',
'label' => 'ID',
'sortable' => true,
],
[
'name' => 's.title',
'alias' => 'slider_title',
'alias' => 'sliderTitle',
'type' => 'string',
'label' => 'title',
],
[
'name' => 's.channel_id',
'alias' => 'channel_id',
'alias' => 'channelId',
'type' => 'string',
'label' => 'Channel ID',
'sortable' => true,
],
[
'name' => 'c.name',
'alias' => 'channel_name',
'alias' => 'channelName',
'type' => 'string',
'label' => 'Channel Name',
'sortable' => true,

View File

@ -155,7 +155,7 @@ class UserDataGrid
],
[
'column' => 'r.id',
'alias' => 'Role_ID',
'alias' => 'xc',
'type' => 'number',
'label' => 'Role ID'
]

View File

@ -123,6 +123,13 @@ class EventServiceProvider extends ServiceProvider
*/
public function createProductFormAccordian()
{
Event::listen('admin.catalog.products.accordian.create', function() {
return ProductFormAccordian::create(function($accordian) {
Event::fire('admin.catalog.products.accordian.build', $accordian);
});
});
Event::listen('admin.catalog.products.accordian.build', function($accordian) {
$accordian->add('inventories', 'Inventories', 'admin::catalog.products.accordians.inventories', 1);

View File

@ -15,7 +15,8 @@
</div>
<div class="page-content">
@inject('attributes','Webkul\Admin\DataGrids\AttributeDataGrid')
{!! $attributes->render() !!}
</div>
</div>
@stop

View File

@ -15,7 +15,8 @@
</div>
<div class="page-content">
@inject('categories','Webkul\Admin\DataGrids\CategoryDataGrid')
{!! $categories->render() !!}
</div>
</div>
@stop

View File

@ -15,7 +15,8 @@
</div>
<div class="page-content">
@inject('product','Webkul\Admin\DataGrids\ProductDataGrid')
{!! $product->render() !!}
</div>
</div>
@stop

View File

@ -24,28 +24,28 @@ class ProductController extends Controller
* @var array
*/
protected $_config;
/**
* AttributeFamilyRepository object
*
* @var array
*/
protected $attributeFamily;
/**
* CategoryRepository object
*
* @var array
*/
protected $category;
/**
* InventorySourceRepository object
*
* @var array
*/
protected $inventorySource;
/**
* ProductRepository object
*
@ -125,7 +125,7 @@ class ProductController extends Controller
$this->validate(request(), [
'type' => 'required',
'attribute_family_id' => 'required',
'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Code]
'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug]
]);
$product = $this->product->create(request()->all());

View File

@ -724,7 +724,7 @@ class DataGrid
//Run this if there are joins
if (!empty($this->join)) {
foreach ($this->join as $join) {
foreach ($this->join as $index => $join) {
$name = strtolower($join['join']);
@ -750,7 +750,8 @@ class DataGrid
$alias2 = trim($exploded_secondary[0]);
if ($alias1 == $alias2) {
$this->getQueryWithJoin();
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');