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:
@@ -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
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user