feat: Initial view controller dependency and snapshot tests.
This commit is contained in:
89
Sources/ViewControllerLive/Views/Utils/Select.swift
Normal file
89
Sources/ViewControllerLive/Views/Utils/Select.swift
Normal file
@@ -0,0 +1,89 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
import SharedModels
|
||||
import Vapor
|
||||
|
||||
struct EmployeeSelect: HTML {
|
||||
|
||||
let employees: [Employee]?
|
||||
let context: ViewRoute.SelectContext
|
||||
|
||||
var content: some HTML {
|
||||
if let employees {
|
||||
select(.name("createdForID"), .class(context.classString)) {
|
||||
for employee in employees {
|
||||
option(.value(employee.id.uuidString)) { employee.fullName }
|
||||
}
|
||||
}
|
||||
.attributes(.style("margin-left: 15px;"), when: context == .purchaseOrderSearch)
|
||||
} else {
|
||||
div(
|
||||
.hx.get(route: .employee(.select(context: context))),
|
||||
.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(employees: employees, context: .purchaseOrderForm)
|
||||
}
|
||||
|
||||
static func purchaseOrderSearch(employees: [Employee]? = nil) -> Self {
|
||||
.init(employees: employees, context: .purchaseOrderSearch)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct VendorBranchSelect: HTML {
|
||||
let branches: [VendorBranch.Detail]?
|
||||
let context: ViewRoute.SelectContext
|
||||
|
||||
var content: some HTML {
|
||||
if let branches {
|
||||
select(.name("vendorBranchID"), .class("col-4")) {
|
||||
for branch in branches {
|
||||
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
||||
}
|
||||
}
|
||||
.attributes(.style("margin-left: 15px;"), when: context == .purchaseOrderSearch)
|
||||
} else {
|
||||
div(
|
||||
.hx.get(route: .vendorBranch(.select(context: context))),
|
||||
.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(branches: [VendorBranch.Detail]? = nil) -> Self {
|
||||
.init(branches: branches, context: .purchaseOrderForm)
|
||||
}
|
||||
|
||||
static func purchaseOrderSearch(branches: [VendorBranch.Detail]? = nil) -> Self {
|
||||
.init(branches: branches, context: .purchaseOrderSearch)
|
||||
}
|
||||
}
|
||||
|
||||
// enum SelectContext: String, Codable, Content {
|
||||
// case purchaseOrderForm
|
||||
// case purchaseOrderSearch
|
||||
|
||||
extension ViewRoute.SelectContext {
|
||||
var classString: String {
|
||||
switch self {
|
||||
case .purchaseOrderForm: return "col-3"
|
||||
case .purchaseOrderSearch: return "col-6"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user