2 Commits

21 changed files with 307 additions and 211 deletions

View File

@@ -4227,8 +4227,11 @@
.top-0 { .top-0 {
top: calc(var(--spacing) * 0); top: calc(var(--spacing) * 0);
} }
.top-40 { .top-2 {
top: calc(var(--spacing) * 40); top: calc(var(--spacing) * 2);
}
.right-2 {
right: calc(var(--spacing) * 2);
} }
.dock-sm { .dock-sm {
@layer daisyui.l1.l2 { @layer daisyui.l1.l2 {
@@ -4287,9 +4290,6 @@
} }
} }
} }
.left-\[25vw\] {
left: 25vw;
}
.join { .join {
display: inline-flex; display: inline-flex;
align-items: stretch; align-items: stretch;
@@ -4676,9 +4676,6 @@
} }
} }
} }
.z-50 {
z-index: 50;
}
.tab-content { .tab-content {
@layer daisyui.l1.l2.l3 { @layer daisyui.l1.l2.l3 {
order: var(--tabcontent-order); order: var(--tabcontent-order);
@@ -5270,9 +5267,6 @@
} }
} }
} }
.mx-10 {
margin-inline: calc(var(--spacing) * 10);
}
.file-input-ghost { .file-input-ghost {
@layer daisyui.l1.l2 { @layer daisyui.l1.l2 {
background-color: transparent; background-color: transparent;
@@ -5562,6 +5556,9 @@
border-width: var(--border, 1px) 0 var(--border, 1px) var(--border, 1px); border-width: var(--border, 1px) 0 var(--border, 1px) var(--border, 1px);
} }
} }
.me-4 {
margin-inline-end: calc(var(--spacing) * 4);
}
.modal-action { .modal-action {
@layer daisyui.l1.l2.l3 { @layer daisyui.l1.l2.l3 {
margin-top: calc(0.25rem * 6); margin-top: calc(0.25rem * 6);
@@ -5604,6 +5601,9 @@
.mt-4 { .mt-4 {
margin-top: calc(var(--spacing) * 4); margin-top: calc(var(--spacing) * 4);
} }
.mt-6 {
margin-top: calc(var(--spacing) * 6);
}
.breadcrumbs { .breadcrumbs {
@layer daisyui.l1.l2.l3 { @layer daisyui.l1.l2.l3 {
max-width: 100%; max-width: 100%;
@@ -5680,6 +5680,9 @@
font-weight: 600; font-weight: 600;
} }
} }
.mb-6 {
margin-bottom: calc(var(--spacing) * 6);
}
.carousel-item { .carousel-item {
@layer daisyui.l1.l2.l3 { @layer daisyui.l1.l2.l3 {
box-sizing: content-box; box-sizing: content-box;
@@ -6522,18 +6525,12 @@
width: calc(var(--size-selector, 0.25rem) * 4); width: calc(var(--size-selector, 0.25rem) * 4);
} }
} }
.w-1\/2 {
width: calc(1/2 * 100%);
}
.w-\[40px\] { .w-\[40px\] {
width: 40px; width: 40px;
} }
.w-full { .w-full {
width: 100%; width: 100%;
} }
.w-xl {
width: var(--container-xl);
}
.max-w-\[280px\] { .max-w-\[280px\] {
max-width: 280px; max-width: 280px;
} }
@@ -7182,15 +7179,9 @@
border-color: currentColor; border-color: currentColor;
} }
} }
.border-base-300 {
border-color: var(--color-base-300);
}
.border-gray-200 { .border-gray-200 {
border-color: var(--color-gray-200); border-color: var(--color-gray-200);
} }
.border-gray-400 {
border-color: var(--color-gray-400);
}
.menu-active { .menu-active {
:where(:not(ul, details, .menu-title, .btn))& { :where(:not(ul, details, .menu-title, .btn))& {
@layer daisyui.l1.l2 { @layer daisyui.l1.l2 {
@@ -7342,15 +7333,6 @@
} }
} }
} }
.bg-base-200 {
background-color: var(--color-base-200);
}
.bg-blue-500 {
background-color: var(--color-blue-500);
}
.bg-gray-200 {
background-color: var(--color-gray-200);
}
.bg-red-500 { .bg-red-500 {
background-color: var(--color-red-500); background-color: var(--color-red-500);
} }
@@ -7774,9 +7756,6 @@
.py-2 { .py-2 {
padding-block: calc(var(--spacing) * 2); padding-block: calc(var(--spacing) * 2);
} }
.py-4 {
padding-block: calc(var(--spacing) * 4);
}
.py-10 { .py-10 {
padding-block: calc(var(--spacing) * 10); padding-block: calc(var(--spacing) * 10);
} }
@@ -7797,6 +7776,9 @@
.pe-2 { .pe-2 {
padding-inline-end: calc(var(--spacing) * 2); padding-inline-end: calc(var(--spacing) * 2);
} }
.pe-4 {
padding-inline-end: calc(var(--spacing) * 4);
}
.pb-4 { .pb-4 {
padding-bottom: calc(var(--spacing) * 4); padding-bottom: calc(var(--spacing) * 4);
} }
@@ -8419,9 +8401,6 @@
.text-gray-400 { .text-gray-400 {
color: var(--color-gray-400); color: var(--color-gray-400);
} }
.text-gray-800 {
color: var(--color-gray-800);
}
.text-slate-900 { .text-slate-900 {
color: var(--color-slate-900); color: var(--color-slate-900);
} }
@@ -9297,13 +9276,6 @@
border-color: var(--color-red-500); border-color: var(--color-red-500);
} }
} }
.hover\:bg-blue-600 {
&:hover {
@media (hover: hover) {
background-color: var(--color-blue-600);
}
}
}
.hover\:bg-gray-300 { .hover\:bg-gray-300 {
&:hover { &:hover {
@media (hover: hover) { @media (hover: hover) {

View File

@@ -10,6 +10,7 @@ extension DatabaseClient {
public var create: @Sendable (User.ID, Project.Create) async throws -> Project public var create: @Sendable (User.ID, Project.Create) async throws -> Project
public var delete: @Sendable (Project.ID) async throws -> Void public var delete: @Sendable (Project.ID) async throws -> Void
public var get: @Sendable (Project.ID) async throws -> Project? public var get: @Sendable (Project.ID) async throws -> Project?
public var getSensibleHeatRatio: @Sendable (Project.ID) async throws -> Double?
public var fetch: @Sendable (User.ID, PageRequest) async throws -> Page<Project> public var fetch: @Sendable (User.ID, PageRequest) async throws -> Page<Project>
public var update: @Sendable (Project.Update) async throws -> Project public var update: @Sendable (Project.Update) async throws -> Project
} }
@@ -34,6 +35,12 @@ extension DatabaseClient.Projects: TestDependencyKey {
get: { id in get: { id in
try await ProjectModel.find(id, on: database).map { try $0.toDTO() } try await ProjectModel.find(id, on: database).map { try $0.toDTO() }
}, },
getSensibleHeatRatio: { id in
guard let model = try await ProjectModel.find(id, on: database) else {
throw NotFoundError()
}
return model.sensibleHeatRatio
},
fetch: { userID, request in fetch: { userID, request in
try await ProjectModel.query(on: database) try await ProjectModel.query(on: database)
.sort(\.$createdAt, .descending) .sort(\.$createdAt, .descending)
@@ -86,6 +93,14 @@ extension Project.Create {
guard !zipCode.isEmpty else { guard !zipCode.isEmpty else {
throw ValidationError("Project zipCode should not be empty.") throw ValidationError("Project zipCode should not be empty.")
} }
if let sensibleHeatRatio {
guard sensibleHeatRatio >= 0 else {
throw ValidationError("Project sensible heat ratio should be greater than 0.")
}
guard sensibleHeatRatio <= 1 else {
throw ValidationError("Project sensible heat ratio should be less than 1.")
}
}
} }
} }
@@ -117,6 +132,14 @@ extension Project.Update {
throw ValidationError("Project zipCode should not be empty.") throw ValidationError("Project zipCode should not be empty.")
} }
} }
if let sensibleHeatRatio {
guard sensibleHeatRatio >= 0 else {
throw ValidationError("Project sensible heat ratio should be greater than 0.")
}
guard sensibleHeatRatio <= 1 else {
throw ValidationError("Project sensible heat ratio should be less than 1.")
}
}
} }
} }
@@ -132,6 +155,7 @@ extension Project {
.field("city", .string, .required) .field("city", .string, .required)
.field("state", .string, .required) .field("state", .string, .required)
.field("zipCode", .string, .required) .field("zipCode", .string, .required)
.field("sensibleHeatRatio", .double)
.field("createdAt", .datetime) .field("createdAt", .datetime)
.field("updatedAt", .datetime) .field("updatedAt", .datetime)
.field("userID", .uuid, .required, .references(UserModel.schema, "id")) .field("userID", .uuid, .required, .references(UserModel.schema, "id"))
@@ -168,6 +192,9 @@ final class ProjectModel: Model, @unchecked Sendable {
@Field(key: "zipCode") @Field(key: "zipCode")
var zipCode: String var zipCode: String
@Field(key: "sensibleHeatRatio")
var sensibleHeatRatio: Double?
@Timestamp(key: "createdAt", on: .create, format: .iso8601) @Timestamp(key: "createdAt", on: .create, format: .iso8601)
var createdAt: Date? var createdAt: Date?
@@ -189,6 +216,7 @@ final class ProjectModel: Model, @unchecked Sendable {
city: String, city: String,
state: String, state: String,
zipCode: String, zipCode: String,
sensibleHeatRatio: Double? = nil,
userID: User.ID, userID: User.ID,
createdAt: Date? = nil, createdAt: Date? = nil,
updatedAt: Date? = nil updatedAt: Date? = nil
@@ -199,6 +227,7 @@ final class ProjectModel: Model, @unchecked Sendable {
self.city = city self.city = city
self.state = state self.state = state
self.zipCode = zipCode self.zipCode = zipCode
self.sensibleHeatRatio = sensibleHeatRatio
$user.id = userID $user.id = userID
self.createdAt = createdAt self.createdAt = createdAt
self.updatedAt = updatedAt self.updatedAt = updatedAt
@@ -212,6 +241,7 @@ final class ProjectModel: Model, @unchecked Sendable {
city: city, city: city,
state: state, state: state,
zipCode: zipCode, zipCode: zipCode,
sensibleHeatRatio: sensibleHeatRatio,
createdAt: createdAt!, createdAt: createdAt!,
updatedAt: updatedAt! updatedAt: updatedAt!
) )
@@ -239,6 +269,12 @@ final class ProjectModel: Model, @unchecked Sendable {
hasUpdates = true hasUpdates = true
self.zipCode = zipCode self.zipCode = zipCode
} }
if let sensibleHeatRatio = updates.sensibleHeatRatio,
sensibleHeatRatio != self.sensibleHeatRatio
{
hasUpdates = true
self.sensibleHeatRatio = sensibleHeatRatio
}
return hasUpdates return hasUpdates
} }
} }

View File

@@ -63,7 +63,8 @@ extension Room.Create {
return .init( return .init(
name: name, name: name,
heatingLoad: heatingLoad, heatingLoad: heatingLoad,
coolingLoad: coolingLoad, coolingTotal: coolingTotal,
coolingSensible: coolingSensible,
registerCount: registerCount, registerCount: registerCount,
projectID: projectID projectID: projectID
) )
@@ -76,9 +77,14 @@ extension Room.Create {
guard heatingLoad >= 0 else { guard heatingLoad >= 0 else {
throw ValidationError("Room heating load should not be less than 0.") throw ValidationError("Room heating load should not be less than 0.")
} }
guard coolingLoad >= 0 else { guard coolingTotal >= 0 else {
throw ValidationError("Room cooling total should not be less than 0.") throw ValidationError("Room cooling total should not be less than 0.")
} }
if let coolingSensible {
guard coolingSensible >= 0 else {
throw ValidationError("Room cooling sensible should not be less than 0.")
}
}
guard registerCount >= 1 else { guard registerCount >= 1 else {
throw ValidationError("Room cooling sensible should not be less than 1.") throw ValidationError("Room cooling sensible should not be less than 1.")
} }
@@ -98,11 +104,16 @@ extension Room.Update {
throw ValidationError("Room heating load should not be less than 0.") throw ValidationError("Room heating load should not be less than 0.")
} }
} }
if let coolingLoad { if let coolingTotal {
guard coolingLoad >= 0 else { guard coolingTotal >= 0 else {
throw ValidationError("Room cooling total should not be less than 0.") throw ValidationError("Room cooling total should not be less than 0.")
} }
} }
if let coolingSensible {
guard coolingSensible >= 0 else {
throw ValidationError("Room cooling sensible should not be less than 0.")
}
}
if let registerCount { if let registerCount {
guard registerCount >= 1 else { guard registerCount >= 1 else {
throw ValidationError("Room cooling sensible should not be less than 1.") throw ValidationError("Room cooling sensible should not be less than 1.")
@@ -120,7 +131,8 @@ extension Room {
.id() .id()
.field("name", .string, .required) .field("name", .string, .required)
.field("heatingLoad", .double, .required) .field("heatingLoad", .double, .required)
.field("coolingLoad", .double, .required) .field("coolingTotal", .double, .required)
.field("coolingSensible", .double)
.field("registerCount", .int8, .required) .field("registerCount", .int8, .required)
.field("createdAt", .datetime) .field("createdAt", .datetime)
.field("updatedAt", .datetime) .field("updatedAt", .datetime)
@@ -150,8 +162,11 @@ final class RoomModel: Model, @unchecked Sendable {
@Field(key: "heatingLoad") @Field(key: "heatingLoad")
var heatingLoad: Double var heatingLoad: Double
@Field(key: "coolingLoad") @Field(key: "coolingTotal")
var coolingLoad: Double var coolingTotal: Double
@Field(key: "coolingSensible")
var coolingSensible: Double?
@Field(key: "registerCount") @Field(key: "registerCount")
var registerCount: Int var registerCount: Int
@@ -171,7 +186,8 @@ final class RoomModel: Model, @unchecked Sendable {
id: UUID? = nil, id: UUID? = nil,
name: String, name: String,
heatingLoad: Double, heatingLoad: Double,
coolingLoad: Double, coolingTotal: Double,
coolingSensible: Double? = nil,
registerCount: Int, registerCount: Int,
createdAt: Date? = nil, createdAt: Date? = nil,
updatedAt: Date? = nil, updatedAt: Date? = nil,
@@ -180,7 +196,8 @@ final class RoomModel: Model, @unchecked Sendable {
self.id = id self.id = id
self.name = name self.name = name
self.heatingLoad = heatingLoad self.heatingLoad = heatingLoad
self.coolingLoad = coolingLoad self.coolingTotal = coolingTotal
self.coolingSensible = coolingSensible
self.registerCount = registerCount self.registerCount = registerCount
self.createdAt = createdAt self.createdAt = createdAt
self.updatedAt = updatedAt self.updatedAt = updatedAt
@@ -193,7 +210,8 @@ final class RoomModel: Model, @unchecked Sendable {
projectID: $project.id, projectID: $project.id,
name: name, name: name,
heatingLoad: heatingLoad, heatingLoad: heatingLoad,
coolingLoad: coolingLoad, coolingTotal: coolingTotal,
coolingSensible: coolingSensible,
registerCount: registerCount, registerCount: registerCount,
createdAt: createdAt!, createdAt: createdAt!,
updatedAt: updatedAt! updatedAt: updatedAt!
@@ -211,9 +229,13 @@ final class RoomModel: Model, @unchecked Sendable {
hasUpdates = true hasUpdates = true
self.heatingLoad = heatingLoad self.heatingLoad = heatingLoad
} }
if let coolingLoad = updates.coolingLoad, coolingLoad != self.coolingLoad { if let coolingTotal = updates.coolingTotal, coolingTotal != self.coolingTotal {
hasUpdates = true hasUpdates = true
self.coolingLoad = coolingLoad self.coolingTotal = coolingTotal
}
if let coolingSensible = updates.coolingSensible, coolingSensible != self.coolingSensible {
hasUpdates = true
self.coolingSensible = coolingSensible
} }
if let registerCount = updates.registerCount, registerCount != self.registerCount { if let registerCount = updates.registerCount, registerCount != self.registerCount {
hasUpdates = true hasUpdates = true

View File

@@ -9,6 +9,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
public let city: String public let city: String
public let state: String public let state: String
public let zipCode: String public let zipCode: String
public let sensibleHeatRatio: Double?
public let createdAt: Date public let createdAt: Date
public let updatedAt: Date public let updatedAt: Date
@@ -19,6 +20,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
city: String, city: String,
state: String, state: String,
zipCode: String, zipCode: String,
sensibleHeatRatio: Double? = nil,
createdAt: Date, createdAt: Date,
updatedAt: Date updatedAt: Date
) { ) {
@@ -28,6 +30,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
self.city = city self.city = city
self.state = state self.state = state
self.zipCode = zipCode self.zipCode = zipCode
self.sensibleHeatRatio = sensibleHeatRatio
self.createdAt = createdAt self.createdAt = createdAt
self.updatedAt = updatedAt self.updatedAt = updatedAt
} }
@@ -42,6 +45,7 @@ extension Project {
public let city: String public let city: String
public let state: String public let state: String
public let zipCode: String public let zipCode: String
public let sensibleHeatRatio: Double?
public init( public init(
name: String, name: String,
@@ -49,12 +53,14 @@ extension Project {
city: String, city: String,
state: String, state: String,
zipCode: String, zipCode: String,
sensibleHeatRatio: Double? = nil,
) { ) {
self.name = name self.name = name
self.streetAddress = streetAddress self.streetAddress = streetAddress
self.city = city self.city = city
self.state = state self.state = state
self.zipCode = zipCode self.zipCode = zipCode
self.sensibleHeatRatio = sensibleHeatRatio
} }
} }
@@ -66,6 +72,7 @@ extension Project {
public let city: String? public let city: String?
public let state: String? public let state: String?
public let zipCode: String? public let zipCode: String?
public let sensibleHeatRatio: Double?
public init( public init(
id: Project.ID, id: Project.ID,
@@ -73,7 +80,8 @@ extension Project {
streetAddress: String? = nil, streetAddress: String? = nil,
city: String? = nil, city: String? = nil,
state: String? = nil, state: String? = nil,
zipCode: String? = nil zipCode: String? = nil,
sensibleHeatRatio: Double? = nil
) { ) {
self.id = id self.id = id
self.name = name self.name = name
@@ -81,6 +89,7 @@ extension Project {
self.city = city self.city = city
self.state = state self.state = state
self.zipCode = zipCode self.zipCode = zipCode
self.sensibleHeatRatio = sensibleHeatRatio
} }
} }
} }

View File

@@ -6,7 +6,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
public let projectID: Project.ID public let projectID: Project.ID
public let name: String public let name: String
public let heatingLoad: Double public let heatingLoad: Double
public let coolingLoad: Double public let coolingTotal: Double
public let coolingSensible: Double?
public let registerCount: Int public let registerCount: Int
public let createdAt: Date public let createdAt: Date
public let updatedAt: Date public let updatedAt: Date
@@ -16,7 +17,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
projectID: Project.ID, projectID: Project.ID,
name: String, name: String,
heatingLoad: Double, heatingLoad: Double,
coolingLoad: Double, coolingTotal: Double,
coolingSensible: Double? = nil,
registerCount: Int = 1, registerCount: Int = 1,
createdAt: Date, createdAt: Date,
updatedAt: Date updatedAt: Date
@@ -25,7 +27,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
self.projectID = projectID self.projectID = projectID
self.name = name self.name = name
self.heatingLoad = heatingLoad self.heatingLoad = heatingLoad
self.coolingLoad = coolingLoad self.coolingTotal = coolingTotal
self.coolingSensible = coolingSensible
self.registerCount = registerCount self.registerCount = registerCount
self.createdAt = createdAt self.createdAt = createdAt
self.updatedAt = updatedAt self.updatedAt = updatedAt
@@ -38,75 +41,48 @@ extension Room {
public let projectID: Project.ID public let projectID: Project.ID
public let name: String public let name: String
public let heatingLoad: Double public let heatingLoad: Double
public let coolingLoad: Double public let coolingTotal: Double
public let coolingSensible: Double?
public let registerCount: Int public let registerCount: Int
public init( public init(
projectID: Project.ID, projectID: Project.ID,
name: String, name: String,
heatingLoad: Double, heatingLoad: Double,
coolingLoad: Double, coolingTotal: Double,
coolingSensible: Double? = nil,
registerCount: Int = 1 registerCount: Int = 1
) { ) {
self.projectID = projectID self.projectID = projectID
self.name = name self.name = name
self.heatingLoad = heatingLoad self.heatingLoad = heatingLoad
self.coolingLoad = coolingLoad self.coolingTotal = coolingTotal
self.coolingSensible = coolingSensible
self.registerCount = registerCount self.registerCount = registerCount
} }
public init(
form: Room.Form,
projectID: Project.ID
) {
self.init(
projectID: projectID,
name: form.name,
heatingLoad: form.heatingLoad,
coolingLoad: form.coolingLoad,
registerCount: form.registerCount
)
}
} }
public struct Update: Codable, Equatable, Sendable { public struct Update: Codable, Equatable, Sendable {
public let id: Room.ID public let id: Room.ID
public let name: String? public let name: String?
public let heatingLoad: Double? public let heatingLoad: Double?
public let coolingLoad: Double? public let coolingTotal: Double?
public let coolingSensible: Double?
public let registerCount: Int? public let registerCount: Int?
public init( public init(
id: Room.ID, id: Room.ID,
name: String? = nil, name: String? = nil,
heatingLoad: Double? = nil, heatingLoad: Double? = nil,
coolingLoad: Double? = nil, coolingTotal: Double? = nil,
coolingSensible: Double? = nil,
registerCount: Int? = nil registerCount: Int? = nil
) { ) {
self.id = id self.id = id
self.name = name self.name = name
self.heatingLoad = heatingLoad self.heatingLoad = heatingLoad
self.coolingLoad = coolingLoad self.coolingTotal = coolingTotal
self.registerCount = registerCount self.coolingSensible = coolingSensible
}
}
// TODO: Remove and just use create.
public struct Form: Codable, Equatable, Sendable {
public let name: String
public let heatingLoad: Double
public let coolingLoad: Double
public let registerCount: Int
public init(
name: String,
heatingLoad: Double,
coolingLoad: Double,
registerCount: Int
) {
self.name = name
self.heatingLoad = heatingLoad
self.coolingLoad = coolingLoad
self.registerCount = registerCount self.registerCount = registerCount
} }
} }
@@ -121,7 +97,7 @@ extension Room {
projectID: UUID(0), projectID: UUID(0),
name: "Kitchen", name: "Kitchen",
heatingLoad: 12345, heatingLoad: 12345,
coolingLoad: 1234, coolingTotal: 1234,
registerCount: 2, registerCount: 2,
createdAt: Date(), createdAt: Date(),
updatedAt: Date() updatedAt: Date()
@@ -131,7 +107,7 @@ extension Room {
projectID: UUID(1), projectID: UUID(1),
name: "Bedroom - 1", name: "Bedroom - 1",
heatingLoad: 12345, heatingLoad: 12345,
coolingLoad: 1456, coolingTotal: 1456,
registerCount: 1, registerCount: 1,
createdAt: Date(), createdAt: Date(),
updatedAt: Date() updatedAt: Date()
@@ -141,7 +117,7 @@ extension Room {
projectID: UUID(2), projectID: UUID(2),
name: "Family Room", name: "Family Room",
heatingLoad: 12345, heatingLoad: 12345,
coolingLoad: 1673, coolingTotal: 1673,
registerCount: 3, registerCount: 3,
createdAt: Date(), createdAt: Date(),
updatedAt: Date() updatedAt: Date()

View File

@@ -57,6 +57,11 @@ extension SiteRoute.View {
Field("city", .string) Field("city", .string)
Field("state", .string) Field("state", .string)
Field("zipCode", .string) Field("zipCode", .string)
Optionally {
Field("sensibleHeatRatio", default: nil) {
Double.parser()
}
}
} }
.map(.memberwise(Project.Create.init)) .map(.memberwise(Project.Create.init))
} }
@@ -125,6 +130,11 @@ extension SiteRoute.View {
Optionally { Optionally {
Field("zipCode", .string) Field("zipCode", .string)
} }
Optionally {
Field("sensibleHeatRatio", default: nil) {
Double.parser()
}
}
} }
.map(.memberwise(Project.Update.init)) .map(.memberwise(Project.Update.init))
} }
@@ -176,8 +186,9 @@ extension SiteRoute.View.ProjectRoute {
case delete(id: Room.ID) case delete(id: Room.ID)
case form(id: Room.ID? = nil, dismiss: Bool = false) case form(id: Room.ID? = nil, dismiss: Bool = false)
case index case index
case submit(Room.Form) case submit(Room.Create)
case update(Room.Update) case update(Room.Update)
case updateSensibleHeatRatio(SHRUpdate)
static let rootPath = "rooms" static let rootPath = "rooms"
@@ -213,12 +224,16 @@ extension SiteRoute.View.ProjectRoute {
Method.post Method.post
Body { Body {
FormData { FormData {
Field("projectID") { Project.ID.parser() }
Field("name", .string) Field("name", .string)
Field("heatingLoad") { Double.parser() } Field("heatingLoad") { Double.parser() }
Field("coolingLoad") { Double.parser() } Field("coolingTotal") { Double.parser() }
Optionally {
Field("coolingSensible", default: nil) { Double.parser() }
}
Field("registerCount") { Digits() } Field("registerCount") { Digits() }
} }
.map(.memberwise(Room.Form.init)) .map(.memberwise(Room.Create.init))
} }
} }
Route(.case(Self.update)) { Route(.case(Self.update)) {
@@ -234,7 +249,10 @@ extension SiteRoute.View.ProjectRoute {
Field("heatingLoad") { Double.parser() } Field("heatingLoad") { Double.parser() }
} }
Optionally { Optionally {
Field("coolingLoad") { Double.parser() } Field("coolingTotal") { Double.parser() }
}
Optionally {
Field("coolingSensible") { Double.parser() }
} }
Optionally { Optionally {
Field("registerCount") { Digits() } Field("registerCount") { Digits() }
@@ -243,6 +261,27 @@ extension SiteRoute.View.ProjectRoute {
.map(.memberwise(Room.Update.init)) .map(.memberwise(Room.Update.init))
} }
} }
Route(.case(Self.updateSensibleHeatRatio)) {
Path {
rootPath
"update-shr"
}
Method.patch
Body {
FormData {
Field("projectID") { Project.ID.parser() }
Optionally {
Field("sensibleHeatRatio") { Double.parser() }
}
}
.map(.memberwise(SHRUpdate.init))
}
}
}
public struct SHRUpdate: Codable, Equatable, Sendable {
public let projectID: Project.ID
public let sensibleHeatRatio: Double?
} }
} }
@@ -405,9 +444,10 @@ extension SiteRoute.View {
Method.get Method.get
Query { Query {
Optionally { Optionally {
Field("next", default: nil) { Field("next", .string, default: nil)
CharacterSet.urlPathAllowed.map(.string) // {
} // CharacterSet.map(.string)
// }
} }
} }
} }
@@ -419,9 +459,7 @@ extension SiteRoute.View {
Field("email", .string) Field("email", .string)
Field("password", .string) Field("password", .string)
Optionally { Optionally {
Field("next", default: nil) { Field("next", .string, default: nil)
CharacterSet.urlPathAllowed.map(.string)
}
} }
} }
.map(.memberwise(User.Login.init)) .map(.memberwise(User.Login.init))

View File

@@ -16,7 +16,7 @@ public struct SubmitButton: HTML, Sendable {
button( button(
.class( .class(
""" """
text-white font-bold text-xl bg-blue-500 hover:bg-blue-600 px-4 py-2 rounded-lg shadow-lg btn btn-secondary
""" """
), ),
.type(type) .type(type)

View File

@@ -29,3 +29,9 @@ extension HTMLAttribute where Tag == HTMLTag.input {
value(double == nil ? "" : "\(double!)") value(double == nil ? "" : "\(double!)")
} }
} }
extension HTMLAttribute where Tag == HTMLTag.button {
public static func showModal(id: String) -> Self {
.on(.click, "\(id).showModal()")
}
}

View File

@@ -2,36 +2,37 @@ import Elementary
public struct ModalForm<T: HTML>: HTML, Sendable where T: Sendable { public struct ModalForm<T: HTML>: HTML, Sendable where T: Sendable {
let closeButton: Bool
let dismiss: Bool let dismiss: Bool
let id: String let id: String
let inner: T let inner: T
public init( public init(
id: String, id: String,
closeButton: Bool = true,
dismiss: Bool, dismiss: Bool,
@HTMLBuilder inner: () -> T @HTMLBuilder inner: () -> T
) { ) {
self.closeButton = closeButton
self.dismiss = dismiss self.dismiss = dismiss
self.id = id self.id = id
self.inner = inner() self.inner = inner()
} }
public var body: some HTML { public var body: some HTML {
if dismiss { dialog(.id(id), .class("modal")) {
div(.id(id)) {} div(.class("modal-box")) {
} else { if closeButton {
div( button(
.id(id), .class("btn btn-sm btn-circle btn-ghost absolute right-2 top-2"),
.class( .on(.click, "\(id).close()")
"""
fixed top-40 left-[25vw] w-1/2 z-50 text-gray-800
bg-gray-200 border border-gray-400
rounded-lg shadow-lg mx-10
"""
)
) { ) {
SVG(.close)
}
}
inner inner
} }
} }
.attributes(.class("modal-open"), when: dismiss == false)
} }
} }

View File

@@ -179,7 +179,7 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
case .submit(let form): case .submit(let form):
request.logger.debug("New room form submitted.") request.logger.debug("New room form submitted.")
let _ = try await database.rooms.create(.init(form: form, projectID: projectID)) let _ = try await database.rooms.create(form)
return request.view { return request.view {
ProjectView(projectID: projectID, activeTab: .rooms) ProjectView(projectID: projectID, activeTab: .rooms)
} }
@@ -187,6 +187,14 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
case .update(let form): case .update(let form):
_ = try await database.rooms.update(form) _ = try await database.rooms.update(form)
return ProjectView(projectID: projectID, activeTab: .rooms) return ProjectView(projectID: projectID, activeTab: .rooms)
case .updateSensibleHeatRatio(let form):
let _ = try await database.projects.update(
.init(id: form.projectID, sensibleHeatRatio: form.sensibleHeatRatio)
)
return request.view {
ProjectView(projectID: projectID, activeTab: .rooms)
}
} }
} }
} }

View File

@@ -5,6 +5,8 @@ import Styleguide
// TODO: Have form hold onto equipment info model to edit. // TODO: Have form hold onto equipment info model to edit.
struct EquipmentInfoForm: HTML, Sendable { struct EquipmentInfoForm: HTML, Sendable {
static let id = "equipmentForm"
let dismiss: Bool let dismiss: Bool
let projectID: Project.ID let projectID: Project.ID
let equipmentInfo: EquipmentInfo? let equipmentInfo: EquipmentInfo?
@@ -31,7 +33,7 @@ struct EquipmentInfoForm: HTML, Sendable {
} }
var body: some HTML { 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" } h1(.class("text-3xl font-bold pb-6 ps-2")) { "Equipment Info" }
form( form(
.class("space-y-4 p-4"), .class("space-y-4 p-4"),
@@ -64,21 +66,9 @@ struct EquipmentInfoForm: HTML, Sendable {
Input(id: "coolingCFM", placeholder: "CFM") Input(id: "coolingCFM", placeholder: "CFM")
.attributes(.type(.number), .min("0"), .value(coolingCFM)) .attributes(.type(.number), .min("0"), .value(coolingCFM))
} }
Row { div {
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") SubmitButton(title: "Save")
} .attributes(.class("btn-block"))
} }
} }
} }

View File

@@ -15,15 +15,11 @@ struct EquipmentInfoView: HTML, Sendable {
Row { Row {
h1(.class("text-2xl font-bold")) { "Equipment Info" } h1(.class("text-2xl font-bold")) { "Equipment Info" }
if equipmentInfo != nil {
EditButton() EditButton()
.attributes( .attributes(
.hx.get(route: .project(.detail(projectID, .equipment(.form(dismiss: false))))), .on(.click, "\(EquipmentInfoForm.id).showModal()")
.hx.target("#equipmentForm"),
.hx.swap(.outerHTML)
) )
} }
}
if let equipmentInfo { if let equipmentInfo {
@@ -45,10 +41,10 @@ struct EquipmentInfoView: HTML, Sendable {
} }
.attributes(.class("border-b border-gray-200")) .attributes(.class("border-b border-gray-200"))
EquipmentInfoForm(dismiss: true, projectID: projectID, equipmentInfo: nil) }
} else { EquipmentInfoForm(
EquipmentInfoForm(dismiss: false, projectID: projectID, equipmentInfo: nil) dismiss: true, projectID: projectID, equipmentInfo: equipmentInfo
} )
} }
} }
} }

View File

@@ -26,7 +26,7 @@ public struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable
} }
public var body: some HTML { public var body: some HTML {
div { div(.class("h-screen w-full")) {
inner inner
} }
script(.src("https://unpkg.com/lucide@latest")) {} script(.src("https://unpkg.com/lucide@latest")) {}

View File

@@ -18,9 +18,7 @@ struct ProjectDetail: HTML, Sendable {
h1(.class("text-2xl font-bold")) { "Project" } h1(.class("text-2xl font-bold")) { "Project" }
EditButton() EditButton()
.attributes( .attributes(
.hx.get(route: .project(.form(id: project.id, dismiss: false))), .on(.click, "projectForm.showModal()")
.hx.target("#projectForm"),
.hx.swap(.outerHTML)
) )
} }
@@ -54,6 +52,6 @@ struct ProjectDetail: HTML, Sendable {
} }
} }
ProjectForm(dismiss: true) ProjectForm(dismiss: true, project: project)
} }
} }

View File

@@ -34,7 +34,7 @@ struct ProjectForm: HTML, Sendable {
div { div {
label(.for("name")) { "Name" } label(.for("name")) { "Name" }
Input(id: "name", placeholder: "Name") Input(id: "name", placeholder: "Name")
.attributes(.type(.text), .required, .autofocus) .attributes(.type(.text), .required, .autofocus, .value(project?.name))
} }
div { div {
label(.for("streetAddress")) { "Address" } label(.for("streetAddress")) { "Address" }
@@ -57,14 +57,9 @@ struct ProjectForm: HTML, Sendable {
.attributes(.type(.text), .required, .value(project?.zipCode)) .attributes(.type(.text), .required, .value(project?.zipCode))
} }
div(.class("flex justify-end space-x-6")) { div(.class("flex mt-6")) {
CancelButton()
.attributes(
.hx.get(route: .project(.form(dismiss: true))),
.hx.target("#projectForm"),
.hx.swap(.outerHTML)
)
SubmitButton() SubmitButton()
.attributes(.class("btn-block"))
} }
} }
} }

View File

@@ -36,7 +36,11 @@ struct ProjectView: HTML, Sendable {
} }
} }
case .rooms: 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: case .effectiveLength:
try await EffectiveLengthsView( try await EffectiveLengthsView(

View File

@@ -67,8 +67,7 @@ extension ProjectsTable {
td { "\(project.name)" } td { "\(project.name)" }
td { "\(project.streetAddress)" } td { "\(project.streetAddress)" }
td { td {
Row { div(.class("flex justify-end space-x-6")) {
div {}
TrashButton() TrashButton()
.attributes( .attributes(
.hx.delete(route: .project(.delete(id: project.id))), .hx.delete(route: .project(.delete(id: project.id))),

View File

@@ -8,15 +8,19 @@ import Styleguide
// TODO: Need to hold the project ID in hidden input field. // TODO: Need to hold the project ID in hidden input field.
struct RoomForm: HTML, Sendable { struct RoomForm: HTML, Sendable {
static let id = "roomForm"
let dismiss: Bool let dismiss: Bool
let projectID: Project.ID let projectID: Project.ID
let room: Room? let room: Room?
var body: some HTML { var body: some HTML {
ModalForm(id: "roomForm", dismiss: dismiss) { ModalForm(id: Self.id, dismiss: dismiss) {
h1(.class("text-3xl font-bold pb-6")) { "Room" } h1(.class("text-3xl font-bold pb-6")) { "Room" }
// TODO: Use htmx here. // TODO: Use htmx here.
form( form(
.class("modal-backdrop"),
.init(name: "method", value: "dialog"),
room == nil room == nil
? .hx.post(route: .project(.detail(projectID, .rooms(.index)))) ? .hx.post(route: .project(.detail(projectID, .rooms(.index))))
: .hx.patch(route: .project(.detail(projectID, .rooms(.index)))), : .hx.patch(route: .project(.detail(projectID, .rooms(.index)))),
@@ -41,11 +45,16 @@ struct RoomForm: HTML, Sendable {
.attributes(.type(.number), .required, .min("0"), .value(room?.heatingLoad)) .attributes(.type(.number), .required, .min("0"), .value(room?.heatingLoad))
} }
div { div {
label(.for("coolingLoad")) { "Cooling Load:" } label(.for("coolingTotal")) { "Cooling Total:" }
Input(id: "coolingLoad", placeholder: "Cooling Load") Input(id: "coolingTotal", placeholder: "Cooling Total")
.attributes(.type(.number), .required, .min("0"), .value(room?.coolingLoad)) .attributes(.type(.number), .required, .min("0"), .value(room?.coolingTotal))
} }
div { div {
label(.for("coolingSensible")) { "Cooling Sensible:" }
Input(id: "coolingSensible", placeholder: "Cooling Sensible (Optional)")
.attributes(.type(.number), .min("0"), .value(room?.coolingSensible))
}
div(.class("pb-6")) {
label(.for("registerCount")) { "Registers:" } label(.for("registerCount")) { "Registers:" }
Input(id: "registerCount", placeholder: "Register Count") Input(id: "registerCount", placeholder: "Register Count")
.attributes( .attributes(
@@ -53,21 +62,10 @@ struct RoomForm: HTML, Sendable {
.value("\(room != nil ? room!.registerCount : 1)"), .value("\(room != nil ? room!.registerCount : 1)"),
) )
} }
Row { div(.class("flex justify-end space-x-4")) {
// Force button to the right, probably a better way.
div {}
div(.class("space-x-4")) {
CancelButton()
.attributes(
.hx.get(route: .project(.detail(projectID, .rooms(.form(dismiss: true))))),
.hx.target("#roomForm"),
.hx.swap(.outerHTML)
)
SubmitButton() SubmitButton()
} }
} }
.attributes(.class("py-4"))
}
} }
} }
} }

View File

@@ -10,6 +10,7 @@ import Styleguide
struct RoomsView: HTML, Sendable { struct RoomsView: HTML, Sendable {
let projectID: Project.ID let projectID: Project.ID
let rooms: [Room] let rooms: [Room]
let sensibleHeatRatio: Double?
var body: some HTML { var body: some HTML {
div { div {
@@ -20,9 +21,7 @@ struct RoomsView: HTML, Sendable {
.data("tip", value: "Add room") .data("tip", value: "Add room")
) { ) {
button( button(
.hx.get(route: .project(.detail(projectID, .rooms(.form(dismiss: false))))), .showModal(id: RoomForm.id),
.hx.target("#roomForm"),
.hx.swap(.outerHTML),
.class("btn btn-primary w-[40px] text-2xl") .class("btn btn-primary w-[40px] text-2xl")
) { ) {
"+" "+"
@@ -31,6 +30,23 @@ struct RoomsView: HTML, Sendable {
} }
.attributes(.class("pb-6")) .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")) { div(.class("overflow-x-auto rounded-box border")) {
table(.class("table table-zebra"), .id("roomsTable")) { table(.class("table table-zebra"), .id("roomsTable")) {
thead { thead {
@@ -81,9 +97,10 @@ struct RoomsView: HTML, Sendable {
.attributes(.class("text-error")) .attributes(.class("text-error"))
} }
td { td {
Number(room.coolingLoad) Number(room.coolingTotal)
.attributes(.class("text-success")) .attributes(.class("text-success"))
} }
// FIX: Add cooling sensible.
td { td {
Number(room.registerCount) Number(room.registerCount)
} }
@@ -112,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 { extension Array where Element == Room {
@@ -120,6 +165,6 @@ extension Array where Element == Room {
} }
var coolingTotal: Double { var coolingTotal: Double {
reduce(into: 0) { $0 += $1.coolingLoad } reduce(into: 0) { $0 += $1.coolingTotal }
} }
} }

View File

@@ -13,22 +13,20 @@ struct LoginForm: HTML, Sendable {
} }
var body: some HTML { var body: some HTML {
div( ModalForm(id: "loginForm", closeButton: false, dismiss: false) {
.id("loginForm"), h1(.class("text-2xl font-bold mb-6")) { style.title }
.class("flex items-center justify-center")
) {
form( form(
.method(.post) .method(.post),
.class("space-y-4")
) { ) {
if let next { if let next {
input(.class("hidden"), .name("next"), .value(next)) input(.class("hidden"), .name("next"), .value(next))
} }
fieldset(.class("fieldset bg-base-200 border-base-300 rounded-box w-xl border p-4")) {
legend(.class("fieldset-legend")) { style.title }
if style == .signup { if style == .signup {
div {
label(.class("input validator w-full")) { label(.class("input validator w-full")) {
SVG(.user) SVG(.user)
input( input(
@@ -43,7 +41,9 @@ struct LoginForm: HTML, Sendable {
"Must be at least 3 characters" "Must be at least 3 characters"
} }
} }
}
div {
label(.class("input validator w-full")) { label(.class("input validator w-full")) {
SVG(.email) SVG(.email)
input( input(
@@ -52,7 +52,9 @@ struct LoginForm: HTML, Sendable {
) )
} }
div(.class("validator-hint hidden")) { "Enter valid email address." } div(.class("validator-hint hidden")) { "Enter valid email address." }
}
div {
label(.class("input validator w-full")) { label(.class("input validator w-full")) {
SVG(.key) SVG(.key)
input( input(
@@ -61,8 +63,10 @@ struct LoginForm: HTML, Sendable {
.name("password"), .id("password"), .name("password"), .id("password"),
) )
} }
}
if style == .signup { if style == .signup {
div {
label(.class("input validator w-full")) { label(.class("input validator w-full")) {
SVG(.key) SVG(.key)
input( input(
@@ -84,10 +88,15 @@ struct LoginForm: HTML, Sendable {
"At least one uppercase letter" "At least one uppercase letter"
} }
} }
}
button(.class("btn btn-secondary mt-4")) { style.title } div(.class("flex")) {
button(.class("btn btn-secondary mt-4 w-full")) { style.title }
}
div(.class("flex justify-center")) {
a( a(
.class("btn btn-link mt-4"), .class("btn btn-link"),
.href(route: style == .signup ? .login(.index(next: next)) : .signup(.index)) .href(route: style == .signup ? .login(.index(next: next)) : .signup(.index))
) { ) {
style == .login ? "Sign Up" : "Login" style == .login ? "Sign Up" : "Login"

View File

@@ -1,6 +0,0 @@
@import "tailwindcss";
@source not "./tailwindcss";
@source not "./daisyui{,*}.mjs";
@plugin "./daisyui.mjs";