update uptime component with dynamic range

This commit is contained in:
Doruk 2025-06-17 15:28:15 +02:00
parent 24b6209651
commit 6c26d32a8e
3 changed files with 41 additions and 8 deletions

View file

@ -126,13 +126,18 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
ping: null ping: null
})); }));
// Calculate uptime for the configured range // Calculate uptime for the exact configured range
if (heartbeatBarDays <= 1) { try {
uptime = uptimeCalculator.get24Hour().uptime; uptime = uptimeCalculator.getDataByDuration(`${heartbeatBarDays}d`).uptime;
} else if (heartbeatBarDays <= 30) { } catch (e) {
uptime = uptimeCalculator.get30Day().uptime; // Fall back to available ranges if duration exceeds limits
} else { if (heartbeatBarDays <= 1) {
uptime = uptimeCalculator.get1Year().uptime; uptime = uptimeCalculator.get24Hour().uptime;
} else if (heartbeatBarDays <= 30) {
uptime = uptimeCalculator.get30Day().uptime;
} else {
uptime = uptimeCalculator.get1Year().uptime;
}
} }
} }
@ -149,7 +154,14 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
// Populate the response objects // Populate the response objects
for (const result of monitorResults) { for (const result of monitorResults) {
heartbeatList[result.monitorID] = result.heartbeats; heartbeatList[result.monitorID] = result.heartbeats;
// Always populate 24h uptime for compatibility
uptimeList[`${result.monitorID}_24`] = result.uptime; uptimeList[`${result.monitorID}_24`] = result.uptime;
// Add dynamic uptime key for the exact range
if (heartbeatBarDays > 0) {
uptimeList[`${result.monitorID}_${heartbeatBarDays}d`] = result.uptime;
}
} }
response.json({ response.json({

View file

@ -38,7 +38,7 @@
<font-awesome-icon v-if="editMode" icon="arrows-alt-v" class="action drag me-3" /> <font-awesome-icon v-if="editMode" icon="arrows-alt-v" class="action drag me-3" />
<font-awesome-icon v-if="editMode" icon="times" class="action remove me-3" @click="removeMonitor(group.index, monitor.index)" /> <font-awesome-icon v-if="editMode" icon="times" class="action remove me-3" @click="removeMonitor(group.index, monitor.index)" />
<Uptime :monitor="monitor.element" type="24" :pill="true" /> <Uptime :monitor="monitor.element" :type="uptimeType" :pill="true" />
<a <a
v-if="showLink(monitor)" v-if="showLink(monitor)"
:href="monitor.element.url" :href="monitor.element.url"
@ -129,6 +129,19 @@ export default {
computed: { computed: {
showGroupDrag() { showGroupDrag() {
return (this.$root.publicGroupList.length >= 2); return (this.$root.publicGroupList.length >= 2);
},
/**
* Get the uptime type based on heartbeatBarDays
* Returns the exact type for dynamic uptime calculation
* @returns {string} The uptime type
*/
uptimeType() {
const days = Number(this.heartbeatBarDays);
if (days === 0 || days === 1) {
return "24"; // 24 hours (for compatibility)
} else {
return `${days}d`; // Dynamic days format (e.g., "7d", "14d", "30d")
}
} }
}, },
created() { created() {

View file

@ -90,6 +90,14 @@ export default {
if (this.type === "720") { if (this.type === "720") {
return `30${this.$t("-day")}`; return `30${this.$t("-day")}`;
} }
if (this.type === "24") {
return `24${this.$t("-hour")}`;
}
// Handle dynamic day formats (e.g., "7d", "14d", "30d")
const dayMatch = this.type.match(/^(\d+)d$/);
if (dayMatch) {
return `${dayMatch[1]}${this.$t("-day")}`;
}
return `24${this.$t("-hour")}`; return `24${this.$t("-hour")}`;
} }
}, },