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,
|
Extension, Router,
|
||||||
extract::{Path, Query, State},
|
extract::{Path, Query, State},
|
||||||
http::HeaderMap,
|
http::HeaderMap,
|
||||||
|
response::Redirect,
|
||||||
routing::{delete, get},
|
routing::{delete, get},
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -16,8 +17,12 @@ use crate::{
|
||||||
|
|
||||||
pub fn router(ctx: Context) -> Router<Context> {
|
pub fn router(ctx: Context) -> Router<Context> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/users", get(get_users))
|
.route(
|
||||||
.route("/users/{id}", delete(delete_user))
|
"/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(
|
.route_layer(axum::middleware::from_fn_with_state(
|
||||||
ctx.clone(),
|
ctx.clone(),
|
||||||
super::auth::auth_web_middleware,
|
super::auth::auth_web_middleware,
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
mod administration;
|
||||||
mod auth;
|
mod auth;
|
||||||
mod sessions;
|
mod sessions;
|
||||||
mod users;
|
|
||||||
|
|
||||||
use axum::{Router, extract::State, http::HeaderMap, routing::get};
|
use axum::{Router, extract::State, http::HeaderMap, routing::get};
|
||||||
use axum_extra::extract::CookieJar;
|
use axum_extra::extract::CookieJar;
|
||||||
|
|
@ -65,7 +65,7 @@ pub fn router(ctx: Context) -> Router<Context> {
|
||||||
// loop
|
// loop
|
||||||
.merge(auth::router(ctx.clone()))
|
.merge(auth::router(ctx.clone()))
|
||||||
.merge(sessions::router(ctx.clone()))
|
.merge(sessions::router(ctx.clone()))
|
||||||
.merge(users::router(ctx.clone()))
|
.merge(administration::router(ctx.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_index(
|
async fn get_index(
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,11 @@ pub fn initialize_tera() -> tera::Result<tera::Tera> {
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
View::Users(Vec::new(), 0, None).template(),
|
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 {
|
View::Signup {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ a:hover {
|
||||||
{% if authenticated %}
|
{% if authenticated %}
|
||||||
<li><a hx-get="/sessions" hx-target="#inner" hx-push-url="true">Sessions</a></li>
|
<li><a hx-get="/sessions" hx-target="#inner" hx-push-url="true">Sessions</a></li>
|
||||||
{% if admin %}
|
{% 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 %}
|
{% endif %}
|
||||||
<li><a hx-post="/logout" hx-target="#inner">Logout</a></li>
|
<li><a hx-post="/logout" hx-target="#inner">Logout</a></li>
|
||||||
{% else %}
|
{% 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
|
<input
|
||||||
type="text" id="username" name="username"
|
type="text" id="username" name="username"
|
||||||
hx-get="/users"
|
hx-get="/administration/users"
|
||||||
hx-target="#users > tbody"
|
hx-target="#users > tbody"
|
||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
hx-select="table > tbody > tr"
|
hx-select="table > tbody > tr"
|
||||||
|
|
@ -26,7 +28,7 @@
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<th>
|
<th>
|
||||||
{%- if user.id != current_user_id -%}
|
{%- if user.id != current_user_id -%}
|
||||||
<a hx-delete="/users/{{ user.id }}"
|
<a hx-delete="/administration/users/{{ user.id }}"
|
||||||
hx-target="closest tr"
|
hx-target="closest tr"
|
||||||
>Remove</a>
|
>Remove</a>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
|
|
@ -38,7 +40,7 @@
|
||||||
|
|
||||||
{%- if next_page_query %}
|
{%- if next_page_query %}
|
||||||
<tr
|
<tr
|
||||||
hx-get="/users?{{ next_page_query }}"
|
hx-get="/administration/users?{{ next_page_query }}"
|
||||||
hx-trigger="revealed"
|
hx-trigger="revealed"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
hx-select="table > tbody > tr"
|
hx-select="table > tbody > tr"
|
||||||
|
|
@ -46,3 +48,4 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -37,7 +37,7 @@ impl Template for View {
|
||||||
Self::Index => "views/index.html",
|
Self::Index => "views/index.html",
|
||||||
Self::Login { .. } => "views/login.html",
|
Self::Login { .. } => "views/login.html",
|
||||||
Self::Sessions(..) => "views/sessions.html",
|
Self::Sessions(..) => "views/sessions.html",
|
||||||
Self::Users(..) => "views/users.html",
|
Self::Users(..) => "views/administration/users.html",
|
||||||
Self::Signup { .. } => "views/signup.html",
|
Self::Signup { .. } => "views/signup.html",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue