diff options
Diffstat (limited to 'mavigator-cockpit/src/main/scala/mavigator/index')
3 files changed, 46 insertions, 34 deletions
diff --git a/mavigator-cockpit/src/main/scala/mavigator/index/ActiveVehicle.scala b/mavigator-cockpit/src/main/scala/mavigator/index/ActiveVehicle.scala index 870d3be..7e59ed8 100644 --- a/mavigator-cockpit/src/main/scala/mavigator/index/ActiveVehicle.scala +++ b/mavigator-cockpit/src/main/scala/mavigator/index/ActiveVehicle.scala @@ -13,7 +13,8 @@ object ActiveVehicle { id, vehicleType(hb.`type`), autopilot(hb.autopilot), - state(hb.systemStatus)) + state(hb.systemStatus) + ) def vehicleType(tpe: Int) = tpe match { case MavType.MavTypeGeneric => "Generic" diff --git a/mavigator-cockpit/src/main/scala/mavigator/index/Main.scala b/mavigator-cockpit/src/main/scala/mavigator/index/Main.scala index 7724f89..452d517 100644 --- a/mavigator-cockpit/src/main/scala/mavigator/index/Main.scala +++ b/mavigator-cockpit/src/main/scala/mavigator/index/Main.scala @@ -5,7 +5,6 @@ import scala.scalajs.js.annotation.JSExport import org.scalajs.dom.html -import mavigator.dashboard.ui.Layout import mavigator.util.Environment import mavigator.util.Application @@ -29,16 +28,17 @@ object Main extends Application { val parser = new Parser( packet => { val m: Message = Message.unpack(packet.messageId, packet.payload) - println(m) m match { case hb: Heartbeat => - active() += ActiveVehicle.fromHeartbeat(packet.systemId, hb) + active() = active.now + ActiveVehicle.fromHeartbeat(packet.systemId, hb) case _ => () } } ) override def main(args: Map[String, String])(implicit env: Environment): Unit = { + import rx.Ctx.Owner.Unsafe._ + val root = env.root val connection = new dom.WebSocket(args("socketUrl")) @@ -64,34 +64,45 @@ object Main extends Application { } - root.appendChild(div( - table(`class` := "table table-hover")( - thead( - tr( - th("System ID"), - th("Type"), - th("Autopilot"), - th("State"), - th("") - ) - ), - Rx { - tbody( - for (vehicle <- active().toSeq) yield { - tr( - td(vehicle.systemId), - td(vehicle.vehicleType), - td(vehicle.autopilot), - td(vehicle.state), - td(a(href := "/dashboard/" + vehicle.systemId, `class` := "btn btn-default")("Pilot")) - ) - } + val elem = + div(`class` := "container")( + div(`class` := "col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3")( + div(`class` := "panel panel-default")( + div(`class` := "panel-heading")( + h3(`class` := "panel-title")("Available vehicles") + ), + div(`class` := "panel-body")( + table(`class` := "table table-hover")( + thead( + tr( + th("System ID"), + th("Type"), + th("Autopilot"), + th("State"), + th("") + ) + ), + Rx { + tbody( + for (vehicle <- active().toSeq) yield { + tr( + td(vehicle.systemId), + td(vehicle.vehicleType), + td(vehicle.autopilot), + td(vehicle.state), + td(a(href := "/cockpit/" + vehicle.systemId, `class` := "btn btn-default")("Pilot")) + ) + } + ) + } + ), + p(i(`class`:="fa fa-spinner fa-spin")(), " Listening for heartbeats...") + ) ) - } - ), - i(`class`:="fa fa-spinner fa-spin")(), - " Listening for heartbeats..." - ).render) + ) + ).render + + root.appendChild(elem) } } diff --git a/mavigator-cockpit/src/main/scala/mavigator/index/Util.scala b/mavigator-cockpit/src/main/scala/mavigator/index/Util.scala index 16f3d5d..2671f2f 100644 --- a/mavigator-cockpit/src/main/scala/mavigator/index/Util.scala +++ b/mavigator-cockpit/src/main/scala/mavigator/index/Util.scala @@ -13,7 +13,7 @@ import scala.util.Failure import scalatags.JsDom.all._ object Util { - + /** * Copied from https://github.com/lihaoyi/workbench-example-app/blob/todomvc/src/main/scala/example/Framework.scala * @@ -22,13 +22,13 @@ object Util { * 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 <: html.Element](r: Rx[HtmlTag]): Frag = { + implicit def rxMod(r: Rx[HtmlTag])(implicit owner: Ctx.Owner): Frag = { 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) { + r.triggerLater{ val newLast = rSafe last.parentElement.replaceChild(newLast, last) last = newLast |