feat(web): move users page into separate administration section
This commit is contained in:
parent
c2e0c4d091
commit
37253c31dd
7 changed files with 34 additions and 11 deletions
|
|
@ -2,6 +2,7 @@ use axum::{
|
|||
Extension, Router,
|
||||
extract::{Path, Query, State},
|
||||
http::HeaderMap,
|
||||
response::Redirect,
|
||||
routing::{delete, get},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
|
@ -16,8 +17,12 @@ use crate::{
|
|||
|
||||
pub fn router(ctx: Context) -> Router<Context> {
|
||||
Router::new()
|
||||
.route("/users", get(get_users))
|
||||
.route("/users/{id}", delete(delete_user))
|
||||
.route(
|
||||
"/administration",
|
||||
get(|| async { Redirect::permanent("/administration/users") }),
|
||||
)
|
||||
.route("/administration/users", get(get_users))
|
||||
.route("/administration/users/{id}", delete(delete_user))
|
||||
.route_layer(axum::middleware::from_fn_with_state(
|
||||
ctx.clone(),
|
||||
super::auth::auth_web_middleware,
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
mod administration;
|
||||
mod auth;
|
||||
mod sessions;
|
||||
mod users;
|
||||
|
||||
use axum::{Router, extract::State, http::HeaderMap, routing::get};
|
||||
use axum_extra::extract::CookieJar;
|
||||
|
|
@ -65,7 +65,7 @@ pub fn router(ctx: Context) -> Router<Context> {
|
|||
// loop
|
||||
.merge(auth::router(ctx.clone()))
|
||||
.merge(sessions::router(ctx.clone()))
|
||||
.merge(users::router(ctx.clone()))
|
||||
.merge(administration::router(ctx.clone()))
|
||||
}
|
||||
|
||||
async fn get_index(
|
||||
|
|
|
|||
|
|
@ -87,7 +87,11 @@ pub fn initialize_tera() -> tera::Result<tera::Tera> {
|
|||
),
|
||||
(
|
||||
View::Users(Vec::new(), 0, None).template(),
|
||||
include_str!("templates/views/users.html"),
|
||||
include_str!("templates/views/administration/users.html"),
|
||||
),
|
||||
(
|
||||
"views/administration/base.html",
|
||||
include_str!("templates/views/administration/base.html"),
|
||||
),
|
||||
(
|
||||
View::Signup {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ a:hover {
|
|||
{% if authenticated %}
|
||||
<li><a hx-get="/sessions" hx-target="#inner" hx-push-url="true">Sessions</a></li>
|
||||
{% if admin %}
|
||||
<li><a hx-get="/users" hx-target="#inner" hx-push-url="true">Users</a></li>
|
||||
<li><a hx-get="/administration/users" hx-target="#inner" hx-push-url="true">Administration</a></li>
|
||||
{% endif %}
|
||||
<li><a hx-post="/logout" hx-target="#inner">Logout</a></li>
|
||||
{% else %}
|
||||
|
|
|
|||
11
otter/src/web/templates/views/administration/base.html
Normal file
11
otter/src/web/templates/views/administration/base.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<h2>Administration</h2>
|
||||
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<a hx-get="/administration/users" hx-target="#inner" hx-push-url="true">Users</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
{% block inner %}{% endblock %}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
<h1>Users</h1>
|
||||
{% extends "views/administration/base.html" %}
|
||||
{% block inner %}
|
||||
<h3>Users</h3>
|
||||
|
||||
<input
|
||||
type="text" id="username" name="username"
|
||||
hx-get="/users"
|
||||
hx-get="/administration/users"
|
||||
hx-target="#users > tbody"
|
||||
hx-swap="innerHTML"
|
||||
hx-select="table > tbody > tr"
|
||||
|
|
@ -26,7 +28,7 @@
|
|||
{%- endif -%}
|
||||
<th>
|
||||
{%- if user.id != current_user_id -%}
|
||||
<a hx-delete="/users/{{ user.id }}"
|
||||
<a hx-delete="/administration/users/{{ user.id }}"
|
||||
hx-target="closest tr"
|
||||
>Remove</a>
|
||||
{%- else -%}
|
||||
|
|
@ -38,7 +40,7 @@
|
|||
|
||||
{%- if next_page_query %}
|
||||
<tr
|
||||
hx-get="/users?{{ next_page_query }}"
|
||||
hx-get="/administration/users?{{ next_page_query }}"
|
||||
hx-trigger="revealed"
|
||||
hx-swap="outerHTML"
|
||||
hx-select="table > tbody > tr"
|
||||
|
|
@ -46,3 +48,4 @@
|
|||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
@ -37,7 +37,7 @@ impl Template for View {
|
|||
Self::Index => "views/index.html",
|
||||
Self::Login { .. } => "views/login.html",
|
||||
Self::Sessions(..) => "views/sessions.html",
|
||||
Self::Users(..) => "views/users.html",
|
||||
Self::Users(..) => "views/administration/users.html",
|
||||
Self::Signup { .. } => "views/signup.html",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue