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.district,
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
LEFT JOIN LATERAL (
SELECT s.active_time, s.level

View File

@@ -9,7 +9,7 @@
</ol>
</nav>
@if ($sirenData->isNotEmpty())
@if ($sirenData->isNotEmpty())
<table class="table caption-top table-bordered">
<thead class="table-light">
@@ -26,17 +26,19 @@
@php
$level = match ($row ->level) {
$level = match ($row->level) {
'N' => __('messages.Normal') ,
'H' => __('messages.danger') ,
'L' => __('messages.warning') ,
null => __('messages.Normal') ,
default => '-'
};
$btnClass = match ($row ->level) {
$btnClass = match ($row->level) {
'N' => 'btn-secondary' ,
'H' => 'btn-danger' ,
'L' => 'btn-warning' ,
null => 'btn-secondary' ,
default => 'btn-secondary'
};
@@ -45,7 +47,7 @@
<tr>
<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>
@@ -56,7 +58,6 @@
</tbody>
</table>
@else
<div class="alert alert-light text-center mt-4" role="alert">
🚫 @lang('messages.nocurrentsiren')