From d691ca7f859796d1061315b91146e8c47c9b84e0 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 8 Jul 2022 11:28:44 +0200 Subject: [PATCH] Dashboard (WIP) Signed-off-by: Romein van Buren --- .gitignore | 1 + builddashboard.js | 22 ++++++++++++++++++++++ gui/dashboard/app.svelte | 1 + gui/dashboard/index.html | 12 ++++++++++++ gui/dashboard/index.js | 7 +++++++ index.js | 14 +++++++++++++- package.json | 30 ++++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 builddashboard.js create mode 100644 gui/dashboard/app.svelte create mode 100644 gui/dashboard/index.html create mode 100644 gui/dashboard/index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 508a790..a9e1726 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules config.custom.js config.temp.js package-lock.json +/gui/dashboard/build/ diff --git a/builddashboard.js b/builddashboard.js new file mode 100644 index 0000000..bc88555 --- /dev/null +++ b/builddashboard.js @@ -0,0 +1,22 @@ +'use strict'; + +const { build: viteBuild } = require('vite'); +const { svelte } = require('@sveltejs/vite-plugin-svelte'); + +module.exports = () => viteBuild({ + root: __dirname + '/gui/dashboard', + base: '.', + plugins: [ svelte() ], + build: { + rollupOptions: { + output: { + assetFileNames: '[hash].[ext]', + entryFileNames: '[hash].js', + chunkFileNames: '[hash].js', + }, + }, + outDir: __dirname + '/gui/dashboard/build', + }, +}); + +module.exports(); diff --git a/gui/dashboard/app.svelte b/gui/dashboard/app.svelte new file mode 100644 index 0000000..0239d19 --- /dev/null +++ b/gui/dashboard/app.svelte @@ -0,0 +1 @@ +

here comes the dashboard

diff --git a/gui/dashboard/index.html b/gui/dashboard/index.html new file mode 100644 index 0000000..1d027f3 --- /dev/null +++ b/gui/dashboard/index.html @@ -0,0 +1,12 @@ + + + + + + Status dashboard + + +
+ + + diff --git a/gui/dashboard/index.js b/gui/dashboard/index.js new file mode 100644 index 0000000..45ddade --- /dev/null +++ b/gui/dashboard/index.js @@ -0,0 +1,7 @@ +import App from './app.svelte'; + +const app = new App({ + target: document.getElementById('outlet'), +}); + +export default app; diff --git a/index.js b/index.js index 71e512d..50737f1 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const { fork } = require('child_process'); const { processOutage } = require('./lib/processoutage'); +const buildDashboard = require('./builddashboard'); +const fs = require('fs').promises; const guiCluster = 'web service status'; const icons = { @@ -117,13 +119,14 @@ module.exports = { }, }, - init: ({ server, settings }) => { + init: async ({ server, settings }) => { settings.autotestInterval = Number(settings.autotestInterval); if (Number.isNaN(settings.autotestInterval)) { server.warn('status: settings.autotestInterval is not a number. Using default value 10.'); settings.autotestInterval = 10; } + await buildDashboard(); return true; }, @@ -529,6 +532,15 @@ module.exports = { }, }, + { route: '/statusdashboard', + method: 'get', + handler: async (req, res) => { + res.send( + (await fs.readFile(__dirname + '/gui/dashboard/build/index.html')).toString() + ); + }, + }, + ], }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..d73d407 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "status", + "version": "1.0.0", + "description": "Display status dashboard", + "main": "index.js", + "directories": { + "lib": "lib" + }, + "scripts": { + "build": "node builddashboard" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/smartyellow/status.git" + }, + "keywords": [ + "status" + ], + "author": "Romein van Buren", + "license": "MIT", + "bugs": { + "url": "https://github.com/smartyellow/status/issues" + }, + "homepage": "https://github.com/smartyellow/status#readme", + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^1.0.0-next.49", + "svelte": "^3.49.0", + "vite": "^2.9.13" + } +}