feat: Adds manual-d group pdf while working on better picker for groups, fixes issues with trunk table not always rendering properly with certain themes.

This commit is contained in:
2026-01-14 16:53:05 -05:00
parent 450791b37e
commit b5d1f87380
18 changed files with 441 additions and 275 deletions

View File

@@ -16,12 +16,22 @@ extension Room {
extension DuctSizing.TrunkSize.RoomProxy {
// We need to make sure if registers got removed after a trunk
// was already made / saved that we do not include registers that
// no longer exist.
private var actualRegisterCount: Int {
guard registers.count <= room.registerCount else {
return room.registerCount
}
return registers.count
}
var totalHeatingLoad: Double {
room.heatingLoadPerRegister * Double(registers.count)
room.heatingLoadPerRegister * Double(actualRegisterCount)
}
func totalCoolingSensible(projectSHR: Double) -> Double {
room.coolingSensiblePerRegister(projectSHR: projectSHR) * Double(registers.count)
room.coolingSensiblePerRegister(projectSHR: projectSHR) * Double(actualRegisterCount)
}
}
@@ -54,6 +64,8 @@ func roundSize(_ size: Double) throws -> Int {
throw ManualDError(message: "Size should be less than 24.")
}
// let size = size.rounded(.toNearestOrEven)
switch size {
case 0..<4:
return 4

View File

@@ -128,6 +128,7 @@ extension DuctSizing {
// Represents the database model that the duct sizes have been calculated
// for.
@dynamicMemberLookup
public struct TrunkContainer: Codable, Equatable, Identifiable, Sendable {
public var id: TrunkSize.ID { trunk.id }
@@ -141,6 +142,14 @@ extension DuctSizing {
self.trunk = trunk
self.ductSize = ductSize
}
public subscript<T>(dynamicMember keyPath: KeyPath<DuctSizing.TrunkSize, T>) -> T {
trunk[keyPath: keyPath]
}
public subscript<T>(dynamicMember keyPath: KeyPath<DuctSizing.SizeContainer, T>) -> T {
ductSize[keyPath: keyPath]
}
}
// Represents the database model.

View File

@@ -20,5 +20,6 @@ extension String {
var idString: Self {
replacing("-", with: "")
.replacing(" ", with: "")
}
}

View File

@@ -13,8 +13,16 @@ extension ViewController.Request {
switch route {
case .test:
let projectID = UUID(uuidString: "A9C20153-E2E5-4C65-B33F-4D8A29C63A7A")!
return await view {
TestPage()
await ResultView {
return (
try await database.projects.getCompletedSteps(projectID),
try await database.calculateDuctSizes(projectID: projectID)
)
} onSuccess: { (_, result) in
TestPage(trunks: result.trunks, rooms: result.rooms)
}
}
case .login(let route):
switch route {

View File

@@ -24,31 +24,28 @@ struct ComponentPressureLossesView: HTML, Sendable {
}
.attributes(.class("px-4"))
div(.class("overflow-x-auto")) {
table(.class("table table-zebra")) {
thead {
tr(.class("text-xl font-bold")) {
th { "Name" }
th { "Value" }
th {
div(.class("flex justify-end mx-auto")) {
Tooltip("Add Component Loss") {
PlusButton()
.attributes(
.class("btn-ghost text-2xl me-2"),
.showModal(id: ComponentLossForm.id())
)
}
table(.class("table table-zebra")) {
thead {
tr(.class("text-xl font-bold")) {
th { "Name" }
th { "Value" }
th {
div(.class("flex justify-end mx-auto")) {
Tooltip("Add Component Loss") {
PlusButton()
.attributes(
.class("btn-ghost text-2xl me-2"),
.showModal(id: ComponentLossForm.id())
)
}
}
}
}
tbody {
for row in componentPressureLosses {
TableRow(row: row)
}
}
tbody {
for row in componentPressureLosses {
TableRow(row: row)
}
}
}
}

View File

@@ -12,23 +12,17 @@ struct DuctSizingView: HTML, Sendable {
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")) {
PageTitle { "Duct Sizes" }
if rooms.count == 0 {
p(.class("text-error italic")) {
"Must complete all the previous sections to display duct sizing calculations."
}
} else {
RoomsTable(rooms: rooms)
div(.class("divider mb-6")) {}
}
Row {
@@ -40,150 +34,14 @@ struct DuctSizingView: HTML, Sendable {
.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)
if trunks.count > 0 {
div(.class("divider -mt-2")) {}
TrunkTable(trunks: trunks, rooms: rooms)
}
TrunkSizeForm(rooms: rooms, dismiss: true)
}
}
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 {
TrunkRow(trunk: trunk, rooms: rooms)
}
}
}
}
}
}
struct TrunkRow: HTML, Sendable {
@Environment(ProjectViewValue.$projectID) var projectID
let trunk: DuctSizing.TrunkContainer
let rooms: [DuctSizing.RoomContainer]
var body: some HTML<HTMLTag.tr> {
tr {
td(.class("space-x-2")) {
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: deleteRoute),
.hx.target("closest tr"),
.hx.swap(.outerHTML)
)
EditButton()
.attributes(
.class("join-item btn-ghost"),
.showModal(id: TrunkSizeForm.id(trunk))
)
}
}
}
TrunkSizeForm(trunk: trunk, rooms: rooms, dismiss: true)
}
}
}
private var deleteRoute: SiteRoute.View {
.project(.detail(projectID, .ductSizing(.trunk(.delete(trunk.id)))))
}
private 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 {
var color: String {
switch self {
case .heating: return "error"
case .cooling: return "info"
}
}
}

View File

@@ -11,24 +11,22 @@ extension DuctSizingView {
let rooms: [DuctSizing.RoomContainer]
var body: some HTML<HTMLTag.div> {
div(.class("overflow-x-auto")) {
var body: some HTML<HTMLTag.table> {
table(.class("table table-zebra")) {
thead {
tr(.class("text-xl text-gray-400 font-bold")) {
th { "ID" }
th { "Name" }
th { "BTU" }
th { "CFM" }
th { "Velocity" }
th { "Size" }
}
table(.class("table table-zebra text-lg")) {
thead {
tr(.class("text-lg")) {
th { "ID" }
th { "Name" }
th { "BTU" }
th { "CFM" }
th { "Velocity" }
th { "Size" }
}
tbody {
for room in rooms {
RoomRow(room: room)
}
}
tbody {
for room in rooms {
RoomRow(room: room)
}
}
}
@@ -66,7 +64,7 @@ extension DuctSizingView {
var rowID: String { Self.id(room) }
var body: some HTML<HTMLTag.tr> {
tr(.class("text-lg items-baseline"), .id(rowID)) {
tr(.class("text-lg"), .id(rowID)) {
td { room.registerID }
td { room.roomName }
td {
@@ -107,7 +105,7 @@ extension DuctSizingView {
div(.class("label")) { "Calculated" }
div(.class("flex justify-center")) {
Badge(number: room.roundSize, digits: 1)
Badge(number: room.roundSize, digits: 2)
}
div {}

View File

@@ -0,0 +1,139 @@
import Elementary
import ElementaryHTMX
import ManualDCore
import Styleguide
extension DuctSizingView {
struct TrunkTable: HTML, Sendable {
let trunks: [DuctSizing.TrunkContainer]
let rooms: [DuctSizing.RoomContainer]
private var sortedTrunks: [DuctSizing.TrunkContainer] {
trunks.sorted(by: { $0.type.rawValue > $1.type.rawValue })
}
var body: some HTML {
table(.class("table table-zebra text-lg")) {
thead {
tr(.class("text-lg")) {
th { "Type" }
th { "Associated Supplies" }
th { "Dsn CFM" }
th { "Velocity" }
th { "Size" }
}
}
tbody {
for trunk in sortedTrunks {
TrunkRow(trunk: trunk, rooms: rooms)
}
}
}
}
}
struct TrunkRow: HTML, Sendable {
@Environment(ProjectViewValue.$projectID) var projectID
let trunk: DuctSizing.TrunkContainer
let rooms: [DuctSizing.RoomContainer]
var body: some HTML<HTMLTag.tr> {
tr {
td {
Badge {
trunk.trunk.type.rawValue
}
.attributes(.class("badge-info"), when: trunk.type == .supply)
.attributes(.class("badge-error"), when: trunk.type == .return)
}
td(.class("space-x-2")) {
for id in registerIDS {
Badge { id }
}
}
td {
Number(trunk.designCFM.value, digits: 0)
}
td {
Number(trunk.velocity)
}
td {
div(.class("grid grid-cols-3 gap-4")) {
div(.class("label")) { "Calculated" }
div(.class("flex justify-center")) {
Badge(number: trunk.roundSize, digits: 1)
}
div {}
div(.class("label")) { "Final" }
div(.class("flex justify-center")) {
Badge(number: trunk.finalSize)
.attributes(.class("badge-secondary"))
}
div {}
div(.class("label")) { "Flex" }
div(.class("flex justify-center")) {
Badge(number: trunk.flexSize)
.attributes(.class("badge-primary"))
}
div {}
div(.class("label")) { "Rectangular" }
div(.class("flex justify-center")) {
if let width = trunk.width,
let height = trunk.ductSize.height
{
Badge {
span { "\(width) x \(height)" }
}
}
}
div(.class("flex justify-end")) {
div(.class("join")) {
TrashButton()
.attributes(.class("join-item btn-ghost"))
.attributes(
.hx.delete(route: deleteRoute),
.hx.target("closest tr"),
.hx.swap(.outerHTML)
)
EditButton()
.attributes(
.class("join-item btn-ghost"),
.showModal(id: TrunkSizeForm.id(trunk))
)
}
}
}
TrunkSizeForm(trunk: trunk, rooms: rooms, dismiss: true)
}
}
}
private var deleteRoute: SiteRoute.View {
.project(.detail(projectID, .ductSizing(.trunk(.delete(trunk.id)))))
}
private var registerIDS: [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()
}
}
}

View File

@@ -200,6 +200,14 @@ struct EffectiveLengthForm: HTML, Sendable {
}
}
a(
.href("/files/ManD.Groups.pdf"),
.target(.blank),
.class("btn btn-link")
) {
"Click here for Manual-D groups reference."
}
div(.id("groups"), .class("space-y-4")) {
if let effectiveLength {
for group in effectiveLength.groups {
@@ -346,7 +354,7 @@ extension EffectiveLength.EffectiveLengthType {
case .return:
return [5, 6, 7, 8, 10, 11, 12]
case .supply:
return [1, 2, 4, 8, 9, 11, 12]
return [1, 2, 3, 4, 8, 9, 11, 12]
}
}
}

View File

@@ -0,0 +1,136 @@
import Elementary
import ElementaryHTMX
import ManualDCore
import Styleguide
struct EffectiveLengthsTable: HTML, Sendable {
let effectiveLengths: [EffectiveLength]
private var sortedLengths: [EffectiveLength] {
effectiveLengths.sorted {
$0.totalEquivalentLength > $1.totalEquivalentLength
}
.sorted {
$0.type.rawValue > $1.type.rawValue
}
}
var body: some HTML<HTMLTag.table> {
table(.class("table table-zebra text-lg")) {
thead {
tr(.class("text-lg")) {
th { "Type" }
th { "Name" }
th { "Straight Lengths" }
th {
div(.class("grid grid-cols-3 gap-2 min-w-[220px]")) {
div(.class("flex justify-center col-span-3")) {
"Groups"
}
div { "Group" }
div(.class("flex justify-center")) {
"T.E.L."
}
div(.class("flex justify-end")) {
"Quantity"
}
}
}
th {
div(.class("flex justify-end me-[140px]")) {
"T.E.L."
}
}
}
}
tbody {
for row in sortedLengths {
EffectiveLenghtRow(effectiveLength: row)
}
}
}
}
struct EffectiveLenghtRow: HTML, Sendable {
let effectiveLength: EffectiveLength
private var deleteRoute: SiteRoute.View {
.project(
.detail(
effectiveLength.projectID,
.equivalentLength(.delete(id: effectiveLength.id))
)
)
}
var body: some HTML<HTMLTag.tr> {
tr(.id(effectiveLength.id.idString)) {
td {
// Type
Badge {
span { effectiveLength.type.rawValue }
}
.attributes(.class("badge-info"), when: effectiveLength.type == .supply)
.attributes(.class("badge-error"), when: effectiveLength.type == .return)
}
td { effectiveLength.name }
td {
// Lengths
div(.class("grid grid-cols-1 gap-2")) {
for length in effectiveLength.straightLengths {
Number(length)
}
}
}
td {
div(.class("grid grid-cols-3 gap-2 min-w-[220px]")) {
for group in effectiveLength.groups {
span { "\(group.group)-\(group.letter)" }
div(.class("flex justify-center")) {
Number(group.value)
}
div(.class("flex justify-end")) {
Number(group.quantity)
}
}
}
}
td {
// Total
// Row {
div(.class("flex justify-end mx-auto space-x-4")) {
Badge(number: effectiveLength.totalEquivalentLength, digits: 0)
.attributes(.class("badge-primary text-xl pt-2"))
// Buttons
div(.class("flex justify-end -mt-2")) {
div(.class("join")) {
TrashButton()
.attributes(
.class("join-item btn-ghost"),
.hx.delete(route: deleteRoute),
.hx.confirm("Are you sure?"),
.hx.target("#\(effectiveLength.id.idString)"),
.hx.swap(.outerHTML)
)
EditButton()
.attributes(
.class("join-item btn-ghost"),
.showModal(id: EffectiveLengthForm.id(effectiveLength))
)
}
}
}
EffectiveLengthForm(effectiveLength: effectiveLength)
}
}
}
}
}

View File

@@ -25,7 +25,7 @@ struct EffectiveLengthsView: HTML, Sendable {
PageTitle { "Equivalent Lengths" }
PlusButton()
.attributes(
.class("btn-ghost"),
.class("btn-ghost me-4"),
.showModal(id: EffectiveLengthForm.id(nil))
)
}
@@ -33,30 +33,12 @@ struct EffectiveLengthsView: HTML, Sendable {
EffectiveLengthForm(projectID: projectID, dismiss: true)
div {
h2(.class("text-xl font-bold pb-4")) { "Supplies" }
.attributes(.class("hidden"), when: supplies.count == 0)
div(.class("grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4")) {
for row in supplies {
EffectiveLengthView(effectiveLength: row)
}
}
}
div {
h2(.class("text-xl font-bold pb-4")) { "Returns" }
.attributes(.class("hidden"), when: returns.count == 0)
div(.class("grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 space-x-4 space-y-4")) {
for row in returns {
EffectiveLengthView(effectiveLength: row)
}
}
}
EffectiveLengthsTable(effectiveLengths: effectiveLengths)
}
}
// TODO: Remove if using table view.
private struct EffectiveLengthView: HTML, Sendable {
let effectiveLength: EffectiveLength

View File

@@ -55,7 +55,9 @@ public struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable
public var body: some HTML {
div(.class("h-screen w-full")) {
inner
div(.class("overflow-auto")) {
inner
}
}
.attributes(.data("theme", value: theme?.rawValue ?? "default"), when: theme != nil)
}

View File

@@ -17,47 +17,45 @@ struct ProjectDetail: HTML, Sendable {
)
}
div(.class("overflow-x-auto")) {
table(.class("table table-zebra text-lg")) {
tbody {
tr {
td(.class("label font-bold")) { "Name" }
td {
div(.class("flex justify-end")) {
project.name
}
table(.class("table table-zebra text-lg")) {
tbody {
tr {
td(.class("label font-bold")) { "Name" }
td {
div(.class("flex justify-end")) {
project.name
}
}
tr {
td(.class("label font-bold")) { "Street Address" }
td {
div(.class("flex justify-end")) {
project.streetAddress
}
}
tr {
td(.class("label font-bold")) { "Street Address" }
td {
div(.class("flex justify-end")) {
project.streetAddress
}
}
tr {
td(.class("label font-bold")) { "City" }
td {
div(.class("flex justify-end")) {
project.city
}
}
tr {
td(.class("label font-bold")) { "City" }
td {
div(.class("flex justify-end")) {
project.city
}
}
tr {
td(.class("label font-bold")) { "State" }
td {
div(.class("flex justify-end")) {
project.state
}
}
tr {
td(.class("label font-bold")) { "State" }
td {
div(.class("flex justify-end")) {
project.state
}
}
tr {
td(.class("label font-bold")) { "Zip" }
td {
div(.class("flex justify-end")) {
project.zipCode
}
}
tr {
td(.class("label font-bold")) { "Zip" }
td {
div(.class("flex justify-end")) {
project.zipCode
}
}
}

View File

@@ -31,24 +31,22 @@ struct ProjectsTable: HTML, Sendable {
}
.attributes(.class("pb-6"))
div(.class("overflow-x-auto")) {
table(.class("table table-zebra")) {
thead {
tr {
th { Label("Date") }
th { Label("Name") }
th { Label("Address") }
th {}
}
}
tbody {
Rows(projects: projects)
table(.class("table table-zebra")) {
thead {
tr {
th { Label("Date") }
th { Label("Name") }
th { Label("Address") }
th {}
}
}
tbody {
Rows(projects: projects)
}
}
ProjectForm(dismiss: true)
}
ProjectForm(dismiss: true)
}
}
}

View File

@@ -2,9 +2,30 @@ import Dependencies
import Elementary
import Foundation
import ManualDCore
import Styleguide
struct TestPage: HTML, Sendable {
let trunks: [DuctSizing.TrunkContainer]
let rooms: [DuctSizing.RoomContainer]
var body: some HTML {
UserProfileForm(userID: UUID(0), profile: nil, dismiss: false)
div(.class("overflow-auto")) {
DuctSizingView.TrunkTable(trunks: trunks, 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")) {}
DuctSizingView.TrunkTable(trunks: trunks, rooms: rooms)
}
}
}