2025-05-28 09:24:03 +08:00
|
|
|
<?php
|
|
|
|
|
2025-06-07 20:53:04 +08:00
|
|
|
namespace App\Livewire\Forms;
|
2025-05-28 09:24:03 +08:00
|
|
|
|
|
|
|
use App\Models\Branch;
|
|
|
|
use App\Jobs\ExportSqliteBranchJob;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Button;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Column;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Facades\Filter;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
|
|
|
|
use PowerComponents\LivewirePowerGrid\PowerGridFields;
|
|
|
|
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable;
|
|
|
|
use PowerComponents\LivewirePowerGrid\Facades\Rule;
|
|
|
|
use Livewire\Attributes\On;
|
|
|
|
use WireUi\Traits\WireUiActions;
|
|
|
|
|
|
|
|
final class BranchTable extends PowerGridComponent
|
|
|
|
{
|
|
|
|
use WithExport, WireUiActions;
|
|
|
|
public string $tableName = 'branch-table';
|
|
|
|
|
|
|
|
public bool $showFilters = false;
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
{
|
|
|
|
config(['livewire-powergrid.filter' => 'outside']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(): array
|
|
|
|
{
|
|
|
|
$actions = [];
|
|
|
|
$header = PowerGrid::header()
|
|
|
|
->withoutLoading()
|
|
|
|
->showToggleColumns();
|
2025-06-07 20:53:04 +08:00
|
|
|
$header->includeViewOnTop('livewire.header.admin.branch') ;
|
2025-05-28 09:24:03 +08:00
|
|
|
|
|
|
|
$actions[]=$header;
|
|
|
|
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function datasource(): Builder
|
|
|
|
{
|
|
|
|
return Branch::query();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function relationSearch(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fields(): PowerGridFields
|
|
|
|
{
|
|
|
|
return PowerGrid::fields()
|
|
|
|
->add('id')
|
|
|
|
->add('name')
|
|
|
|
->add('external_ip')
|
|
|
|
->add('enable')
|
|
|
|
->add('created_at_formatted', fn (Branch $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function columns(): array
|
|
|
|
{
|
|
|
|
$column=[];
|
|
|
|
$column[]=Column::make(__('branches.no'), 'id');
|
|
|
|
$column[]=Column::make(__('branches.name'), 'name')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('branches.external_ip'), 'external_ip')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('branches.enable'), 'enable');
|
|
|
|
$column[]=Column::make('Created at', 'created_at_formatted', 'created_at')->sortable()->hidden(true, false);
|
|
|
|
return $column;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filters(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
Filter::inputText('name')->placeholder(__('branches.name')),
|
|
|
|
Filter::inputText('external_ip')->placeholder(__('branches.external_ip')),
|
|
|
|
Filter::boolean('enable')->label('✅', '❌'),
|
|
|
|
Filter::datetimepicker('created_at'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|