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/src/model/user/mod.rs b/src/model/user/mod.rs index 815fbc7..c700e76 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", false).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 }) diff --git a/templates/admin/user/index.html.tera b/templates/admin/user/index.html.tera index c50e64f..69e0121 100644 --- a/templates/admin/user/index.html.tera +++ b/templates/admin/user/index.html.tera @@ -4,37 +4,59 @@

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 %} -
+
+ +
+ + + + +
@@ -47,7 +69,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 %}