diff options
-rw-r--r-- | src/html.rs | 3 | ||||
-rw-r--r-- | templates/users.html | 63 |
2 files changed, 47 insertions, 19 deletions
diff --git a/src/html.rs b/src/html.rs index debc362..2a80b5d 100644 --- a/src/html.rs +++ b/src/html.rs @@ -6,7 +6,6 @@ use axum::{ routing::get, }; use serde::Deserialize; -use uuid::Uuid; use crate::{ api::users::UserSchema, @@ -19,7 +18,7 @@ pub mod error; pub fn router() -> axum::Router<state::AppState> { axum::Router::new() - .route("/search", get(search)) + .route("/users", get(search)) .route("/healthcheck", get(healthcheck)) .fallback(fallback) } diff --git a/templates/users.html b/templates/users.html index 3f7c3af..fc15fc2 100644 --- a/templates/users.html +++ b/templates/users.html @@ -53,29 +53,58 @@ <hgroup> <h1>Users</h1> <form action="/users" method="get"> - <input type="text" name="name" /> + <input type="search" name="name" /> <input type="submit" value="Search" /> </form> </hgroup> </header> <table> - <tr> - <th scope="col">ID</th> - <th scope="col">Name</th> - <th scope="col">Email</th> - <th scope="col">Created</th> - <th scope="col">Updated</th> - </tr> - {% for user in users %} - <tr> - <td>{{ user.id }}</td> - <td>{{ user.name }}</td> - <td>{{ user.email }}</td> - <td>{{ user.created_at }}</td> - <td>{{ user.updated_at }}</td> - </tr> - {% endfor %} + <form method="POST" onsubmit="return handleSave(event)"> + <tr> + <th scope="col">ID</th> + <th scope="col">Name</th> + <th scope="col">Email</th> + <th scope="col">Created</th> + <th scope="col">Updated</th> + <th> + <!--<input type="submit" value="Save All" />--> + <input type="reset" value="Reset All" /> + </th> + </tr> + {% for user in users %} + <tr> + <form method="POST" onsubmit="return handleSave(event)"> + <input name="id" value="{{ user.id }}" style="display: none" /> + <td>{{ user.id }}</td> + <td> + <input name="name" value="{{ user.name }}" /> + </td> + <td> + <input type="email" name="email" value="{{ user.email }}" /> + </td> + <td>{{ user.created_at }}</td> + <td>{{ user.updated_at }}</td> + <td> + <input type="submit" value="Update" /> + <input type="reset" value="Reset" /> + </td> + </form> + </tr> + {% endfor %} + </form> </table> </main> </body> + <script> + function handleSave(e) { + e.preventDefault(); + const formData = new FormData(e.target); + console.log(formData); + const formProps = Object.fromEntries(formData); + console.log(formProps); + for (var pair of formData.entries()) { + console.log(pair[0] + ": " + pair[1]); + } + } + </script> </html> |