diff --git a/assets/tailwind.css b/assets/tailwind.css index 1f4cb91..aa7cfd4 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -3019,8 +3019,8 @@ details.collapse summary::-webkit-details-marker { max-width: 42rem; } -.max-w-4xl { - max-width: 56rem; +.max-w-3xl { + max-width: 48rem; } .max-w-lg { diff --git a/src/components/admin/members.rs b/src/components/admin/members.rs index e61ca4b..4659600 100644 --- a/src/components/admin/members.rs +++ b/src/components/admin/members.rs @@ -9,34 +9,31 @@ pub fn Members() -> Element { rsx! { div { - class: "flex justify-center", - div { - class: "max-w-4xl w-full", - h2 { class: "font-bold text-lg", "Leden" }, - match &*members.read_unchecked() { - Some(Ok(res)) => rsx! { - div { - class: "overflow-x-auto", - table { - class: "table table-zebra table-pin-rows", - thead { - tr { - th { "Relatiecode" } - th { "Naam" } - th { "Registratiecode" } - } + class: "max-w-3xl w-full", + h2 { class: "font-bold text-lg", "Leden" }, + match &*members.read_unchecked() { + Some(Ok(res)) => rsx! { + div { + class: "overflow-x-auto", + table { + class: "table table-zebra table-pin-rows", + thead { + tr { + th { "Relatiecode" } + th { "Naam" } + th { "Registratiecode" } } - tbody { - for member in res { - MemberRow { member: member.clone() } - } + } + tbody { + for member in res { + MemberRow { member: member.clone() } } } } - }, - Some(Err(_)) => rsx! { div { "Error while loading members" } }, - None => rsx! { div { "Loading..." } }, - } + } + }, + Some(Err(_)) => rsx! { div { "Error while loading members" } }, + None => rsx! { div { "Loading..." } }, } } } diff --git a/src/components/admin/users.rs b/src/components/admin/users.rs index f750c5e..c811eb1 100644 --- a/src/components/admin/users.rs +++ b/src/components/admin/users.rs @@ -7,33 +7,30 @@ pub fn Users() -> Element { rsx! { div { - class: "flex justify-center", - div { - class: "max-w-4xl w-full", - h2 { class: "font-bold text-lg", "Gebruikers" }, - match &*users.read_unchecked() { - Some(Ok(res)) => rsx! { - div { - class: "overflow-x-auto", - table { - class: "table table-zebra table-pin-rows", - thead { - tr { - th { "Id" } - th { "Email" } - } + class: "max-w-3xl w-full", + h2 { class: "font-bold text-lg", "Gebruikers" }, + match &*users.read_unchecked() { + Some(Ok(res)) => rsx! { + div { + class: "overflow-x-auto", + table { + class: "table table-zebra table-pin-rows", + thead { + tr { + th { "Id" } + th { "Email" } } - tbody { - for user in res { - UserRow { user: user.clone() } - } + } + tbody { + for user in res { + UserRow { user: user.clone() } } } } - }, - Some(Err(_)) => rsx! { div { "Error while loading users" } }, - None => rsx! { div { "Loading..." } }, - } + } + }, + Some(Err(_)) => rsx! { div { "Error while loading users" } }, + None => rsx! { div { "Loading..." } }, } } } diff --git a/src/components/settings.rs b/src/components/settings.rs index fe55d36..8abbcba 100644 --- a/src/components/settings.rs +++ b/src/components/settings.rs @@ -251,9 +251,11 @@ fn Members() -> Element { } div { class: "", - span { "LS2" }, - span { class: "mx-1.5", "•" } - span { "A1, B2" } + if let Some(d) = member.diploma { + span { "{d}" } + span { class: "mx-1.5", "•" } + } + span { {member.hours.join(", ")} } } }, div { @@ -308,7 +310,7 @@ fn Members() -> Element { async fn fetch_members() -> Result, ServerFnError> { let user = Session::fetch_current_user().await?; - let members = Member::fetch_from_user(user.id).await?; + let members = Member::fetch_from_user(&user.id).await?; Ok(members) } diff --git a/src/util/model/member.rs b/src/util/model/member.rs index 7731c31..de434ec 100644 --- a/src/util/model/member.rs +++ b/src/util/model/member.rs @@ -1,6 +1,8 @@ #[cfg(feature = "server")] use crate::util::surrealdb::{thing_to_string, DB}; use serde::{Deserialize, Serialize}; +#[cfg(feature = "server")] +use surrealdb::sql::Thing; #[cfg(feature = "server")] mod migration; @@ -57,12 +59,10 @@ impl Member { } } - pub async fn fetch_from_user(user_id: String) -> Result, crate::Error> { + pub async fn fetch_from_user(user_id: &str) -> Result, crate::Error> { let mut res = DB - .query( - "SELECT VALUE ->user_to_member->member.* FROM ONLY type::thing('user', $user_id)", - ) - .bind(("user_id", user_id)) + .query("SELECT VALUE ->user_to_member->member.* FROM ONLY $user") + .bind(("user", Thing::from(("user", user_id)))) .await?; res = res.check()?; diff --git a/src/util/model/member/migration.rs b/src/util/model/member/migration.rs index e99da23..6b63531 100644 --- a/src/util/model/member/migration.rs +++ b/src/util/model/member/migration.rs @@ -202,7 +202,7 @@ impl MembersMigration { } pub async fn migrate(id: u16) -> Result<(), Box> { - let members_store = MEMBERS_STORE.lock().await; + let mut members_store = MEMBERS_STORE.lock().await; let members_migration = match members_store.get(&id) { Some(mm) => mm, @@ -212,31 +212,30 @@ impl MembersMigration { let mut transaction = DB.query(BeginStatement::default()); for member in members_migration.updated.clone() { - // TODO add hours and diploma support let id = member.id.clone(); - transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};")) + transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};")) .bind((format!("id_{id}"), member.id)) .bind((format!("name_first_{id}"), member.name.first)) .bind((format!("name_full_{id}"), member.name.full)) .bind((format!("hours_{id}"), member.hours)) - .bind((format!("groups_{id}"), member.groups)); + .bind((format!("groups_{id}"), member.groups)) + .bind((format!("diploma_{id}"), member.diploma)); } for member in members_migration.inserted.clone() { - // TODO add hours and diploma support let id = member.id.clone(); - transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};")) + transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};")) .bind((format!("id_{id}"), member.id)) .bind((format!("name_first_{id}"), member.name.first)) .bind((format!("name_full_{id}"), member.name.full)) .bind((format!("hours_{id}"), member.hours)) - .bind((format!("groups_{id}"), member.groups)); + .bind((format!("groups_{id}"), member.groups)) + .bind((format!("diploma_{id}"), member.diploma)); } for member in members_migration.removed.clone() { - // TODO add hours and diploma support let id = member.id.clone(); transaction = transaction @@ -249,6 +248,8 @@ impl MembersMigration { .await? .check()?; + members_store.remove(&id); + Ok(()) } } diff --git a/src/util/surrealdb.rs b/src/util/surrealdb.rs index 59a8403..720eac2 100644 --- a/src/util/surrealdb.rs +++ b/src/util/surrealdb.rs @@ -66,6 +66,7 @@ async fn apply_queries() -> surrealdb::Result<()> { DEFINE FIELD name.full ON TABLE member TYPE string; DEFINE FIELD registration_token ON TABLE member TYPE string VALUE rand::string(16); + DEFINE FIELD diploma ON TABLE member TYPE option; DEFINE FIELD hours ON TABLE member TYPE set; DEFINE FIELD groups ON TABLE member TYPE set; ",