Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ctilogic.cvd.web.client.react.component
- import com.ctilogic.cvd.web.client._
- import com.ctilogic.cvd.web.client.react.component.addschedule.{ScheduleState, RootComponent}
- import japgolly.scalajs.react._
- import japgolly.scalajs.react.extra.router.RouterCtl
- import japgolly.scalajs.react.vdom.VdomElement
- import japgolly.scalajs.react.vdom.html_<^._
- import scalacss.Defaults._
- object RootComponent {
- case class Props(url: LocationURL,
- router: RouterCtl[LocationURL])
- case class State(intentURL: Option[LocationURL])
- class Backend(backend: BackendScope[Props, State]) {
- private def menu(): VdomElement = {
- <.div(
- "menu + logo todo"
- )
- }
- private def content(props: Props): VdomElement = {
- val router = props.router
- props.url match {
- case DashboardURL =>
- <.div(
- DashboardComponent.component()
- )
- case AddScheduleURL =>
- <.div(
- addschedule.RootComponent(ScheduleState.dummy)()
- )
- }
- }
- def render(props: Props, state: State): VdomElement = {
- <.div(
- <.styleTag(
- RootStyles.render[String]
- ),
- <.div(
- ^.className := "navbar navbar-default",
- <.div(
- ^.className := "container",
- menu()
- )
- ),
- <.div(
- ^.className := RootStyles.rootContainer.htmlClass,
- <.div(
- ^.className := "row",
- <.div(
- ^.className := RootStyles.centeredContent.htmlClass,
- content(props)
- )
- )
- )
- )
- }
- }
- val component = ScalaComponent.builder[Props](this.getClass.getSimpleName)
- .initialState(State(None))
- .renderBackend[Backend]
- .build
- }
- ///////////////////
- //next file
- package com.ctilogic.cvd.web.client.react.component
- import com.ctilogic.cvd.web.client.AutowireClient
- import com.ctilogic.cvd.web.client.AutowireClient._
- import japgolly.scalajs.react._
- import japgolly.scalajs.react.vdom.VdomElement
- import japgolly.scalajs.react.vdom.html_<^._
- import model.Api
- object DashboardComponent {
- class Backend(bs: BackendScope[Unit, Unit]) {
- val testFileName = "testFile"
- // def createFile: Callback = {
- // Callback(AutowireClient[Api].createFile(testFileName, new Date(2017, 1, 1)).call().foreach {
- // unit =>
- // println("createFile message sent")
- // })
- // }
- //
- def searchFile: Callback = {
- Callback(AutowireClient[Api].searchFile(testFileName).call().foreach {
- unit =>
- println("searchFile message sent")
- })
- }
- def render(): VdomElement =
- <.div(
- // Button(Size.lg, Style.success, createFile, false)()("Create test file"),
- // Button(Size.lg, Style.success, searchFile, false)()("Search file")
- )
- }
- val component = ScalaComponent.builder[Unit](DashboardComponent.getClass.getSimpleName)
- .renderBackend[Backend]
- .build
- }
- ////////////////////
- // next file
- package com.ctilogic.cvd.web.client.react.component.addschedule
- import japgolly.scalajs.react._
- import japgolly.scalajs.react.vdom.VdomElement
- import japgolly.scalajs.react.vdom.html_<^._
- import model.DomainObjects.Holiday
- import scalacss.Defaults._
- object RootComponent {
- class Backend($: BackendScope[Unit, ScheduleState]) {
- def addDay(day: Holiday): Callback =
- $.modState(s => s.days.contains(day) match {
- case true => s
- case false => s.copy(days = s.days :+ day )
- })
- def setTitle(e: ReactEventFromInput): Callback =
- e.target.value match {
- case nonEmpty: String if nonEmpty.nonEmpty =>
- $.modState(_.copy(title = Option(nonEmpty)))
- case _ =>
- $.modState(_.copy(title = None))
- }
- def addSchedule(e: ReactMouseEvent): Callback = {
- //todo
- println("addSchedule")
- Callback.TODO
- }
- def cancelSchedule(e: ReactMouseEvent): Callback = {
- //todo
- println("cancelSchedule")
- Callback.TODO
- }
- def removeDay(day: Holiday): Callback =
- $.modState(s => s.copy(days = s.days.filterNot(_ == day)))
- def render(state: ScheduleState): VdomElement =
- <.div(
- <.styleTag(
- ScheduleStyles.render[String]
- ),
- <.div(
- <.div(
- ^.className := "row",
- <.div(
- ^.className := "col-md-8",
- <.div(
- ^.className := ScheduleStyles.editScheduler.htmlClass,
- <.div(
- ^.className := "form-group",
- <.input(
- ^.className := "form-control",
- ^.`type` := "text",
- ^.placeholder := "Name e.g: My company holidays schedule",
- ^.value := state.title.getOrElse(""),
- ^.onChange ==> setTitle
- )
- ),
- CustomDaysComponent(state.days)
- (removeDay, addDay),
- <.div(
- ^.className := ScheduleStyles.buttons.htmlClass,
- <.button(
- ^.`type` := "button",
- ^.className := "btn btn-default",
- ^.onClick ==> cancelSchedule,
- "Cancel"
- ),
- <.button(
- ^.`type` := "button",
- ^.className := "btn btn-success pull-right",
- ^.onClick ==> addSchedule,
- "Add"
- )
- )
- )
- ),
- <.div(
- ^.className := "col-md-4",
- OfficialHolidaysComponent(addDay)
- )
- )
- )
- )
- }
- def apply(state: ScheduleState) =
- ScalaComponent.builder[Unit](this.getClass.getSimpleName)
- .initialState(state)
- .renderBackend[Backend]
- .build
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement