feat: Adds update route to equipment info, reorganizes views.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import Elementary
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: Have form hold onto equipment info model to edit.
|
||||
struct EquipmentInfoForm: HTML, Sendable {
|
||||
|
||||
let dismiss: Bool
|
||||
let projectID: Project.ID
|
||||
let equipmentInfo: EquipmentInfo?
|
||||
|
||||
var staticPressure: String {
|
||||
guard let staticPressure = equipmentInfo?.staticPressure else {
|
||||
return "0.5"
|
||||
}
|
||||
return "\(staticPressure)"
|
||||
}
|
||||
|
||||
var heatingCFM: String {
|
||||
guard let heatingCFM = equipmentInfo?.heatingCFM else {
|
||||
return ""
|
||||
}
|
||||
return "\(heatingCFM)"
|
||||
}
|
||||
|
||||
var coolingCFM: String {
|
||||
guard let heatingCFM = equipmentInfo?.heatingCFM else {
|
||||
return ""
|
||||
}
|
||||
return "\(heatingCFM)"
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: "equipmentForm", dismiss: dismiss) {
|
||||
h1(.class("text-3xl font-bold pb-6 ps-2")) { "Equipment Info" }
|
||||
form(
|
||||
.class("space-y-4 p-4"),
|
||||
equipmentInfo != nil
|
||||
? .hx.patch(route: .project(.detail(projectID, .equipment(.index))))
|
||||
: .hx.post(route: .project(.detail(projectID, .equipment(.index)))),
|
||||
.hx.target("#equipmentInfo"),
|
||||
.hx.swap(.outerHTML)
|
||||
) {
|
||||
input(.class("hidden"), .name("projectID"), .value("\(projectID)"))
|
||||
|
||||
if let equipmentInfo {
|
||||
input(.class("hidden"), .name("id"), .value("\(equipmentInfo.id)"))
|
||||
}
|
||||
|
||||
div {
|
||||
label(.for("staticPressure")) { "Static Pressure" }
|
||||
Input(id: "staticPressure", placeholder: "Static pressure")
|
||||
.attributes(
|
||||
.type(.number), .value(staticPressure), .min("0"), .max("1.0"), .step("0.1")
|
||||
)
|
||||
}
|
||||
div {
|
||||
label(.for("heatingCFM")) { "Heating CFM" }
|
||||
Input(id: "heatingCFM", placeholder: "CFM")
|
||||
.attributes(.type(.number), .min("0"), .value(heatingCFM))
|
||||
}
|
||||
div {
|
||||
label(.for("coolingCFM")) { "Cooling CFM" }
|
||||
Input(id: "coolingCFM", placeholder: "CFM")
|
||||
.attributes(.type(.number), .min("0"), .value(coolingCFM))
|
||||
}
|
||||
Row {
|
||||
div {}
|
||||
div(.class("space-x-4")) {
|
||||
CancelButton()
|
||||
.attributes(
|
||||
.hx.get(
|
||||
route: .project(
|
||||
.detail(projectID, .equipment(.form(dismiss: true)))
|
||||
)
|
||||
),
|
||||
.hx.target("#equipmentForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
SubmitButton(title: "Save")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import Elementary
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
struct EquipmentInfoView: HTML, Sendable {
|
||||
let equipmentInfo: EquipmentInfo?
|
||||
var projectID: Project.ID
|
||||
|
||||
var body: some HTML {
|
||||
div(
|
||||
.class("space-y-4 border border-gray-200 rounded-lg shadow-lg p-4"),
|
||||
.id("equipmentInfo")
|
||||
) {
|
||||
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Equipment Info" }
|
||||
|
||||
if equipmentInfo != nil {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.hx.get(route: .project(.detail(projectID, .equipment(.form(dismiss: false))))),
|
||||
.hx.target("#equipmentForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if let equipmentInfo {
|
||||
|
||||
Row {
|
||||
Label { "Static Pressure" }
|
||||
Number(equipmentInfo.staticPressure)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
Row {
|
||||
Label { "Heating CFM" }
|
||||
Number(equipmentInfo.heatingCFM)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
Row {
|
||||
Label { "Cooling CFM" }
|
||||
Number(equipmentInfo.coolingCFM)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
EquipmentInfoForm(dismiss: true, projectID: projectID, equipmentInfo: nil)
|
||||
} else {
|
||||
EquipmentInfoForm(dismiss: false, projectID: projectID, equipmentInfo: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import Elementary
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: Have form hold onto equipment info model to edit.
|
||||
struct EquipmentForm: HTML, Sendable {
|
||||
|
||||
let dismiss: Bool
|
||||
let projectID: Project.ID
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: "equipmentForm", dismiss: dismiss) {
|
||||
h1(.class("text-3xl font-bold pb-6 ps-2")) { "Equipment Info" }
|
||||
form(.class("space-y-4 p-4")) {
|
||||
div {
|
||||
label(.for("staticPressure")) { "Static Pressure" }
|
||||
Input(id: "staticPressure", placeholder: "Static pressure")
|
||||
.attributes(
|
||||
.type(.number), .value("0.5"), .min("0"), .max("1.0"), .step("0.1")
|
||||
)
|
||||
}
|
||||
div {
|
||||
label(.for("heatingCFM")) { "Heating CFM" }
|
||||
Input(id: "heatingCFM", placeholder: "CFM")
|
||||
.attributes(.type(.number), .min("0"))
|
||||
}
|
||||
div {
|
||||
label(.for("coolingCFM")) { "Cooling CFM" }
|
||||
Input(id: "coolingCFM", placeholder: "CFM")
|
||||
.attributes(.type(.number), .min("0"))
|
||||
}
|
||||
Row {
|
||||
div {}
|
||||
div(.class("space-x-4")) {
|
||||
CancelButton()
|
||||
.attributes(
|
||||
.hx.get(
|
||||
route: .project(
|
||||
.detail(projectID, .frictionRate(.form(.equipmentInfo, dismiss: true)))
|
||||
)
|
||||
),
|
||||
.hx.target("#equipmentForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
SubmitButton(title: "Save")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import Elementary
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
struct EquipmentInfoView: HTML, Sendable {
|
||||
let equipmentInfo: EquipmentInfo
|
||||
var projectID: Project.ID { equipmentInfo.projectID }
|
||||
|
||||
var body: some HTML {
|
||||
div(.class("space-y-4 border border-gray-200 rounded-lg shadow-lg p-4")) {
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Equipment Info" }
|
||||
}
|
||||
|
||||
Row {
|
||||
Label { "Static Pressure" }
|
||||
Number(equipmentInfo.staticPressure)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
Row {
|
||||
Label { "Heating CFM" }
|
||||
Number(equipmentInfo.heatingCFM)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
Row {
|
||||
Label { "Cooling CFM" }
|
||||
Number(equipmentInfo.coolingCFM)
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
Row {
|
||||
div {}
|
||||
EditButton()
|
||||
.attributes(
|
||||
.hx.get(route: .project(.detail(projectID, .frictionRate(.form(.equipmentInfo))))),
|
||||
.hx.target("#equipmentForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
div(.id("equipmentForm")) {}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,14 @@ import Styleguide
|
||||
|
||||
struct FrictionRateView: HTML, Sendable {
|
||||
|
||||
let equipmentInfo: EquipmentInfo?
|
||||
let componentLosses: [ComponentPressureLoss]
|
||||
let projectID: Project.ID
|
||||
|
||||
var body: some HTML {
|
||||
div(.class("p-4 space-y-6")) {
|
||||
h1(.class("text-4xl font-bold pb-6")) { "Friction Rate" }
|
||||
EquipmentInfoView(equipmentInfo: EquipmentInfo.mock)
|
||||
EquipmentInfoView(equipmentInfo: equipmentInfo, projectID: projectID)
|
||||
ComponentPressureLossesView(
|
||||
componentPressureLosses: componentLosses, projectID: projectID
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ extension ProjectsTable {
|
||||
// if there are more pages left.
|
||||
if projects.metadata.pageCount > projects.metadata.page {
|
||||
tr(
|
||||
.hx.get(route: .project(.page(page: projects.metadata.page + 1, limit: 25))),
|
||||
.hx.get(route: .project(.page(.next(projects)))),
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.target("this"),
|
||||
|
||||
Reference in New Issue
Block a user