Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 6.02 KB | None | 0 0
  1. package com.ctilogic.cvd.web.client.react.component
  2.  
  3.  
  4. import com.ctilogic.cvd.web.client._
  5. import com.ctilogic.cvd.web.client.react.component.addschedule.{ScheduleState, RootComponent}
  6. import japgolly.scalajs.react._
  7. import japgolly.scalajs.react.extra.router.RouterCtl
  8. import japgolly.scalajs.react.vdom.VdomElement
  9. import japgolly.scalajs.react.vdom.html_<^._
  10. import scalacss.Defaults._
  11.  
  12. object RootComponent {
  13.  
  14.   case class Props(url: LocationURL,
  15.                    router: RouterCtl[LocationURL])
  16.  
  17.   case class State(intentURL: Option[LocationURL])
  18.  
  19.   class Backend(backend: BackendScope[Props, State]) {
  20.  
  21.     private def menu(): VdomElement = {
  22.       <.div(
  23.         "menu + logo todo"
  24.       )
  25.     }
  26.  
  27.     private def content(props: Props): VdomElement = {
  28.       val router = props.router
  29.  
  30.       props.url match {
  31.         case DashboardURL =>
  32.           <.div(
  33.             DashboardComponent.component()
  34.           )
  35.         case AddScheduleURL =>
  36.           <.div(
  37.             addschedule.RootComponent(ScheduleState.dummy)()
  38.           )
  39.       }
  40.     }
  41.  
  42.     def render(props: Props, state: State): VdomElement = {
  43.       <.div(
  44.         <.styleTag(
  45.           RootStyles.render[String]
  46.         ),
  47.         <.div(
  48.           ^.className := "navbar navbar-default",
  49.           <.div(
  50.             ^.className := "container",
  51.             menu()
  52.           )
  53.         ),
  54.         <.div(
  55.           ^.className := RootStyles.rootContainer.htmlClass,
  56.           <.div(
  57.             ^.className := "row",
  58.             <.div(
  59.               ^.className := RootStyles.centeredContent.htmlClass,
  60.               content(props)
  61.             )
  62.           )
  63.         )
  64.       )
  65.     }
  66.   }
  67.  
  68.   val component = ScalaComponent.builder[Props](this.getClass.getSimpleName)
  69.     .initialState(State(None))
  70.     .renderBackend[Backend]
  71.     .build
  72.  
  73. }
  74.  
  75. ///////////////////
  76. //next file
  77.  
  78. package com.ctilogic.cvd.web.client.react.component
  79.  
  80. import com.ctilogic.cvd.web.client.AutowireClient
  81. import com.ctilogic.cvd.web.client.AutowireClient._
  82. import japgolly.scalajs.react._
  83. import japgolly.scalajs.react.vdom.VdomElement
  84. import japgolly.scalajs.react.vdom.html_<^._
  85. import model.Api
  86.  
  87. object DashboardComponent {
  88.  
  89.   class Backend(bs: BackendScope[Unit, Unit]) {
  90.  
  91.     val testFileName = "testFile"
  92.  
  93. //    def createFile: Callback = {
  94. //      Callback(AutowireClient[Api].createFile(testFileName, new Date(2017, 1, 1)).call().foreach {
  95. //        unit =>
  96. //          println("createFile message sent")
  97. //      })
  98. //    }
  99. //
  100.     def searchFile: Callback = {
  101.       Callback(AutowireClient[Api].searchFile(testFileName).call().foreach {
  102.         unit =>
  103.           println("searchFile message sent")
  104.       })
  105.     }
  106.  
  107.     def render(): VdomElement =
  108.       <.div(
  109. //        Button(Size.lg, Style.success, createFile, false)()("Create test file"),
  110. //        Button(Size.lg, Style.success, searchFile, false)()("Search file")
  111.       )
  112.   }
  113.  
  114.   val component = ScalaComponent.builder[Unit](DashboardComponent.getClass.getSimpleName)
  115.     .renderBackend[Backend]
  116.     .build
  117. }
  118.  
  119. ////////////////////
  120. // next file
  121.  
  122. package com.ctilogic.cvd.web.client.react.component.addschedule
  123.  
  124. import japgolly.scalajs.react._
  125. import japgolly.scalajs.react.vdom.VdomElement
  126. import japgolly.scalajs.react.vdom.html_<^._
  127. import model.DomainObjects.Holiday
  128. import scalacss.Defaults._
  129.  
  130. object RootComponent {
  131.  
  132.   class Backend($: BackendScope[Unit, ScheduleState]) {
  133.  
  134.     def addDay(day: Holiday): Callback =
  135.       $.modState(s => s.days.contains(day) match {
  136.         case true => s
  137.         case false => s.copy(days = s.days :+ day )
  138.       })
  139.  
  140.     def setTitle(e: ReactEventFromInput): Callback =
  141.       e.target.value match {
  142.         case nonEmpty: String if nonEmpty.nonEmpty =>
  143.           $.modState(_.copy(title = Option(nonEmpty)))
  144.         case _ =>
  145.           $.modState(_.copy(title = None))
  146.       }
  147.  
  148.     def addSchedule(e: ReactMouseEvent): Callback = {
  149.       //todo
  150.       println("addSchedule")
  151.       Callback.TODO
  152.     }
  153.  
  154.     def cancelSchedule(e: ReactMouseEvent): Callback = {
  155.       //todo
  156.       println("cancelSchedule")
  157.       Callback.TODO
  158.     }
  159.  
  160.     def removeDay(day: Holiday): Callback =
  161.       $.modState(s => s.copy(days = s.days.filterNot(_ == day)))
  162.  
  163.     def render(state: ScheduleState): VdomElement =
  164.       <.div(
  165.         <.styleTag(
  166.           ScheduleStyles.render[String]
  167.         ),
  168.         <.div(
  169.           <.div(
  170.             ^.className := "row",
  171.             <.div(
  172.               ^.className := "col-md-8",
  173.               <.div(
  174.                 ^.className := ScheduleStyles.editScheduler.htmlClass,
  175.                 <.div(
  176.                   ^.className := "form-group",
  177.                   <.input(
  178.                     ^.className := "form-control",
  179.                     ^.`type` := "text",
  180.                     ^.placeholder := "Name e.g: My company holidays schedule",
  181.                     ^.value := state.title.getOrElse(""),
  182.                     ^.onChange ==> setTitle
  183.                   )
  184.                 ),
  185.                 CustomDaysComponent(state.days)
  186.                 (removeDay, addDay),
  187.                 <.div(
  188.                   ^.className := ScheduleStyles.buttons.htmlClass,
  189.                   <.button(
  190.                     ^.`type` := "button",
  191.                     ^.className := "btn btn-default",
  192.                     ^.onClick ==> cancelSchedule,
  193.                     "Cancel"
  194.                   ),
  195.                   <.button(
  196.                     ^.`type` := "button",
  197.                     ^.className := "btn btn-success pull-right",
  198.                     ^.onClick ==> addSchedule,
  199.                     "Add"
  200.                   )
  201.                 )
  202.               )
  203.             ),
  204.             <.div(
  205.               ^.className := "col-md-4",
  206.               OfficialHolidaysComponent(addDay)
  207.             )
  208.           )
  209.         )
  210.       )
  211.   }
  212.  
  213.   def apply(state: ScheduleState) =
  214.     ScalaComponent.builder[Unit](this.getClass.getSimpleName)
  215.       .initialState(state)
  216.       .renderBackend[Backend]
  217.       .build
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement