mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add 'display_text' arg as an alert
This commit is contained in:
parent
e638a094d8
commit
19ae0ccada
2 changed files with 34 additions and 4 deletions
|
@ -1,12 +1,26 @@
|
||||||
import i18n from '@/i18n'
|
import i18n from '@/i18n'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to find a translation corresponding to the user's locale/fallback locale in a
|
||||||
|
* Yunohost argument or simply return the string if it's not an object literal.
|
||||||
|
*
|
||||||
|
* @param {(Object|string)} field - A field value containing a translation object or string
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
export function formatI18nField (field) {
|
export function formatI18nField (field) {
|
||||||
if (typeof field === 'string') return field
|
if (typeof field === 'string') return field
|
||||||
const { locale, fallbackLocale } = store.state
|
const { locale, fallbackLocale } = store.state
|
||||||
return field[locale] || field[fallbackLocale] || field.en
|
return field[locale] || field[fallbackLocale] || field.en
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format app install, actions and config panel arguments into a data structure that
|
||||||
|
* will be automaticly transformed into components on screen.
|
||||||
|
*
|
||||||
|
* @param {Object} _arg - a yunohost arg options written by a packager.
|
||||||
|
* @return {Object} an formated argument that can be fed to the FormItemHelper component.
|
||||||
|
*/
|
||||||
export function formatYunoHostArgument (_arg) {
|
export function formatYunoHostArgument (_arg) {
|
||||||
const arg = {
|
const arg = {
|
||||||
component: undefined,
|
component: undefined,
|
||||||
|
@ -14,7 +28,7 @@ export function formatYunoHostArgument (_arg) {
|
||||||
props: { id: _arg.name, value: null }
|
props: { id: _arg.name, value: null }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some apps has `string` as type but expect a select since it has `choices`
|
// Some apps has an argument type `string` as type but expect a select since it has `choices`
|
||||||
if (_arg.choices !== undefined) {
|
if (_arg.choices !== undefined) {
|
||||||
arg.component = 'SelectItem'
|
arg.component = 'SelectItem'
|
||||||
arg.props.choices = _arg.choices
|
arg.props.choices = _arg.choices
|
||||||
|
@ -42,7 +56,7 @@ export function formatYunoHostArgument (_arg) {
|
||||||
arg.component = 'InputItem'
|
arg.component = 'InputItem'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Required
|
// Required for inputs (no need for checkbox and select, their values can't be null)
|
||||||
if (arg.component === 'InputItem') {
|
if (arg.component === 'InputItem') {
|
||||||
arg.props.required = _arg.optional !== true
|
arg.props.required = _arg.optional !== true
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<b-form id="install-form" @submit.prevent="beforeInstall">
|
<b-form id="install-form" @submit.prevent="beforeInstall">
|
||||||
|
<b-alert
|
||||||
|
variant="info" show
|
||||||
|
v-if="form.disclaimer" v-html="form.disclaimer"
|
||||||
|
/>
|
||||||
<form-item-helper v-bind="form.label" />
|
<form-item-helper v-bind="form.label" />
|
||||||
<form-item-helper v-for="arg in form.args" :key="arg.name" v-bind="arg" />
|
<form-item-helper v-for="arg in form.args" :key="arg.name" v-bind="arg" />
|
||||||
|
|
||||||
|
@ -65,7 +69,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { formatYunoHostArgument } from '@/helpers/yunohostArguments'
|
import { formatYunoHostArgument, formatI18nField } from '@/helpers/yunohostArguments'
|
||||||
import { objectToParams } from '@/helpers/commons'
|
import { objectToParams } from '@/helpers/commons'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -138,13 +142,25 @@ export default {
|
||||||
this.infos = infos
|
this.infos = infos
|
||||||
this.name = manifest.name
|
this.name = manifest.name
|
||||||
|
|
||||||
|
const args = []
|
||||||
|
let disclaimer
|
||||||
|
manifest.arguments.install.forEach(ynhArg => {
|
||||||
|
const arg = formatYunoHostArgument(ynhArg)
|
||||||
|
if (ynhArg.type === 'display_text') {
|
||||||
|
disclaimer = formatI18nField(ynhArg.ask)
|
||||||
|
} else {
|
||||||
|
args.push(arg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
this.form = {
|
this.form = {
|
||||||
label: formatYunoHostArgument({
|
label: formatYunoHostArgument({
|
||||||
ask: this.$i18n.t('label_for_manifestname', { name: manifest.name }),
|
ask: this.$i18n.t('label_for_manifestname', { name: manifest.name }),
|
||||||
default: manifest.name,
|
default: manifest.name,
|
||||||
name: 'label'
|
name: 'label'
|
||||||
}),
|
}),
|
||||||
args: manifest.arguments.install.map(arg => formatYunoHostArgument(arg))
|
args,
|
||||||
|
disclaimer
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue