Added diploma support
This commit is contained in:
parent
1aa7a0565d
commit
570edc1b44
@ -3019,8 +3019,8 @@ details.collapse summary::-webkit-details-marker {
|
|||||||
max-width: 42rem;
|
max-width: 42rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.max-w-4xl {
|
.max-w-3xl {
|
||||||
max-width: 56rem;
|
max-width: 48rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.max-w-lg {
|
.max-w-lg {
|
||||||
|
@ -9,34 +9,31 @@ pub fn Members() -> Element {
|
|||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
div {
|
div {
|
||||||
class: "flex justify-center",
|
class: "max-w-3xl w-full",
|
||||||
div {
|
h2 { class: "font-bold text-lg", "Leden" },
|
||||||
class: "max-w-4xl w-full",
|
match &*members.read_unchecked() {
|
||||||
h2 { class: "font-bold text-lg", "Leden" },
|
Some(Ok(res)) => rsx! {
|
||||||
match &*members.read_unchecked() {
|
div {
|
||||||
Some(Ok(res)) => rsx! {
|
class: "overflow-x-auto",
|
||||||
div {
|
table {
|
||||||
class: "overflow-x-auto",
|
class: "table table-zebra table-pin-rows",
|
||||||
table {
|
thead {
|
||||||
class: "table table-zebra table-pin-rows",
|
tr {
|
||||||
thead {
|
th { "Relatiecode" }
|
||||||
tr {
|
th { "Naam" }
|
||||||
th { "Relatiecode" }
|
th { "Registratiecode" }
|
||||||
th { "Naam" }
|
|
||||||
th { "Registratiecode" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tbody {
|
}
|
||||||
for member in res {
|
tbody {
|
||||||
MemberRow { member: member.clone() }
|
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..." } },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,33 +7,30 @@ pub fn Users() -> Element {
|
|||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
div {
|
div {
|
||||||
class: "flex justify-center",
|
class: "max-w-3xl w-full",
|
||||||
div {
|
h2 { class: "font-bold text-lg", "Gebruikers" },
|
||||||
class: "max-w-4xl w-full",
|
match &*users.read_unchecked() {
|
||||||
h2 { class: "font-bold text-lg", "Gebruikers" },
|
Some(Ok(res)) => rsx! {
|
||||||
match &*users.read_unchecked() {
|
div {
|
||||||
Some(Ok(res)) => rsx! {
|
class: "overflow-x-auto",
|
||||||
div {
|
table {
|
||||||
class: "overflow-x-auto",
|
class: "table table-zebra table-pin-rows",
|
||||||
table {
|
thead {
|
||||||
class: "table table-zebra table-pin-rows",
|
tr {
|
||||||
thead {
|
th { "Id" }
|
||||||
tr {
|
th { "Email" }
|
||||||
th { "Id" }
|
|
||||||
th { "Email" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tbody {
|
}
|
||||||
for user in res {
|
tbody {
|
||||||
UserRow { user: user.clone() }
|
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..." } },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,9 +251,11 @@ fn Members() -> Element {
|
|||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
class: "",
|
class: "",
|
||||||
span { "LS2" },
|
if let Some(d) = member.diploma {
|
||||||
span { class: "mx-1.5", "•" }
|
span { "{d}" }
|
||||||
span { "A1, B2" }
|
span { class: "mx-1.5", "•" }
|
||||||
|
}
|
||||||
|
span { {member.hours.join(", ")} }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
div {
|
div {
|
||||||
@ -308,7 +310,7 @@ fn Members() -> Element {
|
|||||||
async fn fetch_members() -> Result<Vec<Member>, ServerFnError> {
|
async fn fetch_members() -> Result<Vec<Member>, ServerFnError> {
|
||||||
let user = Session::fetch_current_user().await?;
|
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)
|
Ok(members)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
use crate::util::surrealdb::{thing_to_string, DB};
|
use crate::util::surrealdb::{thing_to_string, DB};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "server")]
|
||||||
|
use surrealdb::sql::Thing;
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
mod migration;
|
mod migration;
|
||||||
@ -57,12 +59,10 @@ impl Member {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_from_user(user_id: String) -> Result<Vec<Self>, crate::Error> {
|
pub async fn fetch_from_user(user_id: &str) -> Result<Vec<Self>, crate::Error> {
|
||||||
let mut res = DB
|
let mut res = DB
|
||||||
.query(
|
.query("SELECT VALUE ->user_to_member->member.* FROM ONLY $user")
|
||||||
"SELECT VALUE ->user_to_member->member.* FROM ONLY type::thing('user', $user_id)",
|
.bind(("user", Thing::from(("user", user_id))))
|
||||||
)
|
|
||||||
.bind(("user_id", user_id))
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
res = res.check()?;
|
res = res.check()?;
|
||||||
|
@ -202,7 +202,7 @@ impl MembersMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn migrate(id: u16) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn migrate(id: u16) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let members_store = MEMBERS_STORE.lock().await;
|
let mut members_store = MEMBERS_STORE.lock().await;
|
||||||
|
|
||||||
let members_migration = match members_store.get(&id) {
|
let members_migration = match members_store.get(&id) {
|
||||||
Some(mm) => mm,
|
Some(mm) => mm,
|
||||||
@ -212,31 +212,30 @@ impl MembersMigration {
|
|||||||
let mut transaction = DB.query(BeginStatement::default());
|
let mut transaction = DB.query(BeginStatement::default());
|
||||||
|
|
||||||
for member in members_migration.updated.clone() {
|
for member in members_migration.updated.clone() {
|
||||||
// TODO add hours and diploma support
|
|
||||||
let id = member.id.clone();
|
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!("id_{id}"), member.id))
|
||||||
.bind((format!("name_first_{id}"), member.name.first))
|
.bind((format!("name_first_{id}"), member.name.first))
|
||||||
.bind((format!("name_full_{id}"), member.name.full))
|
.bind((format!("name_full_{id}"), member.name.full))
|
||||||
.bind((format!("hours_{id}"), member.hours))
|
.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() {
|
for member in members_migration.inserted.clone() {
|
||||||
// TODO add hours and diploma support
|
|
||||||
let id = member.id.clone();
|
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!("id_{id}"), member.id))
|
||||||
.bind((format!("name_first_{id}"), member.name.first))
|
.bind((format!("name_first_{id}"), member.name.first))
|
||||||
.bind((format!("name_full_{id}"), member.name.full))
|
.bind((format!("name_full_{id}"), member.name.full))
|
||||||
.bind((format!("hours_{id}"), member.hours))
|
.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() {
|
for member in members_migration.removed.clone() {
|
||||||
// TODO add hours and diploma support
|
|
||||||
let id = member.id.clone();
|
let id = member.id.clone();
|
||||||
|
|
||||||
transaction = transaction
|
transaction = transaction
|
||||||
@ -249,6 +248,8 @@ impl MembersMigration {
|
|||||||
.await?
|
.await?
|
||||||
.check()?;
|
.check()?;
|
||||||
|
|
||||||
|
members_store.remove(&id);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ async fn apply_queries() -> surrealdb::Result<()> {
|
|||||||
DEFINE FIELD name.full ON TABLE member TYPE string;
|
DEFINE FIELD name.full ON TABLE member TYPE string;
|
||||||
DEFINE FIELD registration_token ON TABLE member TYPE string
|
DEFINE FIELD registration_token ON TABLE member TYPE string
|
||||||
VALUE rand::string(16);
|
VALUE rand::string(16);
|
||||||
|
DEFINE FIELD diploma ON TABLE member TYPE option<string>;
|
||||||
DEFINE FIELD hours ON TABLE member TYPE set<string>;
|
DEFINE FIELD hours ON TABLE member TYPE set<string>;
|
||||||
DEFINE FIELD groups ON TABLE member TYPE set<string>;
|
DEFINE FIELD groups ON TABLE member TYPE set<string>;
|
||||||
",
|
",
|
||||||
|
Loading…
Reference in New Issue
Block a user