aboutsummaryrefslogtreecommitdiff
path: root/src/modules/adminSettings.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2023-03-16 23:18:55 +0200
committerHenry Jameson <me@hjkos.com>2023-03-16 23:18:55 +0200
commitbfd802ad046886230574cf2262f9c2e5f1b03a3f (patch)
tree90f28ae9b62c5cd70c0a7fa6c170dc041dabf68e /src/modules/adminSettings.js
parent4d23d31fecf480abfccc4db3ac79c6640078dc3b (diff)
setting admin settings works now. also now we have draftable settings
Diffstat (limited to 'src/modules/adminSettings.js')
-rw-r--r--src/modules/adminSettings.js52
1 files changed, 49 insertions, 3 deletions
diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js
index 8006717d..d1df67d4 100644
--- a/src/modules/adminSettings.js
+++ b/src/modules/adminSettings.js
@@ -22,8 +22,8 @@ const adminSettingsStorage = {
},
actions: {
setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) {
- const config = {}
- const modifiedPaths = new Set()
+ const config = state.config || {}
+ const modifiedPaths = state.modifiedPaths || new Set()
backendDbConfig.configs.forEach(c => {
const path = c.group + '.' + c.key
if (c.db) {
@@ -40,8 +40,54 @@ const adminSettingsStorage = {
}
set(config, path, convert(c.value))
})
- console.log(config)
commit('updateAdminSettings', { config, modifiedPaths })
+ },
+ pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) {
+ const [group, key, ...rest] = path.split(/\./g)
+ const clone = {} // not actually cloning the entire thing to avoid excessive writes
+ set(clone, rest.join('.'), value)
+
+ // TODO cleanup paths in modifiedPaths
+ const convert = (value) => {
+ if (typeof value !== 'object') {
+ return value
+ } else if (Array.isArray(value)) {
+ return value.map(convert)
+ } else {
+ return Object.entries(value).map(([k, v]) => ({ tuple: [k, v] }))
+ }
+ }
+
+ rootState.api.backendInteractor.pushInstanceDBConfig({
+ payload: {
+ configs: [{
+ group,
+ key,
+ value: convert(clone)
+ }]
+ }
+ })
+ .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig())
+ .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig }))
+ },
+ resetAdminSetting ({ rootState, state, commit, dispatch }, { path }) {
+ console.log('ASS')
+ const [group, key, subkey] = path.split(/\./g)
+
+ state.modifiedPaths.delete(path)
+
+ return rootState.api.backendInteractor.pushInstanceDBConfig({
+ payload: {
+ configs: [{
+ group,
+ key,
+ delete: true,
+ subkeys: [subkey]
+ }]
+ }
+ })
+ .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig())
+ .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig }))
}
}
}