2017-07-02 17:12:02 +00:00
|
|
|
import R from 'ramda'
|
2017-01-10 18:22:44 +00:00
|
|
|
import React, { Component } from 'react'
|
2017-02-09 12:58:12 +00:00
|
|
|
import classNames from 'classnames'
|
2017-04-18 17:37:38 +00:00
|
|
|
import {Link} from 'react-router-dom'
|
2017-03-15 15:26:00 +00:00
|
|
|
import {connect} from 'react-redux'
|
2017-05-18 10:07:17 +00:00
|
|
|
import { withRouter } from 'react-router'
|
2017-07-17 12:02:07 +00:00
|
|
|
import {formValueSelector} from 'redux-form'
|
2017-07-02 17:12:02 +00:00
|
|
|
|
2017-03-27 13:32:03 +00:00
|
|
|
import './Results.css'
|
2017-05-07 17:45:44 +00:00
|
|
|
import {capitalise0} from '../utils'
|
2017-08-22 09:38:11 +00:00
|
|
|
import {computeRuleValue, clearDict} from 'Engine/traverse'
|
2017-07-07 08:35:40 +00:00
|
|
|
import {encodeRuleName} from 'Engine/rules'
|
|
|
|
import {getObjectives} from 'Engine/generateQuestions'
|
2017-01-10 18:22:44 +00:00
|
|
|
|
2017-03-13 12:35:38 +00:00
|
|
|
let fmt = new Intl.NumberFormat('fr-FR').format
|
|
|
|
let humanFigure = decimalDigits => value => fmt(value.toFixed(decimalDigits))
|
2017-05-18 10:07:17 +00:00
|
|
|
|
|
|
|
@withRouter
|
2017-03-15 15:26:00 +00:00
|
|
|
@connect(
|
|
|
|
state => ({
|
2017-04-18 17:37:38 +00:00
|
|
|
analysedSituation: state.analysedSituation,
|
2017-05-18 13:01:34 +00:00
|
|
|
conversationStarted: !R.isEmpty(state.form),
|
2017-07-17 12:02:07 +00:00
|
|
|
conversationFirstAnswer: R.path(['form', 'conversation', 'values'])(state),
|
2017-09-21 13:46:59 +00:00
|
|
|
situationGate: state.situationGate
|
2017-03-15 15:26:00 +00:00
|
|
|
})
|
|
|
|
)
|
2017-01-10 18:22:44 +00:00
|
|
|
export default class Results extends Component {
|
|
|
|
render() {
|
2017-05-18 10:07:17 +00:00
|
|
|
let {
|
|
|
|
analysedSituation,
|
|
|
|
conversationStarted,
|
2017-05-18 13:01:34 +00:00
|
|
|
conversationFirstAnswer: showResults,
|
2017-07-17 12:02:07 +00:00
|
|
|
situationGate,
|
2017-05-18 10:07:17 +00:00
|
|
|
location
|
2017-08-21 13:39:54 +00:00
|
|
|
} = this.props
|
|
|
|
|
2017-08-22 09:38:11 +00:00
|
|
|
|
|
|
|
let explanation = R.has('root', analysedSituation) && clearDict() && getObjectives(situationGate, analysedSituation.root, analysedSituation.parsedRules)
|
2017-05-18 10:07:17 +00:00
|
|
|
|
2017-03-16 18:30:30 +00:00
|
|
|
if (!explanation) return null
|
|
|
|
|
2017-05-18 10:07:17 +00:00
|
|
|
let onRulePage = R.contains('/regle/')(location.pathname)
|
2017-05-18 13:01:34 +00:00
|
|
|
|
2017-01-10 18:22:44 +00:00
|
|
|
return (
|
2017-05-18 13:01:34 +00:00
|
|
|
<section id="results" className={classNames({show: showResults})}>
|
2017-05-18 10:07:17 +00:00
|
|
|
{onRulePage && conversationStarted ?
|
|
|
|
<div id ="results-actions">
|
2017-07-13 07:49:18 +00:00
|
|
|
<Link id="toSimulation" to={"/simu/" + encodeRuleName(analysedSituation.root.name)}>
|
2017-05-18 10:07:17 +00:00
|
|
|
<i className="fa fa-arrow-circle-left" aria-hidden="true"></i>Reprendre la simulation
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
: <div id="results-titles">
|
|
|
|
<h2>Vos résultats <i className="fa fa-hand-o-right" aria-hidden="true"></i></h2>
|
2017-07-13 07:49:18 +00:00
|
|
|
{do {let text = R.path(['simulateur', 'résultats'])(analysedSituation.root)
|
2017-05-18 10:07:17 +00:00
|
|
|
text &&
|
|
|
|
<p id="resultText">{text}</p>
|
2017-05-30 09:08:10 +00:00
|
|
|
}}
|
|
|
|
<p id="understandTip"><i className="fa fa-lightbulb-o" aria-hidden="true"></i><em>Cliquez pour comprendre chaque calcul</em></p>
|
2017-03-13 14:38:47 +00:00
|
|
|
</div>
|
2017-05-18 10:07:17 +00:00
|
|
|
}
|
2017-01-10 18:22:44 +00:00
|
|
|
<ul>
|
2017-03-16 18:30:30 +00:00
|
|
|
{explanation.map(
|
2017-05-07 17:45:44 +00:00
|
|
|
({name, dottedName, type, 'non applicable si': nonApplicable, formule: {nodeValue: formuleValue}}) =>
|
2017-02-09 12:58:12 +00:00
|
|
|
do {
|
2017-05-07 17:45:44 +00:00
|
|
|
//TODO quel bordel, à revoir
|
2017-02-09 12:58:12 +00:00
|
|
|
let
|
2017-05-07 17:45:44 +00:00
|
|
|
ruleValue = computeRuleValue(formuleValue, nonApplicable && nonApplicable.nodeValue),
|
|
|
|
unsatisfied = ruleValue == null,
|
2017-04-06 16:34:00 +00:00
|
|
|
nonApplicableValue = nonApplicable ? nonApplicable.nodeValue : false,
|
2017-05-07 17:45:44 +00:00
|
|
|
irrelevant = nonApplicableValue === true || formuleValue == 0,
|
2017-09-28 12:14:34 +00:00
|
|
|
number = nonApplicableValue == false && formuleValue != null
|
2017-03-01 19:27:35 +00:00
|
|
|
|
2017-09-28 12:14:34 +00:00
|
|
|
;<li key={name} className={classNames({unsatisfied, irrelevant, number})}>
|
2017-05-30 09:08:10 +00:00
|
|
|
|
|
|
|
|
2017-05-17 16:00:57 +00:00
|
|
|
<Link to={"/regle/" + encodeRuleName(name)} >
|
2017-05-30 09:08:10 +00:00
|
|
|
<div className="rule-type">
|
|
|
|
{type}
|
|
|
|
</div>
|
2017-03-13 14:38:47 +00:00
|
|
|
<div className="rule-box">
|
2017-05-30 09:08:10 +00:00
|
|
|
|
2017-03-13 14:38:47 +00:00
|
|
|
<div className="rule-name">
|
2017-05-07 17:45:44 +00:00
|
|
|
{capitalise0(name)}
|
2017-03-13 14:38:47 +00:00
|
|
|
</div>
|
|
|
|
<p>
|
2017-04-18 17:37:38 +00:00
|
|
|
{conversationStarted && (
|
|
|
|
irrelevant ?
|
|
|
|
"Vous n'êtes pas concerné"
|
|
|
|
: unsatisfied ?
|
|
|
|
'En attente de vos réponses...'
|
2017-05-07 17:45:44 +00:00
|
|
|
: <span className="figure">{humanFigure(2)(formuleValue) + '€'}</span>
|
2017-04-18 17:37:38 +00:00
|
|
|
)}
|
2017-03-13 14:38:47 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-02-13 12:28:49 +00:00
|
|
|
</Link>
|
2017-05-17 16:00:57 +00:00
|
|
|
{/* <div className="pointer">•</div> */}
|
2017-02-09 12:58:12 +00:00
|
|
|
</li>
|
|
|
|
}
|
2017-01-10 18:22:44 +00:00
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|