WIP: Working rooms table and form for project.
This commit is contained in:
@@ -3,6 +3,8 @@ import ElementaryHTMX
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: Need a back button to navigate to all projects table.
|
||||
|
||||
struct ProjectView<Inner: HTML>: HTML, Sendable where Inner: Sendable {
|
||||
let projectID: Project.ID
|
||||
let activeTab: Sidebar.ActiveTab
|
||||
@@ -54,7 +56,7 @@ struct Sidebar: HTML {
|
||||
}
|
||||
.attributes(.class("p-4"))
|
||||
|
||||
row(title: "Project", icon: .mapPin, route: .project(.index))
|
||||
row(title: "Project", icon: .mapPin, route: .project(.detail(projectID)))
|
||||
.attributes(.data("active", value: active == .projects ? "true" : "false"))
|
||||
|
||||
row(title: "Rooms", icon: .doorClosed, route: .room(.index(projectID)))
|
||||
|
||||
@@ -9,11 +9,19 @@ import Styleguide
|
||||
struct RoomForm: HTML, Sendable {
|
||||
|
||||
let dismiss: Bool
|
||||
let projectID: Project.ID
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: "roomForm", dismiss: dismiss) {
|
||||
h1(.class("text-3xl font-bold pb-6")) { "Room" }
|
||||
form {
|
||||
// TODO: Use htmx here.
|
||||
form(
|
||||
.method(.post),
|
||||
.action(route: .room(.index(projectID)))
|
||||
) {
|
||||
div(.class("hidden")) {
|
||||
input(.name("projectID"), .id("projectID"), .value("\(projectID)"))
|
||||
}
|
||||
div {
|
||||
label(.for("name")) { "Name:" }
|
||||
Input(id: "name", placeholder: "Room Name")
|
||||
@@ -40,7 +48,7 @@ struct RoomForm: HTML, Sendable {
|
||||
div(.class("space-x-4")) {
|
||||
CancelButton()
|
||||
.attributes(
|
||||
.hx.get(route: .room(.form(dismiss: true))),
|
||||
.hx.get(route: .room(.form(projectID, dismiss: true))),
|
||||
.hx.target("#roomForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
|
||||
@@ -5,7 +5,10 @@ import Foundation
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: Calculate rooms sensible based on project wide SHR.
|
||||
|
||||
struct RoomsView: HTML, Sendable {
|
||||
let projectID: Project.ID
|
||||
let rooms: [Room]
|
||||
|
||||
var body: some HTML {
|
||||
@@ -17,7 +20,7 @@ struct RoomsView: HTML, Sendable {
|
||||
.data("tip", value: "Add room")
|
||||
) {
|
||||
button(
|
||||
.hx.get(route: .room(.form(dismiss: false))),
|
||||
.hx.get(route: .room(.form(projectID, dismiss: false))),
|
||||
.hx.target("#roomForm"),
|
||||
.hx.swap(.outerHTML),
|
||||
.class("btn btn-primary w-[40px] text-2xl")
|
||||
@@ -35,7 +38,6 @@ struct RoomsView: HTML, Sendable {
|
||||
th { Label("Name") }
|
||||
th { Label("Heating Load") }
|
||||
th { Label("Cooling Total") }
|
||||
th { Label("Cooling Sensible") }
|
||||
th { Label("Register Count") }
|
||||
}
|
||||
}
|
||||
@@ -48,13 +50,9 @@ struct RoomsView: HTML, Sendable {
|
||||
.attributes(.class("text-error"))
|
||||
}
|
||||
td {
|
||||
Number(room.coolingLoad.total)
|
||||
Number(room.coolingLoad)
|
||||
.attributes(.class("text-success"))
|
||||
}
|
||||
td {
|
||||
Number(room.coolingLoad.sensible)
|
||||
.attributes(.class("text-info"))
|
||||
}
|
||||
td {
|
||||
Number(room.registerCount)
|
||||
}
|
||||
@@ -72,16 +70,12 @@ struct RoomsView: HTML, Sendable {
|
||||
.attributes(
|
||||
.class("badge badge-outline badge-success badge-xl"))
|
||||
}
|
||||
td {
|
||||
Number(rooms.coolingSensibleTotal)
|
||||
.attributes(.class("badge badge-outline badge-info badge-xl"))
|
||||
}
|
||||
td {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RoomForm(dismiss: true)
|
||||
RoomForm(dismiss: true, projectID: projectID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,10 +87,6 @@ extension Array where Element == Room {
|
||||
}
|
||||
|
||||
var coolingTotal: Double {
|
||||
reduce(into: 0) { $0 += $1.coolingLoad.total }
|
||||
}
|
||||
|
||||
var coolingSensibleTotal: Double {
|
||||
reduce(into: 0) { $0 += $1.coolingLoad.sensible }
|
||||
reduce(into: 0) { $0 += $1.coolingLoad }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user