2016-12-07 18:08:10 +00:00
|
|
|
import rules from './load-rules'
|
2017-01-23 18:06:46 +00:00
|
|
|
import entityRules from './load-entity-rules'
|
2016-12-07 18:08:10 +00:00
|
|
|
|
2017-01-23 18:06:46 +00:00
|
|
|
import possibleVariableTypes from './possibleVariableTypes.yaml'
|
|
|
|
import {borrify} from './remove-diacritics'
|
2017-01-24 15:22:40 +00:00
|
|
|
import R from 'ramda'
|
2016-12-07 18:08:10 +00:00
|
|
|
|
2017-01-10 18:22:44 +00:00
|
|
|
export let findRuleByName = search =>
|
2016-12-07 18:08:10 +00:00
|
|
|
rules
|
2017-01-24 15:22:40 +00:00
|
|
|
.map(enrichRule)
|
2017-01-10 18:22:44 +00:00
|
|
|
.find( ({name}) =>
|
|
|
|
name === search
|
2016-12-07 18:08:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
export let searchRules = searchInput =>
|
|
|
|
rules
|
|
|
|
.filter( rule =>
|
|
|
|
rule && hasKnownRuleType(rule) &&
|
|
|
|
JSON.stringify(rule).indexOf(searchInput) > -1)
|
2017-01-24 15:22:40 +00:00
|
|
|
.map(enrichRule)
|
2016-12-07 18:08:10 +00:00
|
|
|
|
|
|
|
|
2017-01-24 15:22:40 +00:00
|
|
|
export let enrichRule = rule => {
|
2016-12-07 18:08:10 +00:00
|
|
|
let type = possibleVariableTypes.find(t => rule[t])
|
2017-01-24 15:22:40 +00:00
|
|
|
return {...rule, type, name: rule[type]}
|
2016-12-07 18:08:10 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 15:22:40 +00:00
|
|
|
export let hasKnownRuleType = rule => rule && enrichRule(rule).type
|
2017-01-23 18:06:46 +00:00
|
|
|
|
|
|
|
|
2017-01-26 09:54:36 +00:00
|
|
|
export let fullDottedName = rule => rule.attache && borrify(
|
2017-01-23 18:06:46 +00:00
|
|
|
[ rule.attache,
|
2017-01-24 15:22:40 +00:00
|
|
|
do { let {alias, name} = enrichRule(rule)
|
|
|
|
alias || name
|
|
|
|
}
|
2017-01-23 18:06:46 +00:00
|
|
|
].join(' . ')
|
|
|
|
)
|
|
|
|
|
2017-01-24 15:22:40 +00:00
|
|
|
export let findRuleByDottedName = dottedName =>
|
|
|
|
entityRules.map(enrichRule).find(rule => fullDottedName(rule) == borrify(dottedName))
|
|
|
|
|
|
|
|
export let findGroup = R.pipe(
|
|
|
|
findRuleByDottedName,
|
|
|
|
found => found && found['choix exclusifs'] && found,
|
|
|
|
// Is there a way to express this more litterally in ramda ?
|
|
|
|
// R.unless(
|
|
|
|
// R.isNil,
|
|
|
|
// R.when(
|
|
|
|
// R.has('choix exclusifs'),
|
|
|
|
// R.identity
|
|
|
|
// )
|
|
|
|
// )
|
|
|
|
)
|
|
|
|
|
|
|
|
console.log('findG', findGroup('Salariat . CDD . événements'))
|