From 063886683800b0ac4b3ec024ccc2d1033173469c Mon Sep 17 00:00:00 2001 From: axolotle Date: Wed, 29 Sep 2021 21:42:47 +0200 Subject: [PATCH 1/4] make sure FormatFormData always return a promise and update views using it accordingly --- app/src/helpers/yunohostArguments.js | 15 ++++----------- app/src/views/app/AppConfigPanel.vue | 2 +- app/src/views/app/AppInstall.vue | 5 ++++- app/src/views/domain/DomainConfig.vue | 2 +- app/src/views/user/UserCreate.vue | 4 ++-- app/src/views/user/UserEdit.vue | 4 ++-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/helpers/yunohostArguments.js b/app/src/helpers/yunohostArguments.js index 75b0fac6..06eb385e 100644 --- a/app/src/helpers/yunohostArguments.js +++ b/app/src/helpers/yunohostArguments.js @@ -343,9 +343,9 @@ export function formatFormDataValue (value) { * @param {Boolean} [extraParams.removeEmpty=true] - Removes "empty" values from the object. * @return {Object} the parsed data to be sent to the server, with extracted values if specified. */ -export function formatFormData ( +export async function formatFormData ( formData, - { extract = null, flatten = false, removeEmpty = true, removeNull = false, promise = false, multipart = true } = {} + { extract = null, flatten = false, removeEmpty = true, removeNull = false, multipart = true } = {} ) { const output = { data: {}, @@ -376,14 +376,7 @@ export function formatFormData ( output[type][key] = value } } + if (promises.length) await Promise.all(promises) const { data, extracted } = output - if (promises.length > 0 || promise) { - return new Promise((resolve, reject) => { - Promise.all(promises).then((value) => { - resolve(data) - }) - }) - } else { - return extract ? { data, ...extracted } : data - } + return extract ? { data, ...extracted } : data } diff --git a/app/src/views/app/AppConfigPanel.vue b/app/src/views/app/AppConfigPanel.vue index 753ad635..4df0021e 100644 --- a/app/src/views/app/AppConfigPanel.vue +++ b/app/src/views/app/AppConfigPanel.vue @@ -155,7 +155,7 @@ export default { }, applyConfig (id_) { - formatFormData(this.forms[id_], { promise: true, removeEmpty: false, removeNull: true, multipart: false }).then((formatedData) => { + formatFormData(this.forms[id_], { removeEmpty: false, removeNull: true, multipart: false }).then((formatedData) => { const args = objectToParams(formatedData) api.put( diff --git a/app/src/views/app/AppInstall.vue b/app/src/views/app/AppInstall.vue index 041524c7..e74ba5fc 100644 --- a/app/src/views/app/AppInstall.vue +++ b/app/src/views/app/AppInstall.vue @@ -110,7 +110,10 @@ export default { if (!confirmed) return } - const { data: args, label } = formatFormData(this.form, { extract: ['label'] }) + const { data: args, label } = await formatFormData( + this.form, + { extract: ['label'], removeEmpty: false, removeNull: true, multipart: false } + ) const data = { app: this.id, label, args: Object.entries(args).length ? objectToParams(args) : undefined } api.post('apps', data, { key: 'apps.install', name: this.name }).then(() => { diff --git a/app/src/views/domain/DomainConfig.vue b/app/src/views/domain/DomainConfig.vue index 4a0d4dfd..fdf670f8 100644 --- a/app/src/views/domain/DomainConfig.vue +++ b/app/src/views/domain/DomainConfig.vue @@ -142,7 +142,7 @@ export default { }, applyConfig (id_) { - formatFormData(this.forms[id_], { promise: true, removeEmpty: false, removeNull: true, multipart: false }).then((formatedData) => { + formatFormData(this.forms[id_], { removeEmpty: false, removeNull: true, multipart: false }).then((formatedData) => { const args = objectToParams(formatedData) api.put( diff --git a/app/src/views/user/UserCreate.vue b/app/src/views/user/UserCreate.vue index fb8d7a89..8f3af02c 100644 --- a/app/src/views/user/UserCreate.vue +++ b/app/src/views/user/UserCreate.vue @@ -173,8 +173,8 @@ export default { this.form.domain = this.mainDomain }, - onSubmit () { - const data = formatFormData(this.form, { flatten: true }) + async onSubmit () { + const data = await formatFormData(this.form, { flatten: true }) api.post({ uri: 'users' }, data, { key: 'users.create', name: this.form.username }).then(() => { this.$router.push({ name: 'user-list' }) }).catch(err => { diff --git a/app/src/views/user/UserEdit.vue b/app/src/views/user/UserEdit.vue index 11135820..91ef132c 100644 --- a/app/src/views/user/UserEdit.vue +++ b/app/src/views/user/UserEdit.vue @@ -266,8 +266,8 @@ export default { } }, - onSubmit () { - const formData = formatFormData(this.form, { flatten: true }) + async onSubmit () { + const formData = await formatFormData(this.form, { flatten: true }) const user = this.user(this.name) const data = {} if (!Object.prototype.hasOwnProperty.call(formData, 'mailbox_quota')) { From e40d9b9d2221662608e9962d5072b4205997823b Mon Sep 17 00:00:00 2001 From: axolotle Date: Wed, 29 Sep 2021 21:43:37 +0200 Subject: [PATCH 2/4] add `visible` arg field option handling in AppInstall --- app/src/views/app/AppInstall.vue | 49 ++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/app/src/views/app/AppInstall.vue b/app/src/views/app/AppInstall.vue index e74ba5fc..1bc08e5d 100644 --- a/app/src/views/app/AppInstall.vue +++ b/app/src/views/app/AppInstall.vue @@ -23,10 +23,13 @@ :validation="$v" :server-error="serverError" @submit.prevent="performInstall" > - + @@ -44,9 +47,10 @@ diff --git a/app/src/views/app/AppCatalog.vue b/app/src/views/app/AppCatalog.vue index 2daf3381..e17903d2 100644 --- a/app/src/views/app/AppCatalog.vue +++ b/app/src/views/app/AppCatalog.vue @@ -64,52 +64,56 @@ - - - - {{ app.manifest.name }} - - - {{ $t('app_state_' + app.state) }} - - - - + + + + + {{ app.manifest.name }} - {{ app.manifest.description }} + + + {{ $t('app_state_' + app.state) }} + - - - {{ $t(app.maintained) }} - - - + + + - - - - {{ $t('code') }} - + {{ app.manifest.description }} - - {{ $t('readme') }} - + + + {{ $t(app.maintained) }} + + + - - {{ $t('install') }} - - - {{ $t('installed') }} - - - + + + + {{ $t('code') }} + + + + {{ $t('readme') }} + + + + {{ $t('install') }} + + + {{ $t('installed') }} + + + +