feat: Adds CSV upload form to room view.

This commit is contained in:
2026-02-06 08:22:59 -05:00
parent 57766c990e
commit 728a6c3000
2 changed files with 54 additions and 14 deletions

View File

@@ -26,6 +26,7 @@ extension SVG {
case doorClosed
case email
case fan
case filePlusCorner
case key
case mapPin
case rulerDimensionLine
@@ -94,6 +95,10 @@ extension SVG {
return """
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-fan-icon lucide-fan"><path d="M10.827 16.379a6.082 6.082 0 0 1-8.618-7.002l5.412 1.45a6.082 6.082 0 0 1 7.002-8.618l-1.45 5.412a6.082 6.082 0 0 1 8.618 7.002l-5.412-1.45a6.082 6.082 0 0 1-7.002 8.618l1.45-5.412Z"/><path d="M12 12v.01"/></svg>
"""
case .filePlusCorner:
return """
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-plus-corner-icon lucide-file-plus-corner"><path d="M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M14 19h6"/><path d="M17 16v6"/></svg>
"""
case .key:
return """
<svg class="h-[1em] opacity-50" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">

View File

@@ -7,7 +7,6 @@ import Styleguide
struct RoomsView: HTML, Sendable {
@Environment(ProjectViewValue.$projectID) var projectID
// let projectID: Project.ID
let rooms: [Room]
let sensibleHeatRatio: Double?
@@ -25,7 +24,7 @@ struct RoomsView: HTML, Sendable {
PageTitle { "Room Loads" }
}
div(.class("flex justify-end grow")) {
div(.class("flex justify-end grow space-x-4")) {
Tooltip("Set sensible heat ratio", position: .left) {
button(
.class(
@@ -50,17 +49,6 @@ struct RoomsView: HTML, Sendable {
}
.attributes(.class("tooltip-open"), when: sensibleHeatRatio == nil)
Tooltip("Upload csv file", position: .left) {
form(
.hx.post(csvRoute),
.hx.target("body"),
.hx.swap(.outerHTML),
.custom(name: "enctype", value: "multipart/form-data")
) {
input(.type(.file), .name("file"), .accept(".csv"))
SubmitButton()
}
}
}
div(.class("flex items-end space-x-4 font-bold")) {
@@ -115,7 +103,17 @@ struct RoomsView: HTML, Sendable {
}
}
th {
div(.class("flex justify-end me-2")) {
div(.class("flex justify-end me-2 space-x-4")) {
Tooltip("Upload CSV", position: .left) {
button(
.class("btn btn-secondary"),
.showModal(id: UploadCSVForm.id)
) {
SVG(.filePlusCorner)
}
}
Tooltip("Add Room") {
PlusButton()
.attributes(
@@ -124,6 +122,7 @@ struct RoomsView: HTML, Sendable {
)
.attributes(.class("tooltip-left"))
}
}
}
}
@@ -135,6 +134,7 @@ struct RoomsView: HTML, Sendable {
}
}
RoomForm(dismiss: true, projectID: projectID, room: nil)
UploadCSVForm(dismiss: true)
}
}
@@ -257,4 +257,39 @@ struct RoomsView: HTML, Sendable {
}
}
}
struct UploadCSVForm: HTML {
static let id = "uploadCSV"
@Environment(ProjectViewValue.$projectID) var projectID
let dismiss: Bool
private var route: String {
SiteRoute.router.path(for: .view(.project(.detail(projectID, .rooms(.index)))))
.appendingPath("csv")
}
var body: some HTML {
ModalForm(id: Self.id, dismiss: dismiss) {
div(.class("pb-6 space-y-3")) {
h1(.class("text-3xl font-bold")) { "Upload CSV" }
p(.class("text-sm italic")) {
"Drag and drop, or click to upload"
}
}
form(
.hx.post(route),
.hx.target("body"),
.hx.swap(.outerHTML),
.custom(name: "enctype", value: "multipart/form-data")
) {
input(.type(.file), .name("file"), .accept(".csv"))
SubmitButton()
.attributes(.class("btn-block mt-6"))
}
}
}
}
}