LAR_Maintenance/app/Livewire/MaintenanceHistory/DataTable.php

75 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2024-07-31 15:04:33 +00:00
<?php
2024-07-31 16:45:14 +00:00
2024-07-31 15:04:33 +00:00
namespace App\Livewire\MaintenanceHistory;
use App\Models\MaintenanceHistory;
use SteelAnts\DataTable\Livewire\DataTableComponent;
use Illuminate\Database\Eloquent\Builder;
class DataTable extends DataTableComponent
{
public string $type = "planned";
2024-07-31 15:04:33 +00:00
public $listeners = [
'maintenanceHistoryAdded' => '$refresh',
'closeModal' => '$refresh',
];
public function query(): Builder
{
$query = MaintenanceHistory::query();
if ($this->type == "planned") {
$query->whereNull('finished_at');
} elseif ($this->type == "history") {
$query->whereNotNull('finished_at');
}
return $query;
2024-07-31 15:04:33 +00:00
}
public function headers(): array
{
$headers = [
2024-07-31 15:04:33 +00:00
'maintenance.name' => 'maintenance.name',
2024-07-31 16:45:14 +00:00
'start_at' => 'start_at',
2024-07-31 15:04:33 +00:00
];
if ($this->type == "planned") {
$headers['guestor.name'] = 'guestor';
} else {
$headers['finished_at'] = 'finished_at';
}
return $headers;
2024-07-31 15:04:33 +00:00
}
2024-07-31 16:45:14 +00:00
public function remove($maintenancehistory_id)
{
2024-07-31 15:04:33 +00:00
MaintenanceHistory::find($maintenancehistory_id)->delete();
}
2024-07-31 16:45:14 +00:00
public function renderColumnMaintenanceName($val, $row)
{
if ($this->type == "planned") {
$ret = '<a href="' . route('maintenance.planned.detail', $row['id']) . '">' . e($val) . '</a>';
} else {
$ret = '<a href="' . route('maintenance.history.detail', $row['id']) . '">' . e($val) . '</a>';
}
2024-07-31 16:45:14 +00:00
return $ret;
}
2024-08-06 14:57:48 +00:00
public function actions($item)
{
return [
[
'type' => "livewire",
'action' => "remove",
'text' => "remove",
'parameters' => $item['id']
]
];
}
2024-07-31 15:04:33 +00:00
}