Merge pull request #38 from MieuxVoter/feature/clement

Feature/clement
pull/73/head
guhur 4 years ago committed by GitHub
commit 9a35a98983

@ -1,33 +1,45 @@
import i18n from './i18n.jsx'; import i18n from './i18n.jsx';
const colors = [ const colors = [
'#6f0214',
'#b20616',
'#ff5d00',
'#ffb200',
'#6bca24',
'#019812',
'#015411', '#015411',
'#019812',
'#6bca24',
'#ffb200',
'#ff5d00',
'#b20616',
'#6f0214',
]; ];
const gradeNames = [ const gradeNames = [
'To reject',
'Insufficient',
'Passable',
'Fair',
'Good',
'Very good',
'Excellent', 'Excellent',
'Very good',
'Good',
'Fair',
'Passable',
'Insufficient',
'To reject',
];
const gradeValues = [
6,
5,
4,
3,
2,
1,
0
]; ];
export const grades = gradeNames.map((name, i) => ({ export const grades = gradeNames.map((name, i) => ({
label: name, label: name,
color: colors[i], color: colors[i],
value: gradeValues[i]
})); }));
export const i18nGrades = () => { export const i18nGrades = () => {
return gradeNames.map((name, i) => ({ return gradeNames.map((name, i) => ({
label: i18n.t(name), label: i18n.t(name),
color: colors[i], color: colors[i],
value: gradeValues[i]
})); }));
}; };

@ -33,7 +33,6 @@ class Footer extends Component {
style={linkStyle}> style={linkStyle}>
{t('Who are we?')} {t('Who are we?')}
</a> </a>
<span className="m-2">-</span>
<div className="mt-3"> <div className="mt-3">
<Paypal btnColor="btn-primary" /> <Paypal btnColor="btn-primary" />
</div> </div>

@ -166,7 +166,9 @@ class Result extends Component {
render() { render() {
const {errorMessage, candidates, electionGrades} = this.state; const {errorMessage, candidates, electionGrades} = this.state;
const {t} = this.props; const {t} = this.props;
const grades = i18nGrades(); const i18nGradesObject = i18nGrades();
const offsetGrade = i18nGradesObject.length-(this.state.numGrades);
if (errorMessage && errorMessage !== '') { if (errorMessage && errorMessage !== '') {
return <Error value={errorMessage} />; return <Error value={errorMessage} />;
@ -201,16 +203,17 @@ class Result extends Component {
<hr className="mb-5" /> <hr className="mb-5" />
<ol> <ol>
{candidates.map((candidate, i) => { {candidates.map((candidate, i) => {
const gradeValue=candidate.grade+offsetGrade;
return ( return (
<li key={i} className="mt-2"> <li key={i} className="mt-2">
<span className="mt-2 ml-2">{candidate.name}</span> <span className="mt-2 ml-2">{candidate.name}</span>
<span <span
className="badge badge-light ml-2 mt-2" className="badge badge-light ml-2 mt-2"
style={{ style={{
backgroundColor: electionGrades[candidate.grade].color, backgroundColor: electionGrades.slice(0).reverse()[(candidate.grade)].color,
color: '#fff', color: '#fff',
}}> }}>
{grades[candidate.grade].label} {i18nGradesObject.slice(0).reverse()[gradeValue].label}
</span> </span>
{/* <span className="badge badge-dark mt-2 ml-2"> {/* <span className="badge badge-dark mt-2 ml-2">
{(100 * candidate.score).toFixed(1)}% {(100 * candidate.score).toFixed(1)}%
@ -252,7 +255,7 @@ class Result extends Component {
<table style={{width: '100%'}}> <table style={{width: '100%'}}>
<tbody> <tbody>
<tr> <tr>
{gradeIds.map((id, i) => { {gradeIds.slice(0).reverse().map((id, i) => {
const value = candidate.profile[id]; const value = candidate.profile[id];
if (value > 0) { if (value > 0) {
let percent = let percent =
@ -359,7 +362,7 @@ class Result extends Component {
return ( return (
<tr key={i}> <tr key={i}>
<td>{i + 1}</td> <td>{i + 1}</td>
{gradeIds.map((id, i) => { {gradeIds.slice(0).reverse().map((id, i) => {
const value = candidate.profile[id]; const value = candidate.profile[id];
const percent = ( const percent = (
(value / numVotes) * (value / numVotes) *

@ -169,6 +169,7 @@ class Vote extends Component {
render() { render() {
const {t} = this.props; const {t} = this.props;
const {redirectTo, candidates, electionGrades} = this.state; const {redirectTo, candidates, electionGrades} = this.state;
const offsetGrade = i18nGrades().length-this.state.numGrades;
if (redirectTo) { if (redirectTo) {
return <Redirect to={redirectTo} />; return <Redirect to={redirectTo} />;
@ -220,7 +221,8 @@ class Vote extends Component {
<hr className="d-lg-none" /> <hr className="d-lg-none" />
</Col> </Col>
{this.state.electionGrades.map((grade, gradeId) => { {this.state.electionGrades.map((grade, gradeId) => {
console.assert(gradeId < this.state.numGrades) console.assert(gradeId < this.state.numGrades)
const gradeValue = grade.value-offsetGrade;
return ( return (
<Col <Col
xs={this.state.colSizeGradeXs} xs={this.state.colSizeGradeXs}
@ -229,7 +231,7 @@ class Vote extends Component {
key={gradeId} key={gradeId}
className="text-lg-center"> className="text-lg-center">
<label <label
htmlFor={'candidateGrade' + candidateId + '-' + gradeId} htmlFor={'candidateGrade' + candidateId + '-' + gradeValue}
className="check"> className="check">
<small <small
className="nowrap d-lg-none ml-2 bold badge" className="nowrap d-lg-none ml-2 bold badge"
@ -239,7 +241,7 @@ class Vote extends Component {
) { ) {
return ( return (
JSON.stringify(ratedCandidat) === JSON.stringify(ratedCandidat) ===
JSON.stringify({id: candidate.id, value: gradeId}) JSON.stringify({id: candidate.id, value: gradeValue})
); );
}) })
? {backgroundColor: grade.color, color: '#fff'} ? {backgroundColor: grade.color, color: '#fff'}
@ -253,16 +255,16 @@ class Vote extends Component {
<input <input
type="radio" type="radio"
name={'candidate' + candidateId} name={'candidate' + candidateId}
id={'candidateGrade' + candidateId + '-' + gradeId} id={'candidateGrade' + candidateId + '-' + gradeValue}
data-index={candidateId} data-index={candidateId}
data-id={candidate.id} data-id={candidate.id}
value={gradeId} value={grade.value-offsetGrade}
onClick={this.handleGradeClick} onClick={this.handleGradeClick}
defaultChecked={this.state.ratedCandidates.find( defaultChecked={this.state.ratedCandidates.find(
function(element) { function(element) {
return ( return (
JSON.stringify(element) === JSON.stringify(element) ===
JSON.stringify({id: candidate.id, value: gradeId}) JSON.stringify({id: candidate.id, value: gradeValue})
); );
}, },
)} )}
@ -275,7 +277,7 @@ class Vote extends Component {
) { ) {
return ( return (
JSON.stringify(ratedCandidat) === JSON.stringify(ratedCandidat) ===
JSON.stringify({id: candidate.id, value: gradeId}) JSON.stringify({id: candidate.id, value: gradeValue})
); );
}) })
? {backgroundColor: grade.color, color: '#fff'} ? {backgroundColor: grade.color, color: '#fff'}

Loading…
Cancel
Save