mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-19 10:46:48 +02:00
fix minor issues, falsy check & unnecessary defaults & simplify to a single empty state
This commit is contained in:
parent
5c6cf48a77
commit
29e885b6d4
3 changed files with 23 additions and 16 deletions
|
@ -87,7 +87,7 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
|
|
||||||
// Get the status page to determine the heartbeat range
|
// Get the status page to determine the heartbeat range
|
||||||
let statusPage = await R.findOne("status_page", " id = ? ", [ statusPageID ]);
|
let statusPage = await R.findOne("status_page", " id = ? ", [ statusPageID ]);
|
||||||
let heartbeatBarDays = statusPage ? (statusPage.heartbeat_bar_days || 0) : 0;
|
let heartbeatBarDays = statusPage.heartbeat_bar_days;
|
||||||
|
|
||||||
// Get max beats parameter from query string (for client-side screen width constraints)
|
// Get max beats parameter from query string (for client-side screen width constraints)
|
||||||
const maxBeats = Math.min(parseInt(request.query.maxBeats) || 100, 100);
|
const maxBeats = Math.min(parseInt(request.query.maxBeats) || 100, 100);
|
||||||
|
@ -115,15 +115,22 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
} else {
|
} else {
|
||||||
// For configured day ranges, use aggregated data from UptimeCalculator
|
// For configured day ranges, use aggregated data from UptimeCalculator
|
||||||
const buckets = uptimeCalculator.getAggregatedBuckets(heartbeatBarDays, maxBeats);
|
const buckets = uptimeCalculator.getAggregatedBuckets(heartbeatBarDays, maxBeats);
|
||||||
heartbeats = buckets.map(bucket => ({
|
heartbeats = buckets.map(bucket => {
|
||||||
status: bucket.down > 0 ? DOWN :
|
// If bucket has no data, return 0 (empty beat) to match original behavior
|
||||||
bucket.maintenance > 0 ? MAINTENANCE :
|
if (bucket.up === 0 && bucket.down === 0 && bucket.maintenance === 0 && bucket.pending === 0) {
|
||||||
bucket.pending > 0 ? PENDING :
|
return 0;
|
||||||
bucket.up > 0 ? UP : null,
|
}
|
||||||
time: dayjs.unix(bucket.end).toISOString(),
|
|
||||||
msg: "",
|
return {
|
||||||
ping: null
|
status: bucket.down > 0 ? DOWN :
|
||||||
}));
|
bucket.maintenance > 0 ? MAINTENANCE :
|
||||||
|
bucket.pending > 0 ? PENDING :
|
||||||
|
bucket.up > 0 ? UP : 0,
|
||||||
|
time: dayjs.unix(bucket.end).toISOString(),
|
||||||
|
msg: "",
|
||||||
|
ping: null
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate uptime based on the range
|
// Calculate uptime based on the range
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="beat"
|
class="beat"
|
||||||
:class="{ 'empty': (beat === 0 || beat === null || beat.status === null), 'down': (beat.status === 0), 'pending': (beat.status === 2), 'maintenance': (beat.status === 3) }"
|
:class="{ 'empty': (beat === 0), 'down': (beat.status === 0), 'pending': (beat.status === 2), 'maintenance': (beat.status === 3) }"
|
||||||
:style="beatStyle"
|
:style="beatStyle"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -318,7 +318,7 @@ export default {
|
||||||
* @returns {string} Beat title
|
* @returns {string} Beat title
|
||||||
*/
|
*/
|
||||||
getBeatTitle(beat) {
|
getBeatTitle(beat) {
|
||||||
if (beat === 0 || !beat) {
|
if (beat === 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue