From 7064932c164b7e5a1dd927c15a57fd91597866db Mon Sep 17 00:00:00 2001 From: Mats Stottmeister Date: Wed, 11 Jun 2025 21:40:16 +0200 Subject: [PATCH] fix: lint --- .../2025-06-10-0000-add-daily-view.js | 2 +- server/routers/status-page-router.js | 14 +-- src/components/DailyHeartbeatBar.vue | 98 ++++++++++--------- src/pages/StatusPage.vue | 6 +- 4 files changed, 65 insertions(+), 55 deletions(-) diff --git a/db/knex_migrations/2025-06-10-0000-add-daily-view.js b/db/knex_migrations/2025-06-10-0000-add-daily-view.js index 48e67f6ea..ea46f7ca0 100644 --- a/db/knex_migrations/2025-06-10-0000-add-daily-view.js +++ b/db/knex_migrations/2025-06-10-0000-add-daily-view.js @@ -10,4 +10,4 @@ exports.down = function (knex) { return knex.schema.alterTable("monitor_group", function (table) { table.dropColumn("daily_view"); }); -}; \ No newline at end of file +}; diff --git a/server/routers/status-page-router.js b/server/routers/status-page-router.js index b983c3e94..2de372c3a 100644 --- a/server/routers/status-page-router.js +++ b/server/routers/status-page-router.js @@ -142,7 +142,7 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( for (let monitor of monitorData) { const monitorID = monitor.monitor_id; const useDailyView = monitor.daily_view; - + dailyViewSettings[monitorID] = useDailyView; if (useDailyView) { @@ -173,7 +173,7 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( // Determine overall status for the day based on majority if (row.maintenance_beats > 0) { status = 3; // Maintenance - } else if (row.down_beats > row.up_beats / 2) { + } else if (row.down_beats > row.up_beats / 2) { status = 0; // Down if more than 50% down } else if (row.up_beats > 0) { status = 1; // Up @@ -200,15 +200,15 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( }); heartbeatList[monitorID] = processedData; - + // Calculate uptime based only on actual daily data (not including missing days) if (processedData.length > 0) { // Get recent data (last 30 days worth of actual data) const recentData = processedData.slice(-30); - + let totalUp = 0; let totalDown = 0; - + recentData.forEach(day => { if (day.dailyStats) { // Convert strings to numbers to avoid concatenation @@ -216,7 +216,7 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( totalDown += parseInt(day.dailyStats.down) || 0; } }); - + const totalChecks = totalUp + totalDown; uptimeList[`${monitorID}_24`] = totalChecks > 0 ? (totalUp / totalChecks) : 0; } else { @@ -235,7 +235,7 @@ router.get("/api/status-page/heartbeat-daily/:slug", cache("5 minutes"), async ( list = R.convertToBeans("heartbeat", list); heartbeatList[monitorID] = list.reverse().map(row => row.toPublicJSON()); - + const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID); uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime; } diff --git a/src/components/DailyHeartbeatBar.vue b/src/components/DailyHeartbeatBar.vue index 0152ade21..cb0c985fb 100644 --- a/src/components/DailyHeartbeatBar.vue +++ b/src/components/DailyHeartbeatBar.vue @@ -11,12 +11,12 @@ >
@@ -178,8 +178,10 @@ export default { */ timeSinceFirstBeat() { const firstValidBeat = this.shortBeatList.at(this.numPadding); - if (!firstValidBeat || !firstValidBeat.date) return ""; - + if (!firstValidBeat || !firstValidBeat.date) { + return ""; + } + const days = dayjs().diff(dayjs(firstValidBeat.date), "days"); if (days > 30) { return Math.floor(days / 30) + "mo"; @@ -194,10 +196,12 @@ export default { */ timeSinceLastBeat() { const lastValidBeat = this.shortBeatList.at(-1); - if (!lastValidBeat || !lastValidBeat.date) return ""; - + if (!lastValidBeat || !lastValidBeat.date) { + return ""; + } + const days = dayjs().diff(dayjs(lastValidBeat.date), "days"); - + if (days === 0) { return this.$t("Today"); } else if (days === 1) { @@ -273,31 +277,37 @@ export default { * @returns {string} Beat title */ getBeatTitle(beat) { - if (!beat || beat === 0) return ""; - + if (!beat || beat === 0) { + return ""; + } + // Handle missing data if (beat.missing || beat.status === -1) { - const date = beat.date || beat.time.split(' ')[0]; + const date = beat.date || beat.time.split(" ")[0]; return `${date}\nNo data available`; } - - const date = beat.date || beat.time.split(' ')[0]; + + const date = beat.date || beat.time.split(" ")[0]; const uptime = Math.round(beat.uptime * 100); const stats = beat.dailyStats; - + let tooltip = `${date}\nUptime: ${uptime}%`; - + if (stats) { tooltip += `\nUp: ${stats.up}, Down: ${stats.down}`; - if (stats.pending > 0) tooltip += `, Pending: ${stats.pending}`; - if (stats.maintenance > 0) tooltip += `, Maintenance: ${stats.maintenance}`; + if (stats.pending > 0) { + tooltip += `, Pending: ${stats.pending}`; + } + if (stats.maintenance > 0) { + tooltip += `, Maintenance: ${stats.maintenance}`; + } tooltip += `\nTotal checks: ${stats.total}`; } - + if (beat.ping) { tooltip += `\nAvg ping: ${beat.ping}ms`; } - + return tooltip; }, @@ -329,23 +339,23 @@ export default { */ generateCompleteTimeline(actualData) { const timeline = []; - const today = dayjs().startOf('day'); - const startDate = today.subtract(90, 'day'); // 3 months back - + const today = dayjs().startOf("day"); + const startDate = today.subtract(90, "day"); // 3 months back + // Create a map of existing data by date for quick lookup const dataMap = {}; actualData.forEach(beat => { if (beat && beat.date) { - const dateKey = dayjs(beat.date).format('YYYY-MM-DD'); + const dateKey = dayjs(beat.date).format("YYYY-MM-DD"); dataMap[dateKey] = beat; } }); - + // Generate complete timeline from startDate to today for (let i = 0; i <= 90; i++) { - const currentDate = startDate.add(i, 'day'); - const dateKey = currentDate.format('YYYY-MM-DD'); - + const currentDate = startDate.add(i, "day"); + const dateKey = currentDate.format("YYYY-MM-DD"); + if (dataMap[dateKey]) { // Use actual data if available timeline.push(dataMap[dateKey]); @@ -354,7 +364,7 @@ export default { timeline.push({ status: -1, // Special status for missing data date: dateKey, - time: dateKey + ' 00:00:00', + time: dateKey + " 00:00:00", uptime: 0, ping: 0, missing: true, @@ -368,7 +378,7 @@ export default { }); } } - + return timeline; }, @@ -429,23 +439,23 @@ export default { // Daily beats get special styling &.daily-beat { border: 1px solid rgba(0, 0, 0, 0.1); - + &.down { border-color: darken($danger, 10%); } - + &.pending { border-color: darken($warning, 10%); } - + &.maintenance { border-color: darken($maintenance, 10%); } - + &:not(.empty):not(.down):not(.pending):not(.maintenance):not(.missing) { border-color: darken($primary, 10%); } - + &.missing { border-color: transparent; } @@ -458,31 +468,31 @@ export default { .hp-bar-big .beat.empty { background-color: #848484; } - + .hp-bar-big .beat.missing { background-color: #555555; opacity: 0.6; } - + .hp-bar-big .beat.daily-beat { border-color: rgba(255, 255, 255, 0.2); - + &.down { border-color: lighten($danger, 10%); } - + &.pending { border-color: lighten($warning, 10%); } - + &.maintenance { border-color: lighten($maintenance, 10%); } - + &:not(.empty):not(.down):not(.pending):not(.maintenance):not(.missing) { border-color: lighten($primary, 10%); } - + &.missing { border-color: transparent; } @@ -506,4 +516,4 @@ export default { background-color: #333; } } - \ No newline at end of file + diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index abccc2755..5c0ce4d44 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -773,7 +773,7 @@ export default { if (! this.editMode) { // Fetch mixed data based on per-monitor daily view settings axios.get("/api/status-page/heartbeat-daily/" + this.slug).then((res) => { - const { heartbeatList, uptimeList, dailyViewSettings, hasMixedData } = res.data; + const { heartbeatList, uptimeList, dailyViewSettings } = res.data; // Store both regular and daily data appropriately this.$root.heartbeatList = {}; @@ -785,12 +785,12 @@ export default { if (dailyViewSettings[monitorId]) { // This monitor uses daily view this.$root.dailyHeartbeatList[monitorId] = heartbeatList[monitorId]; - + // Set up lastHeartbeatList for uptime color calculation if (heartbeatList[monitorId] && heartbeatList[monitorId].length > 0) { const lastDailyBeat = heartbeatList[monitorId][heartbeatList[monitorId].length - 1]; // Create a minimal heartbeat list with just the last beat for color calculation - this.$root.heartbeatList[monitorId] = [lastDailyBeat]; + this.$root.heartbeatList[monitorId] = [ lastDailyBeat ]; } } else { // This monitor uses regular view