Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ @AmountBox = React .createClass
2
+ render : ->
3
+ React .DOM .div
4
+ className : ' col-md-4'
5
+ React .DOM .div
6
+ className : " panel panel-#{ @props .type } "
7
+ React .DOM .div
8
+ className : ' panel-heading'
9
+ @props .text
10
+ React .DOM .div
11
+ className : ' panel-body'
12
+ amountFormat (@props .amount )
Original file line number Diff line number Diff line change 5
5
getDefaultProps : ->
6
6
records : []
7
7
8
+ credits : ->
9
+ credits = @state .records .filter (val) -> val .amount >= 0
10
+ credits .reduce ((prev , curr ) ->
11
+ prev + parseFloat (curr .amount )
12
+ ), 0
13
+
14
+ debits : ->
15
+ debits = @state .records .filter (val) -> val .amount < 0
16
+ debits .reduce ((prev , curr ) ->
17
+ prev + parseFloat (curr .amount )
18
+ ), 0
19
+
20
+ balance : ->
21
+ @ debits () + @ credits ()
22
+
8
23
addRecord : (record ) ->
9
24
records = @state .records .slice ()
10
25
records .push record
16
31
React .DOM .h2
17
32
className : ' title'
18
33
' Records'
34
+ React .DOM .div
35
+ className : ' row'
36
+ React .createElement AmountBox, type : ' success' , amount : @ credits (), text : ' Credit'
37
+ React .createElement AmountBox, type : ' danger' , amount : @ debits (), text : ' Debit'
38
+ React .createElement AmountBox, type : ' info' , amount : @ balance (), text : ' Balance'
19
39
React .createElement RecordForm, handleNewRecord : @addRecord
20
40
React .DOM .hr null
21
41
React .DOM .table
0 commit comments