feat: Adds sensible heat ratio for projects, adds initial view / forms to the rooms tab.
This commit is contained in:
@@ -5,6 +5,8 @@ import Styleguide
|
||||
// TODO: Have form hold onto equipment info model to edit.
|
||||
struct EquipmentInfoForm: HTML, Sendable {
|
||||
|
||||
static let id = "equipmentForm"
|
||||
|
||||
let dismiss: Bool
|
||||
let projectID: Project.ID
|
||||
let equipmentInfo: EquipmentInfo?
|
||||
@@ -31,7 +33,7 @@ struct EquipmentInfoForm: HTML, Sendable {
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: "equipmentForm", dismiss: dismiss) {
|
||||
ModalForm(id: Self.id, dismiss: dismiss) {
|
||||
h1(.class("text-3xl font-bold pb-6 ps-2")) { "Equipment Info" }
|
||||
form(
|
||||
.class("space-y-4 p-4"),
|
||||
@@ -64,21 +66,9 @@ struct EquipmentInfoForm: HTML, Sendable {
|
||||
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")
|
||||
}
|
||||
div {
|
||||
SubmitButton(title: "Save")
|
||||
.attributes(.class("btn-block"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,10 @@ struct EquipmentInfoView: HTML, Sendable {
|
||||
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)
|
||||
)
|
||||
}
|
||||
EditButton()
|
||||
.attributes(
|
||||
.on(.click, "\(EquipmentInfoForm.id).showModal()")
|
||||
)
|
||||
}
|
||||
|
||||
if let equipmentInfo {
|
||||
@@ -45,10 +41,10 @@ struct EquipmentInfoView: HTML, Sendable {
|
||||
}
|
||||
.attributes(.class("border-b border-gray-200"))
|
||||
|
||||
EquipmentInfoForm(dismiss: true, projectID: projectID, equipmentInfo: nil)
|
||||
} else {
|
||||
EquipmentInfoForm(dismiss: false, projectID: projectID, equipmentInfo: nil)
|
||||
}
|
||||
EquipmentInfoForm(
|
||||
dismiss: true, projectID: projectID, equipmentInfo: equipmentInfo
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,11 @@ struct ProjectView: HTML, Sendable {
|
||||
}
|
||||
}
|
||||
case .rooms:
|
||||
try await RoomsView(projectID: projectID, rooms: database.rooms.fetch(projectID))
|
||||
try await RoomsView(
|
||||
projectID: projectID,
|
||||
rooms: database.rooms.fetch(projectID),
|
||||
sensibleHeatRatio: database.projects.getSensibleHeatRatio(projectID)
|
||||
)
|
||||
|
||||
case .effectiveLength:
|
||||
try await EffectiveLengthsView(
|
||||
|
||||
@@ -8,12 +8,14 @@ import Styleguide
|
||||
// TODO: Need to hold the project ID in hidden input field.
|
||||
struct RoomForm: HTML, Sendable {
|
||||
|
||||
static let id = "roomForm"
|
||||
|
||||
let dismiss: Bool
|
||||
let projectID: Project.ID
|
||||
let room: Room?
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: "roomForm", dismiss: dismiss) {
|
||||
ModalForm(id: Self.id, dismiss: dismiss) {
|
||||
h1(.class("text-3xl font-bold pb-6")) { "Room" }
|
||||
// TODO: Use htmx here.
|
||||
form(
|
||||
|
||||
@@ -10,6 +10,7 @@ import Styleguide
|
||||
struct RoomsView: HTML, Sendable {
|
||||
let projectID: Project.ID
|
||||
let rooms: [Room]
|
||||
let sensibleHeatRatio: Double?
|
||||
|
||||
var body: some HTML {
|
||||
div {
|
||||
@@ -20,10 +21,7 @@ struct RoomsView: HTML, Sendable {
|
||||
.data("tip", value: "Add room")
|
||||
) {
|
||||
button(
|
||||
// .hx.get(route: .project(.detail(projectID, .rooms(.form(dismiss: false))))),
|
||||
// .hx.target("#roomForm"),
|
||||
// .hx.swap(.outerHTML),
|
||||
.on(.click, "roomForm.showModal()"),
|
||||
.showModal(id: RoomForm.id),
|
||||
.class("btn btn-primary w-[40px] text-2xl")
|
||||
) {
|
||||
"+"
|
||||
@@ -32,6 +30,23 @@ struct RoomsView: HTML, Sendable {
|
||||
}
|
||||
.attributes(.class("pb-6"))
|
||||
|
||||
div(.class("border rounded-lg mb-6")) {
|
||||
Row {
|
||||
div(.class("space-x-6")) {
|
||||
Label("Sensible Heat Ratio")
|
||||
if let sensibleHeatRatio {
|
||||
Number(sensibleHeatRatio)
|
||||
}
|
||||
}
|
||||
|
||||
EditButton()
|
||||
.attributes(.showModal(id: SHRForm.id))
|
||||
}
|
||||
.attributes(.class("m-4"))
|
||||
|
||||
SHRForm(projectID: projectID, sensibleHeatRatio: sensibleHeatRatio)
|
||||
}
|
||||
|
||||
div(.class("overflow-x-auto rounded-box border")) {
|
||||
table(.class("table table-zebra"), .id("roomsTable")) {
|
||||
thead {
|
||||
@@ -114,6 +129,34 @@ struct RoomsView: HTML, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
struct SHRForm: HTML, Sendable {
|
||||
static let id = "shrForm"
|
||||
|
||||
let projectID: Project.ID
|
||||
let sensibleHeatRatio: Double?
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: Self.id, dismiss: true) {
|
||||
form(
|
||||
.class("space-y-6"),
|
||||
.hx.patch("/projects/\(projectID)/rooms/update-shr"),
|
||||
.hx.target("body"),
|
||||
.hx.swap(.outerHTML)
|
||||
) {
|
||||
input(.class("hidden"), .name("projectID"), .value("\(projectID)"))
|
||||
div {
|
||||
label(.for("sensibleHeatRatio")) { "Sensible Heat Ratio" }
|
||||
Input(id: "sensibleHeatRatio", placeholder: "Sensible Heat Ratio")
|
||||
.attributes(.min("0"), .max("1"), .step("0.01"), .value(sensibleHeatRatio))
|
||||
}
|
||||
div {
|
||||
SubmitButton()
|
||||
.attributes(.class("btn-block"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == Room {
|
||||
|
||||
Reference in New Issue
Block a user