diff --git a/.gitignore b/.gitignore index bcd5559..ea8c4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ /target - -.DS_Store diff --git a/BookForge.toml b/BookForge.toml index 0ac7cc8..3c2268e 100644 --- a/BookForge.toml +++ b/BookForge.toml @@ -1,6 +1,4 @@ database_path = "" -locale = "fr" -base_url = "" [listener] port = 8000 diff --git a/Cargo.lock b/Cargo.lock index ef09c66..2ec2f93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,15 +99,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "arc-swap" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d03449bb8ca2cc2ef70869af31463d1ae5ccc8fa3e334b307203fbf815207e" -dependencies = [ - "rustversion", -] - [[package]] name = "arrayvec" version = "0.7.6" @@ -296,12 +287,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "base62" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adf9755786e27479693dedd3271691a92b5e242ab139cacb9fb8e7fb5381111" - [[package]] name = "base64" version = "0.22.1" @@ -337,12 +322,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.10.0" @@ -385,7 +364,6 @@ dependencies = [ "dirs", "log", "pretty_env_logger", - "rust-i18n", "sea-orm", "sea-orm-migration", "serde", @@ -393,7 +371,7 @@ dependencies = [ "snafu", "static-serve", "tokio", - "toml 0.9.11+spec-1.1.0", + "toml", "xdg", ] @@ -420,16 +398,6 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "bstr" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "bumpalo" version = "3.19.1" @@ -615,25 +583,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-queue" version = "0.3.12" @@ -1069,30 +1018,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" -[[package]] -name = "globset" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3" -dependencies = [ - "aho-corasick", - "bstr", - "log", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "globwalk" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" -dependencies = [ - "bitflags 1.3.2", - "ignore", - "walkdir", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1399,22 +1324,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "ignore" -version = "0.4.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" -dependencies = [ - "crossbeam-deque", - "globset", - "log", - "memchr", - "regex-automata", - "same-file", - "walkdir", - "winapi-util", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -1475,15 +1384,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.14.0" @@ -1546,7 +1446,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ - "bitflags 2.10.0", + "bitflags", "libc", "redox_syscall 0.7.0", ] @@ -1651,15 +1551,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "normpath" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf23ab2b905654b4cb177e30b629937b3868311d4e1cba859f899c041046e69b" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "num-bigint" version = "0.4.6" @@ -1915,7 +1806,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" dependencies = [ - "toml_edit 0.23.10+spec-1.0.0", + "toml_edit", ] [[package]] @@ -2039,7 +1930,7 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.10.0", + "bitflags", ] [[package]] @@ -2048,7 +1939,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" dependencies = [ - "bitflags 2.10.0", + "bitflags", ] [[package]] @@ -2169,60 +2060,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rust-i18n" -version = "3.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda2551fdfaf6cc5ee283adc15e157047b92ae6535cf80f6d4962d05717dc332" -dependencies = [ - "globwalk", - "once_cell", - "regex", - "rust-i18n-macro", - "rust-i18n-support", - "smallvec", -] - -[[package]] -name = "rust-i18n-macro" -version = "3.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22baf7d7f56656d23ebe24f6bb57a5d40d2bce2a5f1c503e692b5b2fa450f965" -dependencies = [ - "glob", - "once_cell", - "proc-macro2", - "quote", - "rust-i18n-support", - "serde", - "serde_json", - "serde_yaml", - "syn 2.0.114", -] - -[[package]] -name = "rust-i18n-support" -version = "3.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940ed4f52bba4c0152056d771e563b7133ad9607d4384af016a134b58d758f19" -dependencies = [ - "arc-swap", - "base62", - "globwalk", - "itertools 0.11.0", - "lazy_static", - "normpath", - "once_cell", - "proc-macro2", - "regex", - "serde", - "serde_json", - "serde_yaml", - "siphasher", - "toml 0.8.23", - "triomphe", -] - [[package]] name = "rust_decimal" version = "1.40.0" @@ -2266,15 +2103,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "schemars" version = "0.9.0" @@ -2330,7 +2158,7 @@ dependencies = [ "chrono", "derive_more", "futures-util", - "itertools 0.14.0", + "itertools", "log", "ouroboros", "pgvector", @@ -2534,15 +2362,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "serde_spanned" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" -dependencies = [ - "serde", -] - [[package]] name = "serde_spanned" version = "1.0.4" @@ -2595,19 +2414,6 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.13.0", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha1" version = "0.10.6" @@ -2667,12 +2473,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" -[[package]] -name = "siphasher" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" - [[package]] name = "slab" version = "0.4.11" @@ -2835,7 +2635,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" dependencies = [ "atoi", "base64", - "bitflags 2.10.0", + "bitflags", "byteorder", "bytes", "chrono", @@ -2881,7 +2681,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" dependencies = [ "atoi", "base64", - "bitflags 2.10.0", + "bitflags", "byteorder", "chrono", "crc", @@ -3185,18 +2985,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" -dependencies = [ - "serde", - "serde_spanned 0.6.9", - "toml_datetime 0.6.11", - "toml_edit 0.22.27", -] - [[package]] name = "toml" version = "0.9.11+spec-1.1.0" @@ -3205,22 +2993,13 @@ checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ "indexmap 2.13.0", "serde_core", - "serde_spanned 1.0.4", - "toml_datetime 0.7.5+spec-1.1.0", + "serde_spanned", + "toml_datetime", "toml_parser", "toml_writer", "winnow", ] -[[package]] -name = "toml_datetime" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" -dependencies = [ - "serde", -] - [[package]] name = "toml_datetime" version = "0.7.5+spec-1.1.0" @@ -3230,20 +3009,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "toml_edit" -version = "0.22.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" -dependencies = [ - "indexmap 2.13.0", - "serde", - "serde_spanned 0.6.9", - "toml_datetime 0.6.11", - "toml_write", - "winnow", -] - [[package]] name = "toml_edit" version = "0.23.10+spec-1.0.0" @@ -3251,7 +3016,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269" dependencies = [ "indexmap 2.13.0", - "toml_datetime 0.7.5+spec-1.1.0", + "toml_datetime", "toml_parser", "winnow", ] @@ -3265,12 +3030,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "toml_writer" version = "1.0.6+spec-1.1.0" @@ -3352,17 +3111,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "triomphe" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd69c5aa8f924c7519d6372789a74eac5b94fb0f8fcf0d4a97eb0bfc3e785f39" -dependencies = [ - "arc-swap", - "serde", - "stable_deref_trait", -] - [[package]] name = "typenum" version = "1.19.0" @@ -3408,12 +3156,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "url" version = "2.5.8" @@ -3461,16 +3203,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 83d8600..ba47a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,4 +32,3 @@ pretty_env_logger = "0.5.0" log = "0.4.29" serde_with = "3.16.1" csv = "1.4.0" -rust-i18n = "3.1.5" diff --git a/assets/images/favicon.png b/assets/images/favicon.png deleted file mode 100644 index 5dbbdbe..0000000 Binary files a/assets/images/favicon.png and /dev/null differ diff --git a/locales/en.yml b/locales/en.yml deleted file mode 100644 index 5e258e0..0000000 --- a/locales/en.yml +++ /dev/null @@ -1,92 +0,0 @@ -_version: 1 -name: "BookForge" - -common: - download: Download - create: Create - edit: Edit - delete: Delete - next: Next - previous: Previous - actions: Actions - search: Search - reset: Reset - show: Show - no_result: No results - close: Close - confirmation: Confirmation - are_you_sure: Are you sure? - -nav: - toggle: Toggle navigation - books: Books - users: Users - -theme: - light: Light - dark: Dark - -user: - attributes: - name: Name - owner_books: Owned books - borrowed_books: Borrowed books - - index: - title_tag: Users list | BookForge - title: All Users - button: Add a user - - edit: - title_tag: Edit user | BookForge - title: Edit - button: Edit user - - new: - title_tag: New user | BookForge - title: New user - button: Create user - -book: - attributes: - title: Title - authors: Author(s) - description: Description - owner: Owner - current_holder: Current holder - comment: Comment - - index: - title_tag: Books list | BookForge - title: All Books - - new: - title_tag: New book | BookForge - title: New Book - button: Create book - button_short: Add book - - edit: - title_tag: Edit book | BookForge - title: Edit book - button: Edit book - - show: - title_tag: Details | BookForge - book_details: Book details - user_details: User details - more_informations: More information - -footer: - message: Made with love & Fuck fascists! - -error: - error_404: - title_tag: Error 404 | BookForge - title: Oops! This page does not exist - subtitle: 404 NOT FOUND - button: Back to home - - generic: - title_tag: Error | BookForge - title: Oops! An error occurred diff --git a/locales/fr.yml b/locales/fr.yml deleted file mode 100644 index 22b0675..0000000 --- a/locales/fr.yml +++ /dev/null @@ -1,77 +0,0 @@ -_version: 1 -name: "BookForge" -common: - download: Télécharger - create: Créer - edit: Modifier - delete: Supprimer - next: Suivant - previous: Précédent - actions: Actions - search: Filtrer - reset: Réini. - show: Voir - no_result: Aucun résultat - close: Fermer - confirmation: Confirmation - are_you_sure: Êtes-vous sûr ? -nav: - toggle: Basculer la navigation - books: Livres - users: Utilisateurs -theme: - light: Light - dark: Dark -user: - attributes: - name: Nom - owner_books: Livres possédés - borrowed_books: Livres empruntés - index: - title_tag: Liste des utilisateur.ice.s | BookForge - title: Tous les utilisateur.ice.s - button: Ajouter un.e utilisateur.ice - edit: - title_tag: Modifier l'utilisateur.ice | BookForge - title: Modifier - button: Modifier l'utilisateur.ice - new: - title_tag: Nouvel utilisateur.ice | BookForge - title: Nouvel utilisateur.ice - button: Créer l'utilisateur.ice -book: - attributes: - title: Titre - authors: Auteur.ice.(s) - description: Description - owner: Propriétaire - current_holder: Détenteur.ice actuel.le - comment: Commentaire - index: - title_tag: Liste des livres | BookForge - title: Tous les livres - new: - title_tag: Nouveau livre | BookForge - title: Nouveau livre - button: Créer le livre - button_short: Ajouter un livre - edit: - title_tag: Modifier le livre | BookForge - title: Modifier le livre - button: Modifier le livre - show: - title_tag: Details | BookForge - book_details: Détails du livre - user_details: Détails de l'utilisateur.ice - more_informations: Plus d'informations -footer: - message: Fait avec amour & Nique les fachos ! -error: - error_404: - title_tag: Erreur 404 | BookForge - title: Oups ! Cette page n'existe pas - subtitle: 404 NOT FOUND - button: Retour à l'accueil - generic: - title_tag: Erreur | BookForge - title: Oups ! Une erreur s'est produite diff --git a/src/lib.rs b/src/lib.rs index 6c3de23..c024ef5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,10 @@ use askama::Template; use askama_web::WebTemplate; use axum::{ Router, - extract::State, routing::{get, post}, }; use static_serve::embed_assets; -use crate::routes::router::Router as InternalRouter; use crate::state::AppState; mod migrations; @@ -15,13 +13,7 @@ mod models; mod routes; pub mod state; -#[macro_use] -extern crate rust_i18n; - -i18n!("locales", fallback = "en", minify_key = true); - pub fn build_app(state: AppState) -> Router { - rust_i18n::set_locale(&state.config.locale); embed_assets!("assets", compress = true); Router::new() @@ -46,14 +38,8 @@ pub fn build_app(state: AppState) -> Router { #[derive(Template, WebTemplate)] #[template(path = "404.html")] -struct NotFoundTemplate { - pub router: InternalRouter, -} +struct NotFoundTemplate {} -pub async fn error_handler(State(state): State) -> impl axum::response::IntoResponse { - NotFoundTemplate { - router: InternalRouter { - base_path: state.config.base_path, - }, - } +pub async fn error_handler() -> impl axum::response::IntoResponse { + NotFoundTemplate {} } diff --git a/src/routes/book.rs b/src/routes/book.rs index 8d4fa03..fe9d75d 100644 --- a/src/routes/book.rs +++ b/src/routes/book.rs @@ -13,7 +13,7 @@ use serde::Deserialize; use serde_with::{NoneAsEmptyString, serde_as}; use snafu::prelude::*; -use crate::{models::book::Model as BookModel, routes::router::Router, state::error::CSVSnafu}; +use crate::{models::book::Model as BookModel, state::error::CSVSnafu}; use crate::{models::user::Model as UserModel, state::error::IOSnafu}; use crate::{ @@ -55,7 +55,6 @@ struct BookIndexTemplate { current_page: u64, total_page: u64, base_query: String, - router: Router, } pub async fn index( @@ -74,7 +73,7 @@ pub async fn index( .context(UserSnafu)?; // Get all Book filtered with query - let books_paginate = BookOperator::new(state.clone()) + let books_paginate = BookOperator::new(state) .all_paginate(page, Some(query.clone())) .await .context(BookSnafu)?; @@ -128,9 +127,6 @@ pub async fn index( current_page: books_paginate.current_page, total_page: books_paginate.total_page, base_query, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -140,7 +136,6 @@ struct ShowBookTemplate { book: BookModel, owner: UserModel, current_holder: Option, - router: Router, } pub async fn show( @@ -173,9 +168,6 @@ pub async fn show( book, owner, current_holder, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -208,23 +200,14 @@ pub async fn create( #[template(path = "books/new.html")] struct NewBookTemplate { users: Vec, - router: Router, } pub async fn new( State(state): State, ) -> Result { - let users = UserOperator::new(state.clone()) - .all() - .await - .context(UserSnafu)?; + let users = UserOperator::new(state).all().await.context(UserSnafu)?; - Ok(NewBookTemplate { - users, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(NewBookTemplate { users }) } #[derive(Template, WebTemplate)] @@ -232,7 +215,6 @@ pub async fn new( struct EditBookTemplate { users: Vec, book: BookModel, - router: Router, } pub async fn edit( @@ -243,18 +225,12 @@ pub async fn edit( .all() .await .context(UserSnafu)?; - let book = BookOperator::new(state.clone()) + let book = BookOperator::new(state) .find_by_id(id) .await .context(BookSnafu)?; - Ok(EditBookTemplate { - users, - book, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(EditBookTemplate { users, book }) } pub async fn update( @@ -297,13 +273,13 @@ pub async fn download_csv( let mut wtr = Writer::from_writer(vec![]); wtr.write_record(&[ - "ID", + "id", "Title", "Author(s)", - "Description", - "Owner", - "Current Holder", - "Comment", + "description", + "owner_id", + "current_holder_id", + "comment", ]) .context(CSVSnafu)?; diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 2bbba56..011ff79 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,3 +1,2 @@ pub mod book; -pub mod router; pub mod user; diff --git a/src/routes/router.rs b/src/routes/router.rs deleted file mode 100644 index 52bcd0b..0000000 --- a/src/routes/router.rs +++ /dev/null @@ -1,54 +0,0 @@ -#[derive(Clone)] -pub struct Router { - pub base_path: String, -} - -impl Router { - pub fn assets(&self, path: &str) -> String { - if self.base_path.is_empty() || self.base_path == "/" { - format!("/{}", path) - } else { - format!("{}/{}", self.base_path.trim_end_matches('/'), path) - } - } - - pub fn root_path(&self) -> String { - format!("{}/", &self.base_path) - } - - // BOOKS ROUTES - - pub fn new_book_path(&self) -> String { - format!("{}/books/new", &self.base_path) - } - - pub fn create_book_path(&self) -> String { - format!("{}/books", &self.base_path) - } - - pub fn update_book_path(&self, id: &i32) -> String { - format!("{}/books/{}", &self.base_path, id) - } - - pub fn download_csv_book_path(&self) -> String { - format!("{}/books/download_csv", &self.base_path) - } - - // USERS - - pub fn index_user_path(&self) -> String { - format!("{}/users", &self.base_path) - } - - pub fn new_user_path(&self) -> String { - format!("{}/users/new", &self.base_path) - } - - pub fn create_user_path(&self) -> String { - format!("{}/users", &self.base_path) - } - - pub fn update_user_path(&self, id: &i32) -> String { - format!("{}/users/{}", &self.base_path, id) - } -} diff --git a/src/routes/user.rs b/src/routes/user.rs index 04eed56..3c81570 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -16,7 +16,6 @@ use crate::{ book::BookOperator, user::{self, UserOperator}, }, - routes::router::Router, state::{ AppState, error::{AppStateError, BookSnafu, UserSnafu}, @@ -26,9 +25,8 @@ use crate::{ #[derive(Template, WebTemplate)] #[template(path = "users/index.html")] struct UsersIndexTemplate { - users_with_books_number: Vec, + user_with_books_number: Vec, query: IndexQuery, - router: Router, } pub struct UserWithBookNumber { @@ -86,11 +84,8 @@ pub async fn index( } Ok(UsersIndexTemplate { - users_with_books_number: result, + user_with_books_number: result, query, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -140,36 +135,24 @@ pub async fn delete( #[template(path = "users/edit.html")] struct EditTemplate { user: user::Model, - router: Router, } pub async fn edit( State(state): State, Path(id): Path, ) -> Result { - let user = UserOperator::new(state.clone()) + let user = UserOperator::new(state) .find_by_id(id) .await .context(UserSnafu)?; - Ok(EditTemplate { - user, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(EditTemplate { user }) } #[derive(Template, WebTemplate)] #[template(path = "users/new.html")] -struct NewTemplate { - router: Router, -} +struct NewTemplate {} -pub async fn new(State(state): State) -> impl axum::response::IntoResponse { - NewTemplate { - router: Router { - base_path: state.config.base_path, - }, - } +pub async fn new() -> impl axum::response::IntoResponse { + NewTemplate {} } diff --git a/src/state/config.rs b/src/state/config.rs index f137f8a..4f81560 100644 --- a/src/state/config.rs +++ b/src/state/config.rs @@ -32,8 +32,6 @@ pub enum ConfigError { pub struct AppConfig { #[serde(default = "AppConfig::default_sqlite_path")] pub database_path: Utf8PathBuf, - pub locale: String, - pub base_path: String, pub listener: Listener, } @@ -41,8 +39,6 @@ impl Default for AppConfig { fn default() -> Self { AppConfig { database_path: Self::default_sqlite_path(), - base_path: Self::default_base_path(), - locale: Self::default_locale(), listener: Listener::default(), } } @@ -96,14 +92,6 @@ impl AppConfig { Self::config_path().join("BookForge.toml") } - fn default_locale() -> String { - "en".to_string() - } - - fn default_base_path() -> String { - "".to_string() - } - pub fn default_sqlite_path() -> Utf8PathBuf { Self::config_path().join("db.sqlite") } diff --git a/src/state/error.rs b/src/state/error.rs index 6a031b6..59d8232 100644 --- a/src/state/error.rs +++ b/src/state/error.rs @@ -6,7 +6,6 @@ use snafu::prelude::*; use crate::{ models::{book::BookError, user::UserError}, - routes::router::Router, state::config::ConfigError, }; @@ -48,7 +47,6 @@ pub enum AppStateError { #[template(path = "error.html")] struct ErrorTemplate { state: AppStateErrorContext, - router: Router, } struct AppStateErrorContext { @@ -68,9 +66,6 @@ impl IntoResponse for AppStateError { let error_context = AppStateErrorContext::from(self); ErrorTemplate { state: error_context, - router: Router { - base_path: "".to_string(), - }, } .into_response() } diff --git a/templates/404.html b/templates/404.html index 6f35ef6..854fcc8 100644 --- a/templates/404.html +++ b/templates/404.html @@ -1,13 +1,8 @@ {% extends "base.html" %} - -{% block title %} - {{ t!("error.error_404.title_tag") }} -{% endblock %} - {% block main %}
-

{{ t!("error.error_404.title") }}

-

{{ t!("error.error_404.subtitle") }}

- {{ t!("error.error_404.button") }} +

Oops ! This page does not exist

+

404 NOT FOUND

+ Back to home
{% endblock %} diff --git a/templates/base.html b/templates/base.html index bc0ed7e..58b2ef0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,14 +2,13 @@ - {% block title %}{{ t!("name") }}{% endblock %} + {% block title %}Book Forge{% endblock %} - - - + + - - + + {% block extra_head %}{% endblock extra_head %} @@ -26,7 +25,7 @@ {% endblock %} - - + + diff --git a/templates/books/edit.html b/templates/books/edit.html index f80be6a..6964b99 100644 --- a/templates/books/edit.html +++ b/templates/books/edit.html @@ -2,27 +2,23 @@ {% import "components/typography.html" as typography %} {% import "components/cards.html" as cards %} -{% block title %} - {{ t!("book.edit.title_tag") }} -{% endblock %} - {% block main %} - {{ typography::heading(t!("book.edit.title")) }} + {{ typography::heading("Editer") }} {% call cards::card() %} -
+
- +
- +
- + {% match book.current_holder_id %} @@ -56,7 +52,7 @@
- + {% match book.description %} {% when Some with (description) %} @@ -66,7 +62,7 @@
- + {% match book.comment %} {% when Some with (comment) %} @@ -76,7 +72,7 @@
- +
{% endcall %} diff --git a/templates/books/new.html b/templates/books/new.html index 30deb91..ddd66ce 100644 --- a/templates/books/new.html +++ b/templates/books/new.html @@ -3,32 +3,28 @@ {% import "components/cards.html" as cards %} {% import "components/inputs.html" as form_helpers %} -{% block title %} - {{ t!("book.new.title_tag") }} -{% endblock %} - {% block main %} - {{ typography::heading(t!("book.new.title")) }} + {{ typography::heading("New book") }} {% call cards::card() %} -
- {{ form_helpers::input("title", t!("book.attributes.title"), is_required = true, placeholder = "Ex: La Petite Dernière") }} - {{ form_helpers::input("authors", t!("book.attributes.authors"), is_required = true, placeholder = "Ex: Fatima Daas") }} + + {{ form_helpers::input("title", "Name", is_required = true, placeholder = "Ex: La Petite Dernière") }} + {{ form_helpers::input("authors", "Author(s)", is_required = true, placeholder = "Ex: Fatima Daas") }} - {% call(option) form_helpers::select("owner_id", t!("book.attributes.owner"), users, is_required = true) %} + {% call(option) form_helpers::select("owner_id", "Owner", users, is_required = true) %} {% endcall %} - {% call(option) form_helpers::select("current_holder_id", t!("book.attributes.current_holder"), users, is_required = false) %} + {% call(option) form_helpers::select("current_holder_id", "Current Holder", users, is_required = false) %} {% endcall %} + + {{ form_helpers::textarea("description", "Description", rows = 5, is_required = false, placeholder = "Ex: Je m’appelle Fatima Daas. Je suis la mazoziya, la petite dernière. Celle à laquelle on ne s’est pas préparé. Française d’origine algérienne.") }} - {{ form_helpers::textarea("description", t!("book.attributes.description"), rows = 5, is_required = false, placeholder = "Ex: Je m’appelle Fatima Daas. Je suis la mazoziya, la petite dernière. Celle à laquelle on ne s’est pas préparé. Française d’origine algérienne.") }} - - {{ form_helpers::textarea("comment", t!("book.attributes.comment"), rows = 3, is_required = false, placeholder = "Ex: I recommend it, it's great!") }} + {{ form_helpers::textarea("comment", "Comment", rows = 3, is_required = false, placeholder = "Ex: I recommend it, it's great!") }}
- +
{% endcall %} diff --git a/templates/books/show.html b/templates/books/show.html index 61042f2..aec5bda 100644 --- a/templates/books/show.html +++ b/templates/books/show.html @@ -4,43 +4,39 @@ {% import "components/fields.html" as fields %} {% import "components/cards.html" as cards %} -{% block title %} - {{ t!("book.show.title_tag") }} -{% endblock %} - {% block main %} {{ typography::book_heading(book.title, book, show = false) }} {% call cards::card() %} -
-
{{ t!("book.show.book_details") }}
- {{ fields::field(t!("book.attributes.title"), book.title) }} - {{ fields::field(t!("book.attributes.authors"), book.authors) }} +
+
Book details
+ {{ fields::field("Name", book.title) }} + {{ fields::field("Authors", book.authors) }} {% match book.description %} {% when Some with (description) %} - {{ fields::field(t!("book.attributes.description"), description) }} + {{ fields::field("Description", description) }} {% when None %} - {{ fields::field(t!("book.attributes.description"), "-") }} + {{ fields::field("Description", "-") }} {% endmatch %} -
{{ t!("book.show.user_details") }}
- {{ fields::field(t!("book.attributes.owner"), owner.name) }} +
User Details
+ {{ fields::field("Owner", owner.name) }} {% match current_holder %} {% when Some with (current_holder) %} - {{ fields::field(t!("book.attributes.current_holder"), current_holder.name) }} + {{ fields::field("Current Holder", current_holder.name) }} {% when None %} - {{ fields::field(t!("book.attributes.current_holder"), "-") }} + {{ fields::field("Current Holder", "-") }} {% endmatch %} -
{{ t!("book.show.more_informations") }}
+
More Informations
{% match book.comment %} {% when Some with (comment) %} - {{ fields::field(t!("book.attributes.comment"), comment) }} + {{ fields::field("Comment", comment) }} {% when None %} - {{ fields::field(t!("book.attributes.comment"), "-") }} + {{ fields::field("Comment", "-") }} {% endmatch %}
{% endcall %} diff --git a/templates/components/dropdown.html b/templates/components/dropdown.html index 7b0e55d..37dc290 100644 --- a/templates/components/dropdown.html +++ b/templates/components/dropdown.html @@ -14,15 +14,15 @@ {% macro crud_dropdown_button(book, label, sub_path, show = true) %} @@ -32,16 +32,16 @@ {% endmacro %} diff --git a/templates/error.html b/templates/error.html index 09e125b..e84c368 100644 --- a/templates/error.html +++ b/templates/error.html @@ -1,17 +1,12 @@ {% extends "base.html" %} - -{% block title %} - {{ t!("error.generic.title_tag") }} -{% endblock %} - {% block main %}
-

{{ t!("error.generic.title") }}

+

Oops ! An Error occured

{% for error in state.errors %}

{{ error }}

{% endfor %}
- {{ t!("error.error_404.button") }} + Back to home
{% endblock %} diff --git a/templates/index.html b/templates/index.html index 2701d7b..17a7ddb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,14 +3,10 @@ {% import "components/dropdown.html" as dropdown %} {% import "components/cards.html" as cards %} -{% block title %} - {{ t!("book.index.title_tag") }} -{% endblock %} - {% block main %} - {% call typography::heading(t!("book.index.title")) %} - - {{ t!("common.download") }} (csv) + {% call typography::heading("All books") %} + + Download (csv) {% endcall %} @@ -18,7 +14,7 @@
- + {% match query.title %} {% when Some with (value) %} @@ -28,7 +24,7 @@
- + {% match query.authors %} {% when Some with (value) %} @@ -39,7 +35,7 @@
- + @@ -83,84 +79,73 @@
- +
{% endcall %} {% call cards::card() %} - {% if books_with_user.is_empty() %} -
-

{{ t!("common.no_result") }}

- - - {{ t!("book.new.button_short") }} - -
- {% else %} - - - - - - - - - - - - - {% for book_user in books_with_user %} - - - - - - - - - {% endfor %} - -
#{{ t!("book.attributes.title") }}{{ t!("book.attributes.authors") }}{{ t!("book.attributes.owner") }}{{ t!("book.attributes.current_holder") }}{{ t!("common.actions") }}
{{ book_user.book.id }}{{ book_user.book.title }}{{ book_user.book.authors }}{{ book_user.owner.name }} - {% match book_user.current_holder %} - {% when Some with (current_holder) %} - {{ current_holder.name }} - {% when None %} - - - {% endmatch %} - - {{ dropdown::crud_dropdown_button(book_user.book, t!("common.actions"), "books") }} -
- - {% if total_page > 1 %} -
- -
- {% endif %} + + + + + + + + + + + + + {% for book_user in books_with_user %} + + + + + + + + + {% endfor %} + +
#NameAuthor(s)OwnerCurrent HolderActions
{{ book_user.book.id }}{{ book_user.book.title }}{{ book_user.book.authors }}{{ book_user.owner.name }} + {% match book_user.current_holder %} + {% when Some with (current_holder) %} + {{ current_holder.name }} + {% when None %} + - + {% endmatch %} + + {{ dropdown::crud_dropdown_button(book_user.book, "Actions", "books") }} +
+ {% if total_page > 1 %} +
+ +
{% endif %} {% endcall %} {% endblock %} diff --git a/templates/layout/footer.html b/templates/layout/footer.html index 3f29c8b..3ddc19e 100644 --- a/templates/layout/footer.html +++ b/templates/layout/footer.html @@ -1,5 +1,5 @@
-

{{ t!("footer.message") }}

+

Made with Love & Fuck a Fascist !

-
+
\ No newline at end of file diff --git a/templates/layout/header.html b/templates/layout/header.html index 114aa1f..6471bb9 100644 --- a/templates/layout/header.html +++ b/templates/layout/header.html @@ -1,31 +1,31 @@