Before merge with master

This commit is contained in:
prashant-webkul 2018-08-22 12:58:54 +05:30
parent 36a05a4bcd
commit 01d5cc1f3b
6 changed files with 53 additions and 204 deletions

View File

@ -156,7 +156,7 @@ class ProductDataGrid
[
'name' => 'pi.qty',
'alias' => 'ProductQuantity',
'type' => 'string',
'type' => 'number',
'label' => 'Product Quatity',
],
],

View File

@ -1,151 +0,0 @@
<?php
namespace Webkul\Admin\Datagrids;
use Illuminate\View\View;
use Webkul\Ui\DataGrid\Facades\DataGrid;
class User
{
/**
* Create datagrid.
*
* @return void
*/
public function createDatagrid()
{
return DataGrid::make([
'name' => 'Admins',
'table' => 'admins as u',
'select' => 'u.id',
'perpage' => 5,
'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' => 'roles as r',
'primaryKey' => 'u.role_id',
'condition' => '=',
'secondaryKey' => 'r.id',
]
],
//use aliasing on secodary columns if join is performed
'columns' => [
[
'name' => 'u.id',
'alias' => 'ID',
'type' => 'string',
'label' => 'Admin ID',
'sortable' => true,
'wrapper' => function ($value, $object) {
return '<a class="color-red">' . $object->ID . '</a>';
},
], [
'name' => 'u.name',
'alias' => 'Name',
'type' => 'string',
'label' => 'Name',
'sortable' => true,
'wrapper' => function ($value, $object) {
return '<a class="color-red">' . $object->Name . '</a>';
},
], [
'name' => 'u.email',
'alias' => 'Email',
'type' => 'string',
'label' => 'E-Mail',
'sortable' => true,
], [
'name' => 'r.name',
'alias' => 'xa',
'type' => 'string',
'label' => 'Role Name',
'sortable' => true,
], [
'name' => 'r.id',
'alias' => 'xc',
'type' => 'string',
'label' => 'Role ID',
'sortable' => true,
]
],
//don't use aliasing in case of filters
'filterable' => [
[
'column' => 'u.name',
'alias' => 'Name',
'type' => 'string',
'label' => 'Name'
], [
'column' => 'u.email',
'alias' => 'Email',
'type' => 'string',
'label' => 'Email'
], [
'column' => 'u.id',
'alias' => 'ID',
'type' => 'number',
'label' => 'Admin ID'
], [
'column' => 'r.id',
'alias' => 'Role_ID',
'type' => 'number',
'label' => 'Role ID'
]
],
//don't use aliasing in case of searchables
'searchable' => [
[
'column' => 'u.email',
'type' => 'string',
'label' => 'E-Mail'
], [
'column' => 'u.name',
'type' => 'string',
'label' => 'Name'
]
],
'operators' => [
'eq' => "=",
'lt' => "<",
'gt' => ">",
'lte' => "<=",
'gte' => ">=",
'neqs' => "<>",
'neqn' => "!=",
'like' => "like",
'nlike' => "not like",
],
]);
}
public function render()
{
return $this->createDatagrid()->render();
}
}

View File

@ -169,6 +169,17 @@ class ProductGrid
protected $parsed;
/**
* To store the
* attribute columns aliases
* for search, filter and
* sort.
*
* @var attributeAliases
*/
private $attributeAliases = [];
//Prepares the input parameters passed as the configuration for datagrid.
public function make($args)
{
@ -555,59 +566,48 @@ class ProductGrid
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;
} else {
return $parsed;
}
}
public function getProducts() {
$qb = DB::table('products')->addSelect('products.*');
/**
* Getting all attributes from the repository instance
* type hinted in the contructor of product grid.
*
* @return $this
*/
public function getAttributes() {
$channel = core()->getCurrentChannelCode();
$locale = app()->getLocale();
return $this->attributes->all();
}
foreach (['name', 'description', 'short_description', 'price'] as $code) {
$attribute = $this->attributes->findBy('code', $code);
public function filterProductByAttributes($attributes) {
$productValueAlias = 'pav_' . $attribute->code;
foreach($attributes as $key => $value) {
$qb->leftJoin('product_attribute_values as ' . $productValueAlias, function($leftJoin) use($channel, $locale, $attribute, $productValueAlias) {
$filterAlias = 'filter_' . $attribute->code;
$leftJoin->on('products.id', $productValueAlias . '.product_id');
$qb->leftJoin('product_attribute_values as ' . $filterAlias, 'products.id', '=', $filterAlias . '.product_id');
$qb->where($filterAlias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type], 'Product Name');
if($attribute->value_per_channel) {
if($attribute->value_per_locale) {
$leftJoin->where($productValueAlias . '.channel', $channel)
->where($productValueAlias . '.locale', $locale);
} else {
$leftJoin->where($productValueAlias . '.channel', $channel);
}
} else {
if($attribute->value_per_locale) {
$leftJoin->where($productValueAlias . '.locale', $locale);
}
}
$leftJoin->where($productValueAlias . '.attribute_id', $attribute->id);
});
$qb->addSelect($productValueAlias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type] . ' as ' . $code);
if($code == 'name') {
$filterAlias = 'filter_' . $attribute->code;
$qb->leftJoin('product_attribute_values as ' . $filterAlias, 'products.id', '=', $filterAlias . '.product_id');
$qb->where($filterAlias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type], 'Product Name');
}
}
}
/**
@ -623,14 +623,15 @@ class ProductGrid
if(array_key_exists('withAttributes',$join)) {
$qb = $this->query;
$channel = $this->channel;
$locale = $this->locale;
foreach ($this->attributeColumns as $code) {
$attribute = $this->attributes->findBy('code', $code);
$productValueAlias = 'pav_' . $attribute->code;
$productValueAlias = 'pavxxx' . $attribute->code;
array_push($this->attributeAliases, $productValueAlias);
$qb->leftJoin('product_attribute_values as ' . $productValueAlias, function ($leftJoin) use ($channel, $locale, $attribute, $productValueAlias) {
$leftJoin->on('prods.id', $productValueAlias . '.product_id');
@ -950,21 +951,11 @@ class ProductGrid
'results' => $this->results,
'columns' => $this->columns,
'attribute_columns' => $this->attributeColumns,
'attributeAliases' => $this->attributeAliases,
'filterable' =>$this->filterable,
'operators' => $this->operators,
'massoperations' => $this->massoperations,
'actions' => $this->actions,
]);
}
/**
* Getting all attributes from the repository instance
* type hinted in the contructor of product grid.
*
* @return $this
*/
public function getAttributes() {
// dd($this->attributes->all());
return $this->attributes->all();
}
}

View File

@ -633,7 +633,10 @@ h2 {
}
}
/* Data grid css starts here */
.grid-container {
user-select: none;
.filter-wrapper {
display: block;
box-sizing: border-box;
@ -642,7 +645,6 @@ h2 {
.filter-row-two {
display: flex;
flex-direction: row;
// flex-wrap: wrap;
}
.filter-row-one {
height: 40px;
@ -696,7 +698,7 @@ h2 {
width: 150px;
border: 2px solid $control-border-color;
border-radius: 2px;
background-color: white;
background-color: $color-white;
color: $filter-toggle-color;
font-size: 14px;
@ -866,6 +868,9 @@ h2 {
}
}
th {
text-transform: capitalize;
}
}
}

View File

@ -108,8 +108,12 @@
@endforeach
@if(isset($attribute_columns))
@foreach($attribute_columns as $key => $value)
<th>
{{ $value }}
<th class="grid_head"
data-column-name="{{ $attributeAliases[$key] }}"
data-column-label="{{ $attributeAliases[$key] }}"
data-column-sort="asc"
>
{{ $value }}<span class="icon sort-down-icon"></span>
</th>
@endforeach
@endif

View File

@ -14,7 +14,7 @@ mix.js(
],
"js/ui.js"
)
.copy(__dirname + "/src/Resources/assets/images", publicPath + "/images")
// .copy(__dirname + "/src/Resources/assets/images", publicPath + "/images")
.sass(__dirname + "/src/Resources/assets/sass/app.scss", "css/ui.css")
.options({
processCssUrls: false