feat: Adds update and delete routes to room.

This commit is contained in:
2026-01-05 15:59:23 -05:00
parent fb7cf9905c
commit 4c8a23be94
17 changed files with 366 additions and 125 deletions

View File

@@ -10,34 +10,48 @@ struct RoomForm: HTML, Sendable {
let dismiss: Bool
let projectID: Project.ID
let room: Room?
var body: some HTML {
ModalForm(id: "roomForm", dismiss: dismiss) {
h1(.class("text-3xl font-bold pb-6")) { "Room" }
// TODO: Use htmx here.
form(
.method(.post),
.action(route: .project(.detail(projectID, .rooms(.index))))
room == nil
? .hx.post(route: .project(.detail(projectID, .rooms(.index))))
: .hx.patch(route: .project(.detail(projectID, .rooms(.index)))),
.hx.target("body"),
.hx.swap(.outerHTML)
) {
input(.class("hidden"), .name("projectID"), .value("\(projectID)"))
if let id = room?.id {
input(.class("hidden"), .name("id"), .value("\(id)"))
}
div {
label(.for("name")) { "Name:" }
Input(id: "name", placeholder: "Room Name")
.attributes(.type(.text), .required, .autofocus)
.attributes(.type(.text), .required, .autofocus, .value(room?.name))
}
div {
label(.for("heatingLoad")) { "Heating Load:" }
Input(id: "heatingLoad", placeholder: "Heating Load")
.attributes(.type(.number), .required, .min("0"))
.attributes(.type(.number), .required, .min("0"), .value(room?.heatingLoad))
}
div {
label(.for("coolingLoad")) { "Cooling Load:" }
Input(id: "coolingLoad", placeholder: "Cooling Load")
.attributes(.type(.number), .required, .min("0"))
.attributes(.type(.number), .required, .min("0"), .value(room?.coolingLoad))
}
div {
label(.for("registerCount")) { "Registers:" }
Input(id: "registerCount", placeholder: "Register Count")
.attributes(.type(.number), .required, .value("1"), .min("1"))
.attributes(
.type(.number), .required, .min("0"),
.value("\(room != nil ? room!.registerCount : 1)"),
)
}
Row {
// Force button to the right, probably a better way.

View File

@@ -39,23 +39,13 @@ struct RoomsView: HTML, Sendable {
th { Label("Heating Load") }
th { Label("Cooling Total") }
th { Label("Register Count") }
th {}
}
}
tbody {
for room in rooms {
tr {
td { room.name }
td {
Number(room.heatingLoad)
.attributes(.class("text-error"))
}
td {
Number(room.coolingLoad)
.attributes(.class("text-success"))
}
td {
Number(room.registerCount)
}
div(.id("rooms")) {
for room in rooms {
RoomRow(room: room)
}
}
// TOTALS
@@ -75,7 +65,48 @@ struct RoomsView: HTML, Sendable {
}
}
}
RoomForm(dismiss: true, projectID: projectID)
RoomForm(dismiss: true, projectID: projectID, room: nil)
}
}
public struct RoomRow: HTML, Sendable {
let room: Room
public var body: some HTML {
tr(.id("\(room.id)")) {
td { room.name }
td {
Number(room.heatingLoad)
.attributes(.class("text-error"))
}
td {
Number(room.coolingLoad)
.attributes(.class("text-success"))
}
td {
Number(room.registerCount)
}
td {
Row {
TrashButton()
.attributes(
.hx.delete(route: .project(.detail(room.projectID, .rooms(.delete(id: room.id))))),
.hx.target("closest tr"),
.hx.confirm("Are you sure?")
)
EditButton()
.attributes(
.hx.get(
route: .project(
.detail(room.projectID, .rooms(.form(id: room.id, dismiss: false)))
)
),
.hx.target("#roomForm"),
.hx.swap(.outerHTML)
)
}
}
}
}
}