WIP:
This commit is contained in:
@@ -187,11 +187,12 @@ extension SiteRoute.View.FrictionRateRoute {
|
|||||||
case equipmentInfo
|
case equipmentInfo
|
||||||
case componentPressureLoss
|
case componentPressureLoss
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SiteRoute.View {
|
extension SiteRoute.View {
|
||||||
public enum EffectiveLengthRoute: Equatable, Sendable {
|
public enum EffectiveLengthRoute: Equatable, Sendable {
|
||||||
case field(FieldType)
|
case field(FieldType, style: EffectiveLength.EffectiveLengthType? = nil)
|
||||||
case form(dismiss: Bool = false)
|
case form(dismiss: Bool = false)
|
||||||
case index
|
case index
|
||||||
|
|
||||||
@@ -220,6 +221,11 @@ extension SiteRoute.View {
|
|||||||
Method.get
|
Method.get
|
||||||
Query {
|
Query {
|
||||||
Field("type") { FieldType.parser() }
|
Field("type") { FieldType.parser() }
|
||||||
|
Optionally {
|
||||||
|
Field("style", default: nil) {
|
||||||
|
EffectiveLength.EffectiveLengthType.parser()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,19 +237,13 @@ extension SiteRoute.View.EffectiveLengthRoute {
|
|||||||
case straightLength
|
case straightLength
|
||||||
case group
|
case group
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// extension SiteRoute.View {
|
public enum FormStep: String, CaseIterable, Equatable, Sendable {
|
||||||
// public enum UserRoute: Equatable, Sendable {
|
case nameAndType
|
||||||
// case signup(Signup)
|
case straightLengths
|
||||||
//
|
case groups
|
||||||
// public static let router = OneOf {
|
}
|
||||||
// Route(.case(Self.signup)) {
|
}
|
||||||
// SiteRoute.View.UserRoute.Signup.router
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
extension SiteRoute.View {
|
extension SiteRoute.View {
|
||||||
|
|
||||||
|
|||||||
@@ -28,3 +28,10 @@ extension HTMLAttribute.hx {
|
|||||||
// delete(SiteRoute.Api.router.path(for: route))
|
// delete(SiteRoute.Api.router.path(for: route))
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension HTMLAttribute.hx {
|
||||||
|
@Sendable
|
||||||
|
public static func indicator() -> HTMLAttribute {
|
||||||
|
indicator(".hx-indicator")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -196,12 +196,13 @@ extension SiteRoute.View.EffectiveLengthRoute {
|
|||||||
case .form(let dismiss):
|
case .form(let dismiss):
|
||||||
return EffectiveLengthForm(dismiss: dismiss)
|
return EffectiveLengthForm(dismiss: dismiss)
|
||||||
|
|
||||||
case .field(let type):
|
case .field(let type, let style):
|
||||||
switch type {
|
switch type {
|
||||||
case .straightLength:
|
case .straightLength:
|
||||||
return StraightLengthField()
|
return StraightLengthField()
|
||||||
case .group:
|
case .group:
|
||||||
return GroupField()
|
// FIX:
|
||||||
|
return GroupField(style: style ?? .supply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,20 @@ import ElementaryHTMX
|
|||||||
import ManualDCore
|
import ManualDCore
|
||||||
import Styleguide
|
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.
|
||||||
|
|
||||||
struct EffectiveLengthForm: HTML, Sendable {
|
struct EffectiveLengthForm: HTML, Sendable {
|
||||||
let dismiss: Bool
|
let dismiss: Bool
|
||||||
|
let type: EffectiveLength.EffectiveLengthType
|
||||||
|
|
||||||
|
init(dismiss: Bool, type: EffectiveLength.EffectiveLengthType = .supply) {
|
||||||
|
self.dismiss = dismiss
|
||||||
|
self.type = type
|
||||||
|
}
|
||||||
|
|
||||||
var body: some HTML {
|
var body: some HTML {
|
||||||
ModalForm(id: "effectiveLengthForm", dismiss: dismiss) {
|
ModalForm(id: "effectiveLengthForm", dismiss: dismiss) {
|
||||||
@@ -17,13 +29,8 @@ struct EffectiveLengthForm: HTML, Sendable {
|
|||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
label(.for("type")) { "Type" }
|
label(.for("type")) { "Type" }
|
||||||
select(
|
GroupTypeSelect(selected: type)
|
||||||
.id("type"), .name("type"),
|
.attributes(.class("w-full border rounded-md"))
|
||||||
.class("w-full border rounded-md")
|
|
||||||
) {
|
|
||||||
option(.value("supply")) { "Supply" }
|
|
||||||
option(.value("return")) { "Return" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Row {
|
Row {
|
||||||
Label { "Straigth Lengths" }
|
Label { "Straigth Lengths" }
|
||||||
@@ -44,7 +51,7 @@ struct EffectiveLengthForm: HTML, Sendable {
|
|||||||
Label { "Groups" }
|
Label { "Groups" }
|
||||||
button(
|
button(
|
||||||
.type(.button),
|
.type(.button),
|
||||||
.hx.get(route: .effectiveLength(.field(.group))),
|
.hx.get(route: .effectiveLength(.field(.group, style: type))),
|
||||||
.hx.target("#groups"),
|
.hx.target("#groups"),
|
||||||
.hx.swap(.beforeEnd)
|
.hx.swap(.beforeEnd)
|
||||||
) {
|
) {
|
||||||
@@ -52,7 +59,7 @@ struct EffectiveLengthForm: HTML, Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
div(.id("groups"), .class("space-y-4")) {
|
div(.id("groups"), .class("space-y-4")) {
|
||||||
GroupField()
|
GroupField(style: type)
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
@@ -92,10 +99,13 @@ struct StraightLengthField: HTML, Sendable {
|
|||||||
|
|
||||||
struct GroupField: HTML, Sendable {
|
struct GroupField: HTML, Sendable {
|
||||||
|
|
||||||
|
let style: EffectiveLength.EffectiveLengthType
|
||||||
|
|
||||||
var body: some HTML {
|
var body: some HTML {
|
||||||
Row {
|
Row {
|
||||||
Input(name: "group[][group]", placeholder: "Group")
|
// Input(name: "group[][group]", placeholder: "Group")
|
||||||
.attributes(.type(.number), .min("0"))
|
// .attributes(.type(.number), .min("0"))
|
||||||
|
GroupSelect(style: style)
|
||||||
Input(name: "group[][letter]", placeholder: "Letter")
|
Input(name: "group[][letter]", placeholder: "Letter")
|
||||||
.attributes(.type(.text))
|
.attributes(.type(.text))
|
||||||
Input(name: "group[][length]", placeholder: "Length")
|
Input(name: "group[][length]", placeholder: "Length")
|
||||||
@@ -106,3 +116,53 @@ struct GroupField: HTML, Sendable {
|
|||||||
.attributes(.class("space-x-2"))
|
.attributes(.class("space-x-2"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GroupSelect: HTML, Sendable {
|
||||||
|
|
||||||
|
let style: EffectiveLength.EffectiveLengthType
|
||||||
|
|
||||||
|
var body: some HTML {
|
||||||
|
select(
|
||||||
|
.name("group")
|
||||||
|
) {
|
||||||
|
for value in style.selectOptions {
|
||||||
|
option(.value("\(value)")) { "\(value)" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GroupTypeSelect: HTML, Sendable {
|
||||||
|
|
||||||
|
var selected: EffectiveLength.EffectiveLengthType
|
||||||
|
|
||||||
|
var body: some HTML<HTMLTag.select> {
|
||||||
|
select(.name("type"), .id("type")) {
|
||||||
|
for value in EffectiveLength.EffectiveLengthType.allCases {
|
||||||
|
option(
|
||||||
|
.value("\(value.rawValue)"),
|
||||||
|
.hx.get(route: .effectiveLength(.field(.group, style: value))),
|
||||||
|
.hx.target("#groups"),
|
||||||
|
.hx.swap(.beforeEnd),
|
||||||
|
.hx.trigger(.event(.change).from("#type"))
|
||||||
|
) { value.title }
|
||||||
|
.attributes(.selected, when: value == selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension EffectiveLength.EffectiveLengthType {
|
||||||
|
|
||||||
|
var title: String { rawValue.capitalized }
|
||||||
|
|
||||||
|
var selectOptions: [Int] {
|
||||||
|
switch self {
|
||||||
|
case .return:
|
||||||
|
return [5, 6, 7, 8, 10, 11, 12]
|
||||||
|
case .supply:
|
||||||
|
return [1, 2, 4, 8, 9, 11, 12]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,15 +37,19 @@ public struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct LoggedIn: HTML, Sendable {
|
struct LoggedIn: HTML, Sendable {
|
||||||
let next: String?
|
let next: String
|
||||||
|
|
||||||
|
init(next: String? = nil) {
|
||||||
|
self.next = next ?? SiteRoute.View.router.path(for: .project(.index))
|
||||||
|
}
|
||||||
|
|
||||||
var body: some HTML {
|
var body: some HTML {
|
||||||
div(
|
div(
|
||||||
.hx.get(next ?? SiteRoute.View.router.path(for: .project(.index))),
|
.hx.get(next),
|
||||||
.hx.pushURL(true),
|
.hx.pushURL(true),
|
||||||
.hx.target("body"),
|
.hx.target("body"),
|
||||||
.hx.trigger(.event(.revealed)),
|
.hx.trigger(.event(.revealed)),
|
||||||
.hx.indicator(".hx-indicator")
|
.hx.indicator()
|
||||||
) {
|
) {
|
||||||
Indicator()
|
Indicator()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user