From 2117cc72baaa0eeb23832138c9904346fdca79c0 Mon Sep 17 00:00:00 2001 From: iMidnight Date: Fri, 27 Jan 2023 20:59:15 +0000 Subject: [PATCH] Added multiRow formType and improved types --- dbd-soft-ui.d.ts | 26 ++++++++++++------------- utils/formtypes.js | 15 ++++++++++++++ utils/functions/settingsPage.js | 19 ++++++++++++++++++ views/components/formTypes/multiRow.ejs | 11 +++++++++++ 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 views/components/formTypes/multiRow.ejs diff --git a/dbd-soft-ui.d.ts b/dbd-soft-ui.d.ts index 0f4da81c..0b65db78 100644 --- a/dbd-soft-ui.d.ts +++ b/dbd-soft-ui.d.ts @@ -339,32 +339,32 @@ declare module "dbd-soft-ui" { type: string, themeOptions: Record } - emojiPicker: (disabled: any, themeOptions: Record) => { + emojiPicker: (disabled: boolean, themeOptions: Record) => { type: string, - disabled: any, + disabled: boolean, themeOptions: Record } - slider: (min: any, max: any, step: any, disabled: any, themeOptions: Record) => { + slider: (min: number, max: number, step: number, disabled: boolean, themeOptions: Record) => { type: string, - min: any, - max: any, - step: any, - disabled: any, + min: number, + max: number, + step: number, + disabled: boolean, themeOptions: Record }, - date: (disabled: any, themeOptions: Record) => { + date: (disabled: boolean, themeOptions: Record) => { type: string, - disabled: any, + disabled: boolean, themeOptions: Record }, - numberPicker: (disabled: any, themeOptions: Record) => { + numberPicker: (min: number, max: number, disabled: boolean, themeOptions: Record) => { type: string, - disabled: any, + disabled: boolean, themeOptions: Record }, - tagInput: (disabled: any, themeOptions: Record) => { + tagInput: (disabled: boolean, themeOptions: Record) => { type: string, - disabled: any, + disabled: boolean, themeOptions: Record } } diff --git a/utils/formtypes.js b/utils/formtypes.js index 1d64f0c7..4f1d8fdc 100644 --- a/utils/formtypes.js +++ b/utils/formtypes.js @@ -1,4 +1,19 @@ module.exports = { + multiRow: (options) => { + // Validate Data + if (options && (!options.length || !options[0])) throw new Error("Options in the 'collapsable' form type should be an array."); + + const hasType = (object) => object.hasOwnProperty('optionType') && object.optionType?.hasOwnProperty('type'); + + if (options && !options.every(hasType)) throw new Error("Invalid form type provided in the 'multiRow' form type."); + + if (options && options.find(obj => obj.optionType.type == "multiRow")) throw new Error("You cannot use the form type 'multiRow' in the 'multiRow' form type."); + + return { + type: "multiRow", + options + } + }, spacer: (themeOptions = {}) => { return { type: 'spacer', diff --git a/utils/functions/settingsPage.js b/utils/functions/settingsPage.js index adee561f..03468a9b 100644 --- a/utils/functions/settingsPage.js +++ b/utils/functions/settingsPage.js @@ -236,6 +236,25 @@ module.exports = function (config, themeConfig) { actual[s.categoryId] = {} } if (!actual[s.categoryId][c.optionId]) { + if (c.optionType.type === "multiRow") { + for (const item of c.optionType.options) { + actual[s.categoryId][item.optionId] = await item.getActualSet( + { + guild: { + id: req.params.id, + object: bot.guilds.cache.get(req.params.id) + }, + user: { + id: req.session.user.id, + object: bot.guilds.cache + .get(req.params.id) + .members.cache.get(req.session.user.id) + } + } + ) + } + continue + } actual[s.categoryId][c.optionId] = await c.getActualSet( { guild: { diff --git a/views/components/formTypes/multiRow.ejs b/views/components/formTypes/multiRow.ejs new file mode 100644 index 00000000..a505f04a --- /dev/null +++ b/views/components/formTypes/multiRow.ejs @@ -0,0 +1,11 @@ + +
+ <% option.optionType.options.forEach(opt => { %> + <% console.log({opt}) %> +
+

<%- opt?.optionName || ""%>

+

<%- opt?.optionDescription || ""%>

+ <%- include(`./${opt.optionType.type}.ejs`, {option: opt, s, Allowed}) %> +
+ <% }) %> +
\ No newline at end of file