Compare commits
2 Commits
fc12e47b5c
...
8fb313fddc
| Author | SHA1 | Date | |
|---|---|---|---|
|
8fb313fddc
|
|||
|
5fcc5b88fa
|
@@ -4227,8 +4227,11 @@
|
||||
.top-0 {
|
||||
top: calc(var(--spacing) * 0);
|
||||
}
|
||||
.top-40 {
|
||||
top: calc(var(--spacing) * 40);
|
||||
.top-2 {
|
||||
top: calc(var(--spacing) * 2);
|
||||
}
|
||||
.right-2 {
|
||||
right: calc(var(--spacing) * 2);
|
||||
}
|
||||
.dock-sm {
|
||||
@layer daisyui.l1.l2 {
|
||||
@@ -4287,9 +4290,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.left-\[25vw\] {
|
||||
left: 25vw;
|
||||
}
|
||||
.join {
|
||||
display: inline-flex;
|
||||
align-items: stretch;
|
||||
@@ -4676,9 +4676,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.z-50 {
|
||||
z-index: 50;
|
||||
}
|
||||
.tab-content {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
order: var(--tabcontent-order);
|
||||
@@ -5270,9 +5267,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.mx-10 {
|
||||
margin-inline: calc(var(--spacing) * 10);
|
||||
}
|
||||
.file-input-ghost {
|
||||
@layer daisyui.l1.l2 {
|
||||
background-color: transparent;
|
||||
@@ -5562,6 +5556,9 @@
|
||||
border-width: var(--border, 1px) 0 var(--border, 1px) var(--border, 1px);
|
||||
}
|
||||
}
|
||||
.me-4 {
|
||||
margin-inline-end: calc(var(--spacing) * 4);
|
||||
}
|
||||
.modal-action {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
margin-top: calc(0.25rem * 6);
|
||||
@@ -5604,6 +5601,9 @@
|
||||
.mt-4 {
|
||||
margin-top: calc(var(--spacing) * 4);
|
||||
}
|
||||
.mt-6 {
|
||||
margin-top: calc(var(--spacing) * 6);
|
||||
}
|
||||
.breadcrumbs {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
max-width: 100%;
|
||||
@@ -5680,6 +5680,9 @@
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
.mb-6 {
|
||||
margin-bottom: calc(var(--spacing) * 6);
|
||||
}
|
||||
.carousel-item {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
box-sizing: content-box;
|
||||
@@ -6522,18 +6525,12 @@
|
||||
width: calc(var(--size-selector, 0.25rem) * 4);
|
||||
}
|
||||
}
|
||||
.w-1\/2 {
|
||||
width: calc(1/2 * 100%);
|
||||
}
|
||||
.w-\[40px\] {
|
||||
width: 40px;
|
||||
}
|
||||
.w-full {
|
||||
width: 100%;
|
||||
}
|
||||
.w-xl {
|
||||
width: var(--container-xl);
|
||||
}
|
||||
.max-w-\[280px\] {
|
||||
max-width: 280px;
|
||||
}
|
||||
@@ -7182,15 +7179,9 @@
|
||||
border-color: currentColor;
|
||||
}
|
||||
}
|
||||
.border-base-300 {
|
||||
border-color: var(--color-base-300);
|
||||
}
|
||||
.border-gray-200 {
|
||||
border-color: var(--color-gray-200);
|
||||
}
|
||||
.border-gray-400 {
|
||||
border-color: var(--color-gray-400);
|
||||
}
|
||||
.menu-active {
|
||||
:where(:not(ul, details, .menu-title, .btn))& {
|
||||
@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 {
|
||||
background-color: var(--color-red-500);
|
||||
}
|
||||
@@ -7774,9 +7756,6 @@
|
||||
.py-2 {
|
||||
padding-block: calc(var(--spacing) * 2);
|
||||
}
|
||||
.py-4 {
|
||||
padding-block: calc(var(--spacing) * 4);
|
||||
}
|
||||
.py-10 {
|
||||
padding-block: calc(var(--spacing) * 10);
|
||||
}
|
||||
@@ -7797,6 +7776,9 @@
|
||||
.pe-2 {
|
||||
padding-inline-end: calc(var(--spacing) * 2);
|
||||
}
|
||||
.pe-4 {
|
||||
padding-inline-end: calc(var(--spacing) * 4);
|
||||
}
|
||||
.pb-4 {
|
||||
padding-bottom: calc(var(--spacing) * 4);
|
||||
}
|
||||
@@ -8419,9 +8401,6 @@
|
||||
.text-gray-400 {
|
||||
color: var(--color-gray-400);
|
||||
}
|
||||
.text-gray-800 {
|
||||
color: var(--color-gray-800);
|
||||
}
|
||||
.text-slate-900 {
|
||||
color: var(--color-slate-900);
|
||||
}
|
||||
@@ -9297,13 +9276,6 @@
|
||||
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 {
|
||||
@media (hover: hover) {
|
||||
|
||||
@@ -10,6 +10,7 @@ extension DatabaseClient {
|
||||
public var create: @Sendable (User.ID, Project.Create) async throws -> Project
|
||||
public var delete: @Sendable (Project.ID) async throws -> Void
|
||||
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 update: @Sendable (Project.Update) async throws -> Project
|
||||
}
|
||||
@@ -34,6 +35,12 @@ extension DatabaseClient.Projects: TestDependencyKey {
|
||||
get: { id in
|
||||
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
|
||||
try await ProjectModel.query(on: database)
|
||||
.sort(\.$createdAt, .descending)
|
||||
@@ -86,6 +93,14 @@ extension Project.Create {
|
||||
guard !zipCode.isEmpty else {
|
||||
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.")
|
||||
}
|
||||
}
|
||||
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("state", .string, .required)
|
||||
.field("zipCode", .string, .required)
|
||||
.field("sensibleHeatRatio", .double)
|
||||
.field("createdAt", .datetime)
|
||||
.field("updatedAt", .datetime)
|
||||
.field("userID", .uuid, .required, .references(UserModel.schema, "id"))
|
||||
@@ -168,6 +192,9 @@ final class ProjectModel: Model, @unchecked Sendable {
|
||||
@Field(key: "zipCode")
|
||||
var zipCode: String
|
||||
|
||||
@Field(key: "sensibleHeatRatio")
|
||||
var sensibleHeatRatio: Double?
|
||||
|
||||
@Timestamp(key: "createdAt", on: .create, format: .iso8601)
|
||||
var createdAt: Date?
|
||||
|
||||
@@ -189,6 +216,7 @@ final class ProjectModel: Model, @unchecked Sendable {
|
||||
city: String,
|
||||
state: String,
|
||||
zipCode: String,
|
||||
sensibleHeatRatio: Double? = nil,
|
||||
userID: User.ID,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
@@ -199,6 +227,7 @@ final class ProjectModel: Model, @unchecked Sendable {
|
||||
self.city = city
|
||||
self.state = state
|
||||
self.zipCode = zipCode
|
||||
self.sensibleHeatRatio = sensibleHeatRatio
|
||||
$user.id = userID
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
@@ -212,6 +241,7 @@ final class ProjectModel: Model, @unchecked Sendable {
|
||||
city: city,
|
||||
state: state,
|
||||
zipCode: zipCode,
|
||||
sensibleHeatRatio: sensibleHeatRatio,
|
||||
createdAt: createdAt!,
|
||||
updatedAt: updatedAt!
|
||||
)
|
||||
@@ -239,6 +269,12 @@ final class ProjectModel: Model, @unchecked Sendable {
|
||||
hasUpdates = true
|
||||
self.zipCode = zipCode
|
||||
}
|
||||
if let sensibleHeatRatio = updates.sensibleHeatRatio,
|
||||
sensibleHeatRatio != self.sensibleHeatRatio
|
||||
{
|
||||
hasUpdates = true
|
||||
self.sensibleHeatRatio = sensibleHeatRatio
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ extension Room.Create {
|
||||
return .init(
|
||||
name: name,
|
||||
heatingLoad: heatingLoad,
|
||||
coolingLoad: coolingLoad,
|
||||
coolingTotal: coolingTotal,
|
||||
coolingSensible: coolingSensible,
|
||||
registerCount: registerCount,
|
||||
projectID: projectID
|
||||
)
|
||||
@@ -76,9 +77,14 @@ extension Room.Create {
|
||||
guard heatingLoad >= 0 else {
|
||||
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.")
|
||||
}
|
||||
if let coolingSensible {
|
||||
guard coolingSensible >= 0 else {
|
||||
throw ValidationError("Room cooling sensible should not be less than 0.")
|
||||
}
|
||||
}
|
||||
guard registerCount >= 1 else {
|
||||
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.")
|
||||
}
|
||||
}
|
||||
if let coolingLoad {
|
||||
guard coolingLoad >= 0 else {
|
||||
if let coolingTotal {
|
||||
guard coolingTotal >= 0 else {
|
||||
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 {
|
||||
guard registerCount >= 1 else {
|
||||
throw ValidationError("Room cooling sensible should not be less than 1.")
|
||||
@@ -120,7 +131,8 @@ extension Room {
|
||||
.id()
|
||||
.field("name", .string, .required)
|
||||
.field("heatingLoad", .double, .required)
|
||||
.field("coolingLoad", .double, .required)
|
||||
.field("coolingTotal", .double, .required)
|
||||
.field("coolingSensible", .double)
|
||||
.field("registerCount", .int8, .required)
|
||||
.field("createdAt", .datetime)
|
||||
.field("updatedAt", .datetime)
|
||||
@@ -150,8 +162,11 @@ final class RoomModel: Model, @unchecked Sendable {
|
||||
@Field(key: "heatingLoad")
|
||||
var heatingLoad: Double
|
||||
|
||||
@Field(key: "coolingLoad")
|
||||
var coolingLoad: Double
|
||||
@Field(key: "coolingTotal")
|
||||
var coolingTotal: Double
|
||||
|
||||
@Field(key: "coolingSensible")
|
||||
var coolingSensible: Double?
|
||||
|
||||
@Field(key: "registerCount")
|
||||
var registerCount: Int
|
||||
@@ -171,7 +186,8 @@ final class RoomModel: Model, @unchecked Sendable {
|
||||
id: UUID? = nil,
|
||||
name: String,
|
||||
heatingLoad: Double,
|
||||
coolingLoad: Double,
|
||||
coolingTotal: Double,
|
||||
coolingSensible: Double? = nil,
|
||||
registerCount: Int,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil,
|
||||
@@ -180,7 +196,8 @@ final class RoomModel: Model, @unchecked Sendable {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.heatingLoad = heatingLoad
|
||||
self.coolingLoad = coolingLoad
|
||||
self.coolingTotal = coolingTotal
|
||||
self.coolingSensible = coolingSensible
|
||||
self.registerCount = registerCount
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
@@ -193,7 +210,8 @@ final class RoomModel: Model, @unchecked Sendable {
|
||||
projectID: $project.id,
|
||||
name: name,
|
||||
heatingLoad: heatingLoad,
|
||||
coolingLoad: coolingLoad,
|
||||
coolingTotal: coolingTotal,
|
||||
coolingSensible: coolingSensible,
|
||||
registerCount: registerCount,
|
||||
createdAt: createdAt!,
|
||||
updatedAt: updatedAt!
|
||||
@@ -211,9 +229,13 @@ final class RoomModel: Model, @unchecked Sendable {
|
||||
hasUpdates = true
|
||||
self.heatingLoad = heatingLoad
|
||||
}
|
||||
if let coolingLoad = updates.coolingLoad, coolingLoad != self.coolingLoad {
|
||||
if let coolingTotal = updates.coolingTotal, coolingTotal != self.coolingTotal {
|
||||
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 {
|
||||
hasUpdates = true
|
||||
|
||||
@@ -9,6 +9,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
|
||||
public let city: String
|
||||
public let state: String
|
||||
public let zipCode: String
|
||||
public let sensibleHeatRatio: Double?
|
||||
public let createdAt: Date
|
||||
public let updatedAt: Date
|
||||
|
||||
@@ -19,6 +20,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
|
||||
city: String,
|
||||
state: String,
|
||||
zipCode: String,
|
||||
sensibleHeatRatio: Double? = nil,
|
||||
createdAt: Date,
|
||||
updatedAt: Date
|
||||
) {
|
||||
@@ -28,6 +30,7 @@ public struct Project: Codable, Equatable, Identifiable, Sendable {
|
||||
self.city = city
|
||||
self.state = state
|
||||
self.zipCode = zipCode
|
||||
self.sensibleHeatRatio = sensibleHeatRatio
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
@@ -42,6 +45,7 @@ extension Project {
|
||||
public let city: String
|
||||
public let state: String
|
||||
public let zipCode: String
|
||||
public let sensibleHeatRatio: Double?
|
||||
|
||||
public init(
|
||||
name: String,
|
||||
@@ -49,12 +53,14 @@ extension Project {
|
||||
city: String,
|
||||
state: String,
|
||||
zipCode: String,
|
||||
sensibleHeatRatio: Double? = nil,
|
||||
) {
|
||||
self.name = name
|
||||
self.streetAddress = streetAddress
|
||||
self.city = city
|
||||
self.state = state
|
||||
self.zipCode = zipCode
|
||||
self.sensibleHeatRatio = sensibleHeatRatio
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +72,7 @@ extension Project {
|
||||
public let city: String?
|
||||
public let state: String?
|
||||
public let zipCode: String?
|
||||
public let sensibleHeatRatio: Double?
|
||||
|
||||
public init(
|
||||
id: Project.ID,
|
||||
@@ -73,7 +80,8 @@ extension Project {
|
||||
streetAddress: String? = nil,
|
||||
city: String? = nil,
|
||||
state: String? = nil,
|
||||
zipCode: String? = nil
|
||||
zipCode: String? = nil,
|
||||
sensibleHeatRatio: Double? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
@@ -81,6 +89,7 @@ extension Project {
|
||||
self.city = city
|
||||
self.state = state
|
||||
self.zipCode = zipCode
|
||||
self.sensibleHeatRatio = sensibleHeatRatio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
||||
public let projectID: Project.ID
|
||||
public let name: String
|
||||
public let heatingLoad: Double
|
||||
public let coolingLoad: Double
|
||||
public let coolingTotal: Double
|
||||
public let coolingSensible: Double?
|
||||
public let registerCount: Int
|
||||
public let createdAt: Date
|
||||
public let updatedAt: Date
|
||||
@@ -16,7 +17,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
||||
projectID: Project.ID,
|
||||
name: String,
|
||||
heatingLoad: Double,
|
||||
coolingLoad: Double,
|
||||
coolingTotal: Double,
|
||||
coolingSensible: Double? = nil,
|
||||
registerCount: Int = 1,
|
||||
createdAt: Date,
|
||||
updatedAt: Date
|
||||
@@ -25,7 +27,8 @@ public struct Room: Codable, Equatable, Identifiable, Sendable {
|
||||
self.projectID = projectID
|
||||
self.name = name
|
||||
self.heatingLoad = heatingLoad
|
||||
self.coolingLoad = coolingLoad
|
||||
self.coolingTotal = coolingTotal
|
||||
self.coolingSensible = coolingSensible
|
||||
self.registerCount = registerCount
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
@@ -38,75 +41,48 @@ extension Room {
|
||||
public let projectID: Project.ID
|
||||
public let name: String
|
||||
public let heatingLoad: Double
|
||||
public let coolingLoad: Double
|
||||
public let coolingTotal: Double
|
||||
public let coolingSensible: Double?
|
||||
public let registerCount: Int
|
||||
|
||||
public init(
|
||||
projectID: Project.ID,
|
||||
name: String,
|
||||
heatingLoad: Double,
|
||||
coolingLoad: Double,
|
||||
coolingTotal: Double,
|
||||
coolingSensible: Double? = nil,
|
||||
registerCount: Int = 1
|
||||
) {
|
||||
self.projectID = projectID
|
||||
self.name = name
|
||||
self.heatingLoad = heatingLoad
|
||||
self.coolingLoad = coolingLoad
|
||||
self.coolingTotal = coolingTotal
|
||||
self.coolingSensible = coolingSensible
|
||||
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 let id: Room.ID
|
||||
public let name: String?
|
||||
public let heatingLoad: Double?
|
||||
public let coolingLoad: Double?
|
||||
public let coolingTotal: Double?
|
||||
public let coolingSensible: Double?
|
||||
public let registerCount: Int?
|
||||
|
||||
public init(
|
||||
id: Room.ID,
|
||||
name: String? = nil,
|
||||
heatingLoad: Double? = nil,
|
||||
coolingLoad: Double? = nil,
|
||||
coolingTotal: Double? = nil,
|
||||
coolingSensible: Double? = nil,
|
||||
registerCount: Int? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.heatingLoad = heatingLoad
|
||||
self.coolingLoad = coolingLoad
|
||||
self.registerCount = registerCount
|
||||
}
|
||||
}
|
||||
|
||||
// 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.coolingTotal = coolingTotal
|
||||
self.coolingSensible = coolingSensible
|
||||
self.registerCount = registerCount
|
||||
}
|
||||
}
|
||||
@@ -121,7 +97,7 @@ extension Room {
|
||||
projectID: UUID(0),
|
||||
name: "Kitchen",
|
||||
heatingLoad: 12345,
|
||||
coolingLoad: 1234,
|
||||
coolingTotal: 1234,
|
||||
registerCount: 2,
|
||||
createdAt: Date(),
|
||||
updatedAt: Date()
|
||||
@@ -131,7 +107,7 @@ extension Room {
|
||||
projectID: UUID(1),
|
||||
name: "Bedroom - 1",
|
||||
heatingLoad: 12345,
|
||||
coolingLoad: 1456,
|
||||
coolingTotal: 1456,
|
||||
registerCount: 1,
|
||||
createdAt: Date(),
|
||||
updatedAt: Date()
|
||||
@@ -141,7 +117,7 @@ extension Room {
|
||||
projectID: UUID(2),
|
||||
name: "Family Room",
|
||||
heatingLoad: 12345,
|
||||
coolingLoad: 1673,
|
||||
coolingTotal: 1673,
|
||||
registerCount: 3,
|
||||
createdAt: Date(),
|
||||
updatedAt: Date()
|
||||
|
||||
@@ -57,6 +57,11 @@ extension SiteRoute.View {
|
||||
Field("city", .string)
|
||||
Field("state", .string)
|
||||
Field("zipCode", .string)
|
||||
Optionally {
|
||||
Field("sensibleHeatRatio", default: nil) {
|
||||
Double.parser()
|
||||
}
|
||||
}
|
||||
}
|
||||
.map(.memberwise(Project.Create.init))
|
||||
}
|
||||
@@ -125,6 +130,11 @@ extension SiteRoute.View {
|
||||
Optionally {
|
||||
Field("zipCode", .string)
|
||||
}
|
||||
Optionally {
|
||||
Field("sensibleHeatRatio", default: nil) {
|
||||
Double.parser()
|
||||
}
|
||||
}
|
||||
}
|
||||
.map(.memberwise(Project.Update.init))
|
||||
}
|
||||
@@ -176,8 +186,9 @@ extension SiteRoute.View.ProjectRoute {
|
||||
case delete(id: Room.ID)
|
||||
case form(id: Room.ID? = nil, dismiss: Bool = false)
|
||||
case index
|
||||
case submit(Room.Form)
|
||||
case submit(Room.Create)
|
||||
case update(Room.Update)
|
||||
case updateSensibleHeatRatio(SHRUpdate)
|
||||
|
||||
static let rootPath = "rooms"
|
||||
|
||||
@@ -213,12 +224,16 @@ extension SiteRoute.View.ProjectRoute {
|
||||
Method.post
|
||||
Body {
|
||||
FormData {
|
||||
Field("projectID") { Project.ID.parser() }
|
||||
Field("name", .string)
|
||||
Field("heatingLoad") { Double.parser() }
|
||||
Field("coolingLoad") { Double.parser() }
|
||||
Field("coolingTotal") { Double.parser() }
|
||||
Optionally {
|
||||
Field("coolingSensible", default: nil) { Double.parser() }
|
||||
}
|
||||
Field("registerCount") { Digits() }
|
||||
}
|
||||
.map(.memberwise(Room.Form.init))
|
||||
.map(.memberwise(Room.Create.init))
|
||||
}
|
||||
}
|
||||
Route(.case(Self.update)) {
|
||||
@@ -234,7 +249,10 @@ extension SiteRoute.View.ProjectRoute {
|
||||
Field("heatingLoad") { Double.parser() }
|
||||
}
|
||||
Optionally {
|
||||
Field("coolingLoad") { Double.parser() }
|
||||
Field("coolingTotal") { Double.parser() }
|
||||
}
|
||||
Optionally {
|
||||
Field("coolingSensible") { Double.parser() }
|
||||
}
|
||||
Optionally {
|
||||
Field("registerCount") { Digits() }
|
||||
@@ -243,6 +261,27 @@ extension SiteRoute.View.ProjectRoute {
|
||||
.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
|
||||
Query {
|
||||
Optionally {
|
||||
Field("next", default: nil) {
|
||||
CharacterSet.urlPathAllowed.map(.string)
|
||||
}
|
||||
Field("next", .string, default: nil)
|
||||
// {
|
||||
// CharacterSet.map(.string)
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,9 +459,7 @@ extension SiteRoute.View {
|
||||
Field("email", .string)
|
||||
Field("password", .string)
|
||||
Optionally {
|
||||
Field("next", default: nil) {
|
||||
CharacterSet.urlPathAllowed.map(.string)
|
||||
}
|
||||
Field("next", .string, default: nil)
|
||||
}
|
||||
}
|
||||
.map(.memberwise(User.Login.init))
|
||||
|
||||
@@ -16,7 +16,7 @@ public struct SubmitButton: HTML, Sendable {
|
||||
button(
|
||||
.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)
|
||||
|
||||
@@ -29,3 +29,9 @@ extension HTMLAttribute where Tag == HTMLTag.input {
|
||||
value(double == nil ? "" : "\(double!)")
|
||||
}
|
||||
}
|
||||
|
||||
extension HTMLAttribute where Tag == HTMLTag.button {
|
||||
public static func showModal(id: String) -> Self {
|
||||
.on(.click, "\(id).showModal()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,37 @@ import Elementary
|
||||
|
||||
public struct ModalForm<T: HTML>: HTML, Sendable where T: Sendable {
|
||||
|
||||
let closeButton: Bool
|
||||
let dismiss: Bool
|
||||
let id: String
|
||||
let inner: T
|
||||
|
||||
public init(
|
||||
id: String,
|
||||
closeButton: Bool = true,
|
||||
dismiss: Bool,
|
||||
@HTMLBuilder inner: () -> T
|
||||
) {
|
||||
self.closeButton = closeButton
|
||||
self.dismiss = dismiss
|
||||
self.id = id
|
||||
self.inner = inner()
|
||||
}
|
||||
|
||||
public var body: some HTML {
|
||||
if dismiss {
|
||||
div(.id(id)) {}
|
||||
} else {
|
||||
div(
|
||||
.id(id),
|
||||
.class(
|
||||
"""
|
||||
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
|
||||
"""
|
||||
)
|
||||
dialog(.id(id), .class("modal")) {
|
||||
div(.class("modal-box")) {
|
||||
if closeButton {
|
||||
button(
|
||||
.class("btn btn-sm btn-circle btn-ghost absolute right-2 top-2"),
|
||||
.on(.click, "\(id).close()")
|
||||
) {
|
||||
SVG(.close)
|
||||
}
|
||||
}
|
||||
inner
|
||||
}
|
||||
}
|
||||
.attributes(.class("modal-open"), when: dismiss == false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
|
||||
|
||||
case .submit(let form):
|
||||
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 {
|
||||
ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
}
|
||||
@@ -187,6 +187,14 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
|
||||
case .update(let form):
|
||||
_ = try await database.rooms.update(form)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
div {
|
||||
SubmitButton(title: "Save")
|
||||
}
|
||||
.attributes(.class("btn-block"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,11 @@ 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)
|
||||
.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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable
|
||||
}
|
||||
|
||||
public var body: some HTML {
|
||||
div {
|
||||
div(.class("h-screen w-full")) {
|
||||
inner
|
||||
}
|
||||
script(.src("https://unpkg.com/lucide@latest")) {}
|
||||
|
||||
@@ -18,9 +18,7 @@ struct ProjectDetail: HTML, Sendable {
|
||||
h1(.class("text-2xl font-bold")) { "Project" }
|
||||
EditButton()
|
||||
.attributes(
|
||||
.hx.get(route: .project(.form(id: project.id, dismiss: false))),
|
||||
.hx.target("#projectForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
.on(.click, "projectForm.showModal()")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,6 +52,6 @@ struct ProjectDetail: HTML, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
ProjectForm(dismiss: true)
|
||||
ProjectForm(dismiss: true, project: project)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct ProjectForm: HTML, Sendable {
|
||||
div {
|
||||
label(.for("name")) { "Name" }
|
||||
Input(id: "name", placeholder: "Name")
|
||||
.attributes(.type(.text), .required, .autofocus)
|
||||
.attributes(.type(.text), .required, .autofocus, .value(project?.name))
|
||||
}
|
||||
div {
|
||||
label(.for("streetAddress")) { "Address" }
|
||||
@@ -57,14 +57,9 @@ struct ProjectForm: HTML, Sendable {
|
||||
.attributes(.type(.text), .required, .value(project?.zipCode))
|
||||
}
|
||||
|
||||
div(.class("flex justify-end space-x-6")) {
|
||||
CancelButton()
|
||||
.attributes(
|
||||
.hx.get(route: .project(.form(dismiss: true))),
|
||||
.hx.target("#projectForm"),
|
||||
.hx.swap(.outerHTML)
|
||||
)
|
||||
div(.class("flex mt-6")) {
|
||||
SubmitButton()
|
||||
.attributes(.class("btn-block"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -67,8 +67,7 @@ extension ProjectsTable {
|
||||
td { "\(project.name)" }
|
||||
td { "\(project.streetAddress)" }
|
||||
td {
|
||||
Row {
|
||||
div {}
|
||||
div(.class("flex justify-end space-x-6")) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.hx.delete(route: .project(.delete(id: project.id))),
|
||||
|
||||
@@ -8,15 +8,19 @@ 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(
|
||||
.class("modal-backdrop"),
|
||||
.init(name: "method", value: "dialog"),
|
||||
room == nil
|
||||
? .hx.post(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))
|
||||
}
|
||||
div {
|
||||
label(.for("coolingLoad")) { "Cooling Load:" }
|
||||
Input(id: "coolingLoad", placeholder: "Cooling Load")
|
||||
.attributes(.type(.number), .required, .min("0"), .value(room?.coolingLoad))
|
||||
label(.for("coolingTotal")) { "Cooling Total:" }
|
||||
Input(id: "coolingTotal", placeholder: "Cooling Total")
|
||||
.attributes(.type(.number), .required, .min("0"), .value(room?.coolingTotal))
|
||||
}
|
||||
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:" }
|
||||
Input(id: "registerCount", placeholder: "Register Count")
|
||||
.attributes(
|
||||
@@ -53,21 +62,10 @@ struct RoomForm: HTML, Sendable {
|
||||
.value("\(room != nil ? room!.registerCount : 1)"),
|
||||
)
|
||||
}
|
||||
Row {
|
||||
// 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)
|
||||
)
|
||||
div(.class("flex justify-end space-x-4")) {
|
||||
SubmitButton()
|
||||
}
|
||||
}
|
||||
.attributes(.class("py-4"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,9 +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),
|
||||
.showModal(id: RoomForm.id),
|
||||
.class("btn btn-primary w-[40px] text-2xl")
|
||||
) {
|
||||
"+"
|
||||
@@ -31,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 {
|
||||
@@ -81,9 +97,10 @@ struct RoomsView: HTML, Sendable {
|
||||
.attributes(.class("text-error"))
|
||||
}
|
||||
td {
|
||||
Number(room.coolingLoad)
|
||||
Number(room.coolingTotal)
|
||||
.attributes(.class("text-success"))
|
||||
}
|
||||
// FIX: Add cooling sensible.
|
||||
td {
|
||||
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 {
|
||||
@@ -120,6 +165,6 @@ extension Array where Element == Room {
|
||||
}
|
||||
|
||||
var coolingTotal: Double {
|
||||
reduce(into: 0) { $0 += $1.coolingLoad }
|
||||
reduce(into: 0) { $0 += $1.coolingTotal }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,22 +13,20 @@ struct LoginForm: HTML, Sendable {
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
div(
|
||||
.id("loginForm"),
|
||||
.class("flex items-center justify-center")
|
||||
) {
|
||||
ModalForm(id: "loginForm", closeButton: false, dismiss: false) {
|
||||
h1(.class("text-2xl font-bold mb-6")) { style.title }
|
||||
|
||||
form(
|
||||
.method(.post)
|
||||
.method(.post),
|
||||
.class("space-y-4")
|
||||
) {
|
||||
|
||||
if let 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 {
|
||||
div {
|
||||
label(.class("input validator w-full")) {
|
||||
SVG(.user)
|
||||
input(
|
||||
@@ -43,7 +41,9 @@ struct LoginForm: HTML, Sendable {
|
||||
"Must be at least 3 characters"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div {
|
||||
label(.class("input validator w-full")) {
|
||||
SVG(.email)
|
||||
input(
|
||||
@@ -52,7 +52,9 @@ struct LoginForm: HTML, Sendable {
|
||||
)
|
||||
}
|
||||
div(.class("validator-hint hidden")) { "Enter valid email address." }
|
||||
}
|
||||
|
||||
div {
|
||||
label(.class("input validator w-full")) {
|
||||
SVG(.key)
|
||||
input(
|
||||
@@ -61,8 +63,10 @@ struct LoginForm: HTML, Sendable {
|
||||
.name("password"), .id("password"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if style == .signup {
|
||||
div {
|
||||
label(.class("input validator w-full")) {
|
||||
SVG(.key)
|
||||
input(
|
||||
@@ -84,10 +88,15 @@ struct LoginForm: HTML, Sendable {
|
||||
"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(
|
||||
.class("btn btn-link mt-4"),
|
||||
.class("btn btn-link"),
|
||||
.href(route: style == .signup ? .login(.index(next: next)) : .signup(.index))
|
||||
) {
|
||||
style == .login ? "Sign Up" : "Login"
|
||||
|
||||
Reference in New Issue
Block a user