Skip to content

Commit

Permalink
#17 [front] added add cell form
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Jan 23, 2024
1 parent 8061c85 commit c78dde5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/main/scala/ru/vityaman/mylogistics/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ object API {
dom.ext.Ajax
.get(s"${base}/storage/${id}/balance")
.map(xhr => read[List[Pack]](xhr.responseText))

def addCell(id: Int, atom: Atom): Future[Unit] =
dom.ext.Ajax
.post(
url = s"${base}/storage/${id}/cell",
data = write[Atom](atom)
)
.map(_ => ())
}

object ItemKind {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ru.vityaman.mylogistics.view

import ru.vityaman.mylogistics.API
import ru.vityaman.mylogistics.model.Atom

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util._

import com.raquo.laminar.api.L._
import org.scalajs.dom

object AddCellForm {
def apply(): HtmlElement = {
val storageId: Var[String] = Var("")
val itemKindId: Var[String] = Var("")
val amount: Var[String] = Var("")

val addCell = () => {
API.Storage
.addCell(
storageId.now().toInt,
Atom(
itemKindId.now().toInt,
amount.now().toInt
)
)
.onComplete {
case Failure(_) => dom.window.alert("Sad things happened... :.)")
case Success(_) => dom.window.alert("Added, yoyoyo!")
}
}

div(
display.flex,
flexDirection.row,
justifyContent.center,
div(
margin.percent(1),
a("Storage Id: "),
input(
onInput.mapToValue.filter(
_.forall(Character.isDigit)
) --> storageId
)
),
div(
margin.percent(1),
a("Item Kind Id: "),
input(
onInput.mapToValue.filter(
_.forall(Character.isDigit)
) --> itemKindId
)
),
div(
margin.percent(1),
a("Amount: "),
input(
onInput.mapToValue.filter(
_.forall(Character.isDigit)
) --> amount
)
),
div(
margin.percent(1),
button(typ("button"), "Add", onClick --> (_ => addCell()))
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ object Window {
h2("Storages"),
div(StorageList(storage.storages.signal))
),
div(
h2("Storage Cells"),
div(AddCellForm())
),
div(
h2("Capacity & Balance"),
div(CapacityList())
Expand Down

0 comments on commit c78dde5

Please sign in to comment.