From b9b0dd906fc409d8776e52de22593a561392db6a Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 13 Sep 2021 01:50:07 +0200 Subject: [PATCH] [enh] Add markdown in alert and help --- app/src/components/globals/FormField.vue | 3 +- .../globals/formItems/ReadOnlyAlertItem.vue | 12 +++++- app/src/views/app/AppConfigPanel.vue | 38 +++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/src/components/globals/FormField.vue b/app/src/components/globals/FormField.vue index dca90927..9a067eda 100644 --- a/app/src/components/globals/FormField.vue +++ b/app/src/components/globals/FormField.vue @@ -35,8 +35,7 @@ -
diff --git a/app/src/components/globals/formItems/ReadOnlyAlertItem.vue b/app/src/components/globals/formItems/ReadOnlyAlertItem.vue index 671a1126..8d73f0b0 100644 --- a/app/src/components/globals/formItems/ReadOnlyAlertItem.vue +++ b/app/src/components/globals/formItems/ReadOnlyAlertItem.vue @@ -1,7 +1,8 @@ @@ -29,3 +30,12 @@ export default { } } + + 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) {