mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Support file in match regexp
This commit is contained in:
parent
da87972ca4
commit
338c679287
2 changed files with 21 additions and 21 deletions
|
@ -243,6 +243,8 @@ export function formatYunoHostArgument (arg) {
|
||||||
|
|
||||||
if (arg.visible) {
|
if (arg.visible) {
|
||||||
field.visible = arg.visible
|
field.visible = arg.visible
|
||||||
|
// Temporary value to wait visible expression to be evaluated
|
||||||
|
field.isVisible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-for="section in sections">
|
<template v-for="section in sections">
|
||||||
<div :key="section.id" class="mb-5" v-if="isVisible(section.visible)">
|
<div :key="section.id" class="mb-5" v-if="isVisible(section.visible, section)">
|
||||||
<b-card-title v-if="section.name" title-tag="h3">
|
<b-card-title v-if="section.name" title-tag="h3">
|
||||||
{{ section.name }} <small v-if="section.help">{{ section.help }}</small>
|
{{ section.name }} <small v-if="section.help">{{ section.help }}</small>
|
||||||
</b-card-title>
|
</b-card-title>
|
||||||
<template v-for="(field, fname) in section.fields">
|
<template v-for="(field, fname) in section.fields">
|
||||||
<form-field :key="fname" v-model="forms[id_][fname]"
|
<form-field :key="fname" v-model="forms[id_][fname]"
|
||||||
:validation="$v.forms[id_][fname]"
|
:validation="$v.forms[id_][fname]"
|
||||||
v-if="isVisible(field.visible)" v-bind="field"
|
v-if="isVisible(field.visible, field)" v-bind="field"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,8 +81,8 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
isVisible (expression) {
|
isVisible (expression, field) {
|
||||||
if (!expression) return true
|
if (!expression || !field) return true
|
||||||
const context = {}
|
const context = {}
|
||||||
|
|
||||||
const promises = []
|
const promises = []
|
||||||
|
@ -100,24 +100,22 @@ export default {
|
||||||
// Allow to use match(var,regexp) function
|
// Allow to use match(var,regexp) function
|
||||||
const matchRe = new RegExp('match\\(\\s*(\\w+)\\s*,\\s*"([^"]+)"\\s*\\)', 'g')
|
const matchRe = new RegExp('match\\(\\s*(\\w+)\\s*,\\s*"([^"]+)"\\s*\\)', 'g')
|
||||||
let i = 0
|
let i = 0
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
i = 2
|
|
||||||
resolve(false)
|
|
||||||
Promise.all(promises).then((value) => {
|
Promise.all(promises).then((value) => {
|
||||||
for (const matched of expression.matchAll(matchRe)) {
|
for (const matched of expression.matchAll(matchRe)) {
|
||||||
i++
|
i++
|
||||||
const varName = matched[1] + '__re' + i.toString()
|
const varName = matched[1] + '__re' + i.toString()
|
||||||
context[varName] = new RegExp(matched[2]).test(context[matched[1]])
|
context[varName] = new RegExp(matched[2], 'm').test(context[matched[1]])
|
||||||
expression = expression.replace(matched[0], varName)
|
expression = expression.replace(matched[0], varName)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resolve(evaluate(context, expression))
|
field.isVisible = evaluate(context, expression)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
resolve(false)
|
field.isVisible = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
// This value should be updated magically when vuejs will detect isVisible changed
|
||||||
|
return field.isVisible
|
||||||
},
|
},
|
||||||
onQueriesResponse (data) {
|
onQueriesResponse (data) {
|
||||||
if (!data.panels || data.panels.length === 0) {
|
if (!data.panels || data.panels.length === 0) {
|
||||||
|
@ -137,7 +135,7 @@ export default {
|
||||||
validations_[id] = {}
|
validations_[id] = {}
|
||||||
errors_[id] = {}
|
errors_[id] = {}
|
||||||
for (const { id_, name, help, visible, options } of sections) {
|
for (const { id_, name, help, visible, options } of sections) {
|
||||||
const section_ = { id: id_, visible }
|
const section_ = { id: id_, isVisible: true, visible }
|
||||||
if (help) section_.help = formatI18nField(help)
|
if (help) section_.help = formatI18nField(help)
|
||||||
if (name) section_.name = formatI18nField(name)
|
if (name) section_.name = formatI18nField(name)
|
||||||
const { form, fields, validations, errors } = formatYunoHostArguments(options)
|
const { form, fields, validations, errors } = formatYunoHostArguments(options)
|
||||||
|
|
Loading…
Add table
Reference in a new issue