This commit is contained in:
parent
696b34f2f1
commit
c10105ad75
6 changed files with 146 additions and 47 deletions
|
@ -52,12 +52,15 @@ pub trait AssetRoutes {
|
|||
|
||||
impl AssetRoutes for rocket::Rocket<Build> {
|
||||
fn mount_assets(self) -> Self {
|
||||
self.mount("/", routes![
|
||||
self.mount(
|
||||
"/",
|
||||
routes![
|
||||
crate::asset::htmx_script_route,
|
||||
crate::asset::flowbite_css,
|
||||
crate::asset::flowbite_js,
|
||||
crate::asset::material_css,
|
||||
crate::asset::material_font
|
||||
])
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
84
src/lib.rs
84
src/lib.rs
|
@ -81,6 +81,13 @@ fn transpose<T: Clone>(matrix: Vec<Vec<T>>) -> Vec<Vec<T>> {
|
|||
pub enum DatabaseType {
|
||||
TEXT(String),
|
||||
INTEGER(i32),
|
||||
BIGINT(i64),
|
||||
REAL(f32),
|
||||
DOUBLE(f64),
|
||||
BOOLEAN(bool),
|
||||
BYTEA(Vec<u8>),
|
||||
UUID(uuid::Uuid),
|
||||
JSON(serde_json::Value),
|
||||
}
|
||||
|
||||
impl DatabaseType {
|
||||
|
@ -88,6 +95,62 @@ impl DatabaseType {
|
|||
match self {
|
||||
Self::TEXT(_) => "TEXT",
|
||||
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(_) => {
|
||||
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<_>>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ pub async fn vec_to_api(items: &[impl ToAPI]) -> Vec<serde_json::Value> {
|
|||
ret
|
||||
}
|
||||
|
||||
// TODO : more compact uuids -> base representation (example: yt video ids)
|
||||
|
||||
/// Converts a string into a `Uuid`.
|
||||
///
|
||||
/// This function attempts to parse a string as a UUID. If the parsing fails,
|
||||
|
|
|
@ -29,7 +29,9 @@ pub fn Modal<T: UIWidget + 'static, E: UIWidget + 'static, F: FnOnce(String) ->
|
|||
) -> (String, PreEscaped<String>) {
|
||||
let id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
(format!("modal-{id}"), html! {
|
||||
(
|
||||
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" {
|
||||
div class="relative p-4 w-full max-w-2xl max-h-full" {
|
||||
|
||||
|
@ -53,5 +55,6 @@ pub fn Modal<T: UIWidget + 'static, E: UIWidget + 'static, F: FnOnce(String) ->
|
|||
};
|
||||
};
|
||||
}};
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -287,10 +287,13 @@ pub fn BottomNavigationTile<T: UIWidget + 'static>(
|
|||
) -> ClassicWidget<LinkWidget> {
|
||||
Classic(
|
||||
"inline-flex flex-col items-center justify-center px-5 hover:bg-gray-50 dark:hover:bg-gray-800 group",
|
||||
Link(reference, html! {
|
||||
Link(
|
||||
reference,
|
||||
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) };
|
||||
}),
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,10 @@ impl GridElement {
|
|||
}
|
||||
|
||||
pub fn span(mut self, value: GridElementValue) -> Self {
|
||||
self.1.push(format!("{}-span-{}", self.2, match value {
|
||||
self.1.push(format!(
|
||||
"{}-span-{}",
|
||||
self.2,
|
||||
match value {
|
||||
GridElementValue::_1 => "1",
|
||||
GridElementValue::_2 => "2",
|
||||
GridElementValue::_3 => "3",
|
||||
|
@ -288,7 +291,8 @@ impl GridElement {
|
|||
GridElementValue::_11 => "11",
|
||||
GridElementValue::_12 => "12",
|
||||
GridElementValue::Auto => "full",
|
||||
}));
|
||||
}
|
||||
));
|
||||
self
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue