Base Structure Created

This commit is contained in:
devansh bawari 2021-09-15 18:34:03 +05:30
parent 4f498dfc70
commit 89c24e190a
7 changed files with 161 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js?id=8bcdcf3b86191d1739a5",
"/css/admin.css": "/css/admin.css?id=b24aa6544b82f674840f"
"/css/admin.css": "/css/admin.css?id=59ebf5021195a90c8760"
}

View File

@ -2,31 +2,85 @@
namespace Webkul\Admin\DataGrids;
use Webkul\Core\Models\Locale;
use Webkul\Core\Models\Channel;
use Webkul\Ui\DataGrid\DataGrid;
use Illuminate\Support\Facades\DB;
use Webkul\Core\Models\Channel;
use Webkul\Core\Models\Locale;
use Webkul\Inventory\Repositories\InventorySourceRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Ui\DataGrid\DataGrid;
class ProductDataGrid extends DataGrid
{
/**
* Default sort order of datagrid.
*
* @var string
*/
protected $sortOrder = 'desc';
/**
* Set index columns, ex: id.
*
* @var string
*/
protected $index = 'product_id';
/**
* If paginated then value of pagination.
*
* @var int
*/
protected $itemsPerPage = 10;
/**
* Locale.
*
* @var string
*/
protected $locale = 'all';
/**
* Channel.
*
* @var string
*/
protected $channel = 'all';
/** @var string[] contains the keys for which extra filters to render */
/**
* Contains the keys for which extra filters to show.
*
* @var string[]
*/
protected $extraFilters = [
'channels',
'locales',
];
public function __construct()
{
/**
* Product repository instance.
*
* @var \Webkul\Product\Repositories\ProductRepository
*/
protected $productRepository;
/**
* Inventory source repository instance.
*
* @var \Webkul\Inventory\Repositories\InventorySourceRepository
*/
protected $inventorySourceRepository;
/**
* Create datagrid instance.
*
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySourceRepository
* @return void
*/
public function __construct(
ProductRepository $productRepository,
InventorySourceRepository $inventorySourceRepository
) {
parent::__construct();
/* locale */
@ -40,8 +94,17 @@ class ProductDataGrid extends DataGrid
$this->channel = Channel::query()->find($this->channel);
$this->channel = $this->channel ? $this->channel->code : 'all';
}
$this->productRepository = $productRepository;
$this->inventorySourceRepository = $inventorySourceRepository;
}
/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
{
if ($this->channel === 'all') {
@ -91,6 +154,11 @@ class ProductDataGrid extends DataGrid
$this->setQueryBuilder($queryBuilder);
}
/**
* Add columns.
*
* @return void
*/
public function addColumns()
{
$this->addColumn([
@ -179,16 +247,28 @@ class ProductDataGrid extends DataGrid
'sortable' => true,
'searchable' => false,
'filterable' => false,
'closure' => true,
'wrapper' => function ($value) {
if (is_null($value->quantity)) {
return 0;
} else {
return $value->quantity;
$product = $this->productRepository->find($value->product_id);
$inventorySources = $this->inventorySourceRepository->findWhere(['status' => 1]);
$totalQuantity = $value->quantity;
return view('admin::catalog.products.datagrid.quantity', compact('product', 'inventorySources', 'totalQuantity'))->render();
}
},
]);
}
/**
* Prepare actions.
*
* @return void
*/
public function prepareActions()
{
$this->addAction([
@ -210,6 +290,11 @@ class ProductDataGrid extends DataGrid
]);
}
/**
* Prepare mass actions.
*
* @return void
*/
public function prepareMassActions()
{
$this->addAction([
@ -237,4 +322,4 @@ class ProductDataGrid extends DataGrid
],
]);
}
}
}

View File

@ -9,6 +9,7 @@ $accordian-header: #fbfbfb;
// Buttons
$btn-primary: $white;
$btn-primary-bg: #0041FF;
$btn-danger-bg: $red;
// Cards
$card-title: #a2a2a2;

View File

@ -1,13 +1,17 @@
// Accordion
.accordian-header {
background-color: $accordian-header;
background-color: $accordian-header;
}
// buttons
.btn.btn-primary{
// Buttons
.btn.btn-primary {
background: $btn-primary-bg;
}
.btn.btn-danger {
background: $btn-danger-bg;
}
.fixed-action {
position: fixed;
top: 108px;
@ -24,4 +28,4 @@
.pagination {
margin-top: 30px;
}
}

View File

@ -0,0 +1,35 @@
<span id="product-{{ $product->id }}-quantity">
<a href="javascript:void(0);" onclick="showEditQuantityForm('{{ $product->id }}')">{{ $totalQuantity }}</a>
</span>
<span id="edit-product-{{ $product->id }}-quantity-form-block" style="display: none;">
<form id="edit-product-{{ $product->id }}-quantity-form" action="javascript:void(0);">
@csrf
@foreach ($inventorySources as $inventorySource)
@php
$qty = 0;
foreach ($product->inventories as $inventory) {
if ($inventory->inventory_source_id == $inventorySource->id) {
$qty = $inventory->qty;
break;
}
}
$qty = old('inventories[' . $inventorySource->id . ']') ?: $qty;
@endphp
<div class="control-group" :class="[errors.has('inventories[{{ $inventorySource->id }}]') ? 'has-error' : '']">
<label>{{ $inventorySource->name }}</label>
<input type="text" v-validate="'numeric|min:0'" name="inventories[{{ $inventorySource->id }}]" class="control" value="{{ $qty }}" data-vv-as="&quot;{{ $inventorySource->name }}&quot;"/>
<span class="control-error" v-if="errors.has('inventories[{{ $inventorySource->id }}]')">@{{ errors.first('inventories[{!! $inventorySource->id !!}]') }}</span>
</div>
@endforeach
<button class="btn btn-primary" onclick="saveEditQuantityForm('{{ $product->id }}')">Save</button>
<button class="btn btn-danger" onclick="cancelEditQuantityForm('{{ $product->id }}')">Cancel</button>
</form>
</span>

View File

@ -29,11 +29,11 @@
<div class="page-content">
@inject('products', 'Webkul\Admin\DataGrids\ProductDataGrid')
{!! $products->render() !!}
</div>
{!! view_render_event('bagisto.admin.catalog.products.list.after') !!}
</div>
<modal id="downloadDataGrid" :is-open="modalIds.downloadDataGrid">
@ -46,14 +46,34 @@
@push('scripts')
@include('admin::export.export', ['gridName' => $products])
<script>
<script>
function reloadPage(getVar, getVal) {
let url = new URL(window.location.href);
url.searchParams.set(getVar, getVal);
window.location.href = url.href;
}
function showEditQuantityForm(productId) {
$(`#product-${productId}-quantity`).hide();
$(`#edit-product-${productId}-quantity-form-block`).show();
}
function cancelEditQuantityForm(productId) {
$(`#product-${productId}-quantity`).show();
$(`#edit-product-${productId}-quantity-form-block`).hide();
}
function saveEditQuantityForm(productId) {
let quantityFormData = $(`#edit-product-${productId}-quantity-form`).serializeArray();
console.log(quantityFormData);
alert(`${productId} Saved!`);
}
</script>
@endpush