mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
update AppInstall with new helpers
This commit is contained in:
parent
1346197605
commit
f2d980594a
1 changed files with 48 additions and 89 deletions
|
@ -8,7 +8,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<b-row
|
<b-row
|
||||||
v-for="key in infosKeys" :key="key"
|
v-for="(info, key) in infos" :key="key"
|
||||||
no-gutters class="row-line"
|
no-gutters class="row-line"
|
||||||
>
|
>
|
||||||
<b-col cols="5" md="3" xl="3">
|
<b-col cols="5" md="3" xl="3">
|
||||||
|
@ -16,38 +16,28 @@
|
||||||
<span class="sep" />
|
<span class="sep" />
|
||||||
</b-col>
|
</b-col>
|
||||||
<b-col>
|
<b-col>
|
||||||
<span>{{ infos[key] }}</span>
|
<span>{{ info }}</span>
|
||||||
</b-col>
|
</b-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
</b-card>
|
</b-card>
|
||||||
|
|
||||||
<!-- INSTALL FORM -->
|
<!-- INSTALL FORM -->
|
||||||
<b-card>
|
<basic-form
|
||||||
<template v-slot:header>
|
:title="$t('operations')" icon="wrench"
|
||||||
<h2><icon iname="wrench" /> {{ $t('operations') }}</h2>
|
:validation="$v" :server-error="serverError"
|
||||||
|
@submit.prevent="beforeInstall"
|
||||||
|
>
|
||||||
|
<template v-if="formDisclaimer" #disclaimer>
|
||||||
|
<b-alert show variant="info" v-html="formDisclaimer" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<b-form id="install-form" @submit.prevent="beforeInstall">
|
<form-field
|
||||||
<b-alert
|
v-for="(field, fname) in fields" :key="fname"
|
||||||
variant="info" show
|
v-bind="field" v-model="form[fname]"
|
||||||
v-if="form.disclaimer" v-html="form.disclaimer"
|
:validation="$v.form[fname]"
|
||||||
/>
|
/>
|
||||||
<form-item-helper v-bind="form.label" />
|
|
||||||
<form-item-helper v-for="arg in form.args" :key="arg.name" v-bind="arg" />
|
|
||||||
|
|
||||||
<b-form-invalid-feedback id="global-feedback" :state="server.isValid">
|
</basic-form>
|
||||||
{{ server.error }}
|
|
||||||
</b-form-invalid-feedback>
|
|
||||||
</b-form>
|
|
||||||
|
|
||||||
<template v-slot:footer>
|
|
||||||
<b-button
|
|
||||||
class="ml-auto"
|
|
||||||
type="submit" form="install-form"
|
|
||||||
variant="success" v-t="'install'"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</b-card>
|
|
||||||
|
|
||||||
<!-- CONFIRM INSTALL DOMAIN ROOT MODAL -->
|
<!-- CONFIRM INSTALL DOMAIN ROOT MODAL -->
|
||||||
<b-modal
|
<b-modal
|
||||||
|
@ -56,7 +46,7 @@
|
||||||
@ok="performInstall" hide-header
|
@ok="performInstall" hide-header
|
||||||
:ok-title="$t('install')"
|
:ok-title="$t('install')"
|
||||||
>
|
>
|
||||||
{{ $t('confirm_install_domain_root', { domain: confirmDomain }) }}
|
{{ $t('confirm_install_domain_root', { domain: this.form.domain }) }}
|
||||||
</b-modal>
|
</b-modal>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -69,12 +59,15 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { formatYunoHostArgument, formatI18nField } from '@/helpers/yunohostArguments'
|
import { validationMixin } from 'vuelidate'
|
||||||
|
import { formatYunoHostArguments, formatI18nField, formatFormData } from '@/helpers/yunohostArguments'
|
||||||
import { objectToParams } from '@/helpers/commons'
|
import { objectToParams } from '@/helpers/commons'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AppInstall',
|
name: 'AppInstall',
|
||||||
|
|
||||||
|
mixins: [validationMixin],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
id: {
|
id: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -85,17 +78,19 @@ export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
name: undefined,
|
name: undefined,
|
||||||
infosKeys: ['id', 'description', 'license', 'version', 'multi_instance'],
|
|
||||||
infos: undefined,
|
infos: undefined,
|
||||||
|
formDisclaimer: null,
|
||||||
form: undefined,
|
form: undefined,
|
||||||
server: {
|
fields: undefined,
|
||||||
isValid: null,
|
validations: null,
|
||||||
error: ''
|
serverError: ''
|
||||||
},
|
|
||||||
confirmDomain: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validations () {
|
||||||
|
return this.validations
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getExternalManifest () {
|
getExternalManifest () {
|
||||||
const url = this.id.replace('github.com', 'raw.githubusercontent.com') + 'master/manifest.json'
|
const url = this.id.replace('github.com', 'raw.githubusercontent.com') + 'master/manifest.json'
|
||||||
|
@ -126,48 +121,28 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
setupForm (manifest) {
|
setupForm (manifest) {
|
||||||
if (manifest.license === undefined || manifest.license === 'free') {
|
|
||||||
this.infosKeys.splice(2, 1)
|
|
||||||
}
|
|
||||||
const desc = manifest.description
|
|
||||||
if (typeof desc !== 'string') {
|
|
||||||
manifest.description = desc[this.$i18n.locale] || desc.en
|
|
||||||
}
|
|
||||||
manifest.multi_instance = this.$i18n.t(manifest.multi_instance ? 'yes' : 'no')
|
|
||||||
|
|
||||||
const infos = {}
|
|
||||||
for (const key of this.infosKeys) {
|
|
||||||
infos[key] = manifest[key]
|
|
||||||
}
|
|
||||||
this.infos = infos
|
|
||||||
this.name = manifest.name
|
this.name = manifest.name
|
||||||
|
const infosKeys = ['id', 'description', 'license', 'version', 'multi_instance']
|
||||||
const args = []
|
if (manifest.license === undefined || manifest.license === 'free') {
|
||||||
let disclaimer
|
infosKeys.splice(2, 1)
|
||||||
manifest.arguments.install.forEach(ynhArg => {
|
|
||||||
const arg = formatYunoHostArgument(ynhArg)
|
|
||||||
if (ynhArg.type === 'display_text') {
|
|
||||||
disclaimer = formatI18nField(ynhArg.ask)
|
|
||||||
} else {
|
|
||||||
args.push(arg)
|
|
||||||
}
|
}
|
||||||
})
|
manifest.description = formatI18nField(manifest.description)
|
||||||
|
manifest.multi_instance = this.$i18n.t(manifest.multi_instance ? 'yes' : 'no')
|
||||||
|
this.infos = Object.fromEntries(infosKeys.map(key => [key, manifest[key]]))
|
||||||
|
|
||||||
this.form = {
|
const { form, fields, validations, disclaimer } = formatYunoHostArguments(
|
||||||
label: formatYunoHostArgument({
|
manifest.arguments.install,
|
||||||
ask: this.$i18n.t('label_for_manifestname', { name: manifest.name }),
|
manifest.name
|
||||||
default: manifest.name,
|
)
|
||||||
name: 'label'
|
|
||||||
}),
|
this.formDisclaimer = disclaimer
|
||||||
args,
|
this.fields = fields
|
||||||
disclaimer
|
this.form = form
|
||||||
}
|
this.validations = { form: validations }
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeInstall () {
|
beforeInstall () {
|
||||||
const path = this.form.args.find(arg => arg.props.id === 'path')
|
if ('path' in this.form && this.form.path === '/') {
|
||||||
if (path && path.props.value === '/') {
|
|
||||||
this.confirmDomain = this.form.args.find(arg => arg.props.id === 'domain').props.value
|
|
||||||
this.$refs['confirm-domain-root-modal'].show()
|
this.$refs['confirm-domain-root-modal'].show()
|
||||||
} else {
|
} else {
|
||||||
this.performInstall()
|
this.performInstall()
|
||||||
|
@ -175,25 +150,13 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
performInstall () {
|
performInstall () {
|
||||||
const args = {}
|
const { data: args, label } = formatFormData(this.form, { extract: ['label'] })
|
||||||
for (const arg of this.form.args) {
|
const data = { app: this.id, label, args: objectToParams(args) }
|
||||||
if (arg.component === 'CheckboxItem') {
|
|
||||||
args[arg.props.id] = arg.props.value ? 1 : 0
|
|
||||||
} else {
|
|
||||||
args[arg.props.id] = arg.props.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const data = {
|
|
||||||
app: this.id,
|
|
||||||
label: this.form.label.props.value,
|
|
||||||
args: objectToParams(args)
|
|
||||||
}
|
|
||||||
|
|
||||||
api.post('apps', data).then(response => {
|
api.post('apps', data).then(response => {
|
||||||
this.$router.push({ name: 'app-list' })
|
this.$router.push({ name: 'app-list' })
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.server.isValid = false
|
this.serverError = err.message
|
||||||
this.server.error = err.message
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -203,7 +166,3 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue