feat: Reorganizing views
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
<div id="home-content" class="container" #if(oob): hx-swap-oob="outerHTML" #endif>
|
|
||||||
<div class="container">
|
|
||||||
<h1>Employees</h1>
|
|
||||||
<br>
|
|
||||||
<p>Employees are who purchase orders can be generated for.</p>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
#extend("employee-form", form)
|
|
||||||
#extend("employee-table")
|
|
||||||
</div>
|
|
||||||
14
Resources/Views/employees/index.leaf
Normal file
14
Resources/Views/employees/index.leaf
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#extend("home"):
|
||||||
|
#export("homeContent"):
|
||||||
|
<div id="home-content" class="container" #if(oob): hx-swap-oob="outerHTML" #endif>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Employees</h1>
|
||||||
|
<br>
|
||||||
|
<p>Employees are who purchase orders can be generated for.</p>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
#extend("employees/form", form)
|
||||||
|
#extend("employees/table")
|
||||||
|
</div>
|
||||||
|
#endexport
|
||||||
|
#endextend
|
||||||
@@ -13,26 +13,22 @@
|
|||||||
<ul class="nav-links">
|
<ul class="nav-links">
|
||||||
<li>
|
<li>
|
||||||
<a hx-get="/users"
|
<a hx-get="/users"
|
||||||
hx-target="#home-content"
|
hx-target="body"
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-push-url="true"
|
hx-push-url="true"
|
||||||
#if(route == "users"): hx-trigger="revealed" #endif
|
|
||||||
>
|
>
|
||||||
Users
|
Users
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a hx-get="/employees"
|
<a hx-get="/employees"
|
||||||
hx-target="#home-content"
|
hx-target="body"
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-push-url="true"
|
hx-push-url="true"
|
||||||
#if(route == "employees"): hx-trigger="revealed" #endif
|
|
||||||
>
|
>
|
||||||
Employees
|
Employees
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a hx-get="/vendors?branches=true"
|
<a hx-get="/vendors"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-push-url="true"
|
hx-push-url="true"
|
||||||
>
|
>
|
||||||
@@ -43,9 +39,6 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
#import("homeContent")
|
#import("homeContent")
|
||||||
<!-- <div id="home-content" class="container"> -->
|
|
||||||
<!-- <p>We're in!</p> -->
|
|
||||||
<!-- </div> -->
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
#endexport
|
#endexport
|
||||||
|
|||||||
1
Resources/Views/img/trash-can.leaf
Normal file
1
Resources/Views/img/trash-can.leaf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<img src="images/trash-can.svg" alt="Delete">
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#extend("logo")
|
#extend("logo")
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
#extend("user-form")
|
#extend("users/form")
|
||||||
</div>
|
</div>
|
||||||
#endexport
|
#endexport
|
||||||
#endextend
|
#endextend
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<div id="home-content" class="container">
|
|
||||||
<div class="container">
|
|
||||||
<h1>Users</h1>
|
|
||||||
<br>
|
|
||||||
<p>Users are people that can login and generate puchase orders for employees.</p>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
#extend("user-form", form)
|
|
||||||
#extend("user-table")
|
|
||||||
</div>
|
|
||||||
14
Resources/Views/users/index.leaf
Normal file
14
Resources/Views/users/index.leaf
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#extend("home"):
|
||||||
|
#export("homeContent"):
|
||||||
|
<div id="home-content" class="container">
|
||||||
|
<div class="container">
|
||||||
|
<h1>Users</h1>
|
||||||
|
<br>
|
||||||
|
<p>Users are people that can login and generate puchase orders for employees.</p>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
#extend("users/form", form)
|
||||||
|
#extend("users/table")
|
||||||
|
</div>
|
||||||
|
#endexport
|
||||||
|
#endextend
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
<br>
|
<br>
|
||||||
<p>Vendors are who purchase orders can be issued for, they consist of multiple branches / locations.</p>
|
<p>Vendors are who purchase orders can be issued for, they consist of multiple branches / locations.</p>
|
||||||
<br>
|
<br>
|
||||||
#extend("vendor-form", form)
|
#extend("vendors/form", form)
|
||||||
#extend("vendor-table")
|
#extend("vendors/table")
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
#endexport
|
#endexport
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
hx-swap="outerHTML swap:0.5s"
|
hx-swap="outerHTML swap:0.5s"
|
||||||
hx-confirm="Are you sure you want to delete this vendor?"
|
hx-confirm="Are you sure you want to delete this vendor?"
|
||||||
>
|
>
|
||||||
<img src="images/trash-can.svg" alt="Delete">
|
#extend("img/trash-can")
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -21,14 +21,14 @@ struct EmployeeViewController: RouteCollection {
|
|||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func index(req: Request) async throws -> View {
|
func index(req: Request) async throws -> View {
|
||||||
return try await req.view.render("employees", EmployeesCTX(api: api, req: req))
|
return try await req.view.render("employees/index", EmployeesCTX(api: api, req: req))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func postEmployeeForm(req: Request) async throws -> View {
|
func postEmployeeForm(req: Request) async throws -> View {
|
||||||
_ = try await api.createEmployee(req: req)
|
_ = try await api.createEmployee(req: req)
|
||||||
let employees = try await api.getSortedEmployees(req: req)
|
let employees = try await api.getSortedEmployees(req: req)
|
||||||
return try await req.view.render("employee-table", ["employees": employees])
|
return try await req.view.render("employees/table", ["employees": employees])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
@@ -39,14 +39,14 @@ struct EmployeeViewController: RouteCollection {
|
|||||||
employee.active.toggle()
|
employee.active.toggle()
|
||||||
try await employee.save(on: req.db)
|
try await employee.save(on: req.db)
|
||||||
let employees = try await api.getSortedEmployees(req: req)
|
let employees = try await api.getSortedEmployees(req: req)
|
||||||
return try await req.view.render("employee-table", ["employees": employees])
|
return try await req.view.render("employees/table", ["employees": employees])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func deleteEmployee(req: Request) async throws -> View {
|
func deleteEmployee(req: Request) async throws -> View {
|
||||||
_ = try await api.deleteEmployee(req: req)
|
_ = try await api.deleteEmployee(req: req)
|
||||||
let employees = try await api.getSortedEmployees(req: req)
|
let employees = try await api.getSortedEmployees(req: req)
|
||||||
return try await req.view.render("employee-table", ["employees": employees])
|
return try await req.view.render("employees/table", ["employees": employees])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
@@ -54,18 +54,18 @@ struct EmployeeViewController: RouteCollection {
|
|||||||
guard let employee = try await Employee.find(req.parameters.get("employeeID"), on: req.db) else {
|
guard let employee = try await Employee.find(req.parameters.get("employeeID"), on: req.db) else {
|
||||||
throw Abort(.notFound)
|
throw Abort(.notFound)
|
||||||
}
|
}
|
||||||
return try await req.view.render("employee-form", EmployeeFormCTX(employee: employee.toDTO()))
|
return try await req.view.render("employees/form", EmployeeFormCTX(employee: employee.toDTO()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func updateEmployee(req: Request) async throws -> View {
|
func updateEmployee(req: Request) async throws -> View {
|
||||||
_ = try await api.updateEmployee(req: req)
|
_ = try await api.updateEmployee(req: req)
|
||||||
return try await req.view.render("employees", EmployeesCTX(oob: true, api: api, req: req))
|
return try await req.view.render("employees/index", EmployeesCTX(oob: true, api: api, req: req))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func employeeForm(req: Request) async throws -> View {
|
func employeeForm(req: Request) async throws -> View {
|
||||||
try await req.view.render("employee-form", EmployeeFormCTX())
|
try await req.view.render("employees/form", EmployeeFormCTX())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct UserViewController: RouteCollection {
|
|||||||
@Sendable
|
@Sendable
|
||||||
func index(req: Request) async throws -> View {
|
func index(req: Request) async throws -> View {
|
||||||
try await req.view.render(
|
try await req.view.render(
|
||||||
"users",
|
"users/index",
|
||||||
UsersCTX(users: api.getSortedUsers(req: req))
|
UsersCTX(users: api.getSortedUsers(req: req))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -25,13 +25,13 @@ struct UserViewController: RouteCollection {
|
|||||||
@Sendable
|
@Sendable
|
||||||
func create(req: Request) async throws -> View {
|
func create(req: Request) async throws -> View {
|
||||||
_ = try await api.createUser(req: req)
|
_ = try await api.createUser(req: req)
|
||||||
return try await req.view.render("user-table", ["users": api.getSortedUsers(req: req)])
|
return try await req.view.render("users/table", ["users": api.getSortedUsers(req: req)])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func delete(req: Request) async throws -> View {
|
func delete(req: Request) async throws -> View {
|
||||||
_ = try await api.deleteUser(req: req)
|
_ = try await api.deleteUser(req: req)
|
||||||
return try await req.view.render("user-table", ["users": api.getSortedUsers(req: req)])
|
return try await req.view.render("users/table", ["users": api.getSortedUsers(req: req)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ struct VendorViewController: RouteCollection {
|
|||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func index(req: Request) async throws -> View {
|
func index(req: Request) async throws -> View {
|
||||||
return try await req.view.render("vendors", makeCtx(req: req))
|
return try await req.view.render("vendors/index", makeCtx(req: req))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func create(req: Request) async throws -> View {
|
func create(req: Request) async throws -> View {
|
||||||
let ctx = try req.content.decode(CreateVendorCTX.self)
|
let ctx = try req.content.decode(CreateVendorCTX.self)
|
||||||
req.logger.info("CTX: \(ctx)")
|
req.logger.debug("CTX: \(ctx)")
|
||||||
let vendor = Vendor.Create(name: ctx.name).toModel()
|
let vendor = Vendor.Create(name: ctx.name).toModel()
|
||||||
try await vendor.save(on: req.db)
|
try await vendor.save(on: req.db)
|
||||||
|
|
||||||
@@ -39,8 +39,7 @@ struct VendorViewController: RouteCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ = try await api.createVendor(req: req)
|
return try await req.view.render("vendors/table", makeCtx(req: req))
|
||||||
return try await req.view.render("vendor-table", makeCtx(req: req))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
@@ -51,7 +50,7 @@ struct VendorViewController: RouteCollection {
|
|||||||
@Sendable
|
@Sendable
|
||||||
func update(req: Request) async throws -> View {
|
func update(req: Request) async throws -> View {
|
||||||
_ = try await api.updateVendor(req: req)
|
_ = try await api.updateVendor(req: req)
|
||||||
return try await req.view.render("vendor-table", makeCtx(req: req, oob: true))
|
return try await req.view.render("vendors/table", makeCtx(req: req, oob: true))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func makeCtx(req: Request, vendor: Vendor? = nil, oob: Bool = false) async throws -> VendorsCTX {
|
private func makeCtx(req: Request, vendor: Vendor? = nil, oob: Bool = false) async throws -> VendorsCTX {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ struct ViewController: RouteCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func postLogin(req: Request) async throws -> View {
|
func postLogin(req: Request) async throws -> Response {
|
||||||
let content = try req.content.decode(UserForm.self)
|
let content = try req.content.decode(UserForm.self)
|
||||||
guard let user = try await User.query(on: req.db)
|
guard let user = try await User.query(on: req.db)
|
||||||
.filter(\.$username == content.username)
|
.filter(\.$username == content.username)
|
||||||
@@ -62,18 +62,11 @@ struct ViewController: RouteCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func home(req: Request) async throws -> View {
|
func home(req: Request) async throws -> Response {
|
||||||
var route: HomeRoute?
|
if let loginParams = try? req.query.decode(LoginParameter.self) {
|
||||||
|
return req.redirect(to: loginParams.next)
|
||||||
if let loginParams = try? req.query.decode(LoginParameter.self),
|
|
||||||
let next = loginParams.next.split(separator: "/").last
|
|
||||||
{
|
|
||||||
route = HomeRoute(rawValue: String(next))
|
|
||||||
} else if let routeString = req.parameters.getCatchall().first {
|
|
||||||
route = HomeRoute(rawValue: routeString)
|
|
||||||
}
|
}
|
||||||
|
return try await req.view.render("home").encodeResponse(for: req)
|
||||||
return try await req.view.render("home", HomeCTX(route: route))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
|
|||||||
Reference in New Issue
Block a user