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">
|
||||
<li>
|
||||
<a hx-get="/users"
|
||||
hx-target="#home-content"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="body"
|
||||
hx-push-url="true"
|
||||
#if(route == "users"): hx-trigger="revealed" #endif
|
||||
>
|
||||
Users
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a hx-get="/employees"
|
||||
hx-target="#home-content"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="body"
|
||||
hx-push-url="true"
|
||||
#if(route == "employees"): hx-trigger="revealed" #endif
|
||||
>
|
||||
Employees
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a hx-get="/vendors?branches=true"
|
||||
<a hx-get="/vendors"
|
||||
hx-target="body"
|
||||
hx-push-url="true"
|
||||
>
|
||||
@@ -43,9 +39,6 @@
|
||||
</nav>
|
||||
</div>
|
||||
#import("homeContent")
|
||||
<!-- <div id="home-content" class="container"> -->
|
||||
<!-- <p>We're in!</p> -->
|
||||
<!-- </div> -->
|
||||
</section>
|
||||
</div>
|
||||
#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")
|
||||
</div>
|
||||
</header>
|
||||
#extend("user-form")
|
||||
#extend("users/form")
|
||||
</div>
|
||||
#endexport
|
||||
#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>
|
||||
<p>Vendors are who purchase orders can be issued for, they consist of multiple branches / locations.</p>
|
||||
<br>
|
||||
#extend("vendor-form", form)
|
||||
#extend("vendor-table")
|
||||
#extend("vendors/form", form)
|
||||
#extend("vendors/table")
|
||||
</div>
|
||||
</div>
|
||||
#endexport
|
||||
@@ -25,7 +25,7 @@
|
||||
hx-swap="outerHTML swap:0.5s"
|
||||
hx-confirm="Are you sure you want to delete this vendor?"
|
||||
>
|
||||
<img src="images/trash-can.svg" alt="Delete">
|
||||
#extend("img/trash-can")
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -21,14 +21,14 @@ struct EmployeeViewController: RouteCollection {
|
||||
|
||||
@Sendable
|
||||
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
|
||||
func postEmployeeForm(req: Request) async throws -> View {
|
||||
_ = try await api.createEmployee(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
|
||||
@@ -39,14 +39,14 @@ struct EmployeeViewController: RouteCollection {
|
||||
employee.active.toggle()
|
||||
try await employee.save(on: req.db)
|
||||
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
|
||||
func deleteEmployee(req: Request) async throws -> View {
|
||||
_ = try await api.deleteEmployee(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
|
||||
@@ -54,18 +54,18 @@ struct EmployeeViewController: RouteCollection {
|
||||
guard let employee = try await Employee.find(req.parameters.get("employeeID"), on: req.db) else {
|
||||
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
|
||||
func updateEmployee(req: Request) async throws -> View {
|
||||
_ = 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
|
||||
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
|
||||
func index(req: Request) async throws -> View {
|
||||
try await req.view.render(
|
||||
"users",
|
||||
"users/index",
|
||||
UsersCTX(users: api.getSortedUsers(req: req))
|
||||
)
|
||||
}
|
||||
@@ -25,13 +25,13 @@ struct UserViewController: RouteCollection {
|
||||
@Sendable
|
||||
func create(req: Request) async throws -> View {
|
||||
_ = 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
|
||||
func delete(req: Request) async throws -> View {
|
||||
_ = 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
|
||||
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
|
||||
func create(req: Request) async throws -> View {
|
||||
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()
|
||||
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("vendor-table", makeCtx(req: req))
|
||||
return try await req.view.render("vendors/table", makeCtx(req: req))
|
||||
}
|
||||
|
||||
@Sendable
|
||||
@@ -51,7 +50,7 @@ struct VendorViewController: RouteCollection {
|
||||
@Sendable
|
||||
func update(req: Request) async throws -> View {
|
||||
_ = 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 {
|
||||
|
||||
@@ -37,7 +37,7 @@ struct ViewController: RouteCollection {
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func postLogin(req: Request) async throws -> View {
|
||||
func postLogin(req: Request) async throws -> Response {
|
||||
let content = try req.content.decode(UserForm.self)
|
||||
guard let user = try await User.query(on: req.db)
|
||||
.filter(\.$username == content.username)
|
||||
@@ -62,18 +62,11 @@ struct ViewController: RouteCollection {
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func home(req: Request) async throws -> View {
|
||||
var route: HomeRoute?
|
||||
|
||||
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)
|
||||
func home(req: Request) async throws -> Response {
|
||||
if let loginParams = try? req.query.decode(LoginParameter.self) {
|
||||
return req.redirect(to: loginParams.next)
|
||||
}
|
||||
|
||||
return try await req.view.render("home", HomeCTX(route: route))
|
||||
return try await req.view.render("home").encodeResponse(for: req)
|
||||
}
|
||||
|
||||
@Sendable
|
||||
|
||||
Reference in New Issue
Block a user