feat-WIP: Adds update to trunk-size form, currently height / width is not working though.
This commit is contained in:
@@ -176,6 +176,7 @@ struct DuctSizingView: HTML, Sendable {
|
||||
}
|
||||
|
||||
struct TrunkTable: HTML, Sendable {
|
||||
|
||||
let trunks: [DuctSizing.TrunkContainer]
|
||||
let rooms: [DuctSizing.RoomContainer]
|
||||
|
||||
@@ -196,86 +197,89 @@ struct DuctSizingView: HTML, Sendable {
|
||||
}
|
||||
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.
|
||||
}
|
||||
}
|
||||
TrunkRow(trunk: trunk, rooms: rooms)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func registerIDS(_ trunk: DuctSizing.TrunkSize) -> [String] {
|
||||
}
|
||||
|
||||
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 =
|
||||
|
||||
@@ -5,27 +5,47 @@ import Styleguide
|
||||
|
||||
struct TrunkSizeForm: HTML, Sendable {
|
||||
|
||||
static func id() -> String {
|
||||
"trunkSizeForm"
|
||||
static func id(_ trunk: DuctSizing.TrunkContainer? = nil) -> String {
|
||||
let base = "trunkSizeForm"
|
||||
guard let trunk else { return base }
|
||||
return "\(base)_\(trunk.id.idString)"
|
||||
}
|
||||
|
||||
@Environment(ProjectViewValue.$projectID) var projectID
|
||||
|
||||
let container: DuctSizing.TrunkContainer?
|
||||
let rooms: [DuctSizing.RoomContainer]
|
||||
let dismiss: Bool
|
||||
|
||||
var trunk: DuctSizing.TrunkSize? {
|
||||
container?.trunk
|
||||
}
|
||||
|
||||
init(
|
||||
trunk: DuctSizing.TrunkContainer? = nil,
|
||||
rooms: [DuctSizing.RoomContainer],
|
||||
dismiss: Bool = true
|
||||
) {
|
||||
self.container = trunk
|
||||
self.rooms = rooms
|
||||
self.dismiss = dismiss
|
||||
}
|
||||
|
||||
var route: String {
|
||||
SiteRoute.View.router
|
||||
.path(for: .project(.detail(projectID, .ductSizing(.index))))
|
||||
.appendingPath(SiteRoute.View.ProjectRoute.DuctSizingRoute.TrunkRoute.rootPath)
|
||||
.appendingPath(trunk?.id)
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: Self.id(), dismiss: dismiss) {
|
||||
ModalForm(id: Self.id(container), dismiss: dismiss) {
|
||||
h1(.class("text-lg font-bold mb-4")) { "Trunk Size" }
|
||||
form(
|
||||
.class("space-y-4"),
|
||||
.hx.post(route),
|
||||
trunk == nil
|
||||
? .hx.post(route)
|
||||
: .hx.patch(route),
|
||||
.hx.target("body"),
|
||||
.hx.swap(.outerHTML)
|
||||
) {
|
||||
@@ -38,6 +58,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
||||
select(.name("type")) {
|
||||
for type in DuctSizing.TrunkSize.TrunkType.allCases {
|
||||
option(.value(type.rawValue)) { type.rawValue.capitalized }
|
||||
.attributes(.selected, when: trunk?.type == type)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +67,7 @@ struct TrunkSizeForm: HTML, Sendable {
|
||||
"Height",
|
||||
.type(.text),
|
||||
.name("height"),
|
||||
.value(trunk?.height),
|
||||
.placeholder("8 (Optional)"),
|
||||
)
|
||||
}
|
||||
@@ -63,6 +85,10 @@ struct TrunkSizeForm: HTML, Sendable {
|
||||
.name("rooms"),
|
||||
.value("\(room.roomID)_\(room.roomRegister)")
|
||||
)
|
||||
.attributes(
|
||||
.checked,
|
||||
when: trunk == nil ? false : trunk!.rooms.hasRoom(room)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,3 +101,12 @@ struct TrunkSizeForm: HTML, Sendable {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Array where Element == DuctSizing.TrunkSize.RoomProxy {
|
||||
func hasRoom(_ room: DuctSizing.RoomContainer) -> Bool {
|
||||
first {
|
||||
$0.id == room.roomID
|
||||
&& $0.registers.contains(room.roomRegister)
|
||||
} != nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user