update ConfigPanels using RoutableTabs

This commit is contained in:
axolotle 2022-02-06 20:42:28 +01:00
parent 7d5d29af1e
commit b7aa8117ec

View file

@ -1,67 +1,50 @@
<template> <template>
<b-card no-body> <routable-tabs
<b-tabs fill pills card> :routes="routes_"
<slot name="before" /> v-bind="{ panels, forms, v: $v }"
v-on="$listeners"
<tab-form />
v-for="{ name, id, sections, help, serverError } in panels" :key="id"
v-bind="{ name, id: id + '-form', validation: $v.forms[id], serverError }"
@submit.prevent.stop="$emit('submit', id)"
>
<template v-if="help" #disclaimer>
<div class="alert alert-info" v-html="help" />
</template>
<slot :name="id + '-tab-before'" />
<template v-for="section in sections">
<div v-if="isVisible(section.visible, section)" :key="section.id" class="mb-5">
<b-card-title v-if="section.name" title-tag="h3">
{{ section.name }} <small v-if="section.help">{{ section.help }}</small>
</b-card-title>
<template v-for="(field, fname) in section.fields">
<form-field
v-if="isVisible(field.visible, field)" :key="fname"
v-model="forms[id][fname]" v-bind="field" :validation="$v.forms[id][fname]"
/>
</template>
</div>
</template>
<slot :name="id + '-tab-after'" />
</tab-form>
<slot name="default" />
</b-tabs>
</b-card>
</template> </template>
<script> <script>
import { validationMixin } from 'vuelidate' import { validationMixin } from 'vuelidate'
import { configPanelsFieldIsVisible } from '@/helpers/yunohostArguments'
export default { export default {
name: 'ConfigPanels', name: 'ConfigPanels',
components: {
RoutableTabs: () => import('@/components/RoutableTabs.vue')
},
mixins: [validationMixin], mixins: [validationMixin],
props: { props: {
panels: { type: Array, default: undefined }, panels: { type: Array, default: undefined },
forms: { type: Object, default: undefined }, forms: { type: Object, default: undefined },
validations: { type: Object, default: undefined } validations: { type: Object, default: undefined },
errors: { type: Object, default: undefined }, // never used
routes: { type: Array, default: null },
noRedirect: { type: Boolean, default: false }
},
computed: {
routes_ () {
if (this.routes) return this.routes
return this.panels.map(panel => ({
to: { params: { tabId: panel.id } },
text: panel.name,
icon: panel.icon || 'wrench'
}))
}
}, },
validations () { validations () {
const v = this.validations return { forms: this.validations }
return v ? { forms: v } : null
}, },
methods: { created () {
isVisible (expression, field) { if (!this.noRedirect && !this.$route.params.tabId) {
return configPanelsFieldIsVisible(expression, field, this.forms) this.$router.replace({ params: { tabId: this.panels[0].id } })
} }
} }
} }