From e87cdf4d09e0021155526dfcfa7fce7538214d01 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 17 Mar 2022 16:42:26 +0800 Subject: [PATCH] [Status Page] wip, upload logo and status page listing --- server/model/status_page.js | 12 +++- .../status-page-socket-handler.js | 25 +++---- src/pages/ManageStatusPage.vue | 70 +++++++++---------- src/pages/StatusPage.vue | 17 +++-- src/util-frontend.js | 18 ++++- 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/server/model/status_page.js b/server/model/status_page.js index e2155c4cd..6f763f586 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -22,7 +22,7 @@ class StatusPage extends BeanModel { slug: this.slug, title: this.title, description: this.description, - icon: this.icon, + icon: this.getIcon(), theme: this.theme, published: !!this.published, showTags: !!this.show_tags, @@ -34,7 +34,7 @@ class StatusPage extends BeanModel { slug: this.slug, title: this.title, description: this.description, - icon: this.icon, + icon: this.getIcon(), theme: this.theme, published: !!this.published, showTags: !!this.show_tags, @@ -47,6 +47,14 @@ class StatusPage extends BeanModel { ]); } + getIcon() { + if (!this.icon) { + return "/icon.svg"; + } else { + return this.icon; + } + } + } module.exports = StatusPage; diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index 060ccf8d5..c1d667978 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -90,9 +90,17 @@ module.exports.statusPageSocketHandler = (socket) => { try { checkLogin(socket); - apicache.clear(); + // Save Config + let statusPage = await R.findOne("status_page", " slug = ? ", [ + slug + ]); + + if (!statusPage) { + throw new Error("No slug?"); + } + const header = "data:image/png;base64,"; // Check logo format @@ -103,23 +111,16 @@ module.exports.statusPageSocketHandler = (socket) => { throw new Error("Only allowed PNG logo."); } + const filename = `logo${statusPage.id}.png`; + // Convert to file - await ImageDataURI.outputFile(imgDataUrl, Database.uploadDir + "logo.png"); - config.logo = "/upload/logo.png?t=" + Date.now(); + await ImageDataURI.outputFile(imgDataUrl, Database.uploadDir + filename); + config.logo = `/upload/${filename}?t=` + Date.now(); } else { config.icon = imgDataUrl; } - // Save Config - let statusPage = await R.findOne("status_page", " slug = ? ", [ - slug - ]); - - if (!statusPage) { - throw new Error("No slug?"); - } - statusPage.slug = config.slug; statusPage.title = config.title; statusPage.description = config.description; diff --git a/src/pages/ManageStatusPage.vue b/src/pages/ManageStatusPage.vue index dad92e8ba..2e5d11545 100644 --- a/src/pages/ManageStatusPage.vue +++ b/src/pages/ManageStatusPage.vue @@ -9,33 +9,14 @@ {{ $t("Add New Status Page") }} -
-
-
-
-
{{ statusPage.title }}
-
/status/{{ statusPage.slug }}
-
-
-
- -
- {{ $t("View") }} -
- - -
- {{ $t("Edit") }} -
- - -
- {{ $t("Delete") }} -
-
-
+ +
@@ -43,6 +24,8 @@ @@ -67,11 +56,13 @@ export default { @import "../assets/vars.scss"; .item { - display: block; + display: flex; + align-items: center; + gap: 10px; text-decoration: none; - padding: 13px 15px 10px 15px; border-radius: 10px; transition: all ease-in-out 0.15s; + padding: 10px; &:hover { background-color: $highlight-white; @@ -81,17 +72,22 @@ export default { background-color: #cdf8f4; } - .title { - font-weight: bold; - font-size: 20px; + $logo-width: 70px; + + .logo { + width: $logo-width; } - .slug { - font-size: 14px; - } + .info { - .btn-group { - //margin-top: 7px; + .title { + font-weight: bold; + font-size: 20px; + } + + .slug { + font-size: 14px; + } } } diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index f2850e5df..6450bec0e 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -40,6 +40,11 @@
+ + + +

@@ -232,6 +239,7 @@ import { STATUS_PAGE_ALL_DOWN, STATUS_PAGE_ALL_UP, STATUS_PAGE_PARTIAL_DOWN, UP import { useToast } from "vue-toastification"; import dayjs from "dayjs"; import Favico from "favico.js"; +import { getResBaseURL } from "../util-frontend"; const toast = useToast(); @@ -427,10 +435,7 @@ export default { }); // Special handle for dev - const env = process.env.NODE_ENV; - if (env === "development" || localStorage.dev === "dev") { - this.baseURL = location.protocol + "//" + location.hostname + ":3001"; - } + this.baseURL = getResBaseURL(); }, async mounted() { this.slug = this.$route.params.slug; @@ -442,8 +447,8 @@ export default { axios.get("/api/status-page/" + this.slug).then((res) => { this.config = res.data.config; - if (this.config.logo) { - this.imgDataUrl = this.config.logo; + if (this.config.icon) { + this.imgDataUrl = this.config.icon; } this.incident = res.data.incident; diff --git a/src/util-frontend.js b/src/util-frontend.js index 9094dda43..bf53eaf5b 100644 --- a/src/util-frontend.js +++ b/src/util-frontend.js @@ -51,7 +51,19 @@ export function timezoneList() { } export function setPageLocale() { - const html = document.documentElement - html.setAttribute('lang', currentLocale() ) - html.setAttribute('dir', localeDirection() ) + const html = document.documentElement; + html.setAttribute("lang", currentLocale() ); + html.setAttribute("dir", localeDirection() ); +} + +/** + * Mainly used for dev, because the backend and the frontend are in different ports. + */ +export function getResBaseURL() { + const env = process.env.NODE_ENV; + if (env === "development" || localStorage.dev === "dev") { + return location.protocol + "//" + location.hostname + ":3001"; + } else { + return ""; + } }