feat: Working on search for purchase orders.

This commit is contained in:
2025-01-17 17:04:41 -05:00
parent be0b5a6033
commit 531a385dba
46 changed files with 283 additions and 817 deletions

View File

@@ -25,11 +25,11 @@ struct PurchaseOrderForm: HTML {
}
form(
.hx.post("/purchase-orders"),
.hx.target("purchase-order-table"),
.hx.swap(.afterBegin.transition(true).swap("1s")),
.hx.target("#purchase-order-table"),
.hx.swap(.afterBegin),
.custom(
name: "hx-on::after-request",
value: "if (event.detail.successful) toggleContent('float'); window.location.href='/purchase-orders';"
value: "if(event.detail.successful) toggleContent('float')"
)
) {
div(.class("row")) {
@@ -139,7 +139,7 @@ struct PurchaseOrderForm: HTML {
let vendorBranches: [VendorBranch.Detail]
var content: some HTML<HTMLTag.select> {
select(.name("vendorBranchID"), .class("col-3")) {
select(.name("vendorBranchID"), .class("col-4")) {
for branch in vendorBranches {
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
}

View File

@@ -0,0 +1,50 @@
import Elementary
import ElementaryHTMX
import SharedModels
import Vapor
struct PurchaseOrderSearch: HTML {
let context: PurchaseOrderSearchContext?
init(context: PurchaseOrderSearchContext? = nil) {
self.context = context
}
var content: some HTML {
form(
.id("search"),
.hx.post("/purchase-orders/search"),
.hx.target("#purchase-order-table"),
.hx.swap(.outerHTML.transition(true).swap("1s"))
) {
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)
option(.value("customer")) { "Customer" }
.attributes(.selected, when: context == .customer)
}
if context == .employee || context == nil {
EmployeeSelect.purchaseOrderSearch()
} else if context == .customer {
input(.type(.text), .name("search"), .placeholder("Search"), .required)
}
button(.type(.submit), .class("btn-primary")) { "Search" }
// Img.spinner().attributes(.class("hx-indicator"))
}
}
}
enum PurchaseOrderSearchContext: String, Codable, Content {
case employee
case customer
}

View File

@@ -23,7 +23,7 @@ struct PurchaseOrderTable: HTML {
.attributes(
.hx.get("/purchase-orders/create"),
.hx.target("#float"),
.hx.swap(.outerHTML.transition(true).swap("1s")),
.hx.swap(.outerHTML),
.hx.pushURL(true)
)
}
@@ -49,7 +49,7 @@ struct PurchaseOrderTable: HTML {
.hx.trigger(.event(.revealed)),
.hx.swap(.outerHTML.transition(true).swap("1s")),
.hx.target("this"),
.hx.indicator(".htmx-indicator")
.hx.indicator("next .htmx-indicator")
) {
img(.src("/images/spinner.svg"), .class("htmx-indicator"), .width(60), .height(60))
}

View File

@@ -0,0 +1,47 @@
import Elementary
import ElementaryHTMX
import SharedModels
import Vapor
struct EmployeeSelect: HTML {
let classString: String
let name: String
let employees: [Employee]?
let context: Context
var content: some HTML {
if let employees {
select(.name(name), .class(classString)) {
for employee in employees {
option(.value(employee.id.uuidString)) { employee.fullName }
}
}
.attributes(.style("margin-left: 15px;"), when: context == .search)
} else {
div(
.hx.get("/select/employee?context=\(context.rawValue)"),
.hx.target("this"),
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
.hx.indicator("next .hx-indicator"),
.hx.trigger(.event(.revealed)),
.style("display: inline;")
) {
Img.spinner().attributes(.class("hx-indicator"))
}
}
}
static func purchaseOrderForm(employees: [Employee]? = nil) -> Self {
.init(classString: "col-3", name: "createdForID", employees: employees, context: .form)
}
static func purchaseOrderSearch(employees: [Employee]? = nil) -> Self {
.init(classString: "col-3", name: "employeeID", employees: employees, context: .search)
}
enum Context: String, Codable, Content {
case form
case search
}
}

View File

@@ -8,7 +8,7 @@ struct Navbar: HTML, Sendable {
"x"
}
a(.hx.get("/purchase-orders?page=1&limit=50"), .hx.target("body"), .hx.pushURL(true)) {
"Purchae Orders"
"Purchase Orders"
}
a(.hx.get("/users"), .hx.target("body"), .hx.pushURL(true)) {
"Users"