From 46ef63fb9f3c2688118a9d1511293128cfdfe4c9 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Sun, 10 Jan 2021 02:04:35 +0200 Subject: [PATCH] feat: add dynamic settings page rendering based on the Joi object --- .gitignore | 1 + src/api/routes/service/configSchemaGET.js | 17 +++ src/api/structures/Setting.js | 24 ++-- src/site/components/settings/JoiObject.vue | 141 ++++++++++++++++++++ src/site/pages/dashboard/admin/settings.vue | 117 +--------------- src/site/store/admin.js | 14 +- 6 files changed, 190 insertions(+), 124 deletions(-) create mode 100644 src/api/routes/service/configSchemaGET.js create mode 100644 src/site/components/settings/JoiObject.vue diff --git a/.gitignore b/.gitignore index 03a4363..1b4b1c1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ database.sqlite-journal docker/nginx/chibisafe.moe.conf docker-compose.config.yml /coverage +local/ diff --git a/src/api/routes/service/configSchemaGET.js b/src/api/routes/service/configSchemaGET.js new file mode 100644 index 0000000..90befa9 --- /dev/null +++ b/src/api/routes/service/configSchemaGET.js @@ -0,0 +1,17 @@ +const Route = require('../../structures/Route'); +const { configSchema } = require('../../structures/Setting'); + +class configGET extends Route { + constructor() { + super('/service/config/schema', 'get', { adminOnly: true }); + } + + run(req, res) { + return res.json({ + message: 'Successfully retrieved schema', + schema: configSchema + }); + } +} + +module.exports = configGET; diff --git a/src/api/structures/Setting.js b/src/api/structures/Setting.js index 068ebf1..7b2041d 100644 --- a/src/api/structures/Setting.js +++ b/src/api/structures/Setting.js @@ -9,15 +9,6 @@ const StatsGenerator = require('../utils/StatsGenerator'); // use meta to set custom rendering (render as radio instead of dropdown for example) and custom order // use description to add comments which will show up as a note somewhere next to the option const schema = Joi.object({ - // Server related settings - rateLimitWindow: Joi.number().integer().default(2) - .label('API rate limit window') - .description('Timeframe for which requests are checked/remembered'), - - rateLimitMax: Joi.number().integer().default(5) - .label('API maximum limit') - .description('Max number of connections during windowMs milliseconds before sending a 429 response'), - // Service settings serviceName: Joi.string().default('change-me') .label('Service name') @@ -118,9 +109,18 @@ const schema = Joi.object({ savedStatistics: Joi.array().items(Joi.string().valid(...Object.keys(StatsGenerator.statGenerators)).optional()) .meta({ displayType: 'checkbox' }) .label('Cached statistics') - .description('Which statistics should be saved to the database (refer to Statistics schedule for scheduling). If a statistics is enabled but not set to be saved, it will be generated every time the statistics page is opened') + .description('Which statistics should be saved to the database (refer to Statistics schedule for scheduling).') + .note('If a statistics is enabled but not set to be saved, it will be generated every time the statistics page is opened'), + + // Server related settings + rateLimitWindow: Joi.number().integer().default(2) + .label('API rate limit window') + .description('Timeframe for which requests are checked/remembered'), + + rateLimitMax: Joi.number().integer().default(5) + .label('API maximum limit') + .description('Max number of connections during windowMs milliseconds before sending a 429 response') }); -// schema._ids._byKey.keys() - module.exports.schema = schema; +module.exports.configSchema = schema.describe(); diff --git a/src/site/components/settings/JoiObject.vue b/src/site/components/settings/JoiObject.vue new file mode 100644 index 0000000..e842792 --- /dev/null +++ b/src/site/components/settings/JoiObject.vue @@ -0,0 +1,141 @@ + + + + + diff --git a/src/site/pages/dashboard/admin/settings.vue b/src/site/pages/dashboard/admin/settings.vue index 0a43dcd..bac9683 100644 --- a/src/site/pages/dashboard/admin/settings.vue +++ b/src/site/pages/dashboard/admin/settings.vue @@ -11,114 +11,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
+ @@ -128,21 +21,25 @@