feat(siren): show last data received timestamp in Active column

Active column now uses COALESCE to show the most recent timestamp
from siren, rainfall, or waterlevel data for each siren station.
This commit is contained in:
root
2026-05-30 23:22:03 +08:00
parent c5270926c7
commit 09e45443a8
2 changed files with 15 additions and 9 deletions

View File

@@ -18,7 +18,12 @@ class SirenController extends Controller
station.name, station.name,
station.district, station.district,
latest_siren.active_time, latest_siren.active_time,
latest_siren.level latest_siren.level,
COALESCE(
latest_siren.active_time,
(SELECT MAX(r.timestamp) FROM rainfall r WHERE r.stationid = station.stationid),
(SELECT MAX(w.datetime) FROM waterlevel w WHERE w.stationid = station.stationid)
) AS last_updated
FROM station FROM station
LEFT JOIN LATERAL ( LEFT JOIN LATERAL (
SELECT s.active_time, s.level SELECT s.active_time, s.level

View File

@@ -9,7 +9,7 @@
</ol> </ol>
</nav> </nav>
@if ($sirenData->isNotEmpty()) @if ($sirenData->isNotEmpty())
<table class="table caption-top table-bordered"> <table class="table caption-top table-bordered">
<thead class="table-light"> <thead class="table-light">
@@ -24,19 +24,21 @@
<tbody> <tbody>
@foreach ($sirenData as $row) @foreach ($sirenData as $row)
@php @php
$level = match ($row ->level) { $level = match ($row->level) {
'N' => __('messages.Normal') , 'N' => __('messages.Normal') ,
'H' => __('messages.danger') , 'H' => __('messages.danger') ,
'L' => __('messages.warning') , 'L' => __('messages.warning') ,
null => __('messages.Normal') ,
default => '-' default => '-'
}; };
$btnClass = match ($row ->level) { $btnClass = match ($row->level) {
'N' => 'btn-secondary' , 'N' => 'btn-secondary' ,
'H' => 'btn-danger' , 'H' => 'btn-danger' ,
'L' => 'btn-warning' , 'L' => 'btn-warning' ,
null => 'btn-secondary' ,
default => 'btn-secondary' default => 'btn-secondary'
}; };
@@ -44,8 +46,8 @@
@endphp @endphp
<tr> <tr>
<td>{{$row ->name}}</td> <td>{{$row ->name}}</td>
<td>{{$row ->active_time}}</td> <td>{{ $row->last_updated ? \Carbon\Carbon::parse($row->last_updated)->format('d/m/Y H:i:s') : '-' }}</td>
<td><button type="button" class="btn {{$btnClass}} btn-sm">{{$level}}</button></td> <td><button type="button" class="btn {{$btnClass}} btn-sm">{{$level}}</button></td>
@@ -53,10 +55,9 @@
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
@else @else
<div class="alert alert-light text-center mt-4" role="alert"> <div class="alert alert-light text-center mt-4" role="alert">
🚫 @lang('messages.nocurrentsiren') 🚫 @lang('messages.nocurrentsiren')