add 'display_text' arg as an alert

This commit is contained in:
Axolotle 2020-10-16 13:10:23 +02:00
parent e638a094d8
commit 19ae0ccada
2 changed files with 34 additions and 4 deletions

View file

@ -1,12 +1,26 @@
import i18n from '@/i18n'
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) {
if (typeof field === 'string') return field
const { locale, fallbackLocale } = store.state
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) {
const arg = {
component: undefined,
@ -14,7 +28,7 @@ export function formatYunoHostArgument (_arg) {
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) {
arg.component = 'SelectItem'
arg.props.choices = _arg.choices
@ -42,7 +56,7 @@ export function formatYunoHostArgument (_arg) {
arg.component = 'InputItem'
}
// Required
// Required for inputs (no need for checkbox and select, their values can't be null)
if (arg.component === 'InputItem') {
arg.props.required = _arg.optional !== true
}

View file

@ -28,6 +28,10 @@
</template>
<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-for="arg in form.args" :key="arg.name" v-bind="arg" />
@ -65,7 +69,7 @@
<script>
import api from '@/api'
import { formatYunoHostArgument } from '@/helpers/yunohostArguments'
import { formatYunoHostArgument, formatI18nField } from '@/helpers/yunohostArguments'
import { objectToParams } from '@/helpers/commons'
export default {
@ -138,13 +142,25 @@ export default {
this.infos = infos
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 = {
label: formatYunoHostArgument({
ask: this.$i18n.t('label_for_manifestname', { name: manifest.name }),
default: manifest.name,
name: 'label'
}),
args: manifest.arguments.install.map(arg => formatYunoHostArgument(arg))
args,
disclaimer
}
},