Skip to content

Commit

Permalink
feat: shop package datagrid added and added drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Aug 29, 2023
1 parent b7e5c03 commit d3a59bd
Show file tree
Hide file tree
Showing 30 changed files with 1,777 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function prepareColumns()
$this->addColumn([
'index' => 'created_at',
'label' => trans('admin::app.catalog.attributes.index.datagrid.created-at'),
'type' => 'date_range',
'type' => 'datetime_range',
'searchable' => true,
'filterable' => true,
'sortable' => true,
Expand Down
12 changes: 7 additions & 5 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@
'created-at' => 'Created At',
'edit' => 'Edit',
'delete' => 'Delete',
'mass-delete-success' => 'Selected Attribute Deleted Successfully',
'mass-delete-success' => 'Selected Attribute Deleted Successfully',
],
],

Expand Down Expand Up @@ -1278,8 +1278,8 @@
'images' => 'Images',
'update-success' => 'Update Successfully',
],
'datagrid' => [

'datagrid' => [
'customer_names' => 'Name',
'comment' => 'Comment',
'date' => 'Date',
Expand All @@ -1299,8 +1299,8 @@
'mass-delete-success' => 'Selected Review Deleted Successfully',
'mass-delete-error' => 'Something went wrong',
'mass-update-success' => 'Selected Review Updated Successfully',
],
],
],
],
],

'addresses' => [
Expand Down Expand Up @@ -2792,6 +2792,8 @@
],

'filters' => [
'title' => 'Apply Filter',

'custom-filters' => [
'title' => 'Custom Filters',
'clear-all' => 'Clear All',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div
class="min-w-[0] max-w-[0] transition-all duration-300 [&>*]:whitespace-nowrap"
:class="[showFilters ? '!min-w-[344px] !max-w-[344px] pr-[10px]': 'overflow-hidden']"
>
<div>
<!-- Custom Filter -->
<x-admin::accordion class="w-full rounded-[4px] border border-gray-300 bg-white shadow-[0px_8px_10px_0px_rgba(0,_0,_0,_0.2)]">
<x-slot:header>
Expand All @@ -12,6 +9,7 @@ class="min-w-[0] max-w-[0] transition-all duration-300 [&>*]:whitespace-nowrap"

<x-slot:content>
<div v-for="column in available.columns">
<!-- Date Range -->
<div v-if="column.type === 'date_range'">
<div class="flex items-center justify-between">
<p
Expand Down Expand Up @@ -93,10 +91,9 @@ class="icon-cross ml-[5px] cursor-pointer text-[18px] text-white"
</p>
</div>
</div>

{{-- <hr class="mb-2"> --}}
</div>

<!-- Date Time Range -->
<div v-else-if="column.type === 'datetime_range'">
<div class="flex items-center justify-between">
<p
Expand Down Expand Up @@ -151,7 +148,7 @@ class="flex w-full min-h-[39px] px-3 py-2 rounded-[6px] border text-[14px] text-
<input
type="column.input_type"
value=""
class="flex w-full min-h-[39px] px-3 py-2 rounded-[6px] text-[14px] text-gray-600 transition-all hover:border-gray-400"
class="flex w-full min-h-[39px] px-3 py-2 rounded-[6px] border text-[14px] text-gray-600 transition-all hover:border-gray-400"
:name="`${column.index}[to]`"
:placeholder="column.label"
:ref="`${column.index}[from]`"
Expand All @@ -178,10 +175,9 @@ class="icon-cross ml-[5px] cursor-pointer text-[18px] text-white"
</p>
</div>
</div>

<hr class="mb-2">
</div>

<!-- Rest -->
<div v-else>
<div class="flex items-center justify-between">
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<x-admin::datagrid.toolbar></x-admin::datagrid.toolbar>
<div class="flex mt-[16px]">
<x-admin::datagrid.filters></x-admin::datagrid.filters>
<x-admin::datagrid.table :isMultiRow="$isMultiRow">
<template #header>
<slot
Expand Down Expand Up @@ -63,8 +61,6 @@
return {
isLoading: false,
showFilters: false,
available: {
columns: [],
Expand Down Expand Up @@ -218,18 +214,26 @@
* the addition of a `url` prop. Instead, by using the numeric approach, we can let Axios handle all the query parameters
* using the `applied` prop. This allows for a cleaner and more straightforward implementation.
*
* @param {string} direction
* @param {string|integer} directionOrPageNumber
* @returns {void}
*/
changePage(direction) {
changePage(directionOrPageNumber) {
let newPage;
if (direction === 'previous') {
newPage = this.available.meta.current_page - 1;
} else if (direction === 'next') {
newPage = this.available.meta.current_page + 1;
if (typeof directionOrPageNumber === 'string') {
if (directionOrPageNumber === 'previous') {
newPage = this.available.meta.current_page - 1;
} else if (directionOrPageNumber === 'next') {
newPage = this.available.meta.current_page + 1;
} else {
console.warn('Invalid Direction Provided : ' + directionOrPageNumber);
return;
}
} else if (typeof directionOrPageNumber === 'number') {
newPage = directionOrPageNumber;
} else {
console.error('Invalid Direction Provided : ' + direction);
console.warn('Invalid Input Provided: ' + directionOrPageNumber);
return;
}
Expand All @@ -242,7 +246,7 @@
this.get();
} else {
console.warn('Invalid page provided: ' + newPage);
console.warn('Invalid Page Provided: ' + newPage);
}
},
Expand Down Expand Up @@ -683,10 +687,6 @@
break;
}
},
toggleFilters() {
this.showFilters = !this.showFilters;
},
},
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,14 @@ class="peer hidden"
</p>

<!-- Columns -->

<p
v-if="record.is_closure"
v-for="column in $parent.available.columns"
v-html="record[column.index]"
>
</p>

<p
<p
v-else
v-for="column in $parent.available.columns"
v-html="record[column.index]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,11 @@ class="text-[24px]"
</div>
</div>

<!-- Filters And Search Panel -->
<!-- Search Panel -->
<div
class="flex w-full items-center gap-x-[4px]"
v-else
>
<!-- Filters Activation Button -->
<div
class=""
@click="toggleFilters"
>
<div
class="focus:ring-gratext-gray-600 inline-flex w-full max-w-max cursor-pointer select-none appearance-none items-center justify-between gap-x-[4px] rounded-[6px] border border-gray-300 bg-white px-[4px] py-[6px] text-center font-semibold text-gray-600 transition-all marker:shadow hover:border-gray-400 focus:outline-none focus:ring-2"
:class="{'border-gray-400': showFilters}"
>
<span class="icon-filter text-[24px]"></span>

<span>
@lang('admin::app.components.datagrid.toolbar.filter.title')
</span>

<span class="icon-arrow-up text-[24px]"></span>
</div>

<div class="z-10 hidden w-full divide-y divide-gray-100 rounded bg-white shadow">
</div>
</div>

<!-- Search Panel -->
<div class="flex max-w-[445px] items-center max-sm:w-full max-sm:max-w-full">
<div class="relative w-full">
Expand Down Expand Up @@ -146,7 +124,41 @@ class="block w-full rounded-lg border border-gray-300 bg-white py-[6px] pl-[12px

<!-- Right Toolbar -->
<div class="flex gap-x-[16px]">
<span class="icon-settings cursor-pointer rounded-[6px] p-[6px] text-[24px] transition-all hover:bg-gray-200"></span>
<!-- Filters Activation Button -->
<x-admin::drawer width="350px">
<x-slot:toggle>
<div>
<div
class="focus:ring-gratext-gray-600 inline-flex w-full max-w-max cursor-pointer select-none appearance-none items-center justify-between gap-x-[4px] rounded-[6px] border border-gray-400 bg-white px-[4px] py-[6px] text-center text-gray-600 transition-all marker:shadow focus:outline-none focus:ring-2"
>
<span class="icon-filter text-[24px]"></span>

<span>
@lang('admin::app.components.datagrid.toolbar.filter.title')
</span>

<span class="icon-arrow-up text-[24px]"></span>
</div>

<div class="z-10 hidden w-full divide-y divide-gray-100 rounded bg-white shadow">
</div>
</div>
</x-slot:toggle>

<!-- Drawer Header -->
<x-slot:header>
<div class="flex justify-between items-center p-3">
<p class="text-[20px] font-medium">
@lang('admin::app.components.datagrid.filters.title')
</p>
</div>
</x-slot:header>

<!-- Drawer Content -->
<x-slot:content>
<x-admin::datagrid.filters></x-admin::datagrid.filters>
</x-slot:content>
</x-admin::drawer>

<div class="flex items-center gap-x-[8px]">
<x-admin::dropdown>
Expand All @@ -172,11 +184,12 @@ class="block w-full rounded-lg border border-gray-300 bg-white py-[6px] pl-[12px

<p class="whitespace-nowrap text-gray-600 max-sm:hidden">per page</p>

<div
class="ml-[8px] inline-flex min-h-[38px] w-full min-w-[40px] max-w-max appearance-none items-center justify-center gap-x-[4px] rounded-[6px] border border-gray-300 bg-white px-[12px] py-[6px] text-center leading-[24px] text-gray-600 transition-all marker:shadow hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-black max-sm:hidden"
v-text="available.meta.current_page"
<input
type="text"
class="ml-[8px] inline-flex min-h-[38px] max-w-[40px] appearance-none items-center justify-center gap-x-[4px] rounded-[6px] border border-gray-300 bg-white px-[12px] py-[6px] text-center leading-[24px] text-gray-600 transition-all marker:shadow hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-black max-sm:hidden"
:value="available.meta.current_page"
@change="changePage(parseInt($event.target.value))"
>
</div>

<div class="whitespace-nowrap text-gray-600">
<span>of </span>
Expand Down
26 changes: 6 additions & 20 deletions packages/Webkul/Shop/src/DataGrids/DownloadableProductDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@

class DownloadableProductDataGrid extends DataGrid
{
/**
* Index.
*
* @var string
*/
protected $index = 'id';

/**
* Sort order.
*
* @var string
*/
protected $sortOrder = 'desc';

/**
* Prepare query builder.
*
Expand All @@ -36,9 +22,9 @@ public function prepareQueryBuilder()
->addSelect(DB::raw('(' . DB::getTablePrefix() . 'downloadable_link_purchased.download_bought - ' . DB::getTablePrefix() . 'downloadable_link_purchased.download_canceled - ' . DB::getTablePrefix() . 'downloadable_link_purchased.download_used) as remaining_downloads'))
->where('downloadable_link_purchased.customer_id', auth()->guard('customer')->user()->id);

// $this->addFilter('status', 'downloadable_link_purchased.status');
// $this->addFilter('created_at', 'downloadable_link_purchased.created_at');
// $this->addFilter('increment_id', 'orders.increment_id');
$this->addFilter('increment_id', 'orders.increment_id');
$this->addFilter('status', 'downloadable_link_purchased.status');
$this->addFilter('created_at', 'downloadable_link_purchased.created_at');

return $queryBuilder;
}
Expand Down Expand Up @@ -97,11 +83,11 @@ public function prepareColumns()
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 'pending') {
return '<span class="badge badge-md badge-warning">' .trans('shop::app.customer.account.downloadable_products.pending'). '</span>';
return '<span class="badge badge-md badge-warning">' . trans('shop::app.customer.account.downloadable_products.pending') . '</span>';
} elseif ($value->status == 'available') {
return '<span class="badge badge-md badge-success">' .trans('shop::app.customer.account.downloadable_products.available'). '</span>';
return '<span class="badge badge-md badge-success">' . trans('shop::app.customer.account.downloadable_products.available') . '</span>';
} elseif ($value->status == 'expired') {
return '<span class="badge badge-md badge-danger">' .trans('shop::app.customer.account.downloadable_products.expired'). '</span>';
return '<span class="badge badge-md badge-danger">' . trans('shop::app.customer.account.downloadable_products.expired') . '</span>';
}
},
]);
Expand Down
Loading

0 comments on commit d3a59bd

Please sign in to comment.