2025-06-06 18:11:22 +08:00
|
|
|
<?php
|
|
|
|
|
2025-07-01 10:36:00 +08:00
|
|
|
namespace App\Livewire\Tables;
|
2025-06-06 18:11:22 +08:00
|
|
|
|
|
|
|
use App\Models\MachineStatus;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
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;
|
|
|
|
|
|
|
|
final class MachineStatusTable extends PowerGridComponent
|
|
|
|
{
|
|
|
|
public string $tableName = 'machine-status-table';
|
|
|
|
public bool $canDownload;
|
|
|
|
|
|
|
|
public bool $showFilters = false;
|
|
|
|
public function boot(): void
|
|
|
|
{
|
|
|
|
config(['livewire-powergrid.filter' => 'outside']);
|
|
|
|
//權限設定
|
|
|
|
$this->canDownload=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(): array
|
|
|
|
{
|
|
|
|
if($this->canDownload ){
|
|
|
|
$this->showCheckBox();
|
|
|
|
}
|
|
|
|
$actions = [];
|
|
|
|
if($this->canDownload){
|
|
|
|
$actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file')
|
|
|
|
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV);
|
|
|
|
}
|
|
|
|
$header = PowerGrid::header()
|
|
|
|
->withoutLoading()
|
|
|
|
->showToggleColumns();
|
|
|
|
|
2025-06-07 20:53:04 +08:00
|
|
|
$header->includeViewOnTop('livewire.header.admin.machine-status');
|
2025-06-06 18:11:22 +08:00
|
|
|
|
|
|
|
$actions[]=$header;
|
|
|
|
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function datasource(): Builder
|
|
|
|
{
|
|
|
|
return MachineStatus::query()->latest();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function relationSearch(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fields(): PowerGridFields
|
|
|
|
{
|
|
|
|
return PowerGrid::fields()
|
|
|
|
->add('id')
|
|
|
|
->add('hostname')
|
|
|
|
->add('ip')
|
|
|
|
->add('cpu')
|
|
|
|
->add('memory')
|
|
|
|
->add('disk')
|
|
|
|
->add('created_at');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function columns(): array
|
|
|
|
{
|
|
|
|
$column=[];
|
|
|
|
$column[]=Column::make('Id', 'id');
|
|
|
|
$column[]=Column::make(__('machine-status.hostname'), 'hostname')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('machine-status.Ip'), 'ip')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('machine-status.Cpu'), 'cpu')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('machine-status.Memory'), 'memory')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('machine-status.Disk'), 'disk')->sortable()->searchable();
|
|
|
|
$column[]=Column::make(__('machine-status.Created at'), 'created_at')->sortable()->searchable();
|
|
|
|
|
|
|
|
return $column;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filters(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
Filter::datetimepicker('created_at'),
|
|
|
|
Filter::inputText('hostname')->placeholder(__('machine-status.hostname')),
|
|
|
|
Filter::inputText('ip')->placeholder(__('machine-status.Ip')),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|