WIP: Begin cleaning up duct sizing routes.

This commit is contained in:
2026-01-13 17:01:44 -05:00
parent 930db145a8
commit f990c4b6db
13 changed files with 634 additions and 30 deletions

View File

@@ -3,14 +3,22 @@ import ElementaryHTMX
import ManualDCore
import Styleguide
// TODO: Add error text if prior steps are not completed.
// TODO: Add trunk size table.
struct DuctSizingView: HTML, Sendable {
@Environment(ProjectViewValue.$projectID) var projectID
// let projectID: Project.ID
let rooms: [DuctSizing.RoomContainer]
let trunks: [DuctSizing.TrunkContainer]
var supplyTrunks: [DuctSizing.TrunkContainer] {
trunks.filter { $0.trunk.type == .supply }
}
var returnTrunks: [DuctSizing.TrunkContainer] {
trunks.filter { $0.trunk.type == .return }
}
var body: some HTML {
div(.class("space-y-4")) {
@@ -22,6 +30,31 @@ struct DuctSizingView: HTML, Sendable {
} else {
RoomsTable(projectID: projectID, rooms: rooms)
}
Row {
h2(.class("text-2xl font-bold")) { "Trunk Sizes" }
PlusButton()
.attributes(
.class("me-6"),
.showModal(id: TrunkSizeForm.id())
)
}
.attributes(.class("mt-6"))
div(.class("divider -mt-2")) {}
if supplyTrunks.count > 0 {
h2(.class("text-lg font-bold text-info")) { "Supply Trunks" }
TrunkTable(trunks: supplyTrunks, rooms: rooms)
}
if returnTrunks.count > 0 {
h2(.class("text-lg font-bold text-error")) { "Return Trunks" }
TrunkTable(trunks: returnTrunks, rooms: rooms)
}
TrunkSizeForm(rooms: rooms, dismiss: true)
}
}
@@ -90,8 +123,8 @@ struct DuctSizingView: HTML, Sendable {
.attributes(.class("badge-secondary"))
}
td {
Number(room.flexSize)
.attributes(.class("badge badge-outline badge-primary text-xl font-bold"))
Badge(number: room.flexSize)
.attributes(.class("badge-primary"))
}
td {
if let width = room.rectangularWidth {
@@ -141,6 +174,122 @@ struct DuctSizingView: HTML, Sendable {
}
}
}
struct TrunkTable: HTML, Sendable {
let trunks: [DuctSizing.TrunkContainer]
let rooms: [DuctSizing.RoomContainer]
var body: some HTML {
div(.class("overflow-x-auto")) {
table(.class("table table-zebra text-lg")) {
thead {
tr(.class("text-lg")) {
th { "Associated Supplies" }
th { "Dsn CFM" }
th { "Round Size" }
th { "Velocity" }
th { "Final Size" }
th { "Flex Size" }
th { "Width" }
th { "Height" }
}
}
tbody {
for trunk in trunks {
tr {
td(.class("space-x-2")) {
// div(.class("flex flex-wrap space-x-2 max-w-1/3")) {
for id in registerIDS(trunk.trunk) {
Badge { id }
}
// }
}
td {
Number(trunk.ductSize.designCFM.value, digits: 0)
}
td {
Number(trunk.ductSize.roundSize, digits: 1)
}
td {
Number(trunk.ductSize.velocity)
}
td {
Badge(number: trunk.ductSize.finalSize)
.attributes(.class("badge-secondary"))
}
td {
Badge(number: trunk.ductSize.flexSize)
.attributes(.class("badge-primary"))
}
td {
if let width = trunk.ductSize.width {
Number(width)
}
}
td {
div(.class("flex justify-between items-center space-x-4")) {
div {
if let height = trunk.ductSize.height {
Number(height)
}
}
div {
div(.class("join")) {
TrashButton()
.attributes(.class("join-item btn-ghost"))
.attributes(
// .hx.delete(
// route: .project(
// .detail(
// projectID,
// .ductSizing(
// .deleteRectangularSize(
// room.roomID,
// room.rectangularSize?.id ?? .init())
// )
// )
// )
// ),
.hx.target("closest tr"),
.hx.swap(.outerHTML)
// when: room.rectangularSize != nil
)
EditButton()
.attributes(
.class("join-item btn-ghost"),
// .showModal(id: RectangularSizeForm.id(room))
)
}
}
}
// FIX: Add Trunk form.
}
}
}
}
}
}
}
func registerIDS(_ trunk: DuctSizing.TrunkSize) -> [String] {
trunk.rooms.reduce(into: []) { array, room in
array = room.registers.reduce(into: array) { array, register in
if let room =
rooms
.first(where: { $0.roomID == room.id && $0.roomRegister == register })
{
array.append(room.registerID)
}
}
}
.sorted()
}
}
}
extension DuctSizing.DesignCFM {

View File

@@ -0,0 +1,77 @@
import Elementary
import ElementaryHTMX
import ManualDCore
import Styleguide
struct TrunkSizeForm: HTML, Sendable {
static func id() -> String {
"trunkSizeForm"
}
@Environment(ProjectViewValue.$projectID) var projectID
let rooms: [DuctSizing.RoomContainer]
let dismiss: Bool
var route: String {
SiteRoute.View.router
.path(for: .project(.detail(projectID, .ductSizing(.index))))
.appendingPath(SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkRoute.rootPath)
}
var body: some HTML {
ModalForm(id: Self.id(), dismiss: dismiss) {
h1(.class("text-lg font-bold mb-4")) { "Trunk Size" }
form(
.class("space-y-4"),
.hx.post(route),
.hx.target("body"),
.hx.swap(.outerHTML)
) {
input(.class("hidden"), .name("projectID"), .value(projectID))
div(.class("grid grid-cols-1 md:grid-cols-2 gap-4")) {
label(.class("select w-full")) {
span(.class("label")) { "Type" }
select(.name("type")) {
for type in DuctSizing.TrunkSize.TrunkType.allCases {
option(.value(type.rawValue)) { type.rawValue.capitalized }
}
}
}
LabeledInput(
"Height",
.type(.text),
.name("height"),
.placeholder("8 (Optional)"),
)
}
// Add room select here.
div(.class("grid grid-cols-5 gap-6")) {
h2(.class("label font-bold col-span-5")) { "Associated Supply Runs" }
for room in rooms {
div(.class("flex justify-center items-center col-span-1")) {
div(.class("space-y-1")) {
p(.class("label block")) { room.registerID }
input(
.class("checkbox"),
.type(.checkbox),
.name("rooms"),
.value("\(room.roomID)_\(room.roomRegister)")
)
}
}
}
}
SubmitButton()
.attributes(.class("btn-block"))
}
}
}
}