Merge pull request #432 from Tagadda/enh-global-settings-configpanel

Global settings using ConfigPanel
This commit is contained in:
Alexandre Aubin 2022-09-30 15:25:32 +02:00 committed by GitHub
commit fc8a4c9d19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 0 deletions

View file

@ -452,6 +452,9 @@
"create": "Create user '{name}'",
"delete": "Delete user '{name}'",
"update": "Update user '{name}'"
},
"settings": {
"update": "Update global settings"
}
},
"run": "Run",
@ -501,6 +504,7 @@
"experimental_description": "Gives you access to experimental features. These are considered unstable and may break your system.<br> Enable this only if you know what you are doing.",
"transitions": "Page transition animations"
},
"tools_yunohost_settings": "YunoHost settings",
"tools_webadmin_settings": "Web-admin settings",
"traceback": "Traceback",
"udp": "UDP",

View file

@ -374,6 +374,23 @@ const routes = [
breadcrumb: ['tool-list', 'tool-webadmin']
}
},
{
path: '/tools/settings',
component: () => import(/* webpackChunkName: "views/tools/settings" */ '@/views/tool/ToolSettings'),
children: [
{
name: 'tool-settings',
path: ':tabId?',
component: () => import(/* webpackChunkName: "components/configPanel" */ '@/components/ConfigPanel'),
props: true,
meta: {
routerParams: [],
args: { trad: 'tools_yunohost_settings' },
breadcrumb: ['tool-list', 'tool-settings']
}
}
]
},
{
name: 'tool-power',
path: '/tools/power',

View file

@ -24,6 +24,7 @@ export default {
{ routeName: 'tool-migrations', icon: 'share', translation: 'migrations' },
{ routeName: 'tool-firewall', icon: 'shield', translation: 'firewall' },
{ routeName: 'tool-adminpw', icon: 'key-modern', translation: 'tools_adminpw' },
{ routeName: 'tool-settings', icon: 'cog', translation: 'tools_yunohost_settings' },
{ routeName: 'tool-webadmin', icon: 'cog', translation: 'tools_webadmin_settings' },
{ routeName: 'tool-power', icon: 'power-off', translation: 'tools_shutdown_reboot' }
]

View file

@ -0,0 +1,64 @@
<template>
<view-base
:queries="queries" @queries-response="onQueriesResponse"
ref="view" skeleton="card-form-skeleton"
>
<config-panels v-if="config.panels" v-bind="config" @submit="applyConfig" />
</view-base>
</template>
<script>
import api, { objectToParams } from '@/api'
import {
formatFormData,
formatYunoHostConfigPanels
} from '@/helpers/yunohostArguments'
import ConfigPanels from '@/components/ConfigPanels'
export default {
name: 'ToolSettingsConfig',
components: {
ConfigPanels
},
props: {},
data () {
return {
queries: [
['GET', 'settings?full']
],
config: {}
}
},
methods: {
onQueriesResponse (config) {
this.config = formatYunoHostConfigPanels(config)
},
async applyConfig (id_) {
const formatedData = await formatFormData(
this.config.forms[id_],
{ removeEmpty: false, removeNull: true, multipart: false }
)
api.put(
'settings',
{ key: id_, args: objectToParams(formatedData) },
{ key: 'settings.update', name: this.name }
).then(() => {
this.$refs.view.fetchQueries({ triggerLoading: true })
}).catch(err => {
if (err.name !== 'APIBadRequestError') throw err
const panel = this.config.panels.find(({ id }) => id_ === id)
if (err.data.name) {
this.config.errors[id_][err.data.name].message = err.message
} else this.$set(panel, 'serverError', err.message)
})
}
}
}
</script>