@ -1,15 +1,15 @@
import React , { Component } from "react" ;
import { Container , Row , Col , Collapse , Card , CardHeader , CardBody , Table } from "reactstrap" ;
import { Container , Row , Col , Collapse , Card , CardHeader , CardBody , Table } from "reactstrap" ;
//TODO : variable de config dans un fichier à part (avec les mentions, le min/max de mentions, le nombre max de candidats, les maxlength,l'url api, etc ...)
const mentions = [
{ label : "Excellent" , color : "#015411" } ,
{ label : "Trés Bien" , color : "#019812" } ,
{ label : "Bien" , color : "#6bca24" } ,
{ label : "Assez Bien" , color : "#ffb200" } ,
{ label : "Passable" , color : "#ff5d00" } ,
{ label : "Insuffisant" , color : "#b20616" } ,
{ label : "A Rejeter" , color : "#6f0214" } ,
{ label : "Excellent" , color : "#015411" } ,
{ label : "Trés Bien" , color : "#019812" } ,
{ label : "Bien" , color : "#6bca24" } ,
{ label : "Assez Bien" , color : "#ffb200" } ,
{ label : "Passable" , color : "#ff5d00" } ,
{ label : "Insuffisant" , color : "#b20616" } ,
{ label : "A Rejeter" , color : "#6f0214" } ,
] ;
@ -18,17 +18,17 @@ class Result extends Component {
constructor ( props ) {
super ( props ) ;
this . state = {
candidates : [ ] ,
title : null ,
nbMentions : 0 ,
colSizeCandidateLg : 4 ,
colSizeCandidateMd : 6 ,
colSizeCandidateXs : 12 ,
colSizeMentionLg : 1 ,
colSizeMentionMd : 1 ,
colSizeMentionXs : 1 ,
collapseGraphics : false ,
collapseProfiles : false
candidates : [ ] ,
title : null ,
nbMentions : 0 ,
colSizeCandidateLg : 4 ,
colSizeCandidateMd : 6 ,
colSizeCandidateXs : 12 ,
colSizeMentionLg : 1 ,
colSizeMentionMd : 1 ,
colSizeMentionXs : 1 ,
collapseGraphics : false ,
collapseProfiles : false
} ;
@ -36,44 +36,44 @@ class Result extends Component {
componentDidMount ( ) {
//todo fetch data from API
let fetchedData = {
title : "Merci d'évaluer les candidats suivants" ,
candidates : [
{ id : 0 , label : "Mme ABCD" , mention : 2 , profile : [ 20 , 20 , 20 , 10 , 10 , 20 , 0 ] , score : "55.28" } ,
{ id : 2 , label : "M. EFGH" , mention : 3 , profile : [ 0 , 20 , 20 , 10 , 10 , 30 , 10 ] , score : "43.10" } ,
{ id : 3 , label : "M. IJKL" , mention : 4 , profile : [ 0 , 0 , 20 , 25 , 15 , 20 , 20 ] , score : "22.82" } ,
{ id : 4 , label : "M. MNOP" , mention : 4 , profile : [ 0 , 0 , 15 , 15 , 30 , 10 , 30 ] , score : "12.72" }
] , //ordered by result
nbMentions : 7 ,
let fetchedData = {
title : "Merci d'évaluer les candidats suivants" ,
candidates : [
{ id : 0 , label : "Mme ABCD" , mention : 2 , profile : [ 20 , 20 , 20 , 10 , 10 , 20 , 0 ] , score : "55.28" } ,
{ id : 2 , label : "M. EFGH" , mention : 3 , profile : [ 0 , 20 , 20 , 10 , 10 , 30 , 10 ] , score : "43.10" } ,
{ id : 3 , label : "M. IJKL" , mention : 4 , profile : [ 0 , 0 , 20 , 25 , 15 , 20 , 20 ] , score : "22.82" } ,
{ id : 4 , label : "M. MNOP" , mention : 4 , profile : [ 0 , 0 , 15 , 15 , 30 , 10 , 30 ] , score : "12.72" }
] , //ordered by result
nbMentions : 7 ,
} ;
let data = {
title : fetchedData . title ,
candidates : fetchedData . candidates ,
nbMentions : fetchedData . nbMentions ,
colSizeCandidateLg : 0 ,
colSizeCandidateMd : 0 ,
colSizeCandidateXs : 0 ,
colSizeMentionLg : Math . floor ( ( 12 - this . state . colSizeCandidateLg ) / fetchedData . nbMentions ) ,
colSizeMentionMd : Math . floor ( ( 12 - this . state . colSizeCandidateMd ) / fetchedData . nbMentions ) ,
colSizeMentionXs : Math . floor ( ( 12 - this . state . colSizeCandidateXs ) / fetchedData . nbMentions ) ,
let data = {
title : fetchedData . title ,
candidates : fetchedData . candidates ,
nbMentions : fetchedData . nbMentions ,
colSizeCandidateLg : 0 ,
colSizeCandidateMd : 0 ,
colSizeCandidateXs : 0 ,
colSizeMentionLg : Math . floor ( ( 12 - this . state . colSizeCandidateLg ) / fetchedData . nbMentions ) ,
colSizeMentionMd : Math . floor ( ( 12 - this . state . colSizeCandidateMd ) / fetchedData . nbMentions ) ,
colSizeMentionXs : Math . floor ( ( 12 - this . state . colSizeCandidateXs ) / fetchedData . nbMentions ) ,
} ;
data . colSizeCandidateLg = ( ( 12 - data . colSizeMentionLg * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionLg * data . nbMentions ) : 12 ;
data . colSizeCandidateMd = ( ( 12 - data . colSizeMentionMd * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionMd * data . nbMentions ) : 12 ;
data . colSizeCandidateXs = ( ( 12 - data . colSizeMentionXs * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionXs * data . nbMentions ) : 12 ;
data . colSizeCandidateLg = ( ( 12 - data . colSizeMentionLg * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionLg * data . nbMentions ) : 12 ;
data . colSizeCandidateMd = ( ( 12 - data . colSizeMentionMd * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionMd * data . nbMentions ) : 12 ;
data . colSizeCandidateXs = ( ( 12 - data . colSizeMentionXs * data . nbMentions ) > 0 ) ? ( 12 - data . colSizeMentionXs * data . nbMentions ) : 12 ;
this . setState ( data ) ;
}
toggleGraphics = ( ) => {
this . setState ( state => ( { collapseGraphics : ! state . collapseGraphics } ) ) ;
toggleGraphics = ( ) => {
this . setState ( state => ( { collapseGraphics : ! state . collapseGraphics } ) ) ;
} ;
toggleProfiles = ( ) => {
this . setState ( state => ( { collapseProfiles : ! state . collapseProfiles } ) ) ;
toggleProfiles = ( ) => {
this . setState ( state => ( { collapseProfiles : ! state . collapseProfiles } ) ) ;
} ;
render ( ) {
return (
render ( ) {
return (
< Container >
< Row >
< Col xs = "12" > < h1 > { this . state . title } < / h 1 > < / C o l >
@ -81,11 +81,14 @@ class Result extends Component {
< Row className = "mt-5" >
< Col > < h1 > Résultat du vote : < / h 1 >
< ol >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < li key = { i } className = "mt-2" > { candidate . label } < span className = "badge badge-dark mr-2 mt-2" > { candidate . score } % < / s p a n > < s p a n c l a s s N a m e = " b a d g e b a d g e - l i g h t m r - 2 m t - 2 " s t y l e = { { b a c k g r o u n d C o l o r : m e n t i o n s [ c a n d i d a t e . m e n t i o n ] . c o l o r , c o l o r : " # f f f " } } > { m e n t i o n s [ c a n d i d a t e . m e n t i o n ] . l a b e l } < / s p a n > < / l i > ) ;
} ) }
< / o l >
< ol > { this . state . candidates . map ( ( candidate , i ) => {
return ( < li key = { i } className = "mt-2" > { candidate . label } < span
className = "badge badge-dark mr-2 mt-2" > { candidate . score } % < / s p a n > < s p a n
className = "badge badge-light mr-2 mt-2" style = { {
backgroundColor : mentions [ candidate . mention ] . color ,
color : "#fff"
} } > { mentions [ candidate . mention ] . label } < / s p a n > < / l i > ) ;
} ) } < / o l >
< / C o l >
< / R o w >
@ -93,42 +96,60 @@ class Result extends Component {
< Col >
< Card className = "bg-light text-primary" >
< CardHeader className = "pointer" onClick = { this . toggleGraphics } >
< h4 className = { "m-0 panel-title " + ( this . state . collapseGraphics ? "collapsed" : "" ) } > Graphique < / h 4 >
< h4 className = { "m-0 panel-title " + ( this . state . collapseGraphics ? "collapsed" : "" ) } > Graphique < / h 4 >
< / C a r d H e a d e r >
< Collapse isOpen = { this . state . collapseGraphics } >
< CardBody className = "pt-5" >
< div >
< div className = "median" style = { { height : ( this . state . candidates . length * 28 ) + 30 } } / >
< table style = { { width : "100%" } } >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < tr key = { i } > < td style = { { width : "30px" } } > { i + 1 } < /td> {/ * candidate . label * / }
< td > < table style = { { width : "100%" } } > < tr >
{ candidate . profile . map ( ( value , i ) => {
if ( value > 0 ) {
let percent = value + "%" ;
if ( i === 0 ) {
percent = "auto" ;
}
return ( < td key = { i } style = { { width : percent , backgroundColor : mentions [ i ] . color } } > & nbsp ; < / t d > ) ;
}
} ) } < / t r > < / t a b l e >
< / t d >
< / t r > )
} ) } < / t a b l e >
< div >
< div className = "median"
style = { { height : ( this . state . candidates . length * 28 ) + 30 } } / >
< table style = { { width : "100%" } } > < tbody >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < tr key = { i } >
< td style = { { width : "30px" } } > { i + 1 } < / t d >
{ /*candidate.label*/ }
< td >
< table style = { { width : "100%" } } >
< tbody >
< tr >
{ candidate . profile . map ( ( value , i ) => {
if ( value > 0 ) {
let percent = value + "%" ;
if ( i === 0 ) {
percent = "auto" ;
}
return ( < td key = { i } style = { {
width : percent ,
backgroundColor : mentions [ i ] . color
} } > & nbsp ; < / t d > ) ;
} else {
return null
}
} ) } < / t r >
< / t b o d y >
< / t a b l e >
< / t d >
< / t r > )
} ) } < / t b o d y > < / t a b l e >
< / d i v >
< div className = "mt-4" >
< small >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < span key = { i } > { ( i > 0 ) ? ", " : "" } < b > { i + 1 } < / b > : { c a n d i d a t e . l a b e l } < / s p a n > ) ;
< small >
{ this . state . candidates . map ( ( candidate , i ) => {
return (
< span key = { i } > { ( i > 0 ) ? ", " : "" } < b > { i + 1 } < / b > : { c a n d i d a t e . l a b e l } < / s p a n > ) ;
} ) }
< / s m a l l >
< / d i v >
< div className = "mt-2" >
< small >
{ mentions . map ( ( mention , i ) => {
return ( i < this . state . nbMentions ) ? < span key = { i } className = "badge badge-light mr-2 mt-2" style = { { backgroundColor : mention . color , color : "#fff" } } > { mention . label } < /span>:<span key={i}/ >
< small >
{ mentions . map ( ( mention , i ) => {
return ( i < this . state . nbMentions ) ?
< span key = { i } className = "badge badge-light mr-2 mt-2" style = { {
backgroundColor : mention . color ,
color : "#fff"
} } > { mention . label } < /span> : <span key={i}/ >
} )
}
< / s m a l l >
@ -142,48 +163,46 @@ class Result extends Component {
< Col >
< Card className = "bg-light text-primary" >
< CardHeader className = "pointer" onClick = { this . toggleProfiles } >
< h4 className = { "m-0 panel-title " + ( this . state . collapseProfiles ? "collapsed" : "" ) } > Profils de mérites < / h 4 >
< h4 className = { "m-0 panel-title " + ( this . state . collapseProfiles ? "collapsed" : "" ) } > Profils
de mérites < / h 4 >
< / C a r d H e a d e r >
< Collapse isOpen = { this . state . collapseProfiles } >
< CardBody >
< CardBody >
< div className = "table-responsive" >
< Table className = "profiles" >
< thead >
< tr >
< th > # < / t h >
{ mentions . map ( ( mention , i ) => {
return ( < th key = { i } > < span className = "badge badge-light" style = { { backgroundColor : mention . color , color : "#fff" } } > { mention . label } < / s p a n > < / t h > ) ;
} ) }
< / t r >
< / t h e a d >
< tbody >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < tr key = { i } >
< td > { i + 1 } < /td> {/ * candidate . label * / }
{ candidate . profile . map ( ( value , i ) => {
return ( < td key = { i } > { value } % < / t d > ) ;
< Table className = "profiles" >
< thead >
< tr >
< th > # < / t h >
{ mentions . map ( ( mention , i ) => {
return ( < th key = { i } > < span className = "badge badge-light" style = { {
backgroundColor : mention . color ,
color : "#fff"
} } > { mention . label } < / s p a n > < / t h > ) ;
} ) } < / t r >
< / t h e a d >
< tbody > { this . state . candidates . map ( ( candidate , i ) => {
return ( < tr key = { i } >
< td > { i + 1 } < / t d >
{ /*candidate.label*/ }
{ candidate . profile . map ( ( value , i ) => {
return ( < td key = { i } > { value } % < / t d > ) ;
} ) }
< / t r > )
} ) }
< / t b o d y >
< / T a b l e >
} ) } < / t b o d y >
< / T a b l e >
< / d i v >
< small >
{ this . state . candidates . map ( ( candidate , i ) => {
return ( < span key = { i } > { ( i > 0 ) ? ", " : "" } < b > { i + 1 } < / b > : { c a n d i d a t e . l a b e l } < / s p a n > ) ;
} ) }
< / s m a l l >
< small > { this . state . candidates . map ( ( candidate , i ) => {
return ( < span
key = { i } > { ( i > 0 ) ? ", " : "" } < b > { i + 1 } < / b > : { c a n d i d a t e . l a b e l } < / s p a n > ) ;
} ) } < / s m a l l >
< / C a r d B o d y >
< / C o l l a p s e >
< / C a r d >
< / C o l >
< / R o w >
< / C o n t a i n e r >
)
}
}
export default Result ;