support enabledIfAny enabledIfAll
This commit is contained in:
parent
87fdb355b2
commit
8a725a54f1
4 changed files with 129 additions and 97 deletions
|
|
@ -32,7 +32,7 @@ function allMachineScopes (machineList, machineScope) {
|
|||
return machineScopes
|
||||
}
|
||||
|
||||
function satisfiesRequire (config, cryptos, machineList, field, refFields) {
|
||||
function satisfiesRequireAny (config, cryptos, machineList, field, refFields) {
|
||||
const fieldCode = field.code
|
||||
|
||||
const scopes = allScopes(
|
||||
|
|
@ -54,6 +54,28 @@ function satisfiesRequire (config, cryptos, machineList, field, refFields) {
|
|||
})
|
||||
}
|
||||
|
||||
function satisfiesRequireAll (config, cryptos, machineList, field, refFields) {
|
||||
const fieldCode = field.code
|
||||
|
||||
const scopes = allScopes(
|
||||
allCryptoScopes(cryptos, field.cryptoScope),
|
||||
allMachineScopes(machineList, field.machineScope)
|
||||
)
|
||||
|
||||
return scopes.every(scope => {
|
||||
const isEnabled = () => _.isEmpty(refFields) || refFields.every(refField => {
|
||||
return isScopeEnabled(config, cryptos, machineList, refField, scope)
|
||||
})
|
||||
|
||||
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
|
||||
const isRequired = refFields.length === 0 || isEnabled()
|
||||
|
||||
const isValid = isRequired ? !isBlank : true
|
||||
|
||||
return isValid
|
||||
})
|
||||
}
|
||||
|
||||
function isScopeEnabled (config, cryptos, machineList, refField, scope) {
|
||||
const [cryptoScope, machineScope] = scope
|
||||
const candidateCryptoScopes = cryptoScope === 'global'
|
||||
|
|
@ -150,9 +172,11 @@ function validateRequires (config) {
|
|||
|
||||
if (!field.fieldValidation.find(r => r.code === 'required')) return false
|
||||
|
||||
const refFields = _.map(_.partial(getField, group), field.enabledIf)
|
||||
const refFieldsAny = _.map(_.partial(getField, group), field.enabledIfAny)
|
||||
const refFieldsAll = _.map(_.partial(getField, group), field.enabledIfAll)
|
||||
|
||||
return !satisfiesRequire(config, cryptos, machineList, field, refFields)
|
||||
return !satisfiesRequireAny(config, cryptos, machineList, field, refFieldsAny) &&
|
||||
!satisfiesRequireAll(config, cryptos, machineList, field, refFieldsAll)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue