aboutsummaryrefslogtreecommitdiff
path: root/mavigator-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'mavigator-server/src')
-rw-r--r--mavigator-server/src/main/resources/reference.conf (renamed from mavigator-server/src/main/resources/application.conf)0
-rw-r--r--mavigator-server/src/main/scala/mavigator/Router.scala49
-rw-r--r--mavigator-server/src/main/twirl/mavigator/views/app.scala.html27
-rw-r--r--mavigator-server/src/main/twirl/mavigator/views/dashboard.scala.html11
4 files changed, 43 insertions, 44 deletions
diff --git a/mavigator-server/src/main/resources/application.conf b/mavigator-server/src/main/resources/reference.conf
index 85d609b..85d609b 100644
--- a/mavigator-server/src/main/resources/application.conf
+++ b/mavigator-server/src/main/resources/reference.conf
diff --git a/mavigator-server/src/main/scala/mavigator/Router.scala b/mavigator-server/src/main/scala/mavigator/Router.scala
index c6740cc..07e40b0 100644
--- a/mavigator-server/src/main/scala/mavigator/Router.scala
+++ b/mavigator-server/src/main/scala/mavigator/Router.scala
@@ -19,25 +19,22 @@ import play.twirl.api.{ Xml, Txt, Html }
object Router {
import Directives._
+ val socketUrl = "ws://localhost:8080/mavlink"
+
def route(implicit system: ActorSystem): Route = (
- path("info") {
- get {
- val f: Html = mavigator.views.html.dashboard(
- "ws://localhost:8080/mavlink",
- 0,
- 0,
- 0
- )
- complete(f)
- }
- } ~
path("dashboard" / IntNumber) { id =>
get {
-
-
-
- //get dashboard for remote sys id
- ???
+ val html = mavigator.views.html.app(
+ "Mavigator",
+ "mavigator_dashboard_Main",
+ Map(
+ "socketUrl" -> socketUrl,
+ "remoteSystemId" -> "0",
+ "systemId" -> "0",
+ "componentId" -> "0"
+ )
+ )
+ complete(html)
}
} ~
path("mavlink") {
@@ -64,16 +61,20 @@ object Router {
} ~
pathEndOrSingleSlash {
get {
- complete("hello world")
+ val html = mavigator.views.html.app(
+ "Index",
+ "mavigator_index_Main",
+ Map(
+ "socketUrl" -> socketUrl
+ )
+ )
+ complete(html)
}
}
)
- /** Serialize Twirl `Html` to `text/html`. */
- implicit val twirlHtmlMarshaller = twirlMarshaller[Html](`text/html`)
-
- /** Serialize Twirl formats to `String`. */
- def twirlMarshaller[A <: AnyRef: Manifest](contentType: MediaType): ToEntityMarshaller[A] =
- Marshaller.StringMarshaller.wrap(contentType)(_.toString)
-
+ implicit val twirlHtml : ToEntityMarshaller[Html] = Marshaller.StringMarshaller.wrap(`text/html`){(h: Html) =>
+ h.toString
+ }
+
}
diff --git a/mavigator-server/src/main/twirl/mavigator/views/app.scala.html b/mavigator-server/src/main/twirl/mavigator/views/app.scala.html
index 00459a9..34d1fde 100644
--- a/mavigator-server/src/main/twirl/mavigator/views/app.scala.html
+++ b/mavigator-server/src/main/twirl/mavigator/views/app.scala.html
@@ -1,11 +1,16 @@
-@(appId: String)(args: (String, String)*)
+@(title: String, appId: String, args: Map[String, String])
+
+@*
+* Provides the environment and loads a scalajs application.
+*@
+
+@main(title){
<div id="scalajs-error" class="alert alert-danger" style="display: none;">
<p><strong><i class="fa fa-bug"></i> Error! </strong> An uncaught exception occurred in the browser application,
any information displayed on this website may be corrupt. This is NOT an error that should occur under normal
operation, it is an indication of a bug in the software.</p>
- <p>The error was: "<span id="scalajs-error-message"></span>"
- </p>
+ <p>The error was: "<span id="scalajs-error-message"></span>"</p>
</div>
<div id="@appId">
@@ -17,28 +22,32 @@
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
try {
+ //root element that will contain the ScalaJS application
var root0 = document.getElementById("@appId");
+ //clear any existing content
while (root0.firstChild) {
root0.removeChild(root0.firstChild);
}
+ //run ScalaJS application
@{appId}().start({
root: root0,
assetsBase: "/assets",
- args: @args.map{ case (key, value) =>
+ args: {@args.map{ case (key, value) =>
@key: "@value",
- }
+ }}
});
- } catch(err) {
+ } catch(ex) {
+ //display warning message in case of exception
document.getElementById("scalajs-error").style.display = "block";
- document.getElementById("scalajs-error-message").innerHTML = err;
- console.error(err);
- throw err;
+ document.getElementById("scalajs-error-message").innerHTML = ex;
+ throw ex;
}
});
</script>
<script type="text/javascript" src="/assets/js/mavigator-dashboard-opt.js"></script>
+}
diff --git a/mavigator-server/src/main/twirl/mavigator/views/dashboard.scala.html b/mavigator-server/src/main/twirl/mavigator/views/dashboard.scala.html
deleted file mode 100644
index 2b08797..0000000
--- a/mavigator-server/src/main/twirl/mavigator/views/dashboard.scala.html
+++ /dev/null
@@ -1,11 +0,0 @@
-@(socket: String, remoteSystemId: Byte, systemId: Byte, componentId: Byte)
-
-@main("Main"){
- @app("mavigator_dashboard_Main")(
- "socketUrl" -> socket,
- "remoteSystemId" -> remoteSystemId.toString,
- "systemId" -> systemId.toString,
- "componentId" -> componentId.toString
- )
-}
-