feat: Adds update route to equipment info, reorganizes views.

This commit is contained in:
2026-01-05 11:27:20 -05:00
parent 55a3adde25
commit fb7cf9905c
17 changed files with 357 additions and 121 deletions

View File

@@ -0,0 +1,42 @@
import Elementary
import ElementaryHTMX
import ManualDCore
import Styleguide
struct ComponentLossForm: HTML, Sendable {
let dismiss: Bool
let projectID: Project.ID
var body: some HTML {
ModalForm(id: "componentLossForm", dismiss: dismiss) {
h1(.class("text-2xl font-bold")) { "Component Loss" }
form(.class("space-y-4 p-4")) {
div {
label(.for("name")) { "Name" }
Input(id: "name", placeholder: "Name")
.attributes(.type(.text), .required, .autofocus)
}
div {
label(.for("value")) { "Value" }
Input(id: "name", placeholder: "Pressure loss")
.attributes(.type(.number), .min("0"), .max("1"), .step("0.1"), .required)
}
Row {
div {}
div {
CancelButton()
.attributes(
.hx.get(
route: .project(
.detail(projectID, .frictionRate(.form(.componentPressureLoss, dismiss: true))))
),
.hx.target("#componentLossForm"),
.hx.swap(.outerHTML)
)
SubmitButton()
}
}
}
}
}
}

View File

@@ -0,0 +1,55 @@
import Elementary
import ElementaryHTMX
import ManualDCore
import Styleguide
// TODO: Load component losses when view appears??
struct ComponentPressureLossesView: HTML, Sendable {
let componentPressureLosses: [ComponentPressureLoss]
let projectID: Project.ID
private var total: Double {
componentPressureLosses.reduce(into: 0) { $0 += $1.value }
}
var body: some HTML {
div(
.class(
"""
border border-gray-200 rounded-lg shadow-lg space-y-4 p-4
"""
)
) {
Row {
h1(.class("text-2xl font-bold")) { "Component Pressure Losses" }
PlusButton()
.attributes(
.hx.get(
route: .project(
.detail(projectID, .frictionRate(.form(.componentPressureLoss, dismiss: false))))
),
.hx.target("#componentLossForm"),
.hx.swap(.outerHTML)
)
}
for row in componentPressureLosses {
Row {
Label { row.name }
Number(row.value)
}
.attributes(.class("border-b border-gray-200"))
}
Row {
Label { "Total" }
Number(total)
.attributes(.class("text-xl font-bold"))
}
}
ComponentLossForm(dismiss: true, projectID: projectID)
}
}