2016-12-07 18:08:10 +00:00
|
|
|
|
import React, { Component } from 'react'
|
2017-02-22 16:55:36 +00:00
|
|
|
|
// import {findRuleByName} from '../engine/rules.js'
|
|
|
|
|
import {analyseSituation} from '../engine/traverse'
|
2016-12-07 18:08:10 +00:00
|
|
|
|
import './Rule.css'
|
2016-12-16 16:09:21 +00:00
|
|
|
|
import JSONTree from 'react-json-tree'
|
2017-02-13 12:28:49 +00:00
|
|
|
|
import R from 'ramda'
|
2017-02-22 16:55:36 +00:00
|
|
|
|
import PageTypeIcon from './PageTypeIcon'
|
2017-03-01 19:27:35 +00:00
|
|
|
|
import {connect} from 'react-redux'
|
|
|
|
|
import {formValueSelector} from 'redux-form'
|
2016-12-07 18:08:10 +00:00
|
|
|
|
|
2017-03-02 15:31:24 +00:00
|
|
|
|
// situationGate function useful for testing :
|
2017-03-03 09:43:43 +00:00
|
|
|
|
let testingSituationGate = v => R.path(v.split('.'))(
|
|
|
|
|
{
|
|
|
|
|
"Salariat ":{
|
|
|
|
|
" CDD ":{
|
2017-03-08 16:47:12 +00:00
|
|
|
|
" événements": "_",
|
2017-03-03 09:43:43 +00:00
|
|
|
|
" motif":"usage",
|
|
|
|
|
" engagement employeur complément formation":"non",
|
|
|
|
|
" durée contrat":"2"
|
|
|
|
|
},
|
|
|
|
|
" contrat aidé":"non",
|
|
|
|
|
" salaire de base": 1481,
|
|
|
|
|
" congés non pris": 3
|
|
|
|
|
}
|
|
|
|
|
})
|
2017-03-01 19:27:35 +00:00
|
|
|
|
|
|
|
|
|
@connect(state => ({
|
|
|
|
|
situationGate: name => formValueSelector('conversation')(state, name)
|
|
|
|
|
}))
|
2016-12-07 18:08:10 +00:00
|
|
|
|
export default class Rule extends Component {
|
|
|
|
|
render() {
|
2016-12-16 16:28:42 +00:00
|
|
|
|
let {
|
2017-03-01 19:27:35 +00:00
|
|
|
|
params: {name},
|
|
|
|
|
situationGate
|
|
|
|
|
} = this.props,
|
2017-02-22 16:55:36 +00:00
|
|
|
|
rule = analyseSituation(
|
2017-03-03 09:43:43 +00:00
|
|
|
|
testingSituationGate
|
2017-03-01 19:27:35 +00:00
|
|
|
|
).find(R.propEq('name', name))
|
2016-12-16 16:09:21 +00:00
|
|
|
|
|
2017-03-02 15:31:24 +00:00
|
|
|
|
if (!rule) {
|
|
|
|
|
this.props.router.push('/404')
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 18:08:10 +00:00
|
|
|
|
return (
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<div id="rule">
|
2017-02-22 16:55:36 +00:00
|
|
|
|
Pourquoi cette règle me concerne ? Comment est-elle calculée ?
|
|
|
|
|
<PageTypeIcon type="comprendre"/>
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<h1>
|
|
|
|
|
<span className="rule-type">{rule.type}</span>
|
|
|
|
|
<span className="rule-name">{name}</span>
|
|
|
|
|
</h1>
|
2017-02-22 16:55:36 +00:00
|
|
|
|
<section id="rule-meta" style={{display: 'none'}}>
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<div id="meta-paragraph">
|
|
|
|
|
<p>
|
|
|
|
|
{rule.description}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<h2>Propriétés</h2>
|
2017-03-02 15:31:24 +00:00
|
|
|
|
<JSONView o={{
|
2017-02-13 12:28:49 +00:00
|
|
|
|
...rule.attributs,
|
|
|
|
|
'contexte': rule['attache']
|
2017-03-02 15:31:24 +00:00
|
|
|
|
}} />
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<h2>Références</h2>
|
|
|
|
|
{this.renderReferences(rule)}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
<section id="rule-rules">
|
2017-02-22 16:55:36 +00:00
|
|
|
|
{ do {
|
|
|
|
|
let cond =
|
|
|
|
|
R.toPairs(rule).find(([,v]) => v.rulePropType == 'cond')
|
|
|
|
|
cond != null && <section id="declenchement">
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<h2>Conditions de déclenchement</h2>
|
2017-02-22 16:55:36 +00:00
|
|
|
|
<RuleProp {...cond[1]} />
|
2017-02-13 12:28:49 +00:00
|
|
|
|
</section>
|
2017-02-22 16:55:36 +00:00
|
|
|
|
}}
|
2017-02-13 12:28:49 +00:00
|
|
|
|
<section id="formule">
|
2017-03-01 10:21:53 +00:00
|
|
|
|
<h2>Calcul</h2>
|
|
|
|
|
<RuleProp {...rule['formule']}/>
|
2017-02-13 12:28:49 +00:00
|
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{/* <pre>
|
2017-03-02 15:31:24 +00:00
|
|
|
|
<JSONView data={rule} />
|
2017-02-13 12:28:49 +00:00
|
|
|
|
</pre> */}
|
2016-12-07 18:08:10 +00:00
|
|
|
|
</div>
|
2017-02-13 12:28:49 +00:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderReferences(rule) {
|
|
|
|
|
return (
|
|
|
|
|
rule['référence'] && <div>{rule['référence']}</div>)
|
|
|
|
|
|| (
|
|
|
|
|
rule['références'] && <ul id="rule-references">
|
|
|
|
|
{R.toPairs(rule['références']).map(
|
2017-02-16 16:52:02 +00:00
|
|
|
|
([name, link]) =>
|
|
|
|
|
<li key={name}>
|
|
|
|
|
{link.indexOf('legifrance.gouv') >= 0 &&
|
|
|
|
|
<i className="fa fa-gavel" aria-hidden="true"></i>
|
|
|
|
|
}
|
|
|
|
|
<a href={link} target="_blank">
|
|
|
|
|
{name}
|
|
|
|
|
</a>
|
|
|
|
|
</li>
|
2017-02-13 12:28:49 +00:00
|
|
|
|
)}
|
|
|
|
|
</ul>
|
2016-12-07 18:08:10 +00:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-16 16:22:47 +00:00
|
|
|
|
|
2017-02-22 16:55:36 +00:00
|
|
|
|
let RuleProp = ({nodeValue, explanation, name}) =>
|
|
|
|
|
<div className="ruleProp node" >
|
|
|
|
|
<div>
|
|
|
|
|
<span className="name">{name}</span>
|
|
|
|
|
<NodeValue data={nodeValue}/>
|
|
|
|
|
</div>
|
|
|
|
|
{
|
|
|
|
|
explanation.category == 'mecanism' && <Mecanism {...explanation}/>
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
explanation.category == 'expression' && <Expression {...explanation}/>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
let Mecanism = ({nodeValue, name, explanation}) =>
|
|
|
|
|
<div className="mecanism node" >
|
|
|
|
|
<div>
|
|
|
|
|
<span className="name">{name}</span>
|
|
|
|
|
<NodeValue data={nodeValue}/>
|
|
|
|
|
</div>
|
2017-03-01 10:21:53 +00:00
|
|
|
|
{R.contains(name)(["l'une de ces conditions", 'toutes ces conditions']) &&
|
|
|
|
|
<ul>
|
|
|
|
|
{explanation.map(item => <li key={item.expression + item.name}>
|
|
|
|
|
{item.category == 'expression' ?
|
|
|
|
|
<Expression {...item} /> : <Mecanism {...item} />
|
|
|
|
|
}
|
|
|
|
|
</li>)}
|
|
|
|
|
</ul>
|
|
|
|
|
}
|
|
|
|
|
{name == 'multiplication' &&
|
|
|
|
|
<Multiplication {...explanation}/>
|
|
|
|
|
}
|
2017-03-03 09:43:43 +00:00
|
|
|
|
{name == 'le maximum de' &&
|
|
|
|
|
<JSONView o={{nodeValue, name, explanation}} />
|
|
|
|
|
}
|
2017-03-01 10:21:53 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
let Multiplication = ({base, rate}) =>
|
|
|
|
|
<div className="multiplication node" >
|
|
|
|
|
<Variable {...base}/>
|
|
|
|
|
<span className="multiplicationSign">×</span>
|
2017-03-02 15:31:24 +00:00
|
|
|
|
{
|
|
|
|
|
rate.explanation ?
|
|
|
|
|
<JSONView o={rate} />
|
|
|
|
|
: <Percentage {...rate}/>
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 16:55:36 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2017-03-01 10:21:53 +00:00
|
|
|
|
|
|
|
|
|
let Variable = ({nodeValue, variableName}) =>
|
|
|
|
|
<span className="variable" >
|
|
|
|
|
<span className="name">{variableName}</span>
|
|
|
|
|
<NodeValue data={nodeValue}/>
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let Percentage = ({percentage}) =>
|
|
|
|
|
<span className="rate" >
|
|
|
|
|
<span className="name">{percentage}</span>
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
2017-02-22 16:55:36 +00:00
|
|
|
|
let Expression = ({nodeValue, expression}) =>
|
|
|
|
|
<div className="expression node" >
|
|
|
|
|
<div>
|
|
|
|
|
<span className="name">{expression}</span>
|
|
|
|
|
<NodeValue data={nodeValue}/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2017-03-01 16:58:27 +00:00
|
|
|
|
let NodeValue = ({data}) => do {
|
2017-03-02 15:31:24 +00:00
|
|
|
|
console.log('NodeValue', data)
|
2017-03-01 10:21:53 +00:00
|
|
|
|
let valeur = data == null ?
|
|
|
|
|
'?'
|
|
|
|
|
: ( R.is(Number)(data) ?
|
2017-03-01 16:58:27 +00:00
|
|
|
|
Math.round(data)
|
2017-03-01 10:21:53 +00:00
|
|
|
|
: ( data ? 'oui' : 'non')
|
|
|
|
|
);
|
|
|
|
|
|
2017-02-22 16:55:36 +00:00
|
|
|
|
<span className={"value " + valeur}>←
|
|
|
|
|
{valeur}
|
|
|
|
|
</span>
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-01 10:21:53 +00:00
|
|
|
|
let Formula = ({explanation, nodeValue}) => do {
|
|
|
|
|
<div className="form node" >
|
|
|
|
|
<div>
|
|
|
|
|
<span className="name">{expression}</span>
|
|
|
|
|
<NodeValue data={nodeValue}/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
2017-02-22 16:55:36 +00:00
|
|
|
|
|
2017-03-02 15:31:24 +00:00
|
|
|
|
let JSONView = ({o, rootKey}) =>
|
|
|
|
|
<JSONTree
|
|
|
|
|
getItemString={() => ''}
|
|
|
|
|
theme={theme}
|
|
|
|
|
hideRoot={true}
|
|
|
|
|
shouldExpandNode={() => true}
|
|
|
|
|
data={rootKey ? {[rootKey]: o} : o} />
|
|
|
|
|
|
2016-12-16 16:22:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var theme = {
|
|
|
|
|
scheme: 'atelier forest',
|
|
|
|
|
author: 'bram de haan (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/forest)',
|
|
|
|
|
base00: '#1b1918',
|
|
|
|
|
base01: '#2c2421',
|
|
|
|
|
base02: '#68615e',
|
|
|
|
|
base03: '#766e6b',
|
|
|
|
|
base04: '#9c9491',
|
|
|
|
|
base05: '#a8a19f',
|
|
|
|
|
base06: '#e6e2e0',
|
|
|
|
|
base07: '#f1efee',
|
|
|
|
|
base08: '#f22c40',
|
|
|
|
|
base09: '#df5320',
|
|
|
|
|
base0A: '#d5911a',
|
|
|
|
|
base0B: '#5ab738',
|
|
|
|
|
base0C: '#00ad9c',
|
|
|
|
|
base0D: '#407ee7',
|
|
|
|
|
base0E: '#6666ea',
|
|
|
|
|
base0F: '#c33ff3'
|
|
|
|
|
}
|