1
1
package views
2
2
3
- import scalatags .Text .all ._
4
-
5
3
import scala .annotation .nowarn
6
4
import scalajs .js .annotation .JSExportTopLevel
7
5
import org .scalajs .dom .raw ._
8
6
import scalatags .Text .{all => t }
7
+ import scalatags .Text .all ._
9
8
import io .udash .wrappers .jquery .{jQ => $ , _ }
10
9
11
10
import java .text .DecimalFormat
12
- // TODO: import framework.JsRead._
13
11
14
12
@ JSExportTopLevel (" mortgage_calculator" )
15
13
object MortgageCalculator extends framework.Page (" mortgage_calculator" ) {
@@ -21,11 +19,11 @@ object MortgageCalculator extends framework.Page("mortgage_calculator") {
21
19
input(label = " APR (%)" , id = " apr" , default = 5 ),
22
20
input(label = " Mortgage Period (years)" , id = " years" , default = 30 ),
23
21
input(label = " New APR" , id = " new_apr" , default = 3 ),
24
- button(" Calculate" , id := " calc_payments" , `type` := " button" , `class` := " btn btn-primary m-2" ),
25
- button(" Refinance?" , id := " refinance" , `type` := " button" , `class` := " btn btn-secondary m-2" ),
22
+ button(" Calculate" , id := " calc_payments" , `type` := " button" , `class` := " btn btn-primary m-2" ),
23
+ button(" Refinance?" , id := " refinance" , `type` := " button" , `class` := " btn btn-secondary m-2" ),
26
24
),
27
25
),
28
- div(id := " output" , `class` := " container" ),
26
+ div(id := " output" , `class` := " container" ),
29
27
)
30
28
31
29
def input (label : String , id : String , default : Int ): Tag =
@@ -42,35 +40,33 @@ object MortgageCalculator extends framework.Page("mortgage_calculator") {
42
40
def calc (element : Element , event : JQueryEvent ) = {
43
41
val format = new DecimalFormat (" $ #.00" );
44
42
import api .Mortgage
45
- $(" #output" ).html(table(`class` := " table table-striped font-monospace" )(tr(
46
- th(" #" ),
47
- th(" Balance" ),
48
- th(" Payment" ),
49
- th(" Principal" ),
50
- th(" Interest" ))
51
- ).render)
43
+ $(" #output" ).html(
44
+ table(`class` := " table table-striped font-monospace" )(
45
+ tr(th(" #" ), th(" Balance" ), th(" Payment" ), th(" Principal" ), th(" Interest" )),
46
+ ).render,
47
+ )
52
48
for {
53
49
amount <- $(" #loan" ).value().asInstanceOf [String ].toIntOption
54
50
apr <- $(" #apr" ).value().asInstanceOf [String ].toFloatOption
55
51
years <- $(" #years" ).value().asInstanceOf [String ].toIntOption
56
52
mortgage = Mortgage (amount = amount, apr = apr, years = years)
57
- payments <- Mortgage .API .payments(mortgage)
53
+ payments <- Mortgage .API .payments(mortgage)
58
54
(payment, row) <- payments.zipWithIndex
59
- } $(" #output tr:last" ).after(tr(
60
- td(row+ 1 ),
61
- td(format.format(payment.balance)),
62
- td(format.format(payment.payment)),
63
- td(format.format(payment.principal)),
64
- td(format.format(payment.interest)),
65
- ).render)
55
+ } $(" #output tr:last" ).after(
56
+ tr(
57
+ td(row + 1 ),
58
+ td(format.format(payment.balance)),
59
+ td(format.format(payment.payment)),
60
+ td(format.format(payment.principal)),
61
+ td(format.format(payment.interest)),
62
+ ).render,
63
+ )
66
64
}
67
65
}
68
66
67
+ // TODO: import framework.JsRead._
69
68
70
69
/*
71
- * Mon, Aug 28: FE (ScalaJs Tour) + FE Dependency management
72
- * Tue, Aug 29: RPC
73
- * Wed, Aug 30: BE: Server
74
- * Thu, Sep 1: BE: Shared
75
- * Fri, Sep 2: ScalaCSS + Tooling
70
+ * Thu, Sep 1: Misc: ScalaCSS, JsRead
71
+ * Fri, Sep 2: Tooling (sbt dev)
76
72
*/
0 commit comments