feat: Working on search for purchase orders.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "b5426b686e9548f4fc69224d4e0f13d10ce55816d5b71622f5f446b12d66140a",
|
"originHash" : "aefc6edf3bfecf4e8b49731482d5e8f4fd78c1188ba5d90f5b78a36ab8106df6",
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "async-http-client",
|
"identity" : "async-http-client",
|
||||||
@@ -82,24 +82,6 @@
|
|||||||
"version" : "4.8.0"
|
"version" : "4.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"identity" : "leaf",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/vapor/leaf.git",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "bf48d2423c00292b5937c60166c7db99705cae47",
|
|
||||||
"version" : "4.4.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"identity" : "leaf-kit",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/vapor/leaf-kit.git",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "d0ca4417166ef7868d28ad21bc77d36b8735a0fc",
|
|
||||||
"version" : "1.11.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"identity" : "multipart-kit",
|
"identity" : "multipart-kit",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ let package = Package(
|
|||||||
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"),
|
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"),
|
||||||
// 🪶 Fluent driver for SQLite.
|
// 🪶 Fluent driver for SQLite.
|
||||||
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"),
|
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"),
|
||||||
// 🍃 An expressive, performant, and extensible templating language built for Swift.
|
|
||||||
.package(url: "https://github.com/vapor/leaf.git", from: "4.3.0"),
|
|
||||||
// 🔵 Non-blocking, event-driven networking for Swift. Used for, custom executors
|
// 🔵 Non-blocking, event-driven networking for Swift. Used for, custom executors
|
||||||
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
|
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
|
||||||
.package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.6.3"),
|
.package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.6.3"),
|
||||||
@@ -35,7 +33,6 @@ let package = Package(
|
|||||||
"DatabaseClientLive",
|
"DatabaseClientLive",
|
||||||
.product(name: "Fluent", package: "fluent"),
|
.product(name: "Fluent", package: "fluent"),
|
||||||
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
|
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
|
||||||
.product(name: "Leaf", package: "leaf"),
|
|
||||||
.product(name: "Vapor", package: "vapor"),
|
.product(name: "Vapor", package: "vapor"),
|
||||||
.product(name: "NIOCore", package: "swift-nio"),
|
.product(name: "NIOCore", package: "swift-nio"),
|
||||||
.product(name: "NIOPosix", package: "swift-nio"),
|
.product(name: "NIOPosix", package: "swift-nio"),
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<a href="javascript:void(0)"
|
|
||||||
class="closebtn"
|
|
||||||
onClick="toggleContent('form')"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</a>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<a href="javascript:void(0)"
|
|
||||||
onclick="toggleContent('form')"
|
|
||||||
class="btn-add"
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</a>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<div id="employee-detail" class="float" #if(!employee): style="display:none;" #endif>
|
|
||||||
#if(employee):
|
|
||||||
<button class="closebtn"
|
|
||||||
onclick="toggleContent('employee-detail');">
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
<form hx-put="/employees/#(employee.id)"
|
|
||||||
hx-target="#employee_#(employee.id)"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-disable-elt="this"
|
|
||||||
hx-on::after-request="window.location.href='/employees'; toggleContent('employee-detail');"
|
|
||||||
>
|
|
||||||
<div class="row">
|
|
||||||
<label for="firstName"><h3 class="label">First Name:</h3></label>
|
|
||||||
<input type="text" name="firstName" value="#(employee.firstName)">
|
|
||||||
<label for="lastName"><h3 class="label">Last Name:</h3></label>
|
|
||||||
<input type="text" name="lastName" value="#(employee.lastName)">
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="active-row">
|
|
||||||
<h3 class="label">Active:</h3>
|
|
||||||
#if(employee.active):
|
|
||||||
<a class="toggle"
|
|
||||||
hx-patch="/employees/#(id)/toggle-active"
|
|
||||||
hx-target="#employee_#(id)"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
<img class="toggle" src="/images/toggle-on.svg" alt="Active">
|
|
||||||
</a>
|
|
||||||
#else:
|
|
||||||
<a class="toggle"
|
|
||||||
hx-patch="/employees/#(id)/toggle-active"
|
|
||||||
hx-target="#employee_#(id)"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
<img class="toggle" src="/images/toggle-off.svg" alt="Active">
|
|
||||||
</a>
|
|
||||||
#endif
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="btn-row">
|
|
||||||
<button class="edit"
|
|
||||||
type="submit"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
Update
|
|
||||||
</button>
|
|
||||||
<button class="danger">Delete</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
#endif
|
|
||||||
</div>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#extend("htmx-form", htmxForm):
|
|
||||||
#export("formBody"):
|
|
||||||
<input type="text"
|
|
||||||
id="firstName"
|
|
||||||
name="firstName"
|
|
||||||
placeholder="First Name"
|
|
||||||
autofocus
|
|
||||||
required
|
|
||||||
#if(context.employee.firstName): value=#(context.employee.firstName) #endif
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<input type="text"
|
|
||||||
id="lastName"
|
|
||||||
name="lastName"
|
|
||||||
placeholder="Last Name"
|
|
||||||
required
|
|
||||||
#if(context.employee.lastName): value=#(context.employee.lastName) #endif
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<input type="submit" value=#if(context.employee.id): Update #else: Create #endif>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#extend("home"):
|
|
||||||
#export("homeContent"):
|
|
||||||
<div id="home-content" class="container" #if(oob): hx-swap-oob="outerHTML" #endif>
|
|
||||||
<div class="container">
|
|
||||||
<h1>Employees</h1>
|
|
||||||
<br>
|
|
||||||
<h3>Employees are who purchase orders can be generated for.</h3>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
#extend("employees/detail")
|
|
||||||
#extend("form-container"): #export("formContent"):
|
|
||||||
#extend("employees/form", form)
|
|
||||||
#endexport #endextend
|
|
||||||
#extend("employees/table")
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<tr id="employee_#(id)">
|
|
||||||
<td>#capitalized(firstName) #capitalized(lastName)</td>
|
|
||||||
<td style="width: 10%; text-align: center;">
|
|
||||||
#if(active):
|
|
||||||
<a class="toggle"
|
|
||||||
hx-patch="/employees/#(id)/toggle-active"
|
|
||||||
hx-target="#employee_#(id)"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
<img src="/images/toggle-on.svg" alt="Active">
|
|
||||||
</a>
|
|
||||||
#else:
|
|
||||||
<a class="toggle"
|
|
||||||
hx-patch="/employees/#(id)/toggle-active"
|
|
||||||
hx-target="#employee_#(id)"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
<img src="/images/toggle-off.svg" alt="Active">
|
|
||||||
</a>
|
|
||||||
#endif
|
|
||||||
</td>
|
|
||||||
<td style="width: 50px;">
|
|
||||||
<button hx-get="/employees/#(id)"
|
|
||||||
hx-target="#employee-detail"
|
|
||||||
hx-swap="outerHTML swap:1s"
|
|
||||||
hx-push-url="false"
|
|
||||||
hx-disabled-elt="this"
|
|
||||||
class="btn btn-detail"
|
|
||||||
>
|
|
||||||
›
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<table id="employee-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Active</th>
|
|
||||||
<th>
|
|
||||||
<a href="javascript:void(0)"
|
|
||||||
hx-get="employees/form"
|
|
||||||
hx-target="#employee-form"
|
|
||||||
hx-on::after-request="toggleContent('form')"
|
|
||||||
class="btn-add"
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
#for(employee in employees):
|
|
||||||
#extend("employees/table-row", employee)
|
|
||||||
#endfor
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<div id="form" style="display: none;" class="form-content">
|
|
||||||
#extend("btn/close-form")
|
|
||||||
#import("formContent")
|
|
||||||
</div>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#extend("index"):
|
|
||||||
#export("content"):
|
|
||||||
<div id="content">
|
|
||||||
<header>
|
|
||||||
<div class="container">
|
|
||||||
#extend("logo")
|
|
||||||
#extend("navbar")
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
<section class="content">
|
|
||||||
#import("homeContent")
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<form id="#(formId)"
|
|
||||||
#if(formClass):
|
|
||||||
class="#(formClass)"
|
|
||||||
#endif
|
|
||||||
#if(htmxPostTargetUrl):
|
|
||||||
hx-post="#(htmxPostTargetUrl)"
|
|
||||||
#elseif(htmxPutTargetUrl):
|
|
||||||
hx-put="#(htmxPutTargetUrl)"
|
|
||||||
#endif
|
|
||||||
hx-target="#(htmxTarget)"
|
|
||||||
hx-push-url="#(htmxPushUrl)"
|
|
||||||
#if(htmxSwap):
|
|
||||||
hx-swap="#(htmxSwap)"
|
|
||||||
#endif
|
|
||||||
#if(htmxSwapOob):
|
|
||||||
hx-swap-oob="#(htmxSwapOob)"
|
|
||||||
#endif
|
|
||||||
#if(htmxResetAfterRequest):
|
|
||||||
hx-on::after-request=" if(event.detail.successful) this.reset(); toggleContent('form');"
|
|
||||||
#endif
|
|
||||||
hx-disabled-elt="find input[type='text'], find button, find input[type='submit']"
|
|
||||||
>
|
|
||||||
#import("formBody")
|
|
||||||
</form>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<img src="images/pencil.svg", alt="Edit">
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<img src="/images/spinner.svg" alt="Spinner">
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<img src="images/trash-can.svg" alt="Delete">
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
|
|
||||||
<script src="/js/main.js"></script>
|
|
||||||
<link rel="stylesheet" href="/css/main.css">
|
|
||||||
<title>#(title)</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
#import("content")
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#extend("index"):
|
|
||||||
#export("content"):
|
|
||||||
<div id="content">
|
|
||||||
<header>
|
|
||||||
<div class="container">
|
|
||||||
#extend("logo")
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
#extend("users/form")
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<div id="logo">HHE - Purchase Orders</div>
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<div class="sidepanel" id="sidepanel">
|
|
||||||
<a href="javscript:void(0)" class="closebtn" onclick="closeSidepanel()">×</a>
|
|
||||||
<a hx-get="/purchase-orders?page=1&limit=50"
|
|
||||||
hx-target="body"
|
|
||||||
hx-push-url="true"
|
|
||||||
>
|
|
||||||
Purchase Orders
|
|
||||||
</a>
|
|
||||||
<a hx-get="/users"
|
|
||||||
hx-target="body"
|
|
||||||
hx-push-url="true"
|
|
||||||
>
|
|
||||||
Users
|
|
||||||
</a>
|
|
||||||
<a hx-get="/employees"
|
|
||||||
hx-target="body"
|
|
||||||
hx-push-url="true"
|
|
||||||
>
|
|
||||||
Employees
|
|
||||||
</a>
|
|
||||||
<a hx-get="/vendors"
|
|
||||||
hx-target="body"
|
|
||||||
hx-push-url="true"
|
|
||||||
>
|
|
||||||
Vendors
|
|
||||||
</a>
|
|
||||||
<div style="border-bottom: 1px solid grey; margin-bottom: 5px;"></div>
|
|
||||||
<a style="padding-top: 5px;"
|
|
||||||
hx-post="logout"
|
|
||||||
hx-target="#content"
|
|
||||||
hx-trigger="click"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
Logout
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<button class="openbtn" onclick="openSidepanel()">☰</button>
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<div id="po-detail" class="container float">
|
|
||||||
#if(purchaseOrderDetail):
|
|
||||||
<a href="javascript:void(0)"
|
|
||||||
class="closebtn"
|
|
||||||
hx-get="/purchase-orders/details/close"
|
|
||||||
hx-target="#po-detail"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</a>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Purchase Order:</h3></td>
|
|
||||||
<td><h3>#(purchaseOrderDetail.id)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Work Order:</h3></td>
|
|
||||||
<td><h3>#(purchaseOrderDetail.workOrder)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Customer:</h3></td>
|
|
||||||
<td><h3>#(purchaseOrderDetail.customer)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Vendor:</h3></td>
|
|
||||||
<td><h3>#capitalized(purchaseOrderDetail.vendorBranch.vendor.name) - #capitalized(purchaseOrderDetail.vendorBranch.name)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Materials:</h3></td>
|
|
||||||
<td><h3>#(purchaseOrderDetail.materials)<h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Created For:</h3></td>
|
|
||||||
<td><h3>#capitalized(purchaseOrderDetail.createdFor.firstName) #capitalized(purchaseOrderDetail.createdFor.lastName)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Truck Stock:</h3></td>
|
|
||||||
<td><h3>#capitalized(purchaseOrderDetail.truckStock)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Created By:</h3></td>
|
|
||||||
<td><h3>#(purchaseOrderDetail.createdBy.username)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Date:</h3></td>
|
|
||||||
<td><h3>#date(purchaseOrderDetail.createdAt, "MM-dd-yyyy")<h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Updated:</h3></td>
|
|
||||||
<td><h3>#date(purchaseOrderDetail.updatedAt, "MM-dd-yyyy")<h3></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
#endif
|
|
||||||
</div>
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#extend("htmx-form", htmxForm):
|
|
||||||
#export("formBody"):
|
|
||||||
<input type="text"
|
|
||||||
id="workOrder"
|
|
||||||
name="workOrder"
|
|
||||||
placeholder="Work Order: 12345"
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<select id="vendorBranchID" name="vendorBranchID">
|
|
||||||
#for(branch in context.branches):
|
|
||||||
<option value="#(branch.id)">#capitalized(branch.name) - #capitalized(branch.vendor.name)</option>
|
|
||||||
#endfor
|
|
||||||
</select>
|
|
||||||
<br>
|
|
||||||
<select id="createdForID" name="createdForID">
|
|
||||||
#for(employee in context.employees):
|
|
||||||
<option value="#(employee.id)">#capitalized(employee.firstName) #capitalized(employee.lastName)</option>
|
|
||||||
#endfor
|
|
||||||
</select>
|
|
||||||
<br>
|
|
||||||
<input type="text"
|
|
||||||
id="materials"
|
|
||||||
name="materials"
|
|
||||||
placeholder="Materials"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<input type="text"
|
|
||||||
id="customer"
|
|
||||||
name="customer"
|
|
||||||
placeholder="Customer Name"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
<label for="truckStock">Truck Stock</label>
|
|
||||||
<input type="checkbox"
|
|
||||||
id="truckStock"
|
|
||||||
name="truckStock"
|
|
||||||
>
|
|
||||||
<input type="submit" value="Create">
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#extend("home"):
|
|
||||||
#export("homeContent"):
|
|
||||||
<div id="home-content" class="container" #if(oob): hx-swap-oob="outerHTML" #endif>
|
|
||||||
<div class="container">
|
|
||||||
<h1>Purchase Orders</h1>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
#extend("form-container"): #export("formContent"):
|
|
||||||
#extend("purchaseOrders/form", form)
|
|
||||||
#endexport #endextend
|
|
||||||
<div class="float"
|
|
||||||
id="po-detail"
|
|
||||||
#if(purchaseOrderDetail):
|
|
||||||
hx-get="/purchase-orders/#(purchaseOrderDetail.id)"
|
|
||||||
hx-target="this"
|
|
||||||
hx-trigger="load"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
#endif
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="btn-row">
|
|
||||||
#if(hasPrevious):
|
|
||||||
<button hx-get="/purchase-orders?page=#(page - 1)&limit=#(limit)"
|
|
||||||
hx-target="body"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-push-url="true"
|
|
||||||
style="float: left;"
|
|
||||||
>
|
|
||||||
‹ Previous
|
|
||||||
</button>
|
|
||||||
#endif
|
|
||||||
#if(hasNext):
|
|
||||||
<button hx-get="/purchase-orders?page=#(page + 1)&limit=#(limit)"
|
|
||||||
hx-target="body"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-push-url="true"
|
|
||||||
style="float: right;"
|
|
||||||
>
|
|
||||||
Next ›
|
|
||||||
</button>
|
|
||||||
#endif
|
|
||||||
</div>
|
|
||||||
#extend("purchaseOrders/table")
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<tr id="#(id)">
|
|
||||||
<td>#(id)</td>
|
|
||||||
<td>#(workOrder)</td>
|
|
||||||
<td>#(customer)</td>
|
|
||||||
<td>#capitalized(vendorBranch.vendor.name) - #capitalized(vendorBranch.name)</td>
|
|
||||||
<td>#(materials)</td>
|
|
||||||
<td>#capitalized(createdFor.firstName) #capitalized(createdFor.lastName)</td>
|
|
||||||
<td>#(createdBy.username)</td>
|
|
||||||
<td>#capitalized(truckStock)</td>
|
|
||||||
<td style="text-align: center;">
|
|
||||||
<button class="btn btn-detail"
|
|
||||||
hx-get="/purchase-orders/#(id)"
|
|
||||||
hx-target="#po-detail"
|
|
||||||
hx-push-url="true"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
>
|
|
||||||
›
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<table id="po-table">
|
|
||||||
<tr>
|
|
||||||
<th>PO</th>
|
|
||||||
<th>Work Order</th>
|
|
||||||
<th>Customer</th>
|
|
||||||
<th>Vendor</th>
|
|
||||||
<th>Materials</th>
|
|
||||||
<th>Created For</th>
|
|
||||||
<th>Created By</th>
|
|
||||||
<th>Truck Stock</th>
|
|
||||||
<th>#extend("btn/toggle-form")</th>
|
|
||||||
</tr>
|
|
||||||
<tbody id="po-table-body">
|
|
||||||
#for(po in purchaseOrders):
|
|
||||||
#extend("purchaseOrders/table-row", po)
|
|
||||||
#endfor
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<div id="user-detail" class="float" #if(!user): style="display:none;" #endif>
|
|
||||||
#if(user):
|
|
||||||
<button class="closebtn"
|
|
||||||
hx-get="/users"
|
|
||||||
hx-target="body"
|
|
||||||
hx-push-url="true"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-disable-elt="this"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Username:</h3></td>
|
|
||||||
<td><h3>#(user.username)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Email:</h3></td>
|
|
||||||
<td><h3>#(user.email)</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Created:</h3></td>
|
|
||||||
<td><h3>#date(user.createdAt, "MM-dd-yyyy")</h3></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="label"><h3>Updated:</h3></td>
|
|
||||||
<td><h3>#date(user.updatedAt, "MM-dd-yyyy")</h3></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="btn-row user-buttons">
|
|
||||||
<button class="danger">Delete</button>
|
|
||||||
</div>
|
|
||||||
#endif
|
|
||||||
</div>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#extend("htmx-form", htmxForm):
|
|
||||||
#export("formBody"):
|
|
||||||
<input type="text"
|
|
||||||
id="username"
|
|
||||||
name="username"
|
|
||||||
placeholder="Username"
|
|
||||||
autofocus
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
#if(context.showEmailInput):
|
|
||||||
<input type="email"
|
|
||||||
id="email"
|
|
||||||
name="email"
|
|
||||||
placeholder="Email"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
#endif
|
|
||||||
<input type="password"
|
|
||||||
id="password"
|
|
||||||
name="password"
|
|
||||||
placeholder="Password"
|
|
||||||
autofocus
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
#if(context.showConfirmPassword):
|
|
||||||
<input type="password"
|
|
||||||
id="confirmPassword"
|
|
||||||
name="confirmPassword"
|
|
||||||
placeholder="Confirm Password"
|
|
||||||
autofocus
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
#endif
|
|
||||||
<input type="submit" value="#(context.buttonLabel)">
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#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/detail")
|
|
||||||
#extend("form-container"): #export("formContent"):
|
|
||||||
#extend("users/form", form)
|
|
||||||
#endexport #endextend
|
|
||||||
|
|
||||||
#extend("users/table")
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<tr id="user_#(id)">
|
|
||||||
<td>#(username)</td>
|
|
||||||
<td>#(email)</td>
|
|
||||||
<td style="width: 50px;">
|
|
||||||
<button hx-get="/users/#(id)"
|
|
||||||
hx-target="#user-detail"
|
|
||||||
hx-swap="outerHTML swap:0.5s"
|
|
||||||
hx-push-url="true"
|
|
||||||
class="btn btn-detail"
|
|
||||||
>
|
|
||||||
›
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<table id="user-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Username</th>
|
|
||||||
<th>Email</th>
|
|
||||||
<th>#extend("btn/toggle-form")</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
#for(user in users):
|
|
||||||
#extend("users/table-row", user)
|
|
||||||
#endfor
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
35
Resources/Views/vendors/form.leaf
vendored
35
Resources/Views/vendors/form.leaf
vendored
@@ -1,35 +0,0 @@
|
|||||||
#extend("htmx-form", htmxForm):
|
|
||||||
#export("formBody"):
|
|
||||||
<input type="hidden"
|
|
||||||
id="vendorId"
|
|
||||||
name="id"
|
|
||||||
#if(context.vendor.id):
|
|
||||||
value="#(context.vendor.id)"
|
|
||||||
#endif
|
|
||||||
>
|
|
||||||
|
|
||||||
<input type="text"
|
|
||||||
id="name"
|
|
||||||
name="name"
|
|
||||||
placeholder="Vendor Name"
|
|
||||||
autofocus
|
|
||||||
required
|
|
||||||
#if(context.vendor.name):
|
|
||||||
value="#(context.vendor.name)"
|
|
||||||
#endif
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<input type="text"
|
|
||||||
id="branches"
|
|
||||||
name="branches"
|
|
||||||
#if(context.branches):
|
|
||||||
value="#(context.branches)"
|
|
||||||
#endif
|
|
||||||
placeholder="Monroe, Dayton..."
|
|
||||||
>
|
|
||||||
<br>
|
|
||||||
<input type="submit" value="#(context.buttonLabel)">
|
|
||||||
<br>
|
|
||||||
<p><small>Mutliple branches can be specified separated by a comma.</small></p>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
16
Resources/Views/vendors/index.leaf
vendored
16
Resources/Views/vendors/index.leaf
vendored
@@ -1,16 +0,0 @@
|
|||||||
#extend("home"):
|
|
||||||
#export("homeContent"):
|
|
||||||
<div id="home-content" class="container">
|
|
||||||
<div class="container">
|
|
||||||
<h1>Vendors</h1>
|
|
||||||
<br>
|
|
||||||
<p>Vendors are who purchase orders can be issued for, they consist of multiple branches / locations.</p>
|
|
||||||
<br>
|
|
||||||
#extend("form-container"): #export("formContent"):
|
|
||||||
#extend("vendors/form", form)
|
|
||||||
#endexport #endextend
|
|
||||||
#extend("vendors/table")
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
#endexport
|
|
||||||
#endextend
|
|
||||||
49
Resources/Views/vendors/table.leaf
vendored
49
Resources/Views/vendors/table.leaf
vendored
@@ -1,49 +0,0 @@
|
|||||||
<table id="vendor-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Branches</th>
|
|
||||||
<th>#extend("btn/toggle-form")</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="vendor-table-body">
|
|
||||||
#for(vendor in vendors):
|
|
||||||
<tr id="vendor_#(vendor.id)">
|
|
||||||
<td>#capitalized(vendor.name)</td>
|
|
||||||
<td class="vendor-branches">
|
|
||||||
#if(vendor.branches):
|
|
||||||
<ul>
|
|
||||||
#for(branch in vendor.branches):
|
|
||||||
<li style="list-style-type: none; margin-left: 10px;">
|
|
||||||
<div class="branch-row">
|
|
||||||
<div class="branch-name">#capitalized(branch.name)</div>
|
|
||||||
<a href="javascript:void(0)"
|
|
||||||
class="btn danger"
|
|
||||||
hx-delete="/api/v1/vendors/#(vendor.id)/branches/#(branch.id)"
|
|
||||||
hx-confirm="Are you sure you want to delete this branch?"
|
|
||||||
hx-target="closest li"
|
|
||||||
hx-swap="outerHTML swap:0.3s"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
#endfor
|
|
||||||
</ul>
|
|
||||||
#endif
|
|
||||||
</td>
|
|
||||||
<!-- TODO: Add edit button -->
|
|
||||||
<td style="width: 50px;">
|
|
||||||
<a class="btn btn-delete"
|
|
||||||
hx-delete="/vendors/#(vendor.id)"
|
|
||||||
hx-target="closest tr"
|
|
||||||
hx-swap="outerHTML swap:0.5s"
|
|
||||||
hx-confirm="Are you sure you want to delete this vendor?"
|
|
||||||
>
|
|
||||||
#extend("img/trash-can")
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
#endfor
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import Vapor
|
|
||||||
|
|
||||||
/// Represents a generic form context that is used to generate form templates
|
|
||||||
/// that are handled by htmx.
|
|
||||||
struct HtmxFormCTX<Context: Content>: Content {
|
|
||||||
let formClass: String?
|
|
||||||
let formId: String
|
|
||||||
let htmxPostTargetUrl: String?
|
|
||||||
let htmxPutTargetUrl: String?
|
|
||||||
let htmxTarget: String
|
|
||||||
let htmxPushUrl: Bool
|
|
||||||
let htmxResetAfterRequest: Bool
|
|
||||||
let htmxSwapOob: String?
|
|
||||||
let htmxSwap: String?
|
|
||||||
let context: Context
|
|
||||||
|
|
||||||
init(
|
|
||||||
formClass: String? = nil,
|
|
||||||
formId: String,
|
|
||||||
htmxTargetUrl: TargetUrl,
|
|
||||||
htmxTarget: String,
|
|
||||||
htmxPushUrl: Bool,
|
|
||||||
htmxResetAfterRequest: Bool = true,
|
|
||||||
htmxSwapOob: HtmxSwap? = nil,
|
|
||||||
htmxSwap: HtmxSwap? = nil,
|
|
||||||
context: Context
|
|
||||||
) {
|
|
||||||
self.formClass = formClass
|
|
||||||
self.formId = formId
|
|
||||||
self.htmxPostTargetUrl = htmxTargetUrl.postUrl
|
|
||||||
self.htmxPutTargetUrl = htmxTargetUrl.putUrl
|
|
||||||
self.htmxTarget = htmxTarget
|
|
||||||
self.htmxPushUrl = htmxPushUrl
|
|
||||||
self.htmxResetAfterRequest = htmxResetAfterRequest
|
|
||||||
self.htmxSwapOob = htmxSwapOob?.rawValue
|
|
||||||
self.htmxSwap = htmxSwap?.rawValue
|
|
||||||
self.context = context
|
|
||||||
}
|
|
||||||
|
|
||||||
enum HtmxSwap: String {
|
|
||||||
case innerHTML
|
|
||||||
case outerHTML
|
|
||||||
case afterbegin
|
|
||||||
case beforebegin
|
|
||||||
case afterend
|
|
||||||
case beforeend
|
|
||||||
case delete
|
|
||||||
case none
|
|
||||||
}
|
|
||||||
|
|
||||||
enum TargetUrl {
|
|
||||||
case put(String)
|
|
||||||
case post(String)
|
|
||||||
|
|
||||||
var putUrl: String? {
|
|
||||||
guard case let .put(url) = self else { return nil }
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
|
|
||||||
var postUrl: String? {
|
|
||||||
guard case let .post(url) = self else { return nil }
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EmptyContent: Content {}
|
|
||||||
|
|
||||||
struct ButtonLabelContext: Content {
|
|
||||||
let buttonLabel: String
|
|
||||||
}
|
|
||||||
|
|
||||||
extension HtmxFormCTX where Context == ButtonLabelContext {
|
|
||||||
init(
|
|
||||||
formClass: String? = nil,
|
|
||||||
formId: String,
|
|
||||||
htmxTargetUrl: TargetUrl,
|
|
||||||
htmxTarget: String,
|
|
||||||
htmxPushUrl: Bool,
|
|
||||||
htmxResetAfterRequest: Bool = true,
|
|
||||||
htmxSwapOob: HtmxSwap? = nil,
|
|
||||||
htmxSwap: HtmxSwap? = nil,
|
|
||||||
buttonLabel: String
|
|
||||||
) {
|
|
||||||
self.init(
|
|
||||||
formClass: formClass,
|
|
||||||
formId: formId,
|
|
||||||
htmxTargetUrl: htmxTargetUrl,
|
|
||||||
htmxTarget: htmxTarget,
|
|
||||||
htmxPushUrl: htmxPushUrl,
|
|
||||||
htmxResetAfterRequest: htmxResetAfterRequest,
|
|
||||||
htmxSwapOob: htmxSwapOob,
|
|
||||||
htmxSwap: htmxSwapOob,
|
|
||||||
context: .init(buttonLabel: buttonLabel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,8 @@ struct PurchaseOrderViewController: RouteCollection {
|
|||||||
route.get(use: index)
|
route.get(use: index)
|
||||||
route.get("next", use: nextPage)
|
route.get("next", use: nextPage)
|
||||||
route.post(use: create(req:))
|
route.post(use: create(req:))
|
||||||
|
route.post("search", use: postSearch)
|
||||||
|
route.get("search", use: getSearch)
|
||||||
route.group("create") {
|
route.group("create") {
|
||||||
$0.get(use: form)
|
$0.get(use: form)
|
||||||
$0.get("vendor-branch-select", use: vendorBranchSelect(req:))
|
$0.get("vendor-branch-select", use: vendorBranchSelect(req:))
|
||||||
@@ -39,11 +41,11 @@ struct PurchaseOrderViewController: RouteCollection {
|
|||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func form(req: Request) async throws -> HTMLResponse {
|
func form(req: Request) async throws -> HTMLResponse {
|
||||||
// guard req.isHtmxRequest else {
|
guard req.isHtmxRequest else {
|
||||||
// return try await req.render {
|
return try await req.render {
|
||||||
// try await mainPage(PurchaseOrderForm(shouldShow: true), page: .default)
|
try await mainPage(PurchaseOrderForm(shouldShow: true), page: .default)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
return await req.render { PurchaseOrderForm(shouldShow: true) }
|
return await req.render { PurchaseOrderForm(shouldShow: true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,12 +75,28 @@ struct PurchaseOrderViewController: RouteCollection {
|
|||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
func create(req: Request) async throws -> HTMLResponse {
|
func create(req: Request) async throws -> HTMLResponse {
|
||||||
let create = try req.content.decode(PurchaseOrder.CreateIntermediate.self)
|
let create = try req.content.decode(CreateContext.self).toIntermediate()
|
||||||
let user = try req.auth.require(User.self)
|
let user = try req.auth.require(User.self)
|
||||||
let purchaseOrder = try await purchaseOrders.create(create.toCreate(createdByID: user.id))
|
let purchaseOrder = try await purchaseOrders.create(create.toCreate(createdByID: user.id))
|
||||||
return await req.render { PurchaseOrderTable.Row(purchaseOrder: purchaseOrder) }
|
return await req.render { PurchaseOrderTable.Row(purchaseOrder: purchaseOrder) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sendable
|
||||||
|
func postSearch(req: Request) async throws -> HTMLResponse {
|
||||||
|
let query = try req.content.decode([String: String].self)
|
||||||
|
req.logger.info("query: \(query)")
|
||||||
|
let context = try req.content.decode(SearchContext.self).toSearch()
|
||||||
|
let purchaseOrders = try await purchaseOrders.search(context)
|
||||||
|
req.logger.info("\(purchaseOrders)")
|
||||||
|
return await req.render { PurchaseOrderTable.Rows(page: purchaseOrders) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Sendable
|
||||||
|
func getSearch(req: Request) async throws -> HTMLResponse {
|
||||||
|
let context = try req.query.decode(SearchQuery.self).toSearchContext()
|
||||||
|
return await req.render { PurchaseOrderSearch(context: context) }
|
||||||
|
}
|
||||||
|
|
||||||
private func mainPage<C: HTML>(
|
private func mainPage<C: HTML>(
|
||||||
_ html: C,
|
_ html: C,
|
||||||
page: IndexQuery
|
page: IndexQuery
|
||||||
@@ -87,6 +105,7 @@ struct PurchaseOrderViewController: RouteCollection {
|
|||||||
return MainPage(displayNav: true, route: .purchaseOrders) {
|
return MainPage(displayNav: true, route: .purchaseOrders) {
|
||||||
div(.class("container")) {
|
div(.class("container")) {
|
||||||
html
|
html
|
||||||
|
PurchaseOrderSearch()
|
||||||
PurchaseOrderTable(page: page)
|
PurchaseOrderTable(page: page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,3 +120,54 @@ struct IndexQuery: Content {
|
|||||||
.init(page: 1, limit: 25)
|
.init(page: 1, limit: 25)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct CreateContext: Content {
|
||||||
|
let id: Int?
|
||||||
|
let workOrder: String
|
||||||
|
let materials: String
|
||||||
|
let customer: String
|
||||||
|
let truckStock: Bool?
|
||||||
|
let createdForID: Employee.ID
|
||||||
|
let vendorBranchID: VendorBranch.ID
|
||||||
|
|
||||||
|
func toIntermediate() -> PurchaseOrder.CreateIntermediate {
|
||||||
|
.init(
|
||||||
|
id: id,
|
||||||
|
workOrder: workOrder.isEmpty ? nil : Int(workOrder),
|
||||||
|
materials: materials,
|
||||||
|
customer: customer,
|
||||||
|
truckStock: truckStock,
|
||||||
|
createdForID: createdForID,
|
||||||
|
vendorBranchID: vendorBranchID
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct SearchContext: Content {
|
||||||
|
let context: String
|
||||||
|
let search: String
|
||||||
|
|
||||||
|
func toSearch() throws -> PurchaseOrder.SearchContext {
|
||||||
|
switch context {
|
||||||
|
case "employee":
|
||||||
|
return .employee(search)
|
||||||
|
case "customer":
|
||||||
|
return .customer(search)
|
||||||
|
case "vendor":
|
||||||
|
return .vendor(search)
|
||||||
|
default:
|
||||||
|
throw Abort(.badRequest, reason: "Invalid search context.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SearchQuery: Content {
|
||||||
|
let context: String
|
||||||
|
|
||||||
|
func toSearchContext() throws -> PurchaseOrderSearchContext {
|
||||||
|
guard let context = PurchaseOrderSearchContext(rawValue: context) else {
|
||||||
|
throw Abort(.badRequest, reason: "Invalid context.")
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
38
Sources/App/Controllers/View/UtilsViewController.swift
Normal file
38
Sources/App/Controllers/View/UtilsViewController.swift
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import SharedModels
|
||||||
|
import Vapor
|
||||||
|
import VaporElementary
|
||||||
|
|
||||||
|
struct UtilsViewController: RouteCollection {
|
||||||
|
@Dependency(\.database) var database
|
||||||
|
|
||||||
|
func boot(routes: any RoutesBuilder) throws {
|
||||||
|
let route = routes.protected
|
||||||
|
route.group("select") {
|
||||||
|
$0.get("employee", use: employeeSelect(req:))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Sendable
|
||||||
|
func employeeSelect(req: Request) async throws -> HTMLResponse {
|
||||||
|
let context = try req.query.decode(EmployeeSelectContext.self)
|
||||||
|
let employees = try await database.employees.fetchAll()
|
||||||
|
return await req.render { context.toHTML(employees: employees) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct EmployeeSelectContext: Content {
|
||||||
|
|
||||||
|
let context: EmployeeSelect.Context
|
||||||
|
|
||||||
|
func toHTML(employees: [Employee]) -> EmployeeSelect {
|
||||||
|
switch context {
|
||||||
|
case .form:
|
||||||
|
return .purchaseOrderForm(employees: employees)
|
||||||
|
case .search:
|
||||||
|
return .purchaseOrderSearch(employees: employees)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,14 +9,14 @@ extension RoutesBuilder {
|
|||||||
// Used to ensure views are protected, redirects users to the login page if they're
|
// Used to ensure views are protected, redirects users to the login page if they're
|
||||||
// not authenticated.
|
// not authenticated.
|
||||||
var protected: any RoutesBuilder {
|
var protected: any RoutesBuilder {
|
||||||
// return self
|
return self
|
||||||
return grouped(
|
// return grouped(
|
||||||
UserPasswordAuthenticator(),
|
// UserPasswordAuthenticator(),
|
||||||
UserSessionAuthenticator(),
|
// UserSessionAuthenticator(),
|
||||||
User.redirectMiddleware { req in
|
// User.redirectMiddleware { req in
|
||||||
"login?next=\(req.url)"
|
// "/login?next=\(req.url)"
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiUnprotected(route: PathComponent) -> any RoutesBuilder {
|
func apiUnprotected(route: PathComponent) -> any RoutesBuilder {
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ struct PurchaseOrderForm: HTML {
|
|||||||
}
|
}
|
||||||
form(
|
form(
|
||||||
.hx.post("/purchase-orders"),
|
.hx.post("/purchase-orders"),
|
||||||
.hx.target("purchase-order-table"),
|
.hx.target("#purchase-order-table"),
|
||||||
.hx.swap(.afterBegin.transition(true).swap("1s")),
|
.hx.swap(.afterBegin),
|
||||||
.custom(
|
.custom(
|
||||||
name: "hx-on::after-request",
|
name: "hx-on::after-request",
|
||||||
value: "if (event.detail.successful) toggleContent('float'); window.location.href='/purchase-orders';"
|
value: "if(event.detail.successful) toggleContent('float')"
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
div(.class("row")) {
|
div(.class("row")) {
|
||||||
@@ -139,7 +139,7 @@ struct PurchaseOrderForm: HTML {
|
|||||||
let vendorBranches: [VendorBranch.Detail]
|
let vendorBranches: [VendorBranch.Detail]
|
||||||
|
|
||||||
var content: some HTML<HTMLTag.select> {
|
var content: some HTML<HTMLTag.select> {
|
||||||
select(.name("vendorBranchID"), .class("col-3")) {
|
select(.name("vendorBranchID"), .class("col-4")) {
|
||||||
for branch in vendorBranches {
|
for branch in vendorBranches {
|
||||||
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
option(.value(branch.id.uuidString)) { "\(branch.vendor.name) - \(branch.name)" }
|
||||||
}
|
}
|
||||||
|
|||||||
50
Sources/App/Views/PurchaseOrders/PurchaseOrderSearch.swift
Normal file
50
Sources/App/Views/PurchaseOrders/PurchaseOrderSearch.swift
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import Elementary
|
||||||
|
import ElementaryHTMX
|
||||||
|
import SharedModels
|
||||||
|
import Vapor
|
||||||
|
|
||||||
|
struct PurchaseOrderSearch: HTML {
|
||||||
|
|
||||||
|
let context: PurchaseOrderSearchContext?
|
||||||
|
|
||||||
|
init(context: PurchaseOrderSearchContext? = nil) {
|
||||||
|
self.context = context
|
||||||
|
}
|
||||||
|
|
||||||
|
var content: some HTML {
|
||||||
|
form(
|
||||||
|
.id("search"),
|
||||||
|
.hx.post("/purchase-orders/search"),
|
||||||
|
.hx.target("#purchase-order-table"),
|
||||||
|
.hx.swap(.outerHTML.transition(true).swap("1s"))
|
||||||
|
) {
|
||||||
|
select(
|
||||||
|
.name("context"), .class("col-3"),
|
||||||
|
.hx.get("/purchase-orders/search"),
|
||||||
|
.hx.target("#search"),
|
||||||
|
.hx.swap(.outerHTML)
|
||||||
|
) {
|
||||||
|
option(.value("employee")) { "Employee" }
|
||||||
|
.attributes(.selected, when: context == .employee || context == nil)
|
||||||
|
|
||||||
|
option(.value("customer")) { "Customer" }
|
||||||
|
.attributes(.selected, when: context == .customer)
|
||||||
|
}
|
||||||
|
|
||||||
|
if context == .employee || context == nil {
|
||||||
|
EmployeeSelect.purchaseOrderSearch()
|
||||||
|
} else if context == .customer {
|
||||||
|
input(.type(.text), .name("search"), .placeholder("Search"), .required)
|
||||||
|
}
|
||||||
|
|
||||||
|
button(.type(.submit), .class("btn-primary")) { "Search" }
|
||||||
|
// Img.spinner().attributes(.class("hx-indicator"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum PurchaseOrderSearchContext: String, Codable, Content {
|
||||||
|
case employee
|
||||||
|
case customer
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ struct PurchaseOrderTable: HTML {
|
|||||||
.attributes(
|
.attributes(
|
||||||
.hx.get("/purchase-orders/create"),
|
.hx.get("/purchase-orders/create"),
|
||||||
.hx.target("#float"),
|
.hx.target("#float"),
|
||||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
.hx.swap(.outerHTML),
|
||||||
.hx.pushURL(true)
|
.hx.pushURL(true)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ struct PurchaseOrderTable: HTML {
|
|||||||
.hx.trigger(.event(.revealed)),
|
.hx.trigger(.event(.revealed)),
|
||||||
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
.hx.swap(.outerHTML.transition(true).swap("1s")),
|
||||||
.hx.target("this"),
|
.hx.target("this"),
|
||||||
.hx.indicator(".htmx-indicator")
|
.hx.indicator("next .htmx-indicator")
|
||||||
) {
|
) {
|
||||||
img(.src("/images/spinner.svg"), .class("htmx-indicator"), .width(60), .height(60))
|
img(.src("/images/spinner.svg"), .class("htmx-indicator"), .width(60), .height(60))
|
||||||
}
|
}
|
||||||
|
|||||||
47
Sources/App/Views/Utils/EmployeeSelect.swift
Normal file
47
Sources/App/Views/Utils/EmployeeSelect.swift
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import Elementary
|
||||||
|
import ElementaryHTMX
|
||||||
|
import SharedModels
|
||||||
|
import Vapor
|
||||||
|
|
||||||
|
struct EmployeeSelect: HTML {
|
||||||
|
|
||||||
|
let classString: String
|
||||||
|
let name: String
|
||||||
|
let employees: [Employee]?
|
||||||
|
let context: Context
|
||||||
|
|
||||||
|
var content: some HTML {
|
||||||
|
if let employees {
|
||||||
|
select(.name(name), .class(classString)) {
|
||||||
|
for employee in employees {
|
||||||
|
option(.value(employee.id.uuidString)) { employee.fullName }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.attributes(.style("margin-left: 15px;"), when: context == .search)
|
||||||
|
} else {
|
||||||
|
div(
|
||||||
|
.hx.get("/select/employee?context=\(context.rawValue)"),
|
||||||
|
.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(classString: "col-3", name: "createdForID", employees: employees, context: .form)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func purchaseOrderSearch(employees: [Employee]? = nil) -> Self {
|
||||||
|
.init(classString: "col-3", name: "employeeID", employees: employees, context: .search)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Context: String, Codable, Content {
|
||||||
|
case form
|
||||||
|
case search
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ struct Navbar: HTML, Sendable {
|
|||||||
"x"
|
"x"
|
||||||
}
|
}
|
||||||
a(.hx.get("/purchase-orders?page=1&limit=50"), .hx.target("body"), .hx.pushURL(true)) {
|
a(.hx.get("/purchase-orders?page=1&limit=50"), .hx.target("body"), .hx.pushURL(true)) {
|
||||||
"Purchae Orders"
|
"Purchase Orders"
|
||||||
}
|
}
|
||||||
a(.hx.get("/users"), .hx.target("body"), .hx.pushURL(true)) {
|
a(.hx.get("/users"), .hx.target("body"), .hx.pushURL(true)) {
|
||||||
"Users"
|
"Users"
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ public func configure(_ app: Application) async throws {
|
|||||||
let databaseClient = DatabaseClient.live(database: app.db)
|
let databaseClient = DatabaseClient.live(database: app.db)
|
||||||
try await app.migrations.add(databaseClient.migrations())
|
try await app.migrations.add(databaseClient.migrations())
|
||||||
|
|
||||||
app.views.use(.leaf)
|
|
||||||
|
|
||||||
try withDependencies {
|
try withDependencies {
|
||||||
$0.database = databaseClient
|
$0.database = databaseClient
|
||||||
} operation: {
|
} operation: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import DatabaseClientLive
|
import DatabaseClientLive
|
||||||
import Dependencies
|
import Dependencies
|
||||||
import Elementary
|
import Elementary
|
||||||
|
import ElementaryHTMX
|
||||||
import Fluent
|
import Fluent
|
||||||
import SharedModels
|
import SharedModels
|
||||||
import Vapor
|
import Vapor
|
||||||
@@ -12,6 +13,7 @@ func routes(_ app: Application) throws {
|
|||||||
try app.register(collection: VendorViewController())
|
try app.register(collection: VendorViewController())
|
||||||
try app.register(collection: EmployeeViewController())
|
try app.register(collection: EmployeeViewController())
|
||||||
try app.register(collection: PurchaseOrderViewController())
|
try app.register(collection: PurchaseOrderViewController())
|
||||||
|
try app.register(collection: UtilsViewController())
|
||||||
|
|
||||||
app.get { _ in
|
app.get { _ in
|
||||||
HTMLResponse {
|
HTMLResponse {
|
||||||
@@ -38,7 +40,21 @@ func routes(_ app: Application) throws {
|
|||||||
let token = try await users.login(loginForm)
|
let token = try await users.login(loginForm)
|
||||||
let user = try await users.get(token.userID)!
|
let user = try await users.get(token.userID)!
|
||||||
req.session.authenticate(user)
|
req.session.authenticate(user)
|
||||||
return try await PurchaseOrderViewController().index(req: req)
|
let context = try req.query.decode(LoginContext.self)
|
||||||
|
|
||||||
|
return await req.render {
|
||||||
|
MainPage(displayNav: true, route: .purchaseOrders) {
|
||||||
|
div(
|
||||||
|
.hx.get(context.next ?? "/purchase-orders"),
|
||||||
|
.hx.pushURL(true),
|
||||||
|
.hx.target("body"),
|
||||||
|
.hx.trigger(.event(.revealed)),
|
||||||
|
.hx.indicator(".hx-indicator")
|
||||||
|
) {
|
||||||
|
Img.spinner().attributes(.class("hx-indicator"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let protected = app.grouped(UserPasswordAuthenticator(), UserSessionAuthenticator())
|
let protected = app.grouped(UserPasswordAuthenticator(), UserSessionAuthenticator())
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public extension DatabaseClient {
|
|||||||
public var get: @Sendable (PurchaseOrder.ID) async throws -> PurchaseOrder?
|
public var get: @Sendable (PurchaseOrder.ID) async throws -> PurchaseOrder?
|
||||||
// var update: @Sendable (PurchaseOrder.ID, PurchaseOrder.Update) async throws -> PurchaseOrder
|
// var update: @Sendable (PurchaseOrder.ID, PurchaseOrder.Update) async throws -> PurchaseOrder
|
||||||
public var delete: @Sendable (PurchaseOrder.ID) async throws -> Void
|
public var delete: @Sendable (PurchaseOrder.ID) async throws -> Void
|
||||||
|
public var search: @Sendable (PurchaseOrder.SearchContext) async throws -> Page<PurchaseOrder>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,39 @@ public extension DatabaseClient.PurchaseOrders {
|
|||||||
throw NotFoundError()
|
throw NotFoundError()
|
||||||
}
|
}
|
||||||
try await model.delete(on: database)
|
try await model.delete(on: database)
|
||||||
|
} search: { search in
|
||||||
|
let query = PurchaseOrderModel.allQuery(on: database)
|
||||||
|
|
||||||
|
switch search {
|
||||||
|
case let .employee(employee):
|
||||||
|
guard let employee = try await EmployeeModel.query(on: database).group(.or, { group in
|
||||||
|
group.filter(\.$firstName ~~ employee).filter(\.$lastName ~~ employee)
|
||||||
|
}).first()
|
||||||
|
else { return Page<PurchaseOrder>.empty }
|
||||||
|
|
||||||
|
return try await query.filter(\.$createdFor.$id == employee.id!)
|
||||||
|
.paginate(.init(page: 1, per: 25))
|
||||||
|
.map { try $0.toDTO() }
|
||||||
|
|
||||||
|
case let .customer(search):
|
||||||
|
return try await query.filter(\.$customer ~~ search)
|
||||||
|
.paginate(.init(page: 1, per: 25))
|
||||||
|
.map { try $0.toDTO() }
|
||||||
|
|
||||||
|
case let .vendor(search):
|
||||||
|
guard let vendor = try await VendorModel.query(on: database).filter(\.$name ~~ search).first() else {
|
||||||
|
return .empty
|
||||||
}
|
}
|
||||||
|
// TODO: how to search for this??
|
||||||
|
return .init(items: [], metadata: .init(page: 1, per: 1, total: 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension Page where T == PurchaseOrder {
|
||||||
|
static var empty: Self {
|
||||||
|
.init(items: [], metadata: .init(page: 1, per: 1, total: 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,12 @@ public extension PurchaseOrder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SearchContext: Sendable {
|
||||||
|
case customer(String)
|
||||||
|
case vendor(String)
|
||||||
|
case employee(String)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user