Prechádzať zdrojové kódy

Added standardized module interface.

Thomas Flucke 5 rokov pred
rodič
commit
d764ebade6

+ 5 - 0
client/src/main/scala/com/weEat/modules/Module.scala

@@ -0,0 +1,5 @@
+package com.weEat.modules
+
+trait Module {
+  def render: scala.xml.Node
+}

+ 3 - 2
client/src/main/scala/com/weEat/modules/Overlay.scala

@@ -9,7 +9,7 @@ import scala.xml.Node
 case class Overlay(
   content: Rx[Node],
   cancelFn: Option[() => Unit] = None
-) {
+) extends Module {
   private val backgroundShade = {
     val div = document.createElement("div").asInstanceOf[HTMLDivElement]
     div.addEventListener("click", { e: MouseEvent =>
@@ -34,7 +34,8 @@ case class Overlay(
     </div>
   }
 
-  def selfDestruct(): Unit = backgroundShade.parentNode.removeChild(backgroundShade)
+  def selfDestruct(): Unit =
+    backgroundShade.parentNode.removeChild(backgroundShade)
 
   document.body.appendChild(backgroundShade)
   mount(backgroundShade, render)

+ 4 - 1
client/src/main/scala/com/weEat/modules/PageSelect.scala

@@ -2,7 +2,10 @@ package com.weEat.modules
 
 import mhtml.{Rx,Var}
 
-case class PageSelect(numPages: Rx[Int], revealedRadius: Rx[Int] = Rx(3)) {
+case class PageSelect(
+  numPages: Rx[Int],
+  revealedRadius: Rx[Int] = Rx(3)
+) extends Module {
   private val _page = Var[Int](1)
 
   // TODO: Add buttons for First/Last page

+ 7 - 8
client/src/main/scala/com/weEat/modules/PaginatedTable.scala

@@ -1,16 +1,15 @@
 package com.weEat.modules
 
-import scala.concurrent.duration._
 import scala.xml.Node
 import mhtml.Rx
 
-object PaginatedTable {
-  def apply[T](
-    structure: Seq[(String, Short, (T) => Rx[Node])],
-    tblData: Rx[Seq[T]],
-    page: Rx[Int] = Rx(0),
-    pageSize: Rx[Int] = Rx(10)
-  ) = {
+case class PaginatedTable[T](
+  structure: Seq[(String, Short, (T) => Rx[Node])],
+  tblData: Rx[Seq[T]],
+  page: Rx[Int] = Rx(0),
+  pageSize: Rx[Int] = Rx(10)
+) extends Module {
+  def render = {
     <table class="table table-striped table-hover">
       <thead>
         <tr>

+ 1 - 1
client/src/main/scala/com/weEat/modules/SearchBar.scala

@@ -18,7 +18,7 @@ case class SearchBar[T](
   searchFn: (String) => Future[T],
   minLength: Int = 3,
   delay: FiniteDuration = 500 milliseconds
-)(implicit val ec: ExecutionContext = ExecutionContext.global) {
+)(implicit val ec: ExecutionContext = ExecutionContext.global) extends Module {
 
   // TODO: Refactor these out into utility classes
   def setTimeoutResult[T](delay: FiniteDuration)(body: => T) = {

+ 1 - 1
client/src/main/scala/com/weEat/modules/Select.scala

@@ -4,7 +4,7 @@ import org.scalajs.dom.raw.Event
 import mhtml.Rx
 import com.weEat.util.MHtmlHelpers._
 
-case class Select[T](values: Rx[Seq[T]], defaul: Option[T] = None) {
+case class Select[T](values: Rx[Seq[T]], defaul: Option[T] = None) extends Module {
   private val (_select, _value) =
     (<select class="form-control input-sm">
       {

+ 1 - 1
client/src/main/scala/com/weEat/modules/USDAEditor.scala

@@ -13,7 +13,7 @@ import mhtml.Rx
 import mhtml.future.syntax._
 import com.weEat.util.MHtmlHelpers._
 
-case class USDAEditor(usda: USDANode, defaultOverNone: Boolean) {
+case class USDAEditor(usda: USDANode, defaultOverNone: Boolean) extends Module {
   implicit val ctx = scala.concurrent.ExecutionContext.global
 
   private val _mapPortionMeasure =

+ 1 - 1
client/src/main/scala/com/weEat/views/UsdaImporter.scala

@@ -77,7 +77,7 @@ object UsdaImporter extends View {
       ),
         searchResults,
         pageSel.page,
-        pageSizeSel.value)
+        pageSizeSel.value).render
     }
     { (pageSel.render).addClass("col-3 float-left") }
     { (pageSizeSel.render).addClass("col-1 float-right") }