@@ -15,10 +15,7 @@ class ProjectInfoContainer extends React.Component {
1515 constructor ( props ) {
1616 super ( props )
1717 this . state = {
18- duration : {
19- percent : 0 ,
20- text : 'Complete specification to get estimate'
21- } ,
18+ duration : { } ,
2219 budget : { // FIXME
2320 percent : 80 ,
2421 text : '$1000 remaining'
@@ -34,16 +31,58 @@ class ProjectInfoContainer extends React.Component {
3431 return ! _ . isEqual ( nextProps . project , this . props . project )
3532 }
3633
37- componentWillReceiveProps ( { project} ) {
38- if ( project . duration ) {
39- const percent = project . duration . actualDuration / project . duration . plannedDuration * 100
40- this . setState ( {
41- duration : {
42- percent,
43- text : percent === 0 ? 'Complete specification to get estimate' : ''
34+ setDuration ( { duration, status} ) {
35+ let percent = ''
36+ let title = ''
37+ let text = ''
38+ let type = ''
39+ if ( duration ) {
40+ const { actualDuration, plannedDuration} = duration
41+ if ( status === 'draft' ) {
42+ title = 'Duration'
43+ percent = 0
44+ text = 'Complete specification to get estimate'
45+ } else if ( status === 'in_review' ) {
46+ title = 'Duration'
47+ percent = 0
48+ text = 'Pending review'
49+ } else if ( status === 'reviewed' ) {
50+ title = `${ plannedDuration } days (projected)`
51+ percent = 0
52+ text = `${ plannedDuration } days remaining`
53+ } else if ( status === 'completed' ) {
54+ title = 'Completed'
55+ percent = 100
56+ text = ''
57+ type = 'completed'
58+ } else {
59+ text = `Day ${ actualDuration } of ${ plannedDuration } `
60+ percent = actualDuration / plannedDuration * 100
61+ if ( 0 <= percent && percent < 100 ) {
62+ const diff = plannedDuration - actualDuration
63+ title = `${ diff } ${ diff > 1 ? 'days' : 'day' } remaining`
64+ type = 'working'
65+ } else {
66+ percent = 100
67+ type = 'error'
68+ const diff = actualDuration - plannedDuration
69+ title = `${ diff } ${ diff > 1 ? 'days' : 'day' } over`
4470 }
45- } )
71+ }
72+ } else {
73+ title = 'Duration'
74+ percent = 0
75+ text = 'Complete specification to get estimate'
4676 }
77+ this . setState ( { duration : { title, text, percent, type } } )
78+ }
79+
80+ componentWillMount ( ) {
81+ this . setDuration ( this . props . project )
82+ }
83+
84+ componentWillReceiveProps ( { project} ) {
85+ this . setDuration ( project )
4786 }
4887
4988 onChangeStatus ( status ) {
0 commit comments