From 36a4a21d57b690b594a79991c70e790ca449a4e8 Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 31 May 2021 05:30:18 +0200 Subject: [PATCH 01/30] [enh] Adapt the new config panel mechanism to vuejs webadmin --- app/package.json | 4 +- app/src/components/globals/FormField.vue | 9 +- .../components/globals/formItems/FileItem.vue | 45 ++++ .../globals/formItems/InputItem.vue | 4 + .../globals/formItems/MarkdownItem.vue | 15 ++ .../globals/formItems/ReadOnlyAlertItem.vue | 18 ++ .../components/globals/formItems/TagsItem.vue | 32 +++ .../globals/formItems/TextAreaItem.vue | 29 +++ app/src/helpers/yunohostArguments.js | 220 +++++++++++++----- app/src/main.js | 14 +- app/src/views/app/AppActions.vue | 11 +- app/src/views/app/AppConfigPanel.vue | 66 ++++-- app/src/views/app/AppInstall.vue | 7 +- 13 files changed, 362 insertions(+), 112 deletions(-) create mode 100644 app/src/components/globals/formItems/FileItem.vue create mode 100644 app/src/components/globals/formItems/MarkdownItem.vue create mode 100644 app/src/components/globals/formItems/ReadOnlyAlertItem.vue create mode 100644 app/src/components/globals/formItems/TagsItem.vue create mode 100644 app/src/components/globals/formItems/TextAreaItem.vue diff --git a/app/package.json b/app/package.json index 9e6446f4..53bedea7 100644 --- a/app/package.json +++ b/app/package.json @@ -22,7 +22,9 @@ "vue-i18n": "^8.24.1", "vue-router": "^3.5.1", "vuelidate": "^0.7.6", - "vuex": "^3.6.2" + "vuex": "^3.6.2", + "simple-evaluate": "^1.4.3", + "vue-showdown": "^2.4.1" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.4.0", diff --git a/app/src/components/globals/FormField.vue b/app/src/components/globals/FormField.vue index b61a1157..dca90927 100644 --- a/app/src/components/globals/FormField.vue +++ b/app/src/components/globals/FormField.vue @@ -26,11 +26,11 @@ + + diff --git a/app/src/views/app/AppConfigPanel.vue b/app/src/views/app/AppConfigPanel.vue index 405ca8a8..225c1d11 100644 --- a/app/src/views/app/AppConfigPanel.vue +++ b/app/src/views/app/AppConfigPanel.vue @@ -50,7 +50,7 @@ import evaluate from 'simple-evaluate' // FIXME needs test and rework import api, { objectToParams } from '@/api' -import { formatI18nField, formatYunoHostArguments, formatFormData } from '@/helpers/yunohostArguments' +import { formatI18nField, formatYunoHostArguments, formatFormData, pFileReader } from '@/helpers/yunohostArguments' export default { name: 'AppConfigPanel', @@ -84,16 +84,40 @@ export default { isVisible (expression) { if (!expression) return true const context = {} + + const promises = [] for (const args of Object.values(this.forms)) { for (const shortname in args) { - context[shortname] = args[shortname] + if (args[shortname] instanceof File) { + if (expression.includes(shortname)) { + promises.push(pFileReader(args[shortname], context, shortname, false)) + } + } else { + context[shortname] = args[shortname] + } } } - try { - return evaluate(context, expression) - } catch (error) { - return true - } + // Allow to use match(var,regexp) function + const matchRe = new RegExp('match\\(\\s*(\\w+)\\s*,\\s*"([^"]+)"\\s*\\)', 'g') + let i = 0 + return new Promise((resolve, reject) => { + i = 2 + resolve(false) + Promise.all(promises).then((value) => { + for (const matched of expression.matchAll(matchRe)) { + i++ + const varName = matched[1] + '__re' + i.toString() + context[varName] = new RegExp(matched[2]).test(context[matched[1]]) + expression = expression.replace(matched[0], varName) + } + + try { + resolve(evaluate(context, expression)) + } catch (error) { + resolve(false) + } + }) + }) }, onQueriesResponse (data) { if (!data.panels || data.panels.length === 0) { From abfd018a46de69f88680cf4ac362e91523e92054 Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 13 Sep 2021 02:36:16 +0200 Subject: [PATCH 30/30] [enh] Improve UX in validation --- app/src/components/globals/CardForm.vue | 6 +++--- app/src/components/globals/FormField.vue | 2 +- app/src/components/globals/formItems/ReadOnlyAlertItem.vue | 3 ++- app/src/helpers/yunohostArguments.js | 2 +- app/src/i18n/locales/en.json | 3 ++- app/src/views/user/UserList.vue | 1 - 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/components/globals/CardForm.vue b/app/src/components/globals/CardForm.vue index 8dde1180..5bf3b128 100644 --- a/app/src/components/globals/CardForm.vue +++ b/app/src/components/globals/CardForm.vue @@ -46,12 +46,12 @@ export default { computed: { disabled () { - return this.validation ? this.validation.$invalid : false + return false // this.validation ? this.validation.$invalid : false }, errorFeedback () { if (this.serverError) return this.serverError - else if (this.validation && this.validation.$invalid) { - return this.$t('invalid_form') + else if (this.validation && this.validation.$anyError) { + return this.$i18n.t('form_errors.invalid_form') } else return '' } }, diff --git a/app/src/components/globals/FormField.vue b/app/src/components/globals/FormField.vue index 9a067eda..d7be17e1 100644 --- a/app/src/components/globals/FormField.vue +++ b/app/src/components/globals/FormField.vue @@ -36,7 +36,7 @@ diff --git a/app/src/components/globals/formItems/ReadOnlyAlertItem.vue b/app/src/components/globals/formItems/ReadOnlyAlertItem.vue index 8d73f0b0..2d7ffa42 100644 --- a/app/src/components/globals/formItems/ReadOnlyAlertItem.vue +++ b/app/src/components/globals/formItems/ReadOnlyAlertItem.vue @@ -2,7 +2,8 @@ + tag="span" class="markdown" + /> diff --git a/app/src/helpers/yunohostArguments.js b/app/src/helpers/yunohostArguments.js index bb2e23b2..44486987 100644 --- a/app/src/helpers/yunohostArguments.js +++ b/app/src/helpers/yunohostArguments.js @@ -100,7 +100,7 @@ export function formatYunoHostArgument (arg) { if (!isNaN(parseInt(arg.max))) { validation.maxValue = validators.maxValue(parseInt(arg.max)) } - validation.numValue = validators.numeric + validation.numValue = validators.helpers.regex('Please provide an integer', new RegExp('^-?[0-9]+$')) } }, { diff --git a/app/src/i18n/locales/en.json b/app/src/i18n/locales/en.json index 345489b8..2e90353c 100644 --- a/app/src/i18n/locales/en.json +++ b/app/src/i18n/locales/en.json @@ -183,7 +183,8 @@ "passwordMatch": "Passwords don't match.", "required": "Field is required.", "remote": "{message}", - "pattern": "{type}" + "pattern": "{type}", + "invalid_form": "The form contains some errors." }, "form_input_example": "Example: {example}", "from_to": "from {0} to {1}", diff --git a/app/src/views/user/UserList.vue b/app/src/views/user/UserList.vue index 26f3cac3..98989745 100644 --- a/app/src/views/user/UserList.vue +++ b/app/src/views/user/UserList.vue @@ -26,7 +26,6 @@ {{ $t('users_export') }} -