2025-07-29 00:24:03 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Tables;
|
|
|
|
|
|
|
|
use App\Models\RoomStatusLog;
|
|
|
|
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;
|
|
|
|
|
|
|
|
final class RoomStatusLogTable extends PowerGridComponent
|
|
|
|
{
|
|
|
|
public string $tableName = 'room-status-log-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-08-03 10:22:07 +08:00
|
|
|
$header->includeViewOnTop('livewire.headers.room-status-log');
|
2025-07-29 00:24:03 +08:00
|
|
|
|
|
|
|
$actions[]=$header;
|
|
|
|
$actions[]=PowerGrid::footer()->showPerPage()->showRecordCount();
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function datasource(): Builder
|
|
|
|
{
|
2025-07-30 18:08:09 +08:00
|
|
|
return RoomStatusLog::with(['room', 'branch'])->latest();
|
2025-07-29 00:24:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function relationSearch(): array
|
|
|
|
{
|
2025-07-30 18:08:09 +08:00
|
|
|
return [
|
|
|
|
'branch' => ['name'],
|
|
|
|
'room' => ['name'],
|
|
|
|
'user' => ['name'],
|
|
|
|
];
|
2025-07-29 00:24:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function fields(): PowerGridFields
|
|
|
|
{
|
|
|
|
return PowerGrid::fields()
|
|
|
|
->add('id')
|
2025-07-30 18:08:09 +08:00
|
|
|
->add('branch_name', function (RoomStatusLog $model) {
|
|
|
|
return $model->branch?->name;
|
|
|
|
})
|
2025-07-29 00:24:03 +08:00
|
|
|
->add('room_name', function (RoomStatusLog $model) {
|
|
|
|
return $model->room?->type->labelPowergridFilter().$model->room?->name;
|
|
|
|
})
|
|
|
|
->add('user_name', function (RoomStatusLog $model){
|
|
|
|
return $model->user?->name;
|
|
|
|
})
|
2025-08-03 16:20:50 +08:00
|
|
|
->add('is_online_img', fn ($model) =>
|
|
|
|
[
|
|
|
|
$model->is_online ? 'check-circle' : 'x-circle' => [
|
|
|
|
'text-color' => $model->is_online ? 'text-green-600' : 'text-red-600',
|
|
|
|
],
|
|
|
|
])
|
2025-07-29 00:24:03 +08:00
|
|
|
->add('status_str',function (RoomStatusLog $model){
|
|
|
|
return $model->status->labelPowergridFilter();
|
|
|
|
})
|
2025-07-30 18:08:09 +08:00
|
|
|
->add('started_at')
|
|
|
|
->add('ended_at')
|
2025-07-29 00:24:03 +08:00
|
|
|
->add('message')
|
2025-07-30 18:08:09 +08:00
|
|
|
->add('source')
|
2025-07-29 00:24:03 +08:00
|
|
|
->add('created_at');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function columns(): array
|
|
|
|
{
|
|
|
|
$column=[];
|
|
|
|
$column[]=Column::make(__('room-status-log.id'), 'id');
|
2025-07-30 18:08:09 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.branch'), 'branch_name');
|
2025-07-29 00:24:03 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.room'), 'room_name');
|
|
|
|
$column[]=Column::make(__('room-status-log.user'), 'user_name');
|
2025-08-03 16:20:50 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.is_online'), 'is_online_img')->template();
|
2025-07-29 00:24:03 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.status'), 'status_str');
|
2025-07-30 18:08:09 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.started_at'), 'started_at');
|
|
|
|
$column[]=Column::make(__('room-status-log.ended_at'), 'ended_at');
|
2025-07-29 00:24:03 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.message'), 'message');
|
2025-07-30 18:08:09 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.source'), 'source');
|
2025-07-29 00:24:03 +08:00
|
|
|
$column[]=Column::make(__('room-status-log.created_at'), 'created_at');
|
|
|
|
return $column;
|
|
|
|
}
|
2025-08-03 16:20:50 +08:00
|
|
|
public function rowTemplates(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'check-circle' => '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6 {{ text-color }}">
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
|
|
|
|
</svg>',
|
|
|
|
'x-circle' => '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6 {{ text-color }}">
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
|
|
|
|
</svg>',
|
|
|
|
];
|
|
|
|
}
|
2025-07-29 00:24:03 +08:00
|
|
|
|
|
|
|
public function filters(): array
|
|
|
|
{
|
|
|
|
return [
|
2025-07-30 18:08:09 +08:00
|
|
|
|
2025-07-29 00:24:03 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|