aboutsummaryrefslogtreecommitdiff
path: root/src/modules/adminSettings.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2023-03-13 00:09:47 +0200
committerHenry Jameson <me@hjkos.com>2023-03-13 00:09:47 +0200
commit9632b77786a9d3735f04ecf4a814311fad926ad0 (patch)
treeaaf0a967dc1d1c3e0d78347e09042517a2317719 /src/modules/adminSettings.js
parent55ea6df40b7e2cfe2b1b5bde33204d4c03e54a12 (diff)
initial implementation of an admin settings module
Diffstat (limited to 'src/modules/adminSettings.js')
-rw-r--r--src/modules/adminSettings.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js
new file mode 100644
index 00000000..01e9a49e
--- /dev/null
+++ b/src/modules/adminSettings.js
@@ -0,0 +1,48 @@
+import { set, cloneDeep } from 'lodash'
+
+export const defaultState = {
+ needsReboot: null,
+ config: null,
+ modifiedPaths: null
+}
+
+export const newUserFlags = {
+ ...defaultState.flagStorage
+}
+
+const serverSideStorage = {
+ state: {
+ ...cloneDeep(defaultState)
+ },
+ mutations: {
+ updateAdminSettings (state, { config, modifiedPaths }) {
+ state.config = config
+ state.modifiedPaths = modifiedPaths
+ }
+ },
+ actions: {
+ setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) {
+ const config = {}
+ const modifiedPaths = new Set()
+ backendDbConfig.configs.forEach(c => {
+ const path = c.group + '.' + c.key
+ if (c.db) {
+ c.db.forEach(x => modifiedPaths.add(path + '.' + x))
+ }
+ const convert = (value) => {
+ if (Array.isArray(value) && value.length > 0 && value[0].tuple) {
+ return value.reduce((acc, c) => {
+ return { ...acc, [c.tuple[0]]: convert(c.tuple[1]) }
+ }, {})
+ } else {
+ return value
+ }
+ }
+ set(config, path, convert(c.value))
+ })
+ commit('updateAdminSettings', { config, modifiedPaths })
+ }
+ }
+}
+
+export default serverSideStorage