From 891762961383a424a51e8a328c674899aeb92d87 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Tue, 11 Feb 2025 19:30:09 +0100 Subject: [PATCH 1/6] use proper permissions --- templates/admin/user/index.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index c50e64f..9d58196 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -47,7 +47,7 @@ {{ user.name }} - {% if not user.last_access and "admin" in loggedin_user.roles and user.mail %} + {% if not user.last_access and allowed_to_edit and user.mail %}
Date: Tue, 11 Feb 2025 20:23:18 +0100 Subject: [PATCH 2/6] allow sorting of user --- src/model/user/mod.rs | 31 ++++++++++++++++++++----------- src/tera/admin/user.rs | 8 ++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/model/user/mod.rs b/src/model/user/mod.rs index 815fbc7..839b491 100644 --- a/src/model/user/mod.rs +++ b/src/model/user/mod.rs @@ -591,18 +591,27 @@ WHERE lower(name)=? } pub async fn all(db: &SqlitePool) -> Vec { - sqlx::query_as!( - Self, - " -SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id, user_token -FROM user -WHERE deleted = 0 -ORDER BY last_access DESC + Self::all_with_order(db, "last_access", true).await + } + + pub async fn all_with_order(db: &SqlitePool, sort: &str, asc: bool) -> Vec { + let mut query = format!( " - ) - .fetch_all(db) - .await - .unwrap() + SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id, user_token + FROM user + WHERE deleted = 0 + ORDER BY {} + ", + sort + ); + if !asc { + query.push_str(" DESC"); + } + + sqlx::query_as::<_, User>(&query) + .fetch_all(db) + .await + .unwrap() } pub async fn all_with_role(db: &SqlitePool, role: &Role) -> Vec { diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 8cea3d8..192560b 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -43,13 +43,17 @@ impl<'r> FromRequest<'r> for Referer { } } -#[get("/user")] +#[get("/user?&")] async fn index( db: &State, user: VorstandUser, flash: Option>, + sort: Option, + asc: bool, ) -> Template { - let user_futures: Vec<_> = User::all(db) + let sort_column = sort.unwrap_or_else(|| "last_access".to_string()); + + let user_futures: Vec<_> = User::all_with_order(db, &sort_column, asc) .await .into_iter() .map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await }) From 1fdec59f777a01c41602aff192a280ce1c6f009b Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Tue, 11 Feb 2025 21:12:30 +0100 Subject: [PATCH 3/6] [TASK] add sort element user management --- frontend/main.ts | 19 +++++++++++++++++++ templates/admin/user/index.html.tera | 23 ++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/frontend/main.ts b/frontend/main.ts index 82f59e9..e8d528c 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -23,6 +23,7 @@ document.addEventListener("DOMContentLoaded", function () { addRelationMagic(document.querySelector("body")); reloadPage(); setCurrentdate(document.querySelector("#departure")); + initDropdown(); }); function changeTheme() { @@ -795,3 +796,21 @@ function replaceStrings() { weekday.innerHTML = weekday.innerHTML.replace("Freitag", "Markttag"); }); } + +function initDropdown() { + const popoverTriggerList = document.querySelectorAll('[data-dropdown]'); + + popoverTriggerList.forEach((popoverTriggerEl: Element) => { + const id = popoverTriggerEl.getAttribute('data-dropdown'); + + if (id) { + const element = document.getElementById(id); + if (element) { + // Toggle visibility of the dropdown when clicked + popoverTriggerEl.addEventListener('click', () => { + element.classList.toggle('hidden'); + }); + } + } + }); +} diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index 9d58196..fd6de6c 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -28,13 +28,34 @@ {% endif %} -
+
+ +
+ + + + +
From 31fc0605d9a6c56ba00a50e41f641d651ebd4442 Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Tue, 11 Feb 2025 21:28:28 +0100 Subject: [PATCH 4/6] [TASK] improve user management ux --- templates/admin/user/index.html.tera | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index fd6de6c..648cd61 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -4,28 +4,29 @@

Users

{% if allowed_to_edit %} -
+ Neue Person hinzufügen + + class="flex mt-4 rounded-md sm:flex items-end justify-between">
-

Neuen User hinzufügen

-
-
- - -
+
+ +
-
+
+ + {% endif %}
From 11025738bbc4f32f514ecfbb70a2b8b6846a7783 Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Tue, 11 Feb 2025 21:29:54 +0100 Subject: [PATCH 5/6] [TASK] improve user management ux --- templates/admin/user/index.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index 648cd61..69e0121 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -5,7 +5,7 @@

Users

{% if allowed_to_edit %}
- Neue Person hinzufügen + Neue Person hinzufügen
Date: Tue, 11 Feb 2025 21:39:06 +0100 Subject: [PATCH 6/6] fix default sort --- src/model/user/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/user/mod.rs b/src/model/user/mod.rs index 839b491..c700e76 100644 --- a/src/model/user/mod.rs +++ b/src/model/user/mod.rs @@ -591,7 +591,7 @@ WHERE lower(name)=? } pub async fn all(db: &SqlitePool) -> Vec { - Self::all_with_order(db, "last_access", true).await + Self::all_with_order(db, "last_access", false).await } pub async fn all_with_order(db: &SqlitePool, sort: &str, asc: bool) -> Vec {