add ToolWebadmin view and set settings store as base store's state

This commit is contained in:
Axolotle 2020-09-13 17:35:32 +02:00
parent d47ecb5d57
commit 50568cbe36
8 changed files with 128 additions and 11 deletions

View file

@ -4,7 +4,7 @@
<slot /> <slot />
</b-form> </b-form>
<template v-slot:footer> <template v-if="!noFooter" v-slot:footer>
<slot name="buttons"> <slot name="buttons">
<b-button type="submit" :form="id" variant="success"> <b-button type="submit" :form="id" variant="success">
{{ submit ? submit : $t('save') }} {{ submit ? submit : $t('save') }}
@ -21,7 +21,8 @@ export default {
props: { props: {
header: { type: String, required: true }, header: { type: String, required: true },
id: { type: String, default: 'ynh-form' }, id: { type: String, default: 'ynh-form' },
submit: { type: String, default: null } submit: { type: String, default: null },
noFooter: { type: Boolean, default: false }
} }
} }
</script> </script>

View file

@ -323,6 +323,12 @@
"tools_shutdown_done": "Shutting down...", "tools_shutdown_done": "Shutting down...",
"tools_shuttingdown": "Your server is powering off. As long as your server is off, you won't be able to use the web administration.", "tools_shuttingdown": "Your server is powering off. As long as your server is off, you won't be able to use the web administration.",
"tools_shutdown_reboot": "Shutdown/Reboot", "tools_shutdown_reboot": "Shutdown/Reboot",
"tools_webadmin": {
"locale": "Locale",
"fallback_locale": "Fallback locale",
"cache": "Cache",
"cache_description": "Consider disabling the cache if you plan on working with the CLI while also navigating in this web-admin."
},
"tools_webadmin_settings": "Web-admin settings", "tools_webadmin_settings": "Web-admin settings",
"udp": "UDP", "udp": "UDP",
"unauthorized": "Unauthorized", "unauthorized": "Unauthorized",

View file

@ -241,6 +241,17 @@ const routes = [
{ name: 'tool-adminpw', trad: 'tools_adminpw' } { name: 'tool-adminpw', trad: 'tools_adminpw' }
] ]
} }
},
{
name: 'tool-webadmin',
path: '/tools/webadmin',
component: () => import(/* webpackChunkName: "views/tools" */ '@/views/tool/ToolWebadmin'),
meta: {
breadcrumb: [
{ name: 'tool-list', trad: 'tools' },
{ name: 'tool-webadmin', trad: 'tools_webadmin_settings' }
]
}
} }
] ]

View file

@ -85,23 +85,24 @@ export default {
}, },
actions: { actions: {
'FETCH' ({ state, commit }, { uri, param, storeKey = uri, force = false }) { 'FETCH' ({ state, commit, rootState }, { uri, param, storeKey = uri, cache = rootState.cache }) {
const currentState = param ? state[storeKey][param] : state[storeKey] const currentState = param ? state[storeKey][param] : state[storeKey]
// if data has already been queried, simply return // if data has already been queried, simply return
if (currentState !== undefined && !force) return currentState if (currentState !== undefined && cache) return currentState
return api.get(param ? `${uri}/${param}` : uri).then(responseData => { return api.get(param ? `${uri}/${param}` : uri).then(responseData => {
console.log('api')
const data = responseData[storeKey] ? responseData[storeKey] : responseData const data = responseData[storeKey] ? responseData[storeKey] : responseData
commit('SET_' + storeKey.toUpperCase(), param ? [param, data] : data) commit('SET_' + storeKey.toUpperCase(), param ? [param, data] : data)
return param ? state[storeKey][param] : state[storeKey] return param ? state[storeKey][param] : state[storeKey]
}) })
}, },
'FETCH_ALL' ({ state, commit }, queries) { 'FETCH_ALL' ({ state, commit, rootState }, queries) {
return Promise.all(queries.map(({ uri, param, storeKey = uri, force = false }) => { return Promise.all(queries.map(({ uri, param, storeKey = uri, cache = rootState.cache }) => {
const currentState = param ? state[storeKey][param] : state[storeKey] const currentState = param ? state[storeKey][param] : state[storeKey]
// if data has already been queried, simply return the state as cached // if data has already been queried, simply return the state as cached
if (currentState !== undefined && !force) { if (currentState !== undefined && cache) {
return { cached: currentState } return { cached: currentState }
} }
return api.get(param ? `${uri}/${param}` : uri).then(responseData => { return api.get(param ? `${uri}/${param}` : uri).then(responseData => {

View file

@ -8,9 +8,12 @@ import data from './data'
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state: settings.state,
mutations: settings.mutations,
actions: settings.actions,
getters: settings.getters,
modules: { modules: {
info, info,
settings,
data data
} }
}) })

View file

@ -5,11 +5,14 @@
import i18n from '@/i18n' import i18n from '@/i18n'
import { loadLocaleMessages, updateDocumentLocale, loadDateFnsLocale } from '@/i18n/helpers' import { loadLocaleMessages, updateDocumentLocale, loadDateFnsLocale } from '@/i18n/helpers'
import supportedLocales from '@/i18n/supportedLocales'
export default { export default {
state: { state: {
locale: localStorage.getItem('locale'), locale: localStorage.getItem('locale'),
fallbackLocale: localStorage.getItem('fallbackLocale') fallbackLocale: localStorage.getItem('fallbackLocale'),
cache: localStorage.getItem('cache') !== 'false',
supportedLocales: supportedLocales
}, },
mutations: { mutations: {
@ -21,6 +24,11 @@ export default {
'SET_FALLBACK_LOCALE' (state, locale) { 'SET_FALLBACK_LOCALE' (state, locale) {
localStorage.setItem('fallbackLocale', locale) localStorage.setItem('fallbackLocale', locale)
state.fallbackLocale = locale state.fallbackLocale = locale
},
'SET_CACHE' (state, enable) {
localStorage.setItem('cache', enable)
state.cache = enable
} }
}, },
@ -45,6 +53,13 @@ export default {
getters: { getters: {
locale: state => (state.locale), locale: state => (state.locale),
fallbackLocale: state => (state.fallbackLocale) fallbackLocale: state => (state.fallbackLocale),
cache: state => (state.cache),
availableLocales: state => {
return Object.entries(state.supportedLocales).map(([locale, { name }]) => {
return { value: locale, text: name }
})
}
} }
} }

View file

@ -26,7 +26,7 @@ export default {
{ id: 1, routeName: 'tool-migrations', icon: 'share', translation: 'migrations' }, { id: 1, routeName: 'tool-migrations', icon: 'share', translation: 'migrations' },
{ id: 2, routeName: 'tool-firewall', icon: 'shield', translation: 'firewall' }, { id: 2, routeName: 'tool-firewall', icon: 'shield', translation: 'firewall' },
{ id: 3, routeName: 'tool-adminpw', icon: 'key-modern', translation: 'tools_adminpw' }, { id: 3, routeName: 'tool-adminpw', icon: 'key-modern', translation: 'tools_adminpw' },
{ id: 4, routeName: 'tool-wabadmin', icon: 'cog', translation: 'tools_webadmin_settings' }, { id: 4, routeName: 'tool-webadmin', icon: 'cog', translation: 'tools_webadmin_settings' },
{ id: 5, routeName: 'tool-power', icon: 'power-off', translation: 'tools_shutdown_reboot' } { id: 5, routeName: 'tool-power', icon: 'power-off', translation: 'tools_shutdown_reboot' }
] ]
} }

View file

@ -0,0 +1,80 @@
<template>
<basic-form :header="$t('tools_webadmin_settings')" @submit.prevent="onSubmit" no-footer>
<!-- LOCALE -->
<b-form-group label-cols="auto" :label="$t('tools_webadmin.locale')" label-for="locale">
<b-select
id="locale"
:options="availableLocales"
v-model="currentLocale"
/>
</b-form-group>
<hr>
<!-- FALLBACK LOCALE -->
<b-form-group label-cols="auto" :label="$t('tools_webadmin.fallback_locale')" label-for="fallback-locale">
<b-select
id="fallback-locale"
:options="availableLocales"
v-model="currentFallbackLocale"
/>
</b-form-group>
<hr>
<!-- CACHE -->
<b-form-group label-cols="auto" :label="$t('tools_webadmin.cache')" label-for="cache">
<template v-slot:description>
<b-alert variant="info" show v-t="'tools_webadmin.cache_description'" />
</template>
<b-checkbox
v-model="currentCache"
switch
>
{{ $t(currentCache ? 'enabled' : 'disabled') }}
</b-checkbox>
</b-form-group>
</basic-form>
</template>
<script>
import { mapGetters } from 'vuex'
import BasicForm from '@/components/BasicForm'
export default {
name: 'ToolWebadmin',
computed: {
...mapGetters([
'locale',
'fallbackLocale',
'cache',
'availableLocales'
]),
currentLocale: {
get: function () { return this.locale },
set: function (newValue) {
this.$store.dispatch('UPDATE_LOCALE', newValue)
}
},
currentFallbackLocale: {
get: function () { return this.fallbackLocale },
set: function (newValue) {
this.$store.dispatch('UPDATE_FALLBACK_LOCALE', newValue)
}
},
currentCache: {
get: function () { return this.cache },
set: function (newValue) {
this.$store.commit('SET_CACHE', newValue)
}
}
},
components: {
BasicForm
}
}
</script>