♻️ refactor
Some checks are pending
ci/woodpecker/push/test Pipeline is pending

This commit is contained in:
JMARyA 2025-02-25 09:10:48 +01:00
parent 696b34f2f1
commit c10105ad75
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 146 additions and 47 deletions

View file

@ -52,12 +52,15 @@ pub trait AssetRoutes {
impl AssetRoutes for rocket::Rocket<Build> { impl AssetRoutes for rocket::Rocket<Build> {
fn mount_assets(self) -> Self { fn mount_assets(self) -> Self {
self.mount("/", routes![ self.mount(
crate::asset::htmx_script_route, "/",
crate::asset::flowbite_css, routes![
crate::asset::flowbite_js, crate::asset::htmx_script_route,
crate::asset::material_css, crate::asset::flowbite_css,
crate::asset::material_font crate::asset::flowbite_js,
]) crate::asset::material_css,
crate::asset::material_font
],
)
} }
} }

View file

@ -81,6 +81,13 @@ fn transpose<T: Clone>(matrix: Vec<Vec<T>>) -> Vec<Vec<T>> {
pub enum DatabaseType { pub enum DatabaseType {
TEXT(String), TEXT(String),
INTEGER(i32), INTEGER(i32),
BIGINT(i64),
REAL(f32),
DOUBLE(f64),
BOOLEAN(bool),
BYTEA(Vec<u8>),
UUID(uuid::Uuid),
JSON(serde_json::Value),
} }
impl DatabaseType { impl DatabaseType {
@ -88,6 +95,62 @@ impl DatabaseType {
match self { match self {
Self::TEXT(_) => "TEXT", Self::TEXT(_) => "TEXT",
Self::INTEGER(_) => "INTEGER", Self::INTEGER(_) => "INTEGER",
Self::BIGINT(_) => "BIGINT",
Self::REAL(_) => "REAL",
Self::DOUBLE(_) => "DOUBLE PRECISION",
Self::BOOLEAN(_) => "BOOLEAN",
Self::BYTEA(_) => "BYTEA",
Self::UUID(_) => "UUID",
Self::JSON(_) => "JSONB",
}
}
pub fn as_json(self) -> serde_json::Value {
match self {
DatabaseType::JSON(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_uuid(self) -> uuid::Uuid {
match self {
DatabaseType::UUID(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_vec(self) -> Vec<u8> {
match self {
DatabaseType::BYTEA(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_bool(self) -> bool {
match self {
DatabaseType::BOOLEAN(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_f64(self) -> f64 {
match self {
DatabaseType::DOUBLE(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_f32(self) -> f32 {
match self {
DatabaseType::REAL(result) => return result,
_ => panic!["Wrong DB type"],
}
}
pub fn as_big_int(self) -> i64 {
match self {
DatabaseType::BIGINT(result) => return result,
_ => panic!["Wrong DB type"],
} }
} }
@ -141,6 +204,27 @@ pub async fn batch_insert(table: &str, values: &[String], entries: Vec<Vec<Datab
DatabaseType::INTEGER(_) => { DatabaseType::INTEGER(_) => {
query = query.bind(e.into_iter().map(|x| x.as_integer()).collect::<Vec<_>>()); query = query.bind(e.into_iter().map(|x| x.as_integer()).collect::<Vec<_>>());
} }
DatabaseType::BIGINT(_) => {
query = query.bind(e.into_iter().map(|x| x.as_big_int()).collect::<Vec<_>>());
}
DatabaseType::REAL(_) => {
query = query.bind(e.into_iter().map(|x| x.as_f32()).collect::<Vec<_>>());
}
DatabaseType::DOUBLE(_) => {
query = query.bind(e.into_iter().map(|x| x.as_f64()).collect::<Vec<_>>());
}
DatabaseType::BOOLEAN(_) => {
query = query.bind(e.into_iter().map(|x| x.as_bool()).collect::<Vec<_>>());
}
DatabaseType::BYTEA(_) => {
query = query.bind(e.into_iter().map(|x| x.as_vec()).collect::<Vec<_>>());
}
DatabaseType::UUID(_) => {
query = query.bind(e.into_iter().map(|x| x.as_uuid()).collect::<Vec<_>>());
}
DatabaseType::JSON(_) => {
query = query.bind(e.into_iter().map(|x| x.as_json()).collect::<Vec<_>>());
}
} }
} }

View file

@ -41,6 +41,8 @@ pub async fn vec_to_api(items: &[impl ToAPI]) -> Vec<serde_json::Value> {
ret ret
} }
// TODO : more compact uuids -> base representation (example: yt video ids)
/// Converts a string into a `Uuid`. /// Converts a string into a `Uuid`.
/// ///
/// This function attempts to parse a string as a UUID. If the parsing fails, /// This function attempts to parse a string as a UUID. If the parsing fails,

View file

@ -29,29 +29,32 @@ pub fn Modal<T: UIWidget + 'static, E: UIWidget + 'static, F: FnOnce(String) ->
) -> (String, PreEscaped<String>) { ) -> (String, PreEscaped<String>) {
let id = uuid::Uuid::new_v4().to_string(); let id = uuid::Uuid::new_v4().to_string();
(format!("modal-{id}"), html! { (
div id=(format!("modal-{id}")) tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full" { format!("modal-{id}"),
div class="relative p-4 w-full max-w-2xl max-h-full" { html! {
div id=(format!("modal-{id}")) tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full" {
div class="relative p-4 w-full max-w-2xl max-h-full" {
div class="relative bg-white rounded-lg shadow dark:bg-gray-700" { div class="relative bg-white rounded-lg shadow dark:bg-gray-700" {
div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600" { div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600" {
h3 class="text-xl font-semibold text-gray-900 dark:text-white" { (title) } h3 class="text-xl font-semibold text-gray-900 dark:text-white" { (title) }
button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide=(format!("modal-{id}")) { button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide=(format!("modal-{id}")) {
svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" { svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" {
path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" {}; path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" {};
}; };
span class="sr-only" { "Close modal" }; span class="sr-only" { "Close modal" };
} }
}; };
div class="p-4 md:p-5 space-y-4" { div class="p-4 md:p-5 space-y-4" {
(body) (body)
}; };
div class="flex items-center p-4 md:p-5 border-t border-gray-200 rounded-b dark:border-gray-600" { div class="flex items-center p-4 md:p-5 border-t border-gray-200 rounded-b dark:border-gray-600" {
(footer(format!("modal-{id}"))) (footer(format!("modal-{id}")))
};
}; };
}; }};
}}; },
}) )
} }

View file

@ -287,10 +287,13 @@ pub fn BottomNavigationTile<T: UIWidget + 'static>(
) -> ClassicWidget<LinkWidget> { ) -> ClassicWidget<LinkWidget> {
Classic( Classic(
"inline-flex flex-col items-center justify-center px-5 hover:bg-gray-50 dark:hover:bg-gray-800 group", "inline-flex flex-col items-center justify-center px-5 hover:bg-gray-50 dark:hover:bg-gray-800 group",
Link(reference, html! { Link(
(icon.map(|x| x.render()).unwrap_or_default()); reference,
span class="text-sm text-gray-500 dark:text-gray-400 group-hover:text-blue-600 dark:group-hover:text-blue-500" { (text) }; html! {
}), (icon.map(|x| x.render()).unwrap_or_default());
span class="text-sm text-gray-500 dark:text-gray-400 group-hover:text-blue-600 dark:group-hover:text-blue-500" { (text) };
},
),
) )
} }

View file

@ -274,21 +274,25 @@ impl GridElement {
} }
pub fn span(mut self, value: GridElementValue) -> Self { pub fn span(mut self, value: GridElementValue) -> Self {
self.1.push(format!("{}-span-{}", self.2, match value { self.1.push(format!(
GridElementValue::_1 => "1", "{}-span-{}",
GridElementValue::_2 => "2", self.2,
GridElementValue::_3 => "3", match value {
GridElementValue::_4 => "4", GridElementValue::_1 => "1",
GridElementValue::_5 => "5", GridElementValue::_2 => "2",
GridElementValue::_6 => "6", GridElementValue::_3 => "3",
GridElementValue::_7 => "7", GridElementValue::_4 => "4",
GridElementValue::_8 => "8", GridElementValue::_5 => "5",
GridElementValue::_9 => "9", GridElementValue::_6 => "6",
GridElementValue::_10 => "10", GridElementValue::_7 => "7",
GridElementValue::_11 => "11", GridElementValue::_8 => "8",
GridElementValue::_12 => "12", GridElementValue::_9 => "9",
GridElementValue::Auto => "full", GridElementValue::_10 => "10",
})); GridElementValue::_11 => "11",
GridElementValue::_12 => "12",
GridElementValue::Auto => "full",
}
));
self self
} }