From db05b506f36cd6ce85f5e39e4a8675c09b52e240 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Wed, 15 Sep 2021 14:34:30 +0800 Subject: [PATCH] [status page] checkpoint --- .eslintrc.js | 3 +- server/routers/api-router.js | 85 +++++++++++++++++++++++++++------- src/assets/app.scss | 14 +++++- src/components/GroupList.vue | 81 ++++++++++++++++++++++---------- src/icon.js | 16 +++++-- src/pages/StatusPage.vue | 89 ++++++++++++++++++++++++++++++++---- 6 files changed, 231 insertions(+), 57 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 398d64c84..582e195a3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,6 +37,7 @@ module.exports = { "vue/max-attributes-per-line": "off", "vue/singleline-html-element-content-newline": "off", "vue/html-self-closing": "off", + "vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly "no-multi-spaces": ["error", { ignoreEOLComments: true, }], @@ -84,7 +85,7 @@ module.exports = { }, "overrides": [ { - "files": [ "src/languages/*.js" ], + "files": [ "src/languages/*.js", "src/icon.js" ], "rules": { "comma-dangle": ["error", "always-multiline"], } diff --git a/server/routers/api-router.js b/server/routers/api-router.js index 4cb9d22c6..b8b1b3970 100644 --- a/server/routers/api-router.js +++ b/server/routers/api-router.js @@ -1,17 +1,22 @@ let express = require("express"); -const { allowDevAllOrigin, getSettings } = require("../util-server"); +const { allowDevAllOrigin, getSettings, setting } = require("../util-server"); const { R } = require("redbean-node"); let router = express.Router(); // Status Page Config router.get("/api/status-page/config", async (_request, response) => { allowDevAllOrigin(response); + let config = getSettings("statusPage"); if (! config.statusPageTheme) { config.statusPageTheme = "light"; } + if (! config.statusPagePublished) { + config.statusPagePublished = true; + } + if (! config.title) { config.title = "Uptime Kuma"; } @@ -19,36 +24,82 @@ router.get("/api/status-page/config", async (_request, response) => { response.json(config); }); +// Status Page - Get the current Incident +// Can fetch only if published +router.get("/api/status-page/incident", async (_, response) => { + allowDevAllOrigin(response); + + try { + await checkPublished(); + + // TODO: + + } catch (error) { + send403(response, error.message); + } +}); + // Status Page - Monitor List +// Can fetch only if published router.get("/api/status-page/monitor-list", async (_request, response) => { allowDevAllOrigin(response); - const monitorList = {}; - let list = await R.find("monitor", " public = 1 ORDER BY weight DESC, name ", [ - ]); + try { + await checkPublished(); + const monitorList = {}; + let list = await R.find("monitor", " public = 1 ORDER BY weight DESC, name ", [ + ]); - for (let monitor of list) { - monitorList[monitor.id] = await monitor.toJSON(); + for (let monitor of list) { + monitorList[monitor.id] = await monitor.toJSON(); + } + + response.json(monitorList); + + } catch (error) { + send403(response, error.message); } - - response.json(monitorList); }); // Status Page Polling Data +// Can fetch only if published router.get("/api/status-page/heartbeat", async (_request, response) => { allowDevAllOrigin(response); + try { + await checkPublished(); - const monitorList = {}; - let list = await R.find("", " ", [ - ]) + const monitorList = {}; + let list = await R.find("", " ", [ + ]) - for (let monitor of list) { - monitorList[monitor.id] = await monitor.toJSON(); + for (let monitor of list) { + monitorList[monitor.id] = await monitor.toJSON(); + } + + response.json({ + monitorList: monitorList, + }); + + } catch (error) { + send403(response, error.message); } - - response.json({ - monitorList: monitorList, - }); }); +async function checkPublished() { + if (! await isPublished()) { + throw new Error("The status page is not published"); + } +} + +async function isPublished() { + return await setting("statusPagePublished"); +} + +function send403(res, msg = "") { + res.status(403).json({ + "status": "fail", + "msg": msg, + }) +} + module.exports = router; diff --git a/src/assets/app.scss b/src/assets/app.scss index 3ff5b48e3..f5703799a 100644 --- a/src/assets/app.scss +++ b/src/assets/app.scss @@ -378,7 +378,10 @@ h2 { [contenteditable=true] { &:focus { outline: 0 solid #eee; - border: 1px solid #aaa; + } + + &:hover, &:focus { + background-color: #efefef; border-radius: 8px; } @@ -389,3 +392,12 @@ h2 { color: #eee; } } + +.action { + transition: all $easing-in 0.2s; + + &:hover { + cursor: pointer; + transform: scale(1.2); + } +} diff --git a/src/components/GroupList.vue b/src/components/GroupList.vue index 31436e797..d44aa0761 100644 --- a/src/components/GroupList.vue +++ b/src/components/GroupList.vue @@ -6,38 +6,44 @@ item-key="id" :animation="100" > -