|
| 1 | +package myob |
| 2 | + |
| 3 | +//import myob.modules._ |
| 4 | +//import myob.model._ |
| 5 | +//import spatutorial.client.components.GlobalStyles |
| 6 | +//import spatutorial.client.modules._ |
| 7 | +//import spatutorial.client.services.{RootModel, SPACircuit, ToLearns, Todos} |
| 8 | + |
| 9 | +import japgolly.scalajs.react.{ReactDOM, ReactComponentB} |
| 10 | +import org.scalajs.dom |
| 11 | + |
| 12 | +import scala.scalajs.js.JSApp |
| 13 | +import scala.scalajs.js.annotation.JSExport |
| 14 | +import japgolly.scalajs.react.vdom.prefix_<^._ |
| 15 | + |
| 16 | + |
| 17 | +@JSExport("BankingRulesMain") |
| 18 | +object TutorialApp extends JSApp { |
| 19 | + def main(): Unit = { |
| 20 | +// appendPar(dom.document.body, "Hello World") |
| 21 | + val HelloMessage = ReactComponentB[String]("HelloMessage") |
| 22 | + .render($ => <.div("Hello ", $.props)) |
| 23 | + .build |
| 24 | + |
| 25 | + ReactDOM.render(HelloMessage("John"), dom.document.body) |
| 26 | + } |
| 27 | + def appendPar(targetNode: dom.Node, text: String): Unit = { |
| 28 | + val parNode = dom.document.createElement("p") |
| 29 | + val textNode = dom.document.createTextNode(text) |
| 30 | + parNode.appendChild(textNode) |
| 31 | + targetNode.appendChild(parNode) |
| 32 | + } |
| 33 | +} |
| 34 | +//object BankingRulesMain extends js.JSApp { |
| 35 | +// |
| 36 | +// // Define the locations (pages) used in this application |
| 37 | +// sealed trait Loc |
| 38 | +// |
| 39 | +// case object ListRulesLoc extends Loc |
| 40 | +// case class EditRuleLoc(ruleId:String) extends Loc |
| 41 | +// |
| 42 | +//// case object TodoLoc extends Loc |
| 43 | +// |
| 44 | +// val itemPage = ReactComponentB[EditRuleLoc]("Edit Rule Item page") |
| 45 | +// .render(p => <.div(s"Info page for Rule #${p.props.ruleId}")) |
| 46 | +//// OR -> .render_P((p) => <.div(s"Info page for Rule #${p.ruleId}")) |
| 47 | +// .build |
| 48 | +// |
| 49 | +// |
| 50 | +// |
| 51 | +//// dynamicRouteCT("item" / int.caseClass[ItemPage]) |
| 52 | +//// ~> dynRender(itemPage(_)) |
| 53 | +// |
| 54 | +// // configure the router |
| 55 | +// val routerConfig = RouterConfigDsl[Loc].buildConfig { (dsl: RouterConfigDsl[Loc]) => |
| 56 | +// import dsl._ |
| 57 | +// |
| 58 | +// // wrap/connect components to the circuit |
| 59 | +//// (staticRoute(root, DashboardLoc) ~> renderR(ctl => SPACircuit.wrap(_.motd)((proxy: ModelProxy[Pot[String]]) => Dashboard(ctl, proxy))) |
| 60 | +//// | staticRoute("#todo", TodoLoc) ~> renderR(ctl => SPACircuit.connect((model: RootModel) => model.todos)((proxy: ModelProxy[Pot[Todos]]) => Todo(proxy))) |
| 61 | +//// | staticRoute("#tolearn", ToLearnLoc) ~> renderR(ctl => SPACircuit.connect((model: RootModel) => model.toLearns)((proxy: ModelProxy[Pot[ToLearns]]) => ToLearn(proxy))) |
| 62 | +//// ).notFound(redirectToPage(DashboardLoc)(Redirect.Replace)) |
| 63 | +// |
| 64 | +//// val r: Route[EditRuleLoc] = ("category" / string("[a-z]+") / uuid).caseClass[EditRuleLoc] |
| 65 | +// |
| 66 | +// (staticRoute(root, ListRulesLoc) ~> renderR(ctl => BankingRulesCircuit.wrap((rootModel: model.RootModel) => rootModel.rules)((proxy: ModelProxy[Pot[model.Rules]]) => modules.Rule(ctl, proxy))) |
| 67 | +// | dynamicRouteCT("#item" / string("rule-.*").caseClassDebug[EditRuleLoc]) ~> dynRender(props => itemPage(props)) |
| 68 | +// |
| 69 | +// // | dynamicRouteCT("item" / int.caseClass[EditRuleLoc]) ~> renderR(ctl => BankingRulesCircuit.connect((model: RootModel) => model.todos)((proxy: ModelProxy[Pot[Todos]]) => Todo(proxy))) |
| 70 | +//// | staticRoute("#edit", EditRuleLoc) ~> renderR(ctl => BankingRulesCircuit.connect((model: RootModel) => model.todos)((proxy: ModelProxy[Pot[Todos]]) => Todo(proxy))) |
| 71 | +// ).notFound(redirectToPage(ListRulesLoc)(Redirect.Replace)) |
| 72 | +// }.renderWith(layout) |
| 73 | +// |
| 74 | +// // base layout for all pages |
| 75 | +// def layout(c: RouterCtl[Loc], r: Resolution[Loc]) = { |
| 76 | +// <.div( |
| 77 | +// // here we use plain Bootstrap class names as these are specific to the top level layout defined here |
| 78 | +// <.nav(^.className := "navbar navbar-inverse navbar-fixed-top", |
| 79 | +// <.div(^.className := "container", |
| 80 | +// <.div(^.className := "navbar-header", <.span(^.className := "navbar-brand", "Banking Rules...")), |
| 81 | +// <.div(^.className := "collapse navbar-collapse", |
| 82 | +// // connect menu to model, because it needs to update when the number of open todos changes |
| 83 | +// BankingRulesCircuit.connect { value => |
| 84 | +// val rules = value.rules.map(_.items.count(!_.completed)).toOption |
| 85 | +// rules |
| 86 | +// }((modelProxy: ModelProxy[Option[Int]]) => modules.MainMenu(c, r.page, modelProxy)) |
| 87 | +// |
| 88 | +// ) |
| 89 | +// ) |
| 90 | +// ), |
| 91 | +// // currently active module is shown in this container |
| 92 | +// <.div(^.className := "container", r.render()) |
| 93 | +// ) |
| 94 | +// } |
| 95 | +// |
| 96 | +// @JSExport |
| 97 | +// def main(): Unit = { |
| 98 | +// log.warn("Application starting") |
| 99 | +// // send log messages also to the server |
| 100 | +// log.enableServerLogging("/logging") |
| 101 | +// log.info("This message goes to server as well") |
| 102 | +// |
| 103 | +// // create stylesheet |
| 104 | +// GlobalStyles.addToDocument() |
| 105 | +// // create the router |
| 106 | +// val router = Router(BaseUrl.until_#, routerConfig) |
| 107 | +// // tell React to render the router in the document body |
| 108 | +// ReactDOM.render(router(), dom.document.getElementById("root")) |
| 109 | +// } |
| 110 | +//} |
0 commit comments