Commit 96f90045 authored by Mathieu leclaire's avatar Mathieu leclaire

Refactor and remove scaladget dependency

parent 4dcd9577
package ui package client
import java.util.UUID
import org.scalajs.dom import org.scalajs.dom
import org.scalajs.dom.HTMLElement import org.scalajs.dom.HTMLElement
...@@ -13,11 +15,10 @@ import org.scalajs.dom.extensions.Ajax ...@@ -13,11 +15,10 @@ import org.scalajs.dom.extensions.Ajax
import scala.Some import scala.Some
import shared._ import shared._
import autowire._ import autowire._
import JsRxTags._
import fr.iscpif.scaladget.JsRxTags._
@JSExport @JSExport
object Plot { object Client {
val helloValue = Var(0) val helloValue = Var(0)
...@@ -43,6 +44,7 @@ object Post extends autowire.Client[Web] { ...@@ -43,6 +44,7 @@ object Post extends autowire.Client[Web] {
override def callRequest(req: Request): Future[String] = { override def callRequest(req: Request): Future[String] = {
val url = req.path.mkString("/") val url = req.path.mkString("/")
println(" URL " + url)
dom.extensions.Ajax.post( dom.extensions.Ajax.post(
url = "http://localhost:8080/" + url, url = "http://localhost:8080/" + url,
data = upickle.write(req.args) data = upickle.write(req.args)
......
/*
* Copyright (C) 21/07/14 mathieu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client
import scala.collection.{SortedMap, mutable}
import scalatags.JsDom._
import scala.util.{Failure, Success, Random}
import all._
import rx._
import rx.core.{Propagator, Obs}
import org.scalajs.dom
import org.scalajs.dom.{Element, DOMParser}
import scala.scalajs.js
/**
* A minimal binding between Scala.Rx and Scalatags and Scala-Js-Dom
*/
object JsRxTags {
/**
* Wraps reactive strings in spans, so they can be referenced/replaced
* when the Rx changes.
*/
implicit def RxStr[T](r: Rx[T])(implicit f: T => Modifier): Modifier = {
rxMod(Rx(span(r())))
}
/**
* Sticks some Rx into a Scalatags fragment, which means hooking up an Obs
* to propagate changes into the DOM via the element's ID. Monkey-patches
* the Obs onto the element itself so we have a reference to kill it when
* the element leaves the DOM (e.g. it gets deleted).
*/
implicit def rxMod[T <: dom.HTMLElement](r: Rx[HtmlTag]): Modifier = {
def rSafe = r.toTry match {
case Success(v) => v.render
case Failure(e) => span(e.toString, backgroundColor := "red").render
}
var last = rSafe
Obs(r, skipInitial = true) {
val newLast = rSafe
last.parentElement.replaceChild(newLast, last)
last = newLast
}
bindElement(last)
}
implicit def RxAttrValue[T: scalatags.JsDom.AttrValue] = new scalatags.JsDom.AttrValue[Rx[T]] {
def apply(t: Element, a: Attr, r: Rx[T]): Unit = {
Obs(r) {
implicitly[scalatags.JsDom.AttrValue[T]].apply(t, a, r())
}
}
}
implicit def RxStyleValue[T: scalatags.JsDom.StyleValue] = new scalatags.JsDom.StyleValue[Rx[T]] {
def apply(t: Element, s: Style, r: Rx[T]): Unit = {
Obs(r) {
implicitly[scalatags.JsDom.StyleValue[T]].apply(t, s, r())
}
}
}
}
...@@ -14,9 +14,9 @@ object ScalaTraJSTagsWireRxBuild extends Build { ...@@ -14,9 +14,9 @@ object ScalaTraJSTagsWireRxBuild extends Build {
lazy val shared = project.in(file("./shared")) lazy val shared = project.in(file("./shared"))
.settings(scalaVersion := ScalaVersion) .settings(scalaVersion := ScalaVersion)
lazy val ui = Project( lazy val client = Project(
"ui", "client",
file("./ui"), file("./client"),
settings = Defaults.defaultSettings ++ jsManagerSettings ++ Seq( settings = Defaults.defaultSettings ++ jsManagerSettings ++ Seq(
version := Version, version := Version,
scalaVersion := ScalaVersion, scalaVersion := ScalaVersion,
...@@ -26,7 +26,6 @@ object ScalaTraJSTagsWireRxBuild extends Build { ...@@ -26,7 +26,6 @@ object ScalaTraJSTagsWireRxBuild extends Build {
"com.lihaoyi" %%% "autowire" % "0.1.2", "com.lihaoyi" %%% "autowire" % "0.1.2",
"com.scalatags" %%% "scalatags" % "0.3.8", "com.scalatags" %%% "scalatags" % "0.3.8",
"com.scalarx" %%% "scalarx" % "0.2.5", "com.scalarx" %%% "scalarx" % "0.2.5",
"fr.iscpif" %%% "scaladget" % "0.1.0-SNAPSHOT",
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6", "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
"org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6" "org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6"
), ),
...@@ -38,7 +37,7 @@ object ScalaTraJSTagsWireRxBuild extends Build { ...@@ -38,7 +37,7 @@ object ScalaTraJSTagsWireRxBuild extends Build {
lazy val server = Project( lazy val server = Project(
"server", "server",
file("./server"), file("./server"),
settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ jsManagerSettings ++ Seq( settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ Seq(
organization := Organization, organization := Organization,
name := Name, name := Name,
version := Version, version := Version,
......
package fr.iscpif.app package fr.iscpif.app
import java.util.UUID
import org.scalatra._ import org.scalatra._
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
import autowire._ import autowire._
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment