feat: Initial purchase order views, login seems to be broken though.
This commit is contained in:
@@ -28,7 +28,7 @@ struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable {
|
||||
}
|
||||
|
||||
var body: some HTML {
|
||||
header {
|
||||
header(.class("header")) {
|
||||
Logo()
|
||||
if displayNav {
|
||||
Navbar()
|
||||
|
||||
161
Sources/App/Views/PurchaseOrders/PurchaseOrderForm.swift
Normal file
161
Sources/App/Views/PurchaseOrders/PurchaseOrderForm.swift
Normal file
@@ -0,0 +1,161 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
import SharedModels
|
||||
|
||||
struct PurchaseOrderForm: HTML {
|
||||
|
||||
let purchaseOrder: PurchaseOrder?
|
||||
let shouldShow: Bool
|
||||
|
||||
init(purchaseOrder: PurchaseOrder? = nil, shouldShow: Bool = false) {
|
||||
self.purchaseOrder = purchaseOrder
|
||||
self.shouldShow = shouldShow
|
||||
}
|
||||
|
||||
var content: some HTML {
|
||||
Float(shouldDisplay: shouldShow, resetURL: "/purchase-orders") {
|
||||
if shouldShow {
|
||||
if purchaseOrder != nil {
|
||||
p {
|
||||
span(.class("label"), .style("margin-right: 15px;")) { "Note:" }
|
||||
span { i(.style("font-size: 1em;")) {
|
||||
"Vendor and Employee can not be changed once a purchase order has been created."
|
||||
} }
|
||||
}
|
||||
}
|
||||
form(
|
||||
.hx.post("/purchase-orders"),
|
||||
.hx.target("purchase-order-table"),
|
||||
.hx.swap(.afterBegin.transition(true).swap("1s")),
|
||||
.custom(
|
||||
name: "hx-on::after-request",
|
||||
value: "if (event.detail.successful) toggleContent('float'); window.location.href='/purchase-orders';"
|
||||
)
|
||||
) {
|
||||
div(.class("row")) {
|
||||
label(
|
||||
.for("customer"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Customer:" }
|
||||
input(
|
||||
.type(.text), .class("col-3"),
|
||||
.name("customer"), .placeholder("Customer"),
|
||||
.value(purchaseOrder?.customer ?? ""),
|
||||
.required, .autofocus
|
||||
)
|
||||
label(
|
||||
.for("workOrder"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Work Order:" }
|
||||
input(
|
||||
.type(.text), .class("col-4"),
|
||||
.name("workOrder"), .placeholder("Work Order: (12345)"),
|
||||
.value("\(purchaseOrder?.workOrder != nil ? String(purchaseOrder!.workOrder!) : "")")
|
||||
)
|
||||
}
|
||||
div(.class("row")) {
|
||||
label(
|
||||
.for("materials"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Materials:" }
|
||||
input(
|
||||
.type(.text), .class("col-3"),
|
||||
.name("materials"), .placeholder("Materials"),
|
||||
.value(purchaseOrder?.materials ?? ""),
|
||||
.required
|
||||
)
|
||||
label(
|
||||
.for("vendorBranchID"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Vendor:" }
|
||||
if purchaseOrder == nil {
|
||||
div(
|
||||
.class("col-4"),
|
||||
.hx.get("/purchase-orders/create/vendor-branch-select"),
|
||||
.hx.target("this"),
|
||||
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.indicator(".hx-indicator")
|
||||
) {
|
||||
Img.spinner().attributes(.class("hx-indicator"), .style("float: left;"))
|
||||
}
|
||||
} else {
|
||||
input(
|
||||
.type(.text), .class("col-4"),
|
||||
.name("vendorBranchID"),
|
||||
.value("\(purchaseOrder!.vendorBranch.vendor.name) - \(purchaseOrder!.vendorBranch.name)"),
|
||||
.disabled
|
||||
)
|
||||
}
|
||||
}
|
||||
div(.class("row")) {
|
||||
label(
|
||||
.for("createdForID"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Employee:" }
|
||||
if purchaseOrder == nil {
|
||||
div(
|
||||
.class("col-3"),
|
||||
.hx.get("/purchase-orders/create/employee-select"),
|
||||
.hx.target("this"),
|
||||
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.indicator(".hx-indicator")
|
||||
) {
|
||||
Img.spinner().attributes(.class("hx-indicator"), .style("float: left;"))
|
||||
}
|
||||
} else {
|
||||
input(
|
||||
.type(.text), .class("col-3"),
|
||||
.value(purchaseOrder!.createdFor.fullName),
|
||||
.disabled
|
||||
)
|
||||
}
|
||||
label(
|
||||
.for("truckStock"), .class("label col-2"), .style("margin-right: 15px; margin-bottom: 5px;")
|
||||
) { "Truck Stock:" }
|
||||
if purchaseOrder?.truckStock == true {
|
||||
input(
|
||||
.type(.checkbox), .class("col-2"), .name("truckStock"), .style("margin-top: 20px;"), .checked
|
||||
)
|
||||
} else {
|
||||
input(
|
||||
.type(.checkbox), .class("col-2"), .name("truckStock"), .style("margin-top: 20px;")
|
||||
)
|
||||
}
|
||||
}
|
||||
div(.class("btn-row")) {
|
||||
button(.class("btn-primary"), .type(.submit)) { buttonLabel }
|
||||
if purchaseOrder != nil {
|
||||
Button.danger { "Delete" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var buttonLabel: String {
|
||||
guard purchaseOrder != nil else { return "Create" }
|
||||
return "Update"
|
||||
}
|
||||
|
||||
struct VendorSelect: HTML {
|
||||
let vendorBranches: [VendorBranch.Detail]
|
||||
|
||||
var content: some HTML<HTMLTag.select> {
|
||||
select(.name("vendorBranchID"), .class("col-3")) {
|
||||
for branch in vendorBranches {
|
||||
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EmployeeSelect: HTML {
|
||||
let employees: [Employee]
|
||||
|
||||
var content: some HTML<HTMLTag.select> {
|
||||
select(.name("createdForID"), .class("col-3")) {
|
||||
for employee in employees {
|
||||
option(.value(employee.id.uuidString)) { employee.fullName }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
92
Sources/App/Views/PurchaseOrders/PurchaseOrderTable.swift
Normal file
92
Sources/App/Views/PurchaseOrders/PurchaseOrderTable.swift
Normal file
@@ -0,0 +1,92 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
import Fluent
|
||||
import SharedModels
|
||||
import Vapor
|
||||
|
||||
struct PurchaseOrderTable: HTML {
|
||||
|
||||
let page: Page<PurchaseOrder>
|
||||
|
||||
var content: some HTML {
|
||||
table {
|
||||
thead {
|
||||
tr {
|
||||
th { "PO" }
|
||||
th { "Work Order" }
|
||||
th { "Customer" }
|
||||
th { "Vendor" }
|
||||
th { "Materials" }
|
||||
th { "Created For" }
|
||||
th {
|
||||
Button.add()
|
||||
.attributes(
|
||||
.hx.get("/purchase-orders/create"),
|
||||
.hx.target("#float"),
|
||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
||||
.hx.pushURL(true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
tbody(.id("purchase-order-table")) {
|
||||
Rows(page: page)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Produces only the rows for the given page
|
||||
struct Rows: HTML {
|
||||
let page: Page<PurchaseOrder>
|
||||
|
||||
var content: some HTML {
|
||||
for purchaseOrder in page.items {
|
||||
Row(purchaseOrder: purchaseOrder)
|
||||
}
|
||||
if page.metadata.pageCount > page.metadata.page {
|
||||
tr(
|
||||
.hx.get("/purchase-orders/next?page=\(page.metadata.page + 1)&limit=\(page.metadata.per)"),
|
||||
.hx.trigger(.event(.revealed)),
|
||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
||||
.hx.target("this"),
|
||||
.hx.indicator(".htmx-indicator")
|
||||
) {
|
||||
img(.src("/images/spinner.svg"), .class("htmx-indicator"), .width(60), .height(60))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A single row.
|
||||
struct Row: HTML {
|
||||
let purchaseOrder: PurchaseOrder
|
||||
|
||||
var content: some HTML<HTMLTag.tr> {
|
||||
tr(
|
||||
.id("purchase_order_\(purchaseOrder.id)")
|
||||
) {
|
||||
td { "\(purchaseOrder.id)" }
|
||||
td { purchaseOrder.workOrder != nil ? String(purchaseOrder.workOrder!) : "" }
|
||||
td { purchaseOrder.customer }
|
||||
td { purchaseOrder.vendorBranch.displayName }
|
||||
td { purchaseOrder.materials }
|
||||
td { purchaseOrder.createdFor.fullName }
|
||||
td {
|
||||
Button.detail()
|
||||
.attributes(
|
||||
.hx.get("/purchase-orders/\(purchaseOrder.id)"),
|
||||
.hx.target("#float"),
|
||||
.hx.swap(.outerHTML.transition(true).swap("0.5s")),
|
||||
.hx.pushURL(true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension VendorBranch.Detail {
|
||||
var displayName: String {
|
||||
"\(vendor.name.capitalized) - \(name.capitalized)"
|
||||
}
|
||||
}
|
||||
7
Sources/App/Views/Utils/Img.swift
Normal file
7
Sources/App/Views/Utils/Img.swift
Normal file
@@ -0,0 +1,7 @@
|
||||
import Elementary
|
||||
|
||||
enum Img {
|
||||
static func spinner(width: Int = 30, height: Int = 30) -> some HTML<HTMLTag.img> {
|
||||
img(.src("/images/spinner.svg"), .width(width), .height(height))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user