feat: Working on route and id helpers for views.

This commit is contained in:
2025-01-17 23:50:04 -05:00
parent 531a385dba
commit d8328314ed
21 changed files with 585 additions and 255 deletions

View File

@@ -5,46 +5,70 @@ import Vapor
struct PurchaseOrderSearch: HTML {
let context: PurchaseOrderSearchContext?
let context: PurchaseOrderSearchContext
init(context: PurchaseOrderSearchContext? = nil) {
self.context = context
self.context = context ?? .employee
}
var content: some HTML {
form(
.id("search"),
.hx.post("/purchase-orders/search"),
.hx.target("#purchase-order-table"),
.hx.swap(.outerHTML.transition(true).swap("1s"))
.id(.search),
.hx.post(route: .purchaseOrders(.search())),
.hx.target(.purchaseOrders()),
.hx.swap(.outerHTML)
) {
select(
.name("context"), .class("col-3"),
.hx.get("/purchase-orders/search"),
.hx.target("#search"),
.hx.swap(.outerHTML)
) {
option(.value("employee")) { "Employee" }
.attributes(.selected, when: context == .employee || context == nil)
div(.class("btn-row")) {
button(
.class("btn-secondary"), .style("position: absolute; top: 80px; right: 20px;"),
.hx.get(route: .purchaseOrders()), .hx.pushURL(true), .hx.target("body")
)
{ "x" }
}
div(.class("row")) {
select(
.name("context"), .class("col-3"),
.hx.get(route: .purchaseOrders(.search())),
.hx.target(.search),
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
.hx.pushURL(true)
) {
for context in PurchaseOrderSearchContext.allCases {
option(.value(context.rawValue)) { context.rawValue.capitalized }
.attributes(.selected, when: self.context == context)
}
}
option(.value("customer")) { "Customer" }
.attributes(.selected, when: context == .customer)
if context == .employee {
EmployeeSelect.purchaseOrderSearch()
} else if context == .customer {
input(
.type(.text), .class("col-6"), .style("margin-left: 60px; margin-top: 18px;"),
.name("search"), .placeholder("Search"), .required
)
} else if context == .vendor {
VendorBranchSelect.purchaseOrderSearch()
}
}
if context == .employee || context == nil {
EmployeeSelect.purchaseOrderSearch()
} else if context == .customer {
input(.type(.text), .name("search"), .placeholder("Search"), .required)
div(.class("btn-row")) {
button(.type(.submit), .class("btn-primary"))
{ "Search" }
}
button(.type(.submit), .class("btn-primary")) { "Search" }
// Img.spinner().attributes(.class("hx-indicator"))
}
}
}
enum PurchaseOrderSearchContext: String, Codable, Content {
enum PurchaseOrderSearchContext: String, Codable, Content, CaseIterable {
case employee
case customer
case vendor
}
struct PurchaseOrderSearchContent: Content {
let context: PurchaseOrderSearchContext
let createdForID: Employee.ID?
let search: String?
let vendorBranchID: VendorBranch.ID?
}