Bloc de sélection des objectifs

pull/138/head
mama 2017-11-15 10:49:55 +01:00
parent 4241f3d249
commit 0bcedd7028
5 changed files with 66 additions and 62 deletions

View File

@ -57,7 +57,9 @@
SMIC mi-temps: 740
inversions possibles:
- contrat salarié . salaire net
- salaire net
- salaire super brut
- coût du travail
références:
Le salaire. Fixation et paiement: http://travail-emploi.gouv.fr/droit-du-travail/remuneration-et-participation-financiere/remuneration/article/le-salaire-fixation-et-paiement

View File

@ -1,17 +1,12 @@
import React, { Component } from 'react'
import './Home.css'
import { Link } from 'react-router-dom'
import ReactPiwik from 'Components/Tracker' //TODO réintégrer Piwik
import { rules } from 'Engine/rules'
import { propEq, reject } from 'ramda'
import TargetSelection from './TargetSelection'
export default class Home extends Component {
export default class HomeEmbauche extends Component {
state = {
input: 'salaire de base',
targets: ['salaire net']
}
render() {
let { targets, input } = this.state
return (
<div id="home">
@ -23,55 +18,9 @@ export default class HomeEmbauche extends Component {
/>
<h1>Simulateurs d'embauche</h1>
</div>
<section id="selection">
<h2>Que voulez-vous faire ?</h2>
<p>Choisissez ce que vous allez saisir</p>
{this.renderInputList()}
<div id="conversionSymbol"></div>
<p>Choisissez ce que nous allons calculer</p>
{this.renderOutputList()}
<Link to={'/simu/' + targets.join('+') + '/' + input}>
<button>C'est parti !</button>
</Link>
</section>
<TargetSelection />
</div>
)
}
renderInputList() {
let salaires = rules.filter(propEq('type', 'salaire'))
return (
<select
defaultValue="salaire de base"
onMouseDown={e => this.setState({ input: e.target.value })}
>
{salaires.map(s => (
<option key={s.name} value={s.name}>
{s.title || s.name}
</option>
))}
</select>
)
}
renderOutputList() {
let salaires = rules.filter(propEq('type', 'salaire')),
{ targets, input } = this.state
return (
<select
multiple
value={targets}
onChange={e =>
this.setState({
targets: targets.find(t => t === e.target.value)
? reject(t => t === e.target.value, targets)
: [...targets, e.target.value]
})}
>
{salaires.map(s => (
<option key={s.name} value={s.name} disabled={s.name === input}>
{s.title || s.name}
</option>
))}
</select>
)
}
}

View File

@ -0,0 +1,50 @@
import React, { Component } from 'react'
import { rules } from 'Engine/rules'
import { propEq, reject } from 'ramda'
import { Link } from 'react-router-dom'
export default class TargetSelection extends Component {
state = {
targets: ['salaire net', 'coût du travail']
}
render() {
let { targets } = this.state
return (
<section id="selection">
<h2>Que voulez-vous faire ?</h2>
<p>Choisissez un ou plusieurs objectifs de calcul</p>
{this.renderOutputList()}
{targets.length !==0 && (
<Link to={'/simu/' + targets.join('+')}>
<button>Valider</button>
</Link>
)}
</section>
)
}
renderOutputList() {
let salaires = rules.filter(propEq('type', 'salaire')),
{ targets } = this.state
return (
<select
multiple
value={targets}
onMouseDown={e =>
this.setState({
targets: targets.find(t => t === e.target.value)
? reject(t => t === e.target.value, targets)
: [...targets, e.target.value]
})
}
>
{salaires.map(s => (
<option key={s.name} value={s.name}>
{s.title || s.name}
</option>
))}
</select>
)
}
}

View File

@ -58,7 +58,7 @@ export default class Layout extends Component {
<Route path="/contact" component={Contact} />
<Route path="/regle/:name" component={Rule} />
<Route path="/regles" component={RulesList} />
<Route path="/simu/:targets/:firstInput?" component={Simulateur} />
<Route path="/simu/:targets" component={Simulateur} />
<Redirect from="/simu/:name/intro" to="/simu/:name" />
<Route component={Route404} />
</Switch>

View File

@ -415,7 +415,9 @@ export let findInversion = (situationGate, rules, rule) => {
Ex. s'il nous est demandé de calculer le salaire de base, est-ce qu'un candidat à l'inversion, comme
le salaire net, a été renseigné ?
*/
let fixedObjective = inversions.find(name => situationGate(name) != undefined) //TODO ça va foirer avec des espaces de nom
let fixedObjective = inversions
.map(i => disambiguateRuleReference(rules, rule, i))
.find(name => situationGate(name) != undefined)
if (fixedObjective == null) return null
//par exemple, fixedObjective = 'salaire net', et v('salaire net') == 2000
return {
@ -469,8 +471,9 @@ let doInversion = (situationGate, parsedRules, r) => {
export let treatRuleRoot = (rules, rule) => {
let evaluate = (situationGate, parsedRules, r) => {
let inversion = situationGate(r.dottedName) == undefined // avoid the inversion loop !
&& doInversion(situationGate, parsedRules, r)
let inversion =
situationGate(r.dottedName) == undefined && // avoid the inversion loop !
doInversion(situationGate, parsedRules, r)
if (inversion) return { ...r, ...inversion }
let evolveRule = R.curry(evaluateNode)(situationGate, parsedRules),