Skip to content

Commit

Permalink
Merge pull request #1951 from krayin/export-feature
Browse files Browse the repository at this point in the history
fix: added missing export feature
  • Loading branch information
devansh-webkul authored Jan 14, 2025
2 parents 99a51ee + 41f5430 commit 17729cf
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 14 deletions.
5 changes: 0 additions & 5 deletions packages/Webkul/Admin/src/Config/acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@
'name' => 'admin::app.acl.delete',
'route' => ['admin.contacts.persons.delete', 'admin.contacts.persons.mass_delete'],
'sort' => 4,
], [
'key' => 'contacts.persons.export',
'name' => 'admin::app.acl.export',
'route' => 'ui.datagrid.export',
'sort' => 4,
], [
'key' => 'contacts.persons.view',
'name' => 'admin::app.acl.view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(protected PersonRepository $personRepository)
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
public function index()
{
if (request()->ajax()) {
return datagrid(PersonDataGrid::class)->process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
/**
* Display a listing of the resource.
*/
public function index(): View|JsonResponse
public function index()
{
if (request()->ajax()) {
return datagrid(LeadDataGrid::class)->process();
Expand Down
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2083,4 +2083,13 @@
'title' => '503 الخدمة غير متوفرة',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'تحميل',
'export' => 'تصدير',
'no-records' => 'لا توجد سجلات للتصدير',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2087,4 +2087,13 @@
'title' => '503 Service Unavailable',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'Download',
'export' => 'Export',
'no-records' => 'Nothing to export',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2086,4 +2086,13 @@
'title' => '503 Servicio No Disponible',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'Descargar',
'export' => 'Exportar',
'no-records' => 'No se encontraron registros.',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2087,4 +2087,13 @@
'title' => '503 سرویس در دسترس نیست',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'دانلود',
'export' => 'صادر کردن',
'no-records' => 'هیچ سوابقی برای صادر کردن وجود ندارد.',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2051,4 +2051,13 @@
'errors' => [
'401' => 'Você não tem autorização para acessar esta página',
],

'export' => [
'csv' => 'CSV',
'download' => 'Download',
'export' => 'Exportar',
'no-records' => 'Nenhum registro encontrado.',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2087,4 +2087,13 @@
'title' => '503 Hizmet Kullanılamıyor',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'İndir',
'export' => 'Dışa Aktar',
'no-records' => 'Dışa aktarılacak kayıt bulunamadı.',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
9 changes: 9 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/vi/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2086,4 +2086,13 @@
'title' => '503 Dịch Vụ Không Khả Dụng',
],
],

'export' => [
'csv' => 'CSV',
'download' => 'Tải Xuống',
'export' => 'Xuất',
'no-records' => 'Không có bản ghi nào được tìm thấy.',
'xls' => 'XLS',
'xlsx' => 'XLSX',
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
</div>

<div class="flex items-center gap-x-2.5">
<!-- Export Modal -->
<x-admin::datagrid.export :src="route('admin.contacts.persons.index')" />

<!-- Create button for person -->
<div class="flex items-center gap-x-2.5">
{!! view_render_event('admin.persons.index.create_button.before') !!}
Expand Down Expand Up @@ -44,8 +47,8 @@ class="primary-button"
{!! view_render_event('admin.persons.index.datagrid.after') !!}
</div>

@pushOnce('scripts')
<script
@pushOnce('scripts')
<script
type="text/x-template"
id="v-persons-template"
>
Expand Down Expand Up @@ -167,7 +170,7 @@ class="icon-checkbox-outline peer-checked:icon-checkbox-select cursor-pointer ro
<!-- Name -->
<div class="flex items-center gap-1.5 dark:text-gray-300">
<x-admin::avatar ::name="record.person_name" />
@{{ record.person_name }}
</div>
Expand All @@ -185,7 +188,7 @@ class="icon-checkbox-outline peer-checked:icon-checkbox-select cursor-pointer ro
<p class="flex items-center dark:text-gray-300">
@{{ record.organization }}
</p>
<!-- Actions -->
<div class="flex items-center justify-end gap-x-4">
<div class="flex items-center gap-1.5">
Expand All @@ -202,7 +205,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
></span>
</p>
</div>
</div>
</div>
</div>
</template>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
{!! view_render_event('admin.leads.index.header.right.before') !!}

<div class="flex items-center gap-x-2.5">
@if ((request()->view_type ?? "kanban") == "table")
<!-- Export Modal -->
<x-admin::datagrid.export :src="route('admin.leads.index')" />
@endif

<!-- Create button for Leads -->
<div class="flex items-center gap-x-2.5">
@if (bouncer()->hasPermission('leads.create'))
Expand Down Expand Up @@ -55,4 +60,4 @@ class="primary-button"
</div>

{!! view_render_event('admin.leads.index.content.after') !!}
</x-admin::layouts>
</x-admin::layouts>
21 changes: 21 additions & 0 deletions packages/Webkul/DataGrid/src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class Column
*/
protected bool $sortable = false;

/**
* Column's exportability.
*/
protected bool $exportable = true;

/**
* Column's visibility.
*/
Expand Down Expand Up @@ -253,6 +258,22 @@ public function getSortable(): bool
return $this->sortable;
}

/**
* Set exportable.
*/
public function setExportable(bool $exportable): void
{
$this->exportable = $exportable;
}

/**
* Get exportable.
*/
public function getExportable(): bool
{
return $this->exportable;
}

/**
* Set visibility.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/DataGrid/src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Facades\Excel;
use Webkul\Admin\Exports\DataGridExport;
use Webkul\DataGrid\Enums\ColumnTypeEnum;
use Webkul\DataGrid\Exports\DataGridExport;

abstract class DataGrid
{
Expand Down
49 changes: 49 additions & 0 deletions packages/Webkul/DataGrid/src/Exports/DataGridExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Webkul\DataGrid\Exports;

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Webkul\DataGrid\DataGrid;

class DataGridExport implements FromQuery, ShouldAutoSize, WithHeadings, WithMapping
{
/**
* Create a new instance.
*
* @return void
*/
public function __construct(protected DataGrid $datagrid) {}

/**
* Query.
*/
public function query(): mixed
{
return $this->datagrid->getQueryBuilder();
}

/**
* Headings.
*/
public function headings(): array
{
return collect($this->datagrid->getColumns())
->filter(fn ($column) => $column->getExportable())
->map(fn ($column) => $column->getLabel())
->toArray();
}

/**
* Mapping.
*/
public function map(mixed $record): array
{
return collect($this->datagrid->getColumns())
->filter(fn ($column) => $column->getExportable())
->map(fn ($column) => $record->{$column->getIndex()})
->toArray();
}
}

0 comments on commit 17729cf

Please sign in to comment.