feat: Begins vendor views
This commit is contained in:
44
Sources/App/Views/Utils/Buttons.swift
Normal file
44
Sources/App/Views/Utils/Buttons.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
import Elementary
|
||||
|
||||
struct ToggleFormButton: HTML {
|
||||
var content: some HTML<HTMLTag.a> {
|
||||
a(.href("javascript:void(0)"), .on(.click, "toggleContent('form')"), .class("btn-add")) {
|
||||
"+"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Button {
|
||||
|
||||
static func add() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn btn-add")) { "+" }
|
||||
}
|
||||
|
||||
static func danger<C: HTML>(@HTMLBuilder body: () -> C) -> some HTML<HTMLTag.button> {
|
||||
button(.class("danger")) { body() }
|
||||
}
|
||||
|
||||
static func close(id: String, resetURL: String? = nil) -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-close"), .on(.click, makeOnClick(id, resetURL))) {
|
||||
"x"
|
||||
}
|
||||
}
|
||||
|
||||
static func update() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-update")) { "Update" }
|
||||
}
|
||||
|
||||
static func detail() -> some HTML<HTMLTag.button> {
|
||||
button(.class("btn-detail")) {
|
||||
"〉"
|
||||
}
|
||||
}
|
||||
|
||||
private static func makeOnClick(_ id: String, _ resetURL: String?) -> String {
|
||||
let output = "toggleContent('\(id)');"
|
||||
if let resetURL {
|
||||
return "\(output) window.location.href='\(resetURL)';"
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
||||
49
Sources/App/Views/Utils/Float.swift
Normal file
49
Sources/App/Views/Utils/Float.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
import Elementary
|
||||
|
||||
struct Float<C: HTML>: HTML {
|
||||
|
||||
let id: String
|
||||
let shouldDisplay: Bool
|
||||
let body: C?
|
||||
let resetURL: String?
|
||||
|
||||
init(id: String = "float") {
|
||||
self.id = id
|
||||
self.shouldDisplay = false
|
||||
self.resetURL = nil
|
||||
self.body = nil
|
||||
}
|
||||
|
||||
init(
|
||||
id: String = "float",
|
||||
shouldDisplay: Bool,
|
||||
resetURL: String? = nil,
|
||||
@HTMLBuilder body: () -> C
|
||||
) {
|
||||
self.id = id
|
||||
self.shouldDisplay = shouldDisplay
|
||||
self.resetURL = resetURL
|
||||
self.body = body()
|
||||
}
|
||||
|
||||
private var classString: String {
|
||||
shouldDisplay ? "float" : ""
|
||||
}
|
||||
|
||||
private var display: String {
|
||||
shouldDisplay ? "block" : "hidden"
|
||||
}
|
||||
|
||||
var content: some HTML<HTMLTag.div> {
|
||||
div(.id(id), .class(classString), .style("display: \(display);")) {
|
||||
if let body, shouldDisplay {
|
||||
div(.class("btn-row")) {
|
||||
Button.close(id: id, resetURL: resetURL)
|
||||
}
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Float: Sendable where C: Sendable {}
|
||||
31
Sources/App/Views/Utils/Navbar.swift
Normal file
31
Sources/App/Views/Utils/Navbar.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import Elementary
|
||||
import ElementaryHTMX
|
||||
|
||||
struct Navbar: HTML, Sendable {
|
||||
var content: some HTML {
|
||||
div(.class("sidepanel"), .id("sidepanel")) {
|
||||
a(.href("javascript:void(0)"), .class("closebtn"), .on(.click, "closeSidepanel()")) {
|
||||
"x"
|
||||
}
|
||||
a(.hx.get("/purchase-orders?page=1&limit=50"), .hx.target("body"), .hx.pushURL(true)) {
|
||||
"Purchae Orders"
|
||||
}
|
||||
a(.hx.get("/users"), .hx.target("body"), .hx.pushURL(true)) {
|
||||
"Users"
|
||||
}
|
||||
a(.hx.get("/employees"), .hx.target("body"), .hx.pushURL(true)) {
|
||||
"Employees"
|
||||
}
|
||||
a(.hx.get("/vendors"), .hx.target("body"), .hx.pushURL(true)) {
|
||||
"Vendors"
|
||||
}
|
||||
div(.style("border-bottom: 1px solid grey; margin-bottom: 5px;")) {}
|
||||
a(.hx.post("/logout"), .hx.target("#content"), .hx.swap(.outerHTML), .hx.trigger(.event(.click))) {
|
||||
"Logout"
|
||||
}
|
||||
}
|
||||
button(.class("openbtn"), .on(.click, "openSidepanel()")) {
|
||||
img(.src("/images/menu.svg"), .style("width: 30px;, height: 30px;"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user