|
@ -7,6 +7,9 @@ import scalafx.scene.Node |
|
|
import scalafx.Includes._ |
|
|
import scalafx.Includes._ |
|
|
import scalafx.scene.Parent |
|
|
import scalafx.scene.Parent |
|
|
import scalafx.application.JFXApp.PrimaryStage |
|
|
import scalafx.application.JFXApp.PrimaryStage |
|
|
|
|
|
import nova.monadic_sfx.http.requests.DummyRequest |
|
|
|
|
|
import monix.eval.Task |
|
|
|
|
|
import monix.execution.Scheduler |
|
|
// import io.odin.syntax._ |
|
|
// import io.odin.syntax._ |
|
|
// import _root_.monix.eval.Task |
|
|
// import _root_.monix.eval.Task |
|
|
// import io.odin.monix._ |
|
|
// import io.odin.monix._ |
|
@ -18,33 +21,75 @@ class LoginPage( |
|
|
system: akka.actor.ActorSystem |
|
|
system: akka.actor.ActorSystem |
|
|
) { |
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
val dummyRequester = new DummyRequest(backend) |
|
|
|
|
|
|
|
|
//pure function callbacks, but with side effects still |
|
|
//pure function callbacks, but with side effects still |
|
|
private def onLogout(stage: PrimaryStage) = { |
|
|
|
|
|
println("logging out") |
|
|
|
|
|
stage.scene().setRoot(render) |
|
|
|
|
|
} |
|
|
|
|
|
private def onLogin(stage: PrimaryStage) = { |
|
|
|
|
|
println("logging in") |
|
|
|
|
|
|
|
|
private def onLogout(stage: PrimaryStage) = |
|
|
|
|
|
for { |
|
|
|
|
|
_ <- Task { println("logging out") } |
|
|
|
|
|
root <- render |
|
|
|
|
|
_ <- Task(stage.scene().setRoot(root)) |
|
|
|
|
|
} yield () |
|
|
|
|
|
|
|
|
|
|
|
private def onLogin(stage: PrimaryStage) = |
|
|
|
|
|
Task.deferAction { implicit Scheduler => |
|
|
|
|
|
for { |
|
|
|
|
|
_ <- Task(println("logging in")) |
|
|
|
|
|
root <- Task { |
|
|
stage |
|
|
stage |
|
|
.scene() |
|
|
.scene() |
|
|
.setRoot(HomePage(backend, system, () => onLogout(appStage))) |
|
|
|
|
|
|
|
|
.setRoot( |
|
|
|
|
|
HomePage( |
|
|
|
|
|
backend, |
|
|
|
|
|
system, |
|
|
|
|
|
() => runFxTask(onLogout(appStage)) |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} yield () |
|
|
} |
|
|
} |
|
|
private lazy val root = new VBox { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lazy val root = Task.deferAction(implicit scheduler => |
|
|
|
|
|
Task { |
|
|
|
|
|
new VBox { |
|
|
children = Seq( |
|
|
children = Seq( |
|
|
new TextField { |
|
|
|
|
|
|
|
|
new Label { |
|
|
text = "username" |
|
|
text = "username" |
|
|
editable = true |
|
|
|
|
|
}, |
|
|
}, |
|
|
new TextField { |
|
|
|
|
|
|
|
|
new TextField(), |
|
|
|
|
|
new Label { |
|
|
text = "password" |
|
|
text = "password" |
|
|
}, |
|
|
}, |
|
|
|
|
|
new TextField(), |
|
|
new Button { |
|
|
new Button { |
|
|
text = "Login" |
|
|
text = "Login" |
|
|
onAction = () => onLogin(appStage) |
|
|
|
|
|
|
|
|
onAction = () => |
|
|
|
|
|
runFxTask { |
|
|
|
|
|
Task |
|
|
|
|
|
.parZip2( |
|
|
|
|
|
dummyRequester |
|
|
|
|
|
.send(), |
|
|
|
|
|
// .executeOn(Scheduler.global) |
|
|
|
|
|
onLogin(appStage) |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
def render: Task[Parent] = root |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Implicitly runs monix task as fire and forget. \ |
|
|
|
|
|
* For use in ScalaFX callbacks. |
|
|
|
|
|
* |
|
|
|
|
|
* @param task |
|
|
|
|
|
* @param s |
|
|
|
|
|
*/ |
|
|
|
|
|
def runFxTask[T](task: => Task[T])(implicit s: Scheduler) = { |
|
|
|
|
|
task.runAsyncAndForget |
|
|
} |
|
|
} |
|
|
def render: Parent = root |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|