feat: Adds result view to better handle errors, integrates it into project view.
This commit is contained in:
@@ -31,10 +31,13 @@ struct ComponentPressureLossesView: HTML, Sendable {
|
||||
span(.class("text-sm italic")) { "Total" }
|
||||
}
|
||||
}
|
||||
PlusButton()
|
||||
.attributes(
|
||||
.showModal(id: ComponentLossForm.id())
|
||||
)
|
||||
Tooltip("Add Component Loss") {
|
||||
PlusButton()
|
||||
.attributes(
|
||||
.class("btn-ghost text-2xl"),
|
||||
.showModal(id: ComponentLossForm.id())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
table(.class("table table-zebra")) {
|
||||
@@ -65,24 +68,28 @@ struct ComponentPressureLossesView: HTML, Sendable {
|
||||
td { Number(row.value) }
|
||||
td {
|
||||
div(.class("flex join items-end justify-end mx-auto")) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.hx.delete(
|
||||
route: .project(
|
||||
.detail(row.projectID, .componentLoss(.delete(row.id)))
|
||||
)
|
||||
),
|
||||
.hx.target("body"),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.confirm("Are your sure?")
|
||||
Tooltip("Delete", position: .bottom) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.class("join-item btn-ghost"),
|
||||
.hx.delete(
|
||||
route: .project(
|
||||
.detail(row.projectID, .componentLoss(.delete(row.id)))
|
||||
)
|
||||
),
|
||||
.hx.target("body"),
|
||||
.hx.swap(.outerHTML),
|
||||
.hx.confirm("Are your sure?")
|
||||
|
||||
)
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.showModal(id: ComponentLossForm.id(row))
|
||||
)
|
||||
)
|
||||
}
|
||||
Tooltip("Edit", position: .bottom) {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item btn-ghost"),
|
||||
.showModal(id: ComponentLossForm.id(row))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ComponentLossForm(dismiss: true, projectID: row.projectID, componentLoss: row)
|
||||
|
||||
@@ -7,7 +7,9 @@ import Styleguide
|
||||
|
||||
struct DuctSizingView: HTML, Sendable {
|
||||
|
||||
let projectID: Project.ID
|
||||
@Environment(ProjectViewValue.$projectID) var projectID
|
||||
|
||||
// let projectID: Project.ID
|
||||
let rooms: [DuctSizing.RoomContainer]
|
||||
|
||||
var body: some HTML {
|
||||
|
||||
@@ -74,7 +74,7 @@ struct RectangularSizeForm: HTML, Sendable {
|
||||
form(
|
||||
.class("space-y-4"),
|
||||
.hx.post(route),
|
||||
.hx.target("body"),
|
||||
.hx.target("closest tr"),
|
||||
.hx.swap(.outerHTML)
|
||||
) {
|
||||
input(.class("hidden"), .name("register"), .value(register))
|
||||
|
||||
@@ -3,16 +3,8 @@ import ElementaryHTMX
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: May need a multi-step form were the the effective length type is
|
||||
// determined before groups selections are made in order to use the
|
||||
// appropriate select field values when the type is supply vs. return.
|
||||
// Currently when the select field is changed it doesn't change the group
|
||||
// I can get it to add a new one.
|
||||
|
||||
// TODO: Add back buttons / capability??
|
||||
|
||||
// TODO: Add patch / update capability
|
||||
|
||||
struct EffectiveLengthForm: HTML, Sendable {
|
||||
|
||||
static func id(_ equivalentLength: EffectiveLength?) -> String {
|
||||
|
||||
@@ -7,7 +7,9 @@ import Styleguide
|
||||
|
||||
struct EffectiveLengthsView: HTML, Sendable {
|
||||
|
||||
let projectID: Project.ID
|
||||
@Environment(ProjectViewValue.$projectID) var projectID
|
||||
|
||||
// let projectID: Project.ID
|
||||
let effectiveLengths: [EffectiveLength]
|
||||
|
||||
var supplies: [EffectiveLength] {
|
||||
|
||||
@@ -15,10 +15,13 @@ struct EquipmentInfoView: HTML, Sendable {
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Equipment Info" }
|
||||
|
||||
EditButton()
|
||||
.attributes(
|
||||
.on(.click, "\(EquipmentInfoForm.id).showModal()")
|
||||
)
|
||||
Tooltip("Edit equipment info") {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("btn-ghost"),
|
||||
.showModal(id: EquipmentInfoForm.id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if let equipmentInfo {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Elementary
|
||||
import ManualDClient
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
@@ -6,23 +7,20 @@ import Styleguide
|
||||
|
||||
struct FrictionRateView: HTML, Sendable {
|
||||
|
||||
@Environment(ProjectViewValue.$projectID) var projectID
|
||||
|
||||
let equipmentInfo: EquipmentInfo?
|
||||
let componentLosses: [ComponentPressureLoss]
|
||||
let equivalentLengths: EffectiveLength.MaxContainer
|
||||
let projectID: Project.ID
|
||||
// let projectID: Project.ID
|
||||
let frictionRateResponse: ManualDClient.FrictionRateResponse?
|
||||
|
||||
var availableStaticPressure: Double? {
|
||||
guard let staticPressure = equipmentInfo?.staticPressure else {
|
||||
return nil
|
||||
}
|
||||
return staticPressure - componentLosses.totalComponentPressureLoss
|
||||
frictionRateResponse?.availableStaticPressure
|
||||
}
|
||||
|
||||
var frictionRateDesignValue: Double? {
|
||||
guard let availableStaticPressure, let tel = equivalentLengths.total else {
|
||||
return nil
|
||||
}
|
||||
return (((availableStaticPressure * 100) / tel) * 100) / 100
|
||||
frictionRateResponse?.frictionRate
|
||||
}
|
||||
|
||||
var badgeColor: String {
|
||||
|
||||
@@ -7,6 +7,10 @@ import ManualDClient
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
enum ProjectViewValue {
|
||||
@TaskLocal static var projectID = Project.ID(0)
|
||||
}
|
||||
|
||||
struct ProjectView: HTML, Sendable {
|
||||
@Dependency(\.database) var database
|
||||
@Dependency(\.manualD) var manualD
|
||||
@@ -34,50 +38,65 @@ struct ProjectView: HTML, Sendable {
|
||||
div(.class("drawer-content p-4")) {
|
||||
label(
|
||||
.for("my-drawer-1"),
|
||||
.class("btn btn-square btn-ghost drawer-button size-7")
|
||||
.class("btn btn-square btn-ghost drawer-button size-7 pb-6")
|
||||
) {
|
||||
SVG(.sidebarToggle)
|
||||
}
|
||||
switch self.activeTab {
|
||||
case .project:
|
||||
if let project = try await database.projects.get(projectID) {
|
||||
ProjectDetail(project: project)
|
||||
} else {
|
||||
div {
|
||||
"FIX ME!"
|
||||
await resultView(projectID) {
|
||||
guard let project = try await database.projects.get(projectID) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
return project
|
||||
} onSuccess: { project in
|
||||
ProjectDetail(project: project)
|
||||
}
|
||||
case .rooms:
|
||||
try await RoomsView(
|
||||
projectID: projectID,
|
||||
rooms: database.rooms.fetch(projectID),
|
||||
sensibleHeatRatio: database.projects.getSensibleHeatRatio(projectID)
|
||||
)
|
||||
await resultView(projectID) {
|
||||
try await (
|
||||
database.rooms.fetch(projectID),
|
||||
database.projects.getSensibleHeatRatio(projectID)
|
||||
)
|
||||
} onSuccess: { (rooms, shr) in
|
||||
RoomsView(rooms: rooms, sensibleHeatRatio: shr)
|
||||
}
|
||||
|
||||
case .equivalentLength:
|
||||
try await EffectiveLengthsView(
|
||||
projectID: projectID,
|
||||
effectiveLengths: database.effectiveLength.fetch(projectID)
|
||||
)
|
||||
await resultView(projectID) {
|
||||
try await database.effectiveLength.fetch(projectID)
|
||||
} onSuccess: {
|
||||
EffectiveLengthsView(effectiveLengths: $0)
|
||||
}
|
||||
case .frictionRate:
|
||||
try await FrictionRateView(
|
||||
equipmentInfo: database.equipment.fetch(projectID),
|
||||
componentLosses: database.componentLoss.fetch(projectID),
|
||||
equivalentLengths: database.effectiveLength.fetchMax(projectID),
|
||||
projectID: projectID
|
||||
)
|
||||
case .ductSizing:
|
||||
try await DuctSizingView(
|
||||
projectID: projectID,
|
||||
rooms: manualD.calculate(
|
||||
rooms: database.rooms.fetch(projectID),
|
||||
designFrictionRateResult: database.designFrictionRate(projectID: projectID),
|
||||
projectSHR: database.projects.getSensibleHeatRatio(projectID),
|
||||
logger: logger
|
||||
)
|
||||
)
|
||||
// div { "FIX ME!" }
|
||||
|
||||
await resultView(projectID) {
|
||||
|
||||
let equipmentInfo = try await database.equipment.fetch(projectID)
|
||||
let componentLosses = try await database.componentLoss.fetch(projectID)
|
||||
let equivalentLengths = try await database.effectiveLength.fetchMax(projectID)
|
||||
let frictionRateResponse = try await manualD.frictionRate(
|
||||
equipmentInfo: equipmentInfo,
|
||||
componentLosses: componentLosses,
|
||||
effectiveLength: equivalentLengths
|
||||
)
|
||||
return (
|
||||
equipmentInfo, componentLosses, equivalentLengths, frictionRateResponse
|
||||
)
|
||||
} onSuccess: {
|
||||
FrictionRateView(
|
||||
equipmentInfo: $0.0,
|
||||
componentLosses: $0.1,
|
||||
equivalentLengths: $0.2,
|
||||
frictionRateResponse: $0.3
|
||||
)
|
||||
}
|
||||
case .ductSizing:
|
||||
await resultView(projectID) {
|
||||
try await database.calculateDuctSizes(projectID: projectID)
|
||||
} onSuccess: {
|
||||
DuctSizingView(rooms: $0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +108,77 @@ struct ProjectView: HTML, Sendable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func resultView<V: Sendable, E: Error, ValueView: HTML>(
|
||||
_ projectID: Project.ID,
|
||||
catching: @escaping @Sendable () async throws(E) -> V,
|
||||
onSuccess: @escaping @Sendable (V) -> ValueView
|
||||
) async -> ResultView<V, E, _ModifiedTaskLocal<Project.ID, ValueView>, ErrorView<E>>
|
||||
where
|
||||
ValueView: Sendable, E: Sendable
|
||||
{
|
||||
await .init(
|
||||
result: .init(catching: catching),
|
||||
onSuccess: { result in
|
||||
onSuccess(result)
|
||||
.environment(ProjectViewValue.$projectID, projectID)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// extension SiteRoute.View.ProjectRoute.DetailRoute.Tab {
|
||||
//
|
||||
// func view(projectID: Project.ID) async throws -> AnySendableHTML {
|
||||
// @Dependency(\.database) var database
|
||||
// @Dependency(\.manualD) var manualD
|
||||
//
|
||||
// switch self {
|
||||
// case .project:
|
||||
// if let project = try await database.projects.get(projectID) {
|
||||
// return ProjectDetail(project: project)
|
||||
// } else {
|
||||
// return div {
|
||||
// "FIX ME!"
|
||||
// }
|
||||
// }
|
||||
// case .rooms:
|
||||
// return try await RoomsView(
|
||||
// projectID: projectID,
|
||||
// rooms: database.rooms.fetch(projectID),
|
||||
// sensibleHeatRatio: database.projects.getSensibleHeatRatio(projectID)
|
||||
// )
|
||||
//
|
||||
// case .equivalentLength:
|
||||
// return try await EffectiveLengthsView(
|
||||
// projectID: projectID,
|
||||
// effectiveLengths: database.effectiveLength.fetch(projectID)
|
||||
// )
|
||||
// case .frictionRate:
|
||||
// let equipmentInfo = try await database.equipment.fetch(projectID)
|
||||
// let componentLosses = try await database.componentLoss.fetch(projectID)
|
||||
// let equivalentLengths = try await database.effectiveLength.fetchMax(projectID)
|
||||
//
|
||||
// return try await FrictionRateView(
|
||||
// equipmentInfo: equipmentInfo,
|
||||
// componentLosses: componentLosses,
|
||||
// equivalentLengths: equivalentLengths,
|
||||
// projectID: projectID,
|
||||
// frictionRateResponse: manualD.frictionRate(
|
||||
// equipmentInfo: equipmentInfo,
|
||||
// componentLosses: componentLosses,
|
||||
// effectiveLength: equivalentLengths
|
||||
// )
|
||||
// )
|
||||
// case .ductSizing:
|
||||
// return try await DuctSizingView(
|
||||
// projectID: projectID,
|
||||
// rooms: database.calculateDuctSizes(projectID: projectID)
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
extension ProjectView {
|
||||
|
||||
struct Sidebar: HTML {
|
||||
@@ -261,3 +349,27 @@ extension ProjectView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ManualDClient {
|
||||
|
||||
func frictionRate(
|
||||
equipmentInfo: EquipmentInfo?,
|
||||
componentLosses: [ComponentPressureLoss],
|
||||
effectiveLength: EffectiveLength.MaxContainer
|
||||
) async throws -> FrictionRateResponse? {
|
||||
guard let staticPressure = equipmentInfo?.staticPressure else {
|
||||
return nil
|
||||
}
|
||||
guard let totalEquivalentLength = effectiveLength.total else {
|
||||
return nil
|
||||
}
|
||||
return try await self.frictionRate(
|
||||
.init(
|
||||
externalStaticPressure: staticPressure,
|
||||
componentPressureLosses: componentLosses,
|
||||
totalEffectiveLength: Int(totalEquivalentLength)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,40 +5,36 @@ import Foundation
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
// TODO: Calculate rooms sensible based on project wide SHR.
|
||||
|
||||
struct RoomsView: HTML, Sendable {
|
||||
let projectID: Project.ID
|
||||
@Environment(ProjectViewValue.$projectID) var projectID
|
||||
// let projectID: Project.ID
|
||||
let rooms: [Room]
|
||||
let sensibleHeatRatio: Double?
|
||||
|
||||
var body: some HTML {
|
||||
div {
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Room Loads" }
|
||||
// div(
|
||||
// .class("tooltip tooltip-left"),
|
||||
// .data("tip", value: "Add room")
|
||||
// ) {
|
||||
// div(.class("flex me-4")) {
|
||||
// PlusButton()
|
||||
// .attributes(.showModal(id: RoomForm.id()))
|
||||
// }
|
||||
// }
|
||||
}
|
||||
.attributes(.class("pb-6"))
|
||||
h1(.class("text-2xl font-bold pb-6")) { "Room Loads" }
|
||||
|
||||
div(.class("border rounded-lg mb-6")) {
|
||||
Row {
|
||||
div(.class("space-x-6 my-2")) {
|
||||
Label("Sensible Heat Ratio")
|
||||
if let sensibleHeatRatio {
|
||||
Number(sensibleHeatRatio)
|
||||
div {
|
||||
div(.class("space-x-6 my-2 items-center")) {
|
||||
Label("Sensible Heat Ratio")
|
||||
.attributes(.class("my-auto"))
|
||||
if let sensibleHeatRatio {
|
||||
Number(sensibleHeatRatio)
|
||||
.attributes(.class("badge badge-outline"))
|
||||
}
|
||||
}
|
||||
p(.class("text-sm italic")) {
|
||||
"Project wide sensible heat ratio"
|
||||
}
|
||||
}
|
||||
|
||||
EditButton()
|
||||
.attributes(.showModal(id: SHRForm.id))
|
||||
Tooltip("Edit SHR") {
|
||||
EditButton()
|
||||
.attributes(.showModal(id: SHRForm.id))
|
||||
}
|
||||
}
|
||||
.attributes(.class("m-4"))
|
||||
|
||||
@@ -134,7 +130,7 @@ struct RoomsView: HTML, Sendable {
|
||||
td {
|
||||
div(.class("flex justify-end")) {
|
||||
div(.class("join")) {
|
||||
Tooltip("Delete room") {
|
||||
Tooltip("Delete room", position: .bottom) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.class("join-item btn-ghost"),
|
||||
@@ -144,16 +140,14 @@ struct RoomsView: HTML, Sendable {
|
||||
.hx.confirm("Are you sure?")
|
||||
)
|
||||
}
|
||||
.attributes(.class("tooltip-bottom"))
|
||||
|
||||
Tooltip("Edit room") {
|
||||
Tooltip("Edit room", position: .bottom) {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item btn-ghost"),
|
||||
.showModal(id: RoomForm.id(room))
|
||||
)
|
||||
}
|
||||
.attributes(.class("tooltip-bottom"))
|
||||
}
|
||||
}
|
||||
RoomForm(
|
||||
|
||||
Reference in New Issue
Block a user