Compare commits
3 Commits
07818d24ed
...
1446540109
| Author | SHA1 | Date | |
|---|---|---|---|
|
1446540109
|
|||
|
20065ebf10
|
|||
|
a356aa2a13
|
@@ -2206,9 +2206,6 @@
|
||||
.collapse {
|
||||
visibility: collapse;
|
||||
}
|
||||
.invisible {
|
||||
visibility: hidden;
|
||||
}
|
||||
.visible {
|
||||
visibility: visible;
|
||||
}
|
||||
@@ -5363,15 +5360,15 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.my-1 {
|
||||
margin-block: calc(var(--spacing) * 1);
|
||||
}
|
||||
.my-1\.5 {
|
||||
margin-block: calc(var(--spacing) * 1.5);
|
||||
}
|
||||
.my-2 {
|
||||
margin-block: calc(var(--spacing) * 2);
|
||||
}
|
||||
.my-auto {
|
||||
margin-block: auto;
|
||||
}
|
||||
.label {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
display: inline-flex;
|
||||
@@ -5578,15 +5575,6 @@
|
||||
.ms-4 {
|
||||
margin-inline-start: calc(var(--spacing) * 4);
|
||||
}
|
||||
.ms-6 {
|
||||
margin-inline-start: calc(var(--spacing) * 6);
|
||||
}
|
||||
.ms-8 {
|
||||
margin-inline-start: calc(var(--spacing) * 8);
|
||||
}
|
||||
.me-4 {
|
||||
margin-inline-end: calc(var(--spacing) * 4);
|
||||
}
|
||||
.modal-action {
|
||||
@layer daisyui.l1.l2.l3 {
|
||||
margin-top: calc(0.25rem * 6);
|
||||
@@ -6760,9 +6748,6 @@
|
||||
.grid-cols-1 {
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
.grid-cols-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.grid-cols-5 {
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
}
|
||||
@@ -7811,9 +7796,6 @@
|
||||
.px-4 {
|
||||
padding-inline: calc(var(--spacing) * 4);
|
||||
}
|
||||
.py-1 {
|
||||
padding-block: calc(var(--spacing) * 1);
|
||||
}
|
||||
.py-1\.5 {
|
||||
padding-block: calc(var(--spacing) * 1.5);
|
||||
}
|
||||
@@ -7826,9 +7808,6 @@
|
||||
.ps-2 {
|
||||
padding-inline-start: calc(var(--spacing) * 2);
|
||||
}
|
||||
.ps-8 {
|
||||
padding-inline-start: calc(var(--spacing) * 8);
|
||||
}
|
||||
.file-input-xl {
|
||||
@layer daisyui.l1.l2 {
|
||||
padding-inline-end: calc(0.25rem * 6);
|
||||
@@ -9377,6 +9356,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.hover\:text-white {
|
||||
&:hover {
|
||||
@media (hover: hover) {
|
||||
color: var(--color-white);
|
||||
}
|
||||
}
|
||||
}
|
||||
.focus\:outline {
|
||||
&:focus {
|
||||
outline-style: var(--tw-outline-style);
|
||||
@@ -9393,11 +9379,6 @@
|
||||
outline-color: var(--color-indigo-600);
|
||||
}
|
||||
}
|
||||
.md\:grid-cols-1 {
|
||||
@media (width >= 48rem) {
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
.md\:grid-cols-2 {
|
||||
@media (width >= 48rem) {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
@@ -9456,26 +9437,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.lg\:visible {
|
||||
@media (width >= 64rem) {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
.lg\:block {
|
||||
@media (width >= 64rem) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
.lg\:inline-block {
|
||||
@media (width >= 64rem) {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
.lg\:table-cell {
|
||||
@media (width >= 64rem) {
|
||||
display: table-cell;
|
||||
}
|
||||
}
|
||||
.lg\:grid-cols-2 {
|
||||
@media (width >= 64rem) {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
@@ -9486,26 +9447,11 @@
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
.xl\:visible {
|
||||
@media (width >= 80rem) {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
.xl\:table-cell {
|
||||
@media (width >= 80rem) {
|
||||
display: table-cell;
|
||||
}
|
||||
}
|
||||
.xl\:grid-cols-2 {
|
||||
@media (width >= 80rem) {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
.xl\:grid-cols-3 {
|
||||
@media (width >= 80rem) {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
.\32 xl\:table-cell {
|
||||
@media (width >= 96rem) {
|
||||
display: table-cell;
|
||||
|
||||
@@ -9,4 +9,6 @@ public struct ValidationError: Error {
|
||||
}
|
||||
}
|
||||
|
||||
public struct NotFoundError: Error {}
|
||||
public struct NotFoundError: Error {
|
||||
public init() {}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ extension DatabaseClient {
|
||||
public struct Rooms: Sendable {
|
||||
public var create: @Sendable (Room.Create) async throws -> Room
|
||||
public var delete: @Sendable (Room.ID) async throws -> Void
|
||||
public var deleteRectangularSize:
|
||||
@Sendable (Room.ID, DuctSizing.RectangularDuct.ID) async throws -> Room
|
||||
public var get: @Sendable (Room.ID) async throws -> Room?
|
||||
public var fetch: @Sendable (Project.ID) async throws -> [Room]
|
||||
public var update: @Sendable (Room.ID, Room.Update) async throws -> Room
|
||||
@@ -31,6 +33,18 @@ extension DatabaseClient.Rooms: TestDependencyKey {
|
||||
}
|
||||
try await model.delete(on: database)
|
||||
},
|
||||
deleteRectangularSize: { roomID, rectangularDuctID in
|
||||
guard let model = try await RoomModel.find(roomID, on: database) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
model.rectangularSizes?.removeAll {
|
||||
$0.id == rectangularDuctID
|
||||
}
|
||||
if model.hasChanges {
|
||||
try await model.save(on: database)
|
||||
}
|
||||
return try model.toDTO()
|
||||
},
|
||||
get: { id in
|
||||
try await RoomModel.find(id, on: database).map { try $0.toDTO() }
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import ManualDCore
|
||||
extension Room {
|
||||
|
||||
var heatingLoadPerRegister: Double {
|
||||
|
||||
heatingLoad / Double(registerCount)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ extension ManualDClient: DependencyKey {
|
||||
throw ManualDError(message: "Total Effective Length should be greater than 0.")
|
||||
}
|
||||
|
||||
let totalComponentLosses = request.componentPressureLosses.totalLosses
|
||||
let totalComponentLosses = request.componentPressureLosses.totalComponentPressureLoss
|
||||
let availableStaticPressure = request.externalStaticPressure - totalComponentLosses
|
||||
let frictionRate = availableStaticPressure * 100.0 / Double(request.totalEffectiveLength)
|
||||
return .init(availableStaticPressure: availableStaticPressure, frictionRate: frictionRate)
|
||||
|
||||
@@ -130,12 +130,12 @@ extension ManualDClient {
|
||||
public struct FrictionRateRequest: Codable, Equatable, Sendable {
|
||||
|
||||
public let externalStaticPressure: Double
|
||||
public let componentPressureLosses: ComponentPressureLosses
|
||||
public let componentPressureLosses: [ComponentPressureLoss]
|
||||
public let totalEffectiveLength: Int
|
||||
|
||||
public init(
|
||||
externalStaticPressure: Double,
|
||||
componentPressureLosses: ComponentPressureLosses,
|
||||
componentPressureLosses: [ComponentPressureLoss],
|
||||
totalEffectiveLength: Int
|
||||
) {
|
||||
self.externalStaticPressure = externalStaticPressure
|
||||
|
||||
@@ -3,15 +3,18 @@ import Foundation
|
||||
|
||||
public enum DuctSizing {
|
||||
|
||||
public struct RectangularDuct: Codable, Equatable, Sendable {
|
||||
public struct RectangularDuct: Codable, Equatable, Identifiable, Sendable {
|
||||
|
||||
public let id: UUID
|
||||
public let register: Int?
|
||||
public let height: Int
|
||||
|
||||
public init(
|
||||
id: UUID = .init(),
|
||||
register: Int? = nil,
|
||||
height: Int,
|
||||
) {
|
||||
self.id = id
|
||||
self.register = register
|
||||
self.height = height
|
||||
}
|
||||
|
||||
@@ -677,6 +677,7 @@ extension SiteRoute.View.ProjectRoute {
|
||||
|
||||
public enum DuctSizingRoute: Equatable, Sendable {
|
||||
case index
|
||||
case deleteRectangularSize(Room.ID, DuctSizing.RectangularDuct.ID)
|
||||
case roomRectangularForm(Room.ID, RoomRectangularForm)
|
||||
|
||||
static let rootPath = "duct-sizing"
|
||||
@@ -686,6 +687,17 @@ extension SiteRoute.View.ProjectRoute {
|
||||
Path { rootPath }
|
||||
Method.get
|
||||
}
|
||||
Route(.case(Self.deleteRectangularSize)) {
|
||||
Path {
|
||||
rootPath
|
||||
"room"
|
||||
Room.ID.parser()
|
||||
}
|
||||
Method.delete
|
||||
Query {
|
||||
Field("rectangularSize") { DuctSizing.RectangularDuct.ID.parser() }
|
||||
}
|
||||
}
|
||||
Route(.case(Self.roomRectangularForm)) {
|
||||
Path {
|
||||
rootPath
|
||||
@@ -695,6 +707,9 @@ extension SiteRoute.View.ProjectRoute {
|
||||
Method.post
|
||||
Body {
|
||||
FormData {
|
||||
Optionally {
|
||||
Field("id") { DuctSizing.RectangularDuct.ID.parser() }
|
||||
}
|
||||
Field("register") { Int.parser() }
|
||||
Field("height") { Int.parser() }
|
||||
}
|
||||
@@ -704,6 +719,7 @@ extension SiteRoute.View.ProjectRoute {
|
||||
}
|
||||
|
||||
public struct RoomRectangularForm: Equatable, Sendable {
|
||||
public let id: DuctSizing.RectangularDuct.ID?
|
||||
public let register: Int
|
||||
public let height: Int
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public struct EditButton: HTML, Sendable {
|
||||
}
|
||||
|
||||
public var body: some HTML<HTMLTag.button> {
|
||||
button(.class("btn btn-success btn-circle dark:text-white"), .type(type)) {
|
||||
button(.class("btn btn-success btn-circle"), .type(type)) {
|
||||
div(.class("flex")) {
|
||||
if let title {
|
||||
span(.class("pe-2")) { title }
|
||||
@@ -94,7 +94,7 @@ public struct TrashButton: HTML, Sendable {
|
||||
public var body: some HTML<HTMLTag.button> {
|
||||
button(
|
||||
.type(.button),
|
||||
.class("btn btn-error btn-circle dark:text-white")
|
||||
.class("btn btn-error")
|
||||
) {
|
||||
SVG(.trash)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Elementary
|
||||
import Foundation
|
||||
import ManualDCore
|
||||
|
||||
extension HTMLAttribute where Tag: HTMLTrait.Attributes.href {
|
||||
@@ -28,6 +29,10 @@ extension HTMLAttribute where Tag == HTMLTag.input {
|
||||
public static func value(_ double: Double?) -> Self {
|
||||
value(double == nil ? "" : "\(double!)")
|
||||
}
|
||||
|
||||
public static func value(_ uuid: UUID?) -> Self {
|
||||
value(uuid?.uuidString ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
extension HTMLAttribute where Tag == HTMLTag.button {
|
||||
|
||||
89
Sources/Styleguide/ResultView.swift
Normal file
89
Sources/Styleguide/ResultView.swift
Normal file
@@ -0,0 +1,89 @@
|
||||
import Elementary
|
||||
import Foundation
|
||||
|
||||
public struct ResultView<
|
||||
V: Sendable,
|
||||
E: Error,
|
||||
ValueView: HTML,
|
||||
ErrorView: HTML
|
||||
>: HTML {
|
||||
|
||||
let onSuccess: @Sendable (V) -> ValueView
|
||||
let onError: @Sendable (E) -> ErrorView
|
||||
let result: Result<V, E>
|
||||
|
||||
public init(
|
||||
result: Result<V, E>,
|
||||
@HTMLBuilder onSuccess: @escaping @Sendable (V) -> ValueView,
|
||||
@HTMLBuilder onError: @escaping @Sendable (E) -> ErrorView
|
||||
) {
|
||||
self.result = result
|
||||
self.onError = onError
|
||||
self.onSuccess = onSuccess
|
||||
}
|
||||
|
||||
public var body: some HTML {
|
||||
switch result {
|
||||
case .success(let value):
|
||||
onSuccess(value)
|
||||
case .failure(let error):
|
||||
onError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ResultView {
|
||||
|
||||
public init(
|
||||
result: Result<V, E>,
|
||||
@HTMLBuilder onSuccess: @escaping @Sendable (V) -> ValueView
|
||||
) where ErrorView == Styleguide.ErrorView<E> {
|
||||
self.init(result: result, onSuccess: onSuccess) { error in
|
||||
Styleguide.ErrorView(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public init(
|
||||
catching: @escaping @Sendable () async throws(E) -> V,
|
||||
@HTMLBuilder onSuccess: @escaping @Sendable (V) -> ValueView
|
||||
) async where ErrorView == Styleguide.ErrorView<E> {
|
||||
await self.init(
|
||||
result: .init(catching: catching),
|
||||
onSuccess: onSuccess
|
||||
) { error in
|
||||
Styleguide.ErrorView(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
public init(
|
||||
catching: @escaping @Sendable () async throws(E) -> V,
|
||||
) async where ErrorView == Styleguide.ErrorView<E>, V == Void, ValueView == EmptyHTML {
|
||||
await self.init(
|
||||
result: .init(catching: catching),
|
||||
onSuccess: { EmptyHTML() }
|
||||
) { error in
|
||||
Styleguide.ErrorView(error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ResultView: Sendable where Error: Sendable, ValueView: Sendable, ErrorView: Sendable {}
|
||||
|
||||
public struct ErrorView<E: Error>: HTML, Sendable where Error: Sendable {
|
||||
|
||||
let error: E
|
||||
|
||||
public init(error: E) {
|
||||
self.error = error
|
||||
}
|
||||
|
||||
public var body: some HTML<HTMLTag.div> {
|
||||
div {
|
||||
h1(.class("text-2xl font-bold text-error")) { "Oops: Error" }
|
||||
p {
|
||||
"\(error)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
37
Sources/Styleguide/Tooltip.swift
Normal file
37
Sources/Styleguide/Tooltip.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
import Elementary
|
||||
|
||||
public struct Tooltip<Inner: HTML & Sendable>: HTML, Sendable {
|
||||
|
||||
let tooltip: String
|
||||
let position: TooltipPosition
|
||||
let inner: Inner
|
||||
|
||||
public init(
|
||||
_ tooltip: String,
|
||||
position: TooltipPosition = .default,
|
||||
@HTMLBuilder inner: () -> Inner
|
||||
) {
|
||||
self.tooltip = tooltip
|
||||
self.position = position
|
||||
self.inner = inner()
|
||||
}
|
||||
|
||||
public var body: some HTML<HTMLTag.div> {
|
||||
div(
|
||||
.class("tooltip tooltip-\(position.rawValue)"),
|
||||
.data("tip", value: tooltip)
|
||||
) {
|
||||
inner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TooltipPosition: String, CaseIterable, Sendable {
|
||||
|
||||
public static let `default` = Self.left
|
||||
|
||||
case bottom
|
||||
case left
|
||||
case right
|
||||
case top
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import DatabaseClient
|
||||
import Dependencies
|
||||
import Fluent
|
||||
import ManualDClient
|
||||
import ManualDCore
|
||||
import Vapor
|
||||
|
||||
@@ -24,6 +26,16 @@ extension DatabaseClient.Projects {
|
||||
|
||||
extension DatabaseClient {
|
||||
|
||||
func calculateDuctSizes(projectID: Project.ID) async throws -> [DuctSizing.RoomContainer] {
|
||||
@Dependency(\.manualD) var manualD
|
||||
|
||||
return try await manualD.calculate(
|
||||
rooms: rooms.fetch(projectID),
|
||||
designFrictionRateResult: designFrictionRate(projectID: projectID),
|
||||
projectSHR: projects.getSensibleHeatRatio(projectID)
|
||||
)
|
||||
}
|
||||
|
||||
func designFrictionRate(
|
||||
projectID: Project.ID
|
||||
) async throws -> (EquipmentInfo, EffectiveLength.MaxContainer, Double)? {
|
||||
|
||||
@@ -55,7 +55,7 @@ extension ViewController: DependencyKey {
|
||||
// FIX: Fix.
|
||||
public static let liveValue = Self(
|
||||
view: { request in
|
||||
try await request.render()
|
||||
await request.render()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ import Dependencies
|
||||
import Elementary
|
||||
import Foundation
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
extension ViewController.Request {
|
||||
|
||||
func render() async throws -> AnySendableHTML {
|
||||
func render() async -> AnySendableHTML {
|
||||
|
||||
@Dependency(\.database) var database
|
||||
|
||||
@@ -22,11 +23,15 @@ extension ViewController.Request {
|
||||
LoginForm(next: next)
|
||||
}
|
||||
case .submit(let login):
|
||||
let _ = try await authenticate(login)
|
||||
return view {
|
||||
// let _ = try await authenticate(login)
|
||||
return await view {
|
||||
await ResultView {
|
||||
try await authenticate(login)
|
||||
} onSuccess: { _ in
|
||||
LoggedIn(next: login.next)
|
||||
}
|
||||
}
|
||||
}
|
||||
case .signup(let route):
|
||||
switch route {
|
||||
case .index:
|
||||
@@ -35,14 +40,20 @@ extension ViewController.Request {
|
||||
}
|
||||
case .submit(let request):
|
||||
// Create a new user and log them in.
|
||||
return await view {
|
||||
await ResultView {
|
||||
let user = try await createAndAuthenticate(request)
|
||||
let projects = try await database.projects.fetch(user.id, .init(page: 1, per: 25))
|
||||
return view {
|
||||
ProjectsTable(userID: user.id, projects: projects)
|
||||
return (
|
||||
user.id,
|
||||
try await database.projects.fetch(user.id, .init(page: 1, per: 25))
|
||||
)
|
||||
} onSuccess: { (userID, projects) in
|
||||
ProjectsTable(userID: userID, projects: projects)
|
||||
}
|
||||
}
|
||||
}
|
||||
case .project(let route):
|
||||
return try await route.renderView(on: self)
|
||||
return await route.renderView(on: self)
|
||||
default:
|
||||
// FIX: FIX
|
||||
return _render(isHtmxRequest: false) {
|
||||
@@ -59,6 +70,14 @@ extension ViewController.Request {
|
||||
}
|
||||
}
|
||||
|
||||
func view<C: HTML>(
|
||||
@HTMLBuilder inner: () async -> C
|
||||
) async -> AnySendableHTML where C: Sendable {
|
||||
await _render(isHtmxRequest: isHtmxRequest, showSidebar: showSidebar) {
|
||||
await inner()
|
||||
}
|
||||
}
|
||||
|
||||
var showSidebar: Bool {
|
||||
switch route {
|
||||
case .login, .signup, .project(.page):
|
||||
@@ -71,43 +90,70 @@ extension ViewController.Request {
|
||||
|
||||
extension SiteRoute.View.ProjectRoute {
|
||||
|
||||
func renderView(on request: ViewController.Request) async throws -> AnySendableHTML {
|
||||
func renderView(on request: ViewController.Request) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
let user = try request.currentUser()
|
||||
// let user = try request.currentUser()
|
||||
|
||||
switch self {
|
||||
case .index:
|
||||
let projects = try await database.projects.fetchPage(userID: user.id)
|
||||
return request.view {
|
||||
ProjectsTable(userID: user.id, projects: projects)
|
||||
return await request.view {
|
||||
await ResultView {
|
||||
let user = try request.currentUser()
|
||||
return try await (
|
||||
user.id,
|
||||
database.projects.fetchPage(userID: user.id)
|
||||
)
|
||||
|
||||
} onSuccess: { (userID, projects) in
|
||||
ProjectsTable(userID: userID, projects: projects)
|
||||
}
|
||||
}
|
||||
case .page(let page):
|
||||
let projects = try await database.projects.fetch(user.id, page)
|
||||
return ProjectsTable(userID: user.id, projects: projects)
|
||||
return await ResultView {
|
||||
let user = try request.currentUser()
|
||||
return try await (
|
||||
user.id,
|
||||
database.projects.fetch(user.id, page)
|
||||
)
|
||||
} onSuccess: { (userID, projects) in
|
||||
ProjectsTable(userID: userID, projects: projects)
|
||||
}
|
||||
|
||||
case .form(let id, let dismiss):
|
||||
request.logger.debug("Project form: \(id != nil ? "Fetching project for: \(id!)" : "N/A")")
|
||||
return await ResultView {
|
||||
var project: Project? = nil
|
||||
if let id, dismiss == false {
|
||||
project = try await database.projects.get(id)
|
||||
}
|
||||
request.logger.debug(
|
||||
project == nil ? "No project found" : "Showing form for existing project"
|
||||
)
|
||||
return ProjectForm(dismiss: dismiss, project: project)
|
||||
return project
|
||||
} onSuccess: { project in
|
||||
ProjectForm(dismiss: dismiss, project: project)
|
||||
}
|
||||
|
||||
case .create(let form):
|
||||
return await ResultView {
|
||||
let user = try request.currentUser()
|
||||
let project = try await database.projects.create(user.id, form)
|
||||
try await database.componentLoss.createDefaults(projectID: project.id)
|
||||
return ProjectView(projectID: project.id, activeTab: .rooms)
|
||||
return project.id
|
||||
|
||||
} onSuccess: { projectID in
|
||||
ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
}
|
||||
|
||||
case .delete(let id):
|
||||
return await ResultView {
|
||||
try await database.projects.delete(id)
|
||||
return EmptyHTML()
|
||||
} onSuccess: {
|
||||
EmptyHTML()
|
||||
}
|
||||
|
||||
case .update(let id, let form):
|
||||
let project = try await database.projects.update(id, form)
|
||||
return ProjectView(projectID: project.id, activeTab: .project)
|
||||
return await ResultView {
|
||||
try await database.projects.update(id, form).id
|
||||
} onSuccess: { projectID in
|
||||
return ProjectView(projectID: projectID, activeTab: .project)
|
||||
}
|
||||
|
||||
case .detail(let projectID, let route):
|
||||
switch route {
|
||||
@@ -116,17 +162,17 @@ extension SiteRoute.View.ProjectRoute {
|
||||
ProjectView(projectID: projectID, activeTab: tab)
|
||||
}
|
||||
case .componentLoss(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return await route.renderView(on: request, projectID: projectID)
|
||||
case .ductSizing(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return await route.renderView(on: request, projectID: projectID)
|
||||
case .equipment(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return await route.renderView(on: request, projectID: projectID)
|
||||
case .equivalentLength(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return await route.renderView(on: request, projectID: projectID)
|
||||
case .frictionRate(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return route.renderView(on: request, projectID: projectID)
|
||||
case .rooms(let route):
|
||||
return try await route.renderView(on: request, projectID: projectID)
|
||||
return await route.renderView(on: request, projectID: projectID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,22 +184,34 @@ extension SiteRoute.View.ProjectRoute.EquipmentInfoRoute {
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) async throws -> AnySendableHTML {
|
||||
) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
|
||||
switch self {
|
||||
case .index:
|
||||
let equipment = try await database.equipment.fetch(projectID)
|
||||
return EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
return await ResultView {
|
||||
try await database.equipment.fetch(projectID)
|
||||
} onSuccess: { equipment in
|
||||
EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
}
|
||||
case .form(let dismiss):
|
||||
let equipment = try await database.equipment.fetch(projectID)
|
||||
return EquipmentInfoForm(dismiss: dismiss, projectID: projectID, equipmentInfo: equipment)
|
||||
return await ResultView {
|
||||
try await database.equipment.fetch(projectID)
|
||||
} onSuccess: { equipment in
|
||||
EquipmentInfoForm(dismiss: dismiss, projectID: projectID, equipmentInfo: equipment)
|
||||
}
|
||||
case .submit(let form):
|
||||
let equipment = try await database.equipment.create(form)
|
||||
return EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
return await ResultView {
|
||||
try await database.equipment.create(form)
|
||||
} onSuccess: { equipment in
|
||||
EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
}
|
||||
case .update(let id, let updates):
|
||||
let equipment = try await database.equipment.update(id, updates)
|
||||
return EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
return await ResultView {
|
||||
try await database.equipment.update(id, updates)
|
||||
} onSuccess: { equipment in
|
||||
EquipmentInfoView(equipmentInfo: equipment, projectID: projectID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,21 +220,26 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) async throws -> AnySendableHTML {
|
||||
) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
|
||||
switch self {
|
||||
|
||||
case .delete(let id):
|
||||
return await ResultView {
|
||||
try await database.rooms.delete(id)
|
||||
return EmptyHTML()
|
||||
}
|
||||
|
||||
case .form(let id, let dismiss):
|
||||
return await ResultView {
|
||||
var room: Room? = nil
|
||||
if let id, dismiss == false {
|
||||
room = try await database.rooms.get(id)
|
||||
}
|
||||
return RoomForm(dismiss: dismiss, projectID: projectID, room: room)
|
||||
return room
|
||||
} onSuccess: { room in
|
||||
RoomForm(dismiss: dismiss, projectID: projectID, room: room)
|
||||
}
|
||||
|
||||
case .index:
|
||||
return request.view {
|
||||
@@ -184,40 +247,46 @@ extension SiteRoute.View.ProjectRoute.RoomRoute {
|
||||
}
|
||||
|
||||
case .submit(let form):
|
||||
return await request.view {
|
||||
await ResultView {
|
||||
request.logger.debug("New room form submitted.")
|
||||
// FIX: Just return a room row??
|
||||
let _ = try await database.rooms.create(form)
|
||||
return request.view {
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
}
|
||||
}
|
||||
|
||||
case .update(let id, let form):
|
||||
return await ResultView {
|
||||
let _ = try await database.rooms.update(id, form)
|
||||
return ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
}
|
||||
|
||||
case .updateSensibleHeatRatio(let form):
|
||||
return await request.view {
|
||||
await ResultView {
|
||||
let _ = try await database.projects.update(
|
||||
form.projectID,
|
||||
.init(sensibleHeatRatio: form.sensibleHeatRatio)
|
||||
)
|
||||
return request.view {
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .rooms)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SiteRoute.View.ProjectRoute.FrictionRateRoute {
|
||||
func renderView(on request: ViewController.Request, projectID: Project.ID) async throws
|
||||
-> AnySendableHTML
|
||||
{
|
||||
@Dependency(\.database) var database
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) -> AnySendableHTML {
|
||||
|
||||
switch self {
|
||||
case .index:
|
||||
// let equipment = try await database.equipment.fetch(projectID)
|
||||
// let componentLosses = try await database.componentLoss.fetch(projectID)
|
||||
|
||||
return request.view {
|
||||
ProjectView(projectID: projectID, activeTab: .frictionRate)
|
||||
}
|
||||
@@ -240,21 +309,31 @@ extension SiteRoute.View.ProjectRoute.ComponentLossRoute {
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) async throws -> AnySendableHTML {
|
||||
) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
|
||||
switch self {
|
||||
case .index:
|
||||
return EmptyHTML()
|
||||
case .delete(let id):
|
||||
return await ResultView {
|
||||
_ = try await database.componentLoss.delete(id)
|
||||
return EmptyHTML()
|
||||
} onSuccess: {
|
||||
EmptyHTML()
|
||||
}
|
||||
// return EmptyHTML()
|
||||
case .submit(let form):
|
||||
return await ResultView {
|
||||
_ = try await database.componentLoss.create(form)
|
||||
return ProjectView(projectID: projectID, activeTab: .frictionRate)
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .frictionRate)
|
||||
}
|
||||
case .update(let id, let form):
|
||||
return await ResultView {
|
||||
_ = try await database.componentLoss.update(id, form)
|
||||
return ProjectView(projectID: projectID, activeTab: .frictionRate)
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .frictionRate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,14 +354,15 @@ extension SiteRoute.View.ProjectRoute.EquivalentLengthRoute {
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) async throws -> AnySendableHTML {
|
||||
) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
|
||||
switch self {
|
||||
|
||||
case .delete(let id):
|
||||
return await ResultView {
|
||||
try await database.effectiveLength.delete(id)
|
||||
return EmptyHTML()
|
||||
}
|
||||
|
||||
case .index:
|
||||
return request.view {
|
||||
@@ -301,35 +381,50 @@ extension SiteRoute.View.ProjectRoute.EquivalentLengthRoute {
|
||||
}
|
||||
|
||||
case .update(let id, let form):
|
||||
return await ResultView {
|
||||
_ = try await database.effectiveLength.update(id, .init(form: form, projectID: projectID))
|
||||
return ProjectView(projectID: projectID, activeTab: .equivalentLength)
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .equivalentLength)
|
||||
}
|
||||
|
||||
case .submit(let step):
|
||||
switch step {
|
||||
case .one(let stepOne):
|
||||
return await ResultView {
|
||||
var effectiveLength: EffectiveLength? = nil
|
||||
if let id = stepOne.id {
|
||||
effectiveLength = try await database.effectiveLength.get(id)
|
||||
}
|
||||
return EffectiveLengthForm.StepTwo(
|
||||
return effectiveLength
|
||||
} onSuccess: { effectiveLength in
|
||||
EffectiveLengthForm.StepTwo(
|
||||
projectID: projectID,
|
||||
stepOne: stepOne,
|
||||
effectiveLength: effectiveLength
|
||||
)
|
||||
}
|
||||
case .two(let stepTwo):
|
||||
return await ResultView {
|
||||
request.logger.debug("ViewController: Got step two...")
|
||||
var effectiveLength: EffectiveLength? = nil
|
||||
if let id = stepTwo.id {
|
||||
effectiveLength = try await database.effectiveLength.get(id)
|
||||
}
|
||||
return effectiveLength
|
||||
} onSuccess: { effectiveLength in
|
||||
return EffectiveLengthForm.StepThree(
|
||||
projectID: projectID, effectiveLength: effectiveLength, stepTwo: stepTwo
|
||||
)
|
||||
}
|
||||
case .three(let stepThree):
|
||||
return await ResultView {
|
||||
request.logger.debug("ViewController: Got step three: \(stepThree)")
|
||||
try stepThree.validate()
|
||||
_ = try await database.effectiveLength.create(.init(form: stepThree, projectID: projectID))
|
||||
return ProjectView(projectID: projectID, activeTab: .equivalentLength)
|
||||
_ = try await database.effectiveLength.create(
|
||||
.init(form: stepThree, projectID: projectID))
|
||||
} onSuccess: {
|
||||
ProjectView(projectID: projectID, activeTab: .equivalentLength)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -339,9 +434,10 @@ extension SiteRoute.View.ProjectRoute.EquivalentLengthRoute {
|
||||
|
||||
extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
||||
|
||||
func renderView(on request: ViewController.Request, projectID: Project.ID) async throws
|
||||
-> AnySendableHTML
|
||||
{
|
||||
func renderView(
|
||||
on request: ViewController.Request,
|
||||
projectID: Project.ID
|
||||
) async -> AnySendableHTML {
|
||||
@Dependency(\.database) var database
|
||||
@Dependency(\.manualD) var manualD
|
||||
|
||||
@@ -350,23 +446,33 @@ extension SiteRoute.View.ProjectRoute.DuctSizingRoute {
|
||||
return request.view {
|
||||
ProjectView(projectID: projectID, activeTab: .ductSizing, logger: request.logger)
|
||||
}
|
||||
|
||||
case .deleteRectangularSize(let roomID, let rectangularSizeID):
|
||||
return await ResultView {
|
||||
let room = try await database.rooms.deleteRectangularSize(roomID, rectangularSizeID)
|
||||
return try await database.calculateDuctSizes(projectID: projectID)
|
||||
.filter({ $0.roomID == room.id })
|
||||
.first!
|
||||
} onSuccess: { container in
|
||||
DuctSizingView.RoomRow(projectID: projectID, room: container)
|
||||
}
|
||||
|
||||
case .roomRectangularForm(let roomID, let form):
|
||||
let _ = try await database.rooms.update(
|
||||
return await ResultView {
|
||||
let room = try await database.rooms.update(
|
||||
roomID,
|
||||
.init(rectangularSizes: [.init(register: form.register, height: form.height)])
|
||||
.init(
|
||||
rectangularSizes: [
|
||||
.init(id: form.id ?? .init(), register: form.register, height: form.height)
|
||||
]
|
||||
)
|
||||
// request.logger.debug("Got room rectangular form: \(roomID)")
|
||||
//
|
||||
// let containers = try await manualD.calculate(
|
||||
// rooms: [room],
|
||||
// designFrictionRateResult: database.designFrictionRate(projectID: projectID),
|
||||
// projectSHR: database.projects.getSensibleHeatRatio(projectID)
|
||||
// )
|
||||
// request.logger.debug("Room Containers: \(containers)")
|
||||
// let container = containers.first(where: { $0.roomName == "\(room.name)-\(form.register)" })!
|
||||
// request.logger.debug("Room Container: \(container)")
|
||||
// return DuctSizingView.RoomRow(projectID: projectID, room: container)
|
||||
return ProjectView(projectID: projectID, activeTab: .ductSizing, logger: request.logger)
|
||||
)
|
||||
return try await database.calculateDuctSizes(projectID: projectID)
|
||||
.filter({ $0.roomID == room.id })
|
||||
.first!
|
||||
} onSuccess: { container in
|
||||
DuctSizingView.RoomRow(projectID: projectID, room: container)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,6 +490,19 @@ private func _render<C: HTML>(
|
||||
return MainPage { inner }
|
||||
}
|
||||
|
||||
private func _render<C: HTML>(
|
||||
isHtmxRequest: Bool,
|
||||
active activeTab: SiteRoute.View.ProjectRoute.DetailRoute.Tab = .rooms,
|
||||
showSidebar: Bool = true,
|
||||
@HTMLBuilder inner: () async -> C
|
||||
) async -> AnySendableHTML where C: Sendable {
|
||||
let inner = await inner()
|
||||
if isHtmxRequest {
|
||||
return inner
|
||||
}
|
||||
return MainPage { inner }
|
||||
}
|
||||
|
||||
private func _render<C: HTML>(
|
||||
isHtmxRequest: Bool,
|
||||
active activeTab: SiteRoute.View.ProjectRoute.DetailRoute.Tab = .rooms,
|
||||
|
||||
@@ -31,11 +31,14 @@ struct ComponentPressureLossesView: HTML, Sendable {
|
||||
span(.class("text-sm italic")) { "Total" }
|
||||
}
|
||||
}
|
||||
Tooltip("Add Component Loss") {
|
||||
PlusButton()
|
||||
.attributes(
|
||||
.class("btn-ghost text-2xl"),
|
||||
.showModal(id: ComponentLossForm.id())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
table(.class("table table-zebra")) {
|
||||
thead {
|
||||
@@ -65,9 +68,10 @@ struct ComponentPressureLossesView: HTML, Sendable {
|
||||
td { Number(row.value) }
|
||||
td {
|
||||
div(.class("flex join items-end justify-end mx-auto")) {
|
||||
Tooltip("Delete", position: .bottom) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.class("join-item btn-ghost"),
|
||||
.hx.delete(
|
||||
route: .project(
|
||||
.detail(row.projectID, .componentLoss(.delete(row.id)))
|
||||
@@ -78,12 +82,15 @@ struct ComponentPressureLossesView: HTML, Sendable {
|
||||
.hx.confirm("Are your sure?")
|
||||
|
||||
)
|
||||
}
|
||||
Tooltip("Edit", position: .bottom) {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.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 {
|
||||
@@ -42,9 +44,9 @@ struct DuctSizingView: HTML, Sendable {
|
||||
th(.class("hidden xl:table-cell")) { "Round Size" }
|
||||
th { "Velocity" }
|
||||
th { "Final Size" }
|
||||
th { "Height" }
|
||||
th { "Width" }
|
||||
th { "Flex Size" }
|
||||
th { "Width" }
|
||||
th { "Height" }
|
||||
}
|
||||
}
|
||||
tbody {
|
||||
@@ -70,7 +72,7 @@ struct DuctSizingView: HTML, Sendable {
|
||||
}
|
||||
|
||||
var body: some HTML<HTMLTag.tr> {
|
||||
tr(.class("text-lg"), .id(room.roomID.idString)) {
|
||||
tr(.class("text-lg items-baseline"), .id(room.roomID.idString)) {
|
||||
td { room.registerID }
|
||||
td { room.roomName }
|
||||
td { Number(room.heatingLoad, digits: 0) }
|
||||
@@ -89,25 +91,8 @@ struct DuctSizingView: HTML, Sendable {
|
||||
.attributes(.class("badge badge-outline badge-secondary text-xl font-bold"))
|
||||
}
|
||||
td {
|
||||
form(
|
||||
.hx.post(route),
|
||||
.hx.target("body"),
|
||||
.hx.swap(.outerHTML)
|
||||
// .hx.trigger(
|
||||
// .event(.change).from("#rectangularSize_\(room.roomID.idString)")
|
||||
// )
|
||||
) {
|
||||
input(.class("hidden"), .name("register"), .value("\(room.roomName.last!)"))
|
||||
Row {
|
||||
Input(
|
||||
id: "height",
|
||||
name: "height",
|
||||
placeholder: "Height"
|
||||
)
|
||||
.attributes(.type(.number), .min("0"), .value(room.rectangularSize?.height))
|
||||
SubmitButton()
|
||||
}
|
||||
}
|
||||
Number(room.flexSize)
|
||||
.attributes(.class("badge badge-outline badge-primary text-xl font-bold"))
|
||||
}
|
||||
td {
|
||||
if let width = room.rectangularWidth {
|
||||
@@ -115,8 +100,44 @@ struct DuctSizingView: HTML, Sendable {
|
||||
}
|
||||
}
|
||||
td {
|
||||
Number(room.flexSize)
|
||||
.attributes(.class("badge badge-outline badge-primary text-xl font-bold"))
|
||||
div(.class("flex justify-between items-center space-x-4")) {
|
||||
div(.id("height_\(room.roomID.idString)"), .class("h-full my-auto")) {
|
||||
if let height = room.rectangularSize?.height {
|
||||
Number(height)
|
||||
}
|
||||
}
|
||||
div {
|
||||
div(.class("join")) {
|
||||
// FIX: Delete rectangular size from room.
|
||||
TrashButton()
|
||||
.attributes(.class("join-item btn-ghost"))
|
||||
.attributes(
|
||||
.hx.delete(
|
||||
route: .project(
|
||||
.detail(
|
||||
projectID,
|
||||
.ductSizing(
|
||||
.deleteRectangularSize(
|
||||
room.roomID,
|
||||
room.rectangularSize?.id ?? .init())
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
.hx.target("closest tr"),
|
||||
.hx.swap(.outerHTML),
|
||||
when: room.rectangularSize != nil
|
||||
)
|
||||
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item btn-ghost text-success hover:text-white"),
|
||||
.showModal(id: RectangularSizeForm.id(room))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
RectangularSizeForm(projectID: projectID, room: room)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
import ManualDCore
|
||||
import Styleguide
|
||||
|
||||
struct RectangularSizeForm: HTML, Sendable {
|
||||
|
||||
static func id(_ roomID: Room.ID? = nil) -> String {
|
||||
let base = "rectangularSizeForm"
|
||||
guard let roomID else { return base }
|
||||
return "\(base)_\(roomID.idString)"
|
||||
}
|
||||
|
||||
static func id(_ room: DuctSizing.RoomContainer) -> String {
|
||||
return id(room.roomID)
|
||||
}
|
||||
|
||||
let projectID: Project.ID
|
||||
let roomID: Room.ID
|
||||
let rectangularSizeID: DuctSizing.RectangularDuct.ID?
|
||||
let register: Int
|
||||
let height: Int?
|
||||
let dismiss: Bool
|
||||
|
||||
init(
|
||||
projectID: Project.ID,
|
||||
roomID: Room.ID,
|
||||
rectangularSizeID: DuctSizing.RectangularDuct.ID? = nil,
|
||||
register: Int,
|
||||
height: Int? = nil,
|
||||
dismiss: Bool = true
|
||||
) {
|
||||
self.projectID = projectID
|
||||
self.roomID = roomID
|
||||
self.rectangularSizeID = rectangularSizeID
|
||||
self.register = register
|
||||
self.height = height
|
||||
self.dismiss = dismiss
|
||||
}
|
||||
|
||||
init(
|
||||
projectID: Project.ID,
|
||||
room: DuctSizing.RoomContainer,
|
||||
dismiss: Bool = true
|
||||
) {
|
||||
let register =
|
||||
room.rectangularSize?.register
|
||||
?? (Int("\(room.roomName.last!)") ?? 1)
|
||||
|
||||
self.init(
|
||||
projectID: projectID,
|
||||
roomID: room.roomID,
|
||||
rectangularSizeID: room.rectangularSize?.id,
|
||||
register: register,
|
||||
height: room.rectangularSize?.height,
|
||||
dismiss: dismiss
|
||||
)
|
||||
}
|
||||
|
||||
var route: String {
|
||||
SiteRoute.View.router.path(
|
||||
for: .project(.detail(projectID, .ductSizing(.index)))
|
||||
)
|
||||
.appendingPath("room")
|
||||
.appendingPath(roomID)
|
||||
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
ModalForm(id: Self.id(roomID), dismiss: dismiss) {
|
||||
|
||||
h1(.class("text-lg pb-6")) { "Rectangular Size" }
|
||||
|
||||
form(
|
||||
.class("space-y-4"),
|
||||
.hx.post(route),
|
||||
.hx.target("closest tr"),
|
||||
.hx.swap(.outerHTML)
|
||||
) {
|
||||
input(.class("hidden"), .name("register"), .value(register))
|
||||
input(.class("hidden"), .name("id"), .value(rectangularSizeID))
|
||||
|
||||
Input(id: "height", placeholder: "Height")
|
||||
.attributes(.type(.number), .min("0"), .value(height), .required, .autofocus)
|
||||
|
||||
SubmitButton()
|
||||
.attributes(.class("btn-block"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,11 +15,14 @@ struct EquipmentInfoView: HTML, Sendable {
|
||||
Row {
|
||||
h1(.class("text-2xl font-bold")) { "Equipment Info" }
|
||||
|
||||
Tooltip("Edit equipment info") {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.on(.click, "\(EquipmentInfoForm.id).showModal()")
|
||||
.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,7 +108,76 @@ 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 {
|
||||
|
||||
@@ -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,41 +5,37 @@ 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")) {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
Tooltip("Edit SHR") {
|
||||
EditButton()
|
||||
.attributes(.showModal(id: SHRForm.id))
|
||||
}
|
||||
}
|
||||
.attributes(.class("m-4"))
|
||||
|
||||
SHRForm(projectID: projectID, sensibleHeatRatio: sensibleHeatRatio)
|
||||
@@ -54,7 +50,18 @@ struct RoomsView: HTML, Sendable {
|
||||
th { Label("Cooling Total") }
|
||||
th { Label("Cooling Sensible") }
|
||||
th { Label("Register Count") }
|
||||
th {}
|
||||
th {
|
||||
div(.class("flex justify-end")) {
|
||||
Tooltip("Add Room") {
|
||||
PlusButton()
|
||||
.attributes(
|
||||
.class("mx-auto"),
|
||||
.showModal(id: RoomForm.id())
|
||||
)
|
||||
}
|
||||
.attributes(.class("tooltip-left"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tbody {
|
||||
@@ -123,21 +130,26 @@ struct RoomsView: HTML, Sendable {
|
||||
td {
|
||||
div(.class("flex justify-end")) {
|
||||
div(.class("join")) {
|
||||
Tooltip("Delete room", position: .bottom) {
|
||||
TrashButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.class("join-item btn-ghost"),
|
||||
.hx.delete(
|
||||
route: .project(.detail(room.projectID, .rooms(.delete(id: room.id))))),
|
||||
.hx.target("closest tr"),
|
||||
.hx.confirm("Are you sure?")
|
||||
)
|
||||
}
|
||||
|
||||
Tooltip("Edit room", position: .bottom) {
|
||||
EditButton()
|
||||
.attributes(
|
||||
.class("join-item"),
|
||||
.class("join-item btn-ghost"),
|
||||
.showModal(id: RoomForm.id(room))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
RoomForm(
|
||||
dismiss: true,
|
||||
projectID: room.projectID,
|
||||
|
||||
6
input.css
Normal file
6
input.css
Normal file
@@ -0,0 +1,6 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
@source not "./tailwindcss";
|
||||
@source not "./daisyui{,*}.mjs";
|
||||
|
||||
@plugin "./daisyui.mjs";
|
||||
3167
output.css
Normal file
3167
output.css
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user