diff --git a/Cargo.lock b/Cargo.lock index 6c85149..eadcf9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,6 +69,7 @@ dependencies = [ "askama", "askama_axum", "axum", + "serde", "tokio", "tower-http", ] diff --git a/README.md b/README.md index 11854be..c0714d4 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,40 @@ Logiciel de Pharmacie libre et open-source. ### Pré-requis +#### Tauri CLI + La CLI Tauri est nécessaire au lancement du client `desktop`. Elle peut être installée via Cargo : ```bash cargo install tauri-cli --version "^2.0.0-beta" ``` -### Exécution de l'application cliente desktop +#### Tailwindcss CLI + +Le CLI Tailwindcss est nécessaire pour la génération du fichier `crates/app/assets/css/style.css`. + +La documentation d'installation est disponible sur le site officiel de Tailwindcss : https://tailwindcss.com/blog/standalone-cli + +La version actuellement utilisée est la [`v3.4.7`](https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.4.7) + +#### SESAM-Vitale + +La crate `sesam-vitale` nécessite la présence des librairies dynamiques fournies par le package FSV et la CryptolibCPS. Les instructions d'installation sont disponibles dans le [README](crates/sesam-vitale/README.md) de la crate `sesam-vitale`. + +### Lancement + +Le logiciel dans sa globalité peut être lancé via la commande suivante : ```bash cargo tauri dev ``` -### Exécution du serveur web `app` en mode endpoint +/!\ Attention, le lancement du client `desktop` ne génère pas le fichier `crates/app/assets/css/style.css` automatiquement pour le moment. En cas de modification des interfaces web, il est donc nécessaire de procéder à sa génération comme indiqué dans le [README](crates/app/README.md) de la crate `app`. -```bash -cargo run --bin app -``` +Si vous souhaitez lancer les composants séparément, les indications de lancement sont disponibles dans les README des différents crates. + +- [app](crates/app/README.md) +- [sesam-vitale](crates/sesam-vitale/README.md) ## Build diff --git a/crates/app/.gitignore b/crates/app/.gitignore index ea8c4bf..60f12af 100644 --- a/crates/app/.gitignore +++ b/crates/app/.gitignore @@ -1 +1,4 @@ /target + +# Tailwind CSS CLI +tailwindcss \ No newline at end of file diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml index 786b7b6..23c7568 100644 --- a/crates/app/Cargo.toml +++ b/crates/app/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" askama = "0.12.1" askama_axum = "0.4.0" axum = "0.7.5" +serde = { version = "1.0.204", features = ["derive"] } tokio = { version = "1.39.1", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.5.2", features = ["fs"] } diff --git a/crates/app/README.md b/crates/app/README.md new file mode 100644 index 0000000..e728e9a --- /dev/null +++ b/crates/app/README.md @@ -0,0 +1,15 @@ +## Pré-requis + +- Récupérer le binaire TailwindCSS : https://tailwindcss.com/blog/standalone-cli + +## Exécution + +- Lancer tailwindcss en mode watch dans un terminal : +```bash +./tailwindcss -i css/input.css -o assets/css/style.css --watch +``` + +- Lancer le serveur web dans un autre terminal : +```bash +cargo run --bin app +``` diff --git a/crates/app/assets/css/style.css b/crates/app/assets/css/style.css new file mode 100644 index 0000000..c7c4c04 --- /dev/null +++ b/crates/app/assets/css/style.css @@ -0,0 +1,927 @@ +/* +! tailwindcss v3.4.7 | MIT License | https://tailwindcss.com +*/ + +/* +1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4) +2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116) +*/ + +*, +::before, +::after { + box-sizing: border-box; + /* 1 */ + border-width: 0; + /* 2 */ + border-style: solid; + /* 2 */ + border-color: #e5e7eb; + /* 2 */ +} + +::before, +::after { + --tw-content: ''; +} + +/* +1. Use a consistent sensible line-height in all browsers. +2. Prevent adjustments of font size after orientation changes in iOS. +3. Use a more readable tab size. +4. Use the user's configured `sans` font-family by default. +5. Use the user's configured `sans` font-feature-settings by default. +6. Use the user's configured `sans` font-variation-settings by default. +7. Disable tap highlights on iOS +*/ + +html, +:host { + line-height: 1.5; + /* 1 */ + -webkit-text-size-adjust: 100%; + /* 2 */ + -moz-tab-size: 4; + /* 3 */ + -o-tab-size: 4; + tab-size: 4; + /* 3 */ + font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + /* 4 */ + font-feature-settings: normal; + /* 5 */ + font-variation-settings: normal; + /* 6 */ + -webkit-tap-highlight-color: transparent; + /* 7 */ +} + +/* +1. Remove the margin in all browsers. +2. Inherit line-height from `html` so users can set them as a class directly on the `html` element. +*/ + +body { + margin: 0; + /* 1 */ + line-height: inherit; + /* 2 */ +} + +/* +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +3. Ensure horizontal rules are visible by default. +*/ + +hr { + height: 0; + /* 1 */ + color: inherit; + /* 2 */ + border-top-width: 1px; + /* 3 */ +} + +/* +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr:where([title]) { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; +} + +/* +Remove the default font size and weight for headings. +*/ + +h1, +h2, +h3, +h4, +h5, +h6 { + font-size: inherit; + font-weight: inherit; +} + +/* +Reset links to optimize for opt-in styling instead of opt-out. +*/ + +a { + color: inherit; + text-decoration: inherit; +} + +/* +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/* +1. Use the user's configured `mono` font-family by default. +2. Use the user's configured `mono` font-feature-settings by default. +3. Use the user's configured `mono` font-variation-settings by default. +4. Correct the odd `em` font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + /* 1 */ + font-feature-settings: normal; + /* 2 */ + font-variation-settings: normal; + /* 3 */ + font-size: 1em; + /* 4 */ +} + +/* +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/* +Prevent `sub` and `sup` elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +3. Remove gaps between table borders by default. +*/ + +table { + text-indent: 0; + /* 1 */ + border-color: inherit; + /* 2 */ + border-collapse: collapse; + /* 3 */ +} + +/* +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +3. Remove default padding in all browsers. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; + /* 1 */ + font-feature-settings: inherit; + /* 1 */ + font-variation-settings: inherit; + /* 1 */ + font-size: 100%; + /* 1 */ + font-weight: inherit; + /* 1 */ + line-height: inherit; + /* 1 */ + letter-spacing: inherit; + /* 1 */ + color: inherit; + /* 1 */ + margin: 0; + /* 2 */ + padding: 0; + /* 3 */ +} + +/* +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Remove default button styles. +*/ + +button, +input:where([type='button']), +input:where([type='reset']), +input:where([type='submit']) { + -webkit-appearance: button; + /* 1 */ + background-color: transparent; + /* 2 */ + background-image: none; + /* 2 */ +} + +/* +Use the modern Firefox focus style for all focusable elements. +*/ + +:-moz-focusring { + outline: auto; +} + +/* +Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737) +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/* +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/* +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/* +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; + /* 1 */ + outline-offset: -2px; + /* 2 */ +} + +/* +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to `inherit` in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; + /* 1 */ + font: inherit; + /* 2 */ +} + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} + +/* +Removes the default spacing and border for appropriate elements. +*/ + +blockquote, +dl, +dd, +h1, +h2, +h3, +h4, +h5, +h6, +hr, +figure, +p, +pre { + margin: 0; +} + +fieldset { + margin: 0; + padding: 0; +} + +legend { + padding: 0; +} + +ol, +ul, +menu { + list-style: none; + margin: 0; + padding: 0; +} + +/* +Reset default styling for dialogs. +*/ + +dialog { + padding: 0; +} + +/* +Prevent resizing textareas horizontally by default. +*/ + +textarea { + resize: vertical; +} + +/* +1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300) +2. Set the default placeholder color to the user's configured gray 400 color. +*/ + +input::-moz-placeholder, textarea::-moz-placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +input::placeholder, +textarea::placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +/* +Set the default cursor for buttons. +*/ + +button, +[role="button"] { + cursor: pointer; +} + +/* +Make sure disabled buttons don't get the pointer cursor. +*/ + +:disabled { + cursor: default; +} + +/* +1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14) +2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210) + This can trigger a poorly considered lint error in some tools but is included by design. +*/ + +img, +svg, +video, +canvas, +audio, +iframe, +embed, +object { + display: block; + /* 1 */ + vertical-align: middle; + /* 2 */ +} + +/* +Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14) +*/ + +img, +video { + max-width: 100%; + height: auto; +} + +/* Make elements with the HTML hidden attribute stay hidden by default */ + +[hidden] { + display: none; +} + +*, ::before, ::after { + --tw-border-spacing-x: 0; + --tw-border-spacing-y: 0; + --tw-translate-x: 0; + --tw-translate-y: 0; + --tw-rotate: 0; + --tw-skew-x: 0; + --tw-skew-y: 0; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-pan-x: ; + --tw-pan-y: ; + --tw-pinch-zoom: ; + --tw-scroll-snap-strictness: proximity; + --tw-gradient-from-position: ; + --tw-gradient-via-position: ; + --tw-gradient-to-position: ; + --tw-ordinal: ; + --tw-slashed-zero: ; + --tw-numeric-figure: ; + --tw-numeric-spacing: ; + --tw-numeric-fraction: ; + --tw-ring-inset: ; + --tw-ring-offset-width: 0px; + --tw-ring-offset-color: #fff; + --tw-ring-color: rgb(59 130 246 / 0.5); + --tw-ring-offset-shadow: 0 0 #0000; + --tw-ring-shadow: 0 0 #0000; + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + --tw-blur: ; + --tw-brightness: ; + --tw-contrast: ; + --tw-grayscale: ; + --tw-hue-rotate: ; + --tw-invert: ; + --tw-saturate: ; + --tw-sepia: ; + --tw-drop-shadow: ; + --tw-backdrop-blur: ; + --tw-backdrop-brightness: ; + --tw-backdrop-contrast: ; + --tw-backdrop-grayscale: ; + --tw-backdrop-hue-rotate: ; + --tw-backdrop-invert: ; + --tw-backdrop-opacity: ; + --tw-backdrop-saturate: ; + --tw-backdrop-sepia: ; + --tw-contain-size: ; + --tw-contain-layout: ; + --tw-contain-paint: ; + --tw-contain-style: ; +} + +::backdrop { + --tw-border-spacing-x: 0; + --tw-border-spacing-y: 0; + --tw-translate-x: 0; + --tw-translate-y: 0; + --tw-rotate: 0; + --tw-skew-x: 0; + --tw-skew-y: 0; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-pan-x: ; + --tw-pan-y: ; + --tw-pinch-zoom: ; + --tw-scroll-snap-strictness: proximity; + --tw-gradient-from-position: ; + --tw-gradient-via-position: ; + --tw-gradient-to-position: ; + --tw-ordinal: ; + --tw-slashed-zero: ; + --tw-numeric-figure: ; + --tw-numeric-spacing: ; + --tw-numeric-fraction: ; + --tw-ring-inset: ; + --tw-ring-offset-width: 0px; + --tw-ring-offset-color: #fff; + --tw-ring-color: rgb(59 130 246 / 0.5); + --tw-ring-offset-shadow: 0 0 #0000; + --tw-ring-shadow: 0 0 #0000; + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + --tw-blur: ; + --tw-brightness: ; + --tw-contrast: ; + --tw-grayscale: ; + --tw-hue-rotate: ; + --tw-invert: ; + --tw-saturate: ; + --tw-sepia: ; + --tw-drop-shadow: ; + --tw-backdrop-blur: ; + --tw-backdrop-brightness: ; + --tw-backdrop-contrast: ; + --tw-backdrop-grayscale: ; + --tw-backdrop-hue-rotate: ; + --tw-backdrop-invert: ; + --tw-backdrop-opacity: ; + --tw-backdrop-saturate: ; + --tw-backdrop-sepia: ; + --tw-contain-size: ; + --tw-contain-layout: ; + --tw-contain-paint: ; + --tw-contain-style: ; +} + +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border-width: 0; +} + +.absolute { + position: absolute; +} + +.relative { + position: relative; +} + +.-inset-0\.5 { + inset: -0.125rem; +} + +.-inset-1\.5 { + inset: -0.375rem; +} + +.right-0 { + right: 0px; +} + +.z-10 { + z-index: 10; +} + +.mx-auto { + margin-left: auto; + margin-right: auto; +} + +.-mr-2 { + margin-right: -0.5rem; +} + +.ml-3 { + margin-left: 0.75rem; +} + +.ml-auto { + margin-left: auto; +} + +.mt-2 { + margin-top: 0.5rem; +} + +.mt-3 { + margin-top: 0.75rem; +} + +.block { + display: block; +} + +.flex { + display: flex; +} + +.inline-flex { + display: inline-flex; +} + +.hidden { + display: none; +} + +.h-10 { + height: 2.5rem; +} + +.h-16 { + height: 4rem; +} + +.h-6 { + height: 1.5rem; +} + +.h-8 { + height: 2rem; +} + +.h-full { + height: 100%; +} + +.min-h-full { + min-height: 100%; +} + +.w-10 { + width: 2.5rem; +} + +.w-48 { + width: 12rem; +} + +.w-6 { + width: 1.5rem; +} + +.w-8 { + width: 2rem; +} + +.w-auto { + width: auto; +} + +.max-w-7xl { + max-width: 80rem; +} + +.max-w-xs { + max-width: 20rem; +} + +.flex-shrink-0 { + flex-shrink: 0; +} + +.origin-top-right { + transform-origin: top right; +} + +.items-center { + align-items: center; +} + +.justify-center { + justify-content: center; +} + +.justify-between { + justify-content: space-between; +} + +.space-y-1 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(0.25rem * var(--tw-space-y-reverse)); +} + +.rounded-full { + border-radius: 9999px; +} + +.rounded-md { + border-radius: 0.375rem; +} + +.border-b { + border-bottom-width: 1px; +} + +.border-t { + border-top-width: 1px; +} + +.border-gray-200 { + --tw-border-opacity: 1; + border-color: rgb(229 231 235 / var(--tw-border-opacity)); +} + +.bg-white { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); +} + +.p-1 { + padding: 0.25rem; +} + +.p-2 { + padding: 0.5rem; +} + +.px-4 { + padding-left: 1rem; + padding-right: 1rem; +} + +.py-1 { + padding-top: 0.25rem; + padding-bottom: 0.25rem; +} + +.py-10 { + padding-top: 2.5rem; + padding-bottom: 2.5rem; +} + +.py-8 { + padding-top: 2rem; + padding-bottom: 2rem; +} + +.pb-3 { + padding-bottom: 0.75rem; +} + +.pt-2 { + padding-top: 0.5rem; +} + +.pt-4 { + padding-top: 1rem; +} + +.text-3xl { + font-size: 1.875rem; + line-height: 2.25rem; +} + +.text-base { + font-size: 1rem; + line-height: 1.5rem; +} + +.text-sm { + font-size: 0.875rem; + line-height: 1.25rem; +} + +.font-bold { + font-weight: 700; +} + +.font-medium { + font-weight: 500; +} + +.leading-tight { + line-height: 1.25; +} + +.tracking-tight { + letter-spacing: -0.025em; +} + +.text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity)); +} + +.text-gray-500 { + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity)); +} + +.text-gray-800 { + --tw-text-opacity: 1; + color: rgb(31 41 55 / var(--tw-text-opacity)); +} + +.text-gray-900 { + --tw-text-opacity: 1; + color: rgb(17 24 39 / var(--tw-text-opacity)); +} + +.shadow-lg { + --tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); + --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color); + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); +} + +.ring-1 { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); +} + +.ring-black { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(0 0 0 / var(--tw-ring-opacity)); +} + +.ring-opacity-5 { + --tw-ring-opacity: 0.05; +} + +.hover\:bg-gray-100:hover { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity)); +} + +.hover\:text-gray-500:hover { + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity)); +} + +.focus\:outline-none:focus { + outline: 2px solid transparent; + outline-offset: 2px; +} + +.focus\:ring-2:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); +} + +.focus\:ring-indigo-500:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(99 102 241 / var(--tw-ring-opacity)); +} + +.focus\:ring-offset-2:focus { + --tw-ring-offset-width: 2px; +} + +@media (min-width: 640px) { + .sm\:-my-px { + margin-top: -1px; + margin-bottom: -1px; + } + + .sm\:ml-6 { + margin-left: 1.5rem; + } + + .sm\:flex { + display: flex; + } + + .sm\:hidden { + display: none; + } + + .sm\:items-center { + align-items: center; + } + + .sm\:space-x-8 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(2rem * var(--tw-space-x-reverse)); + margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse))); + } + + .sm\:px-6 { + padding-left: 1.5rem; + padding-right: 1.5rem; + } +} + +@media (min-width: 1024px) { + .lg\:block { + display: block; + } + + .lg\:hidden { + display: none; + } + + .lg\:px-8 { + padding-left: 2rem; + padding-right: 2rem; + } +} diff --git a/crates/app/css/input.css b/crates/app/css/input.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/crates/app/css/input.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index cb78fca..e7ac668 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -2,26 +2,27 @@ mod templates; use std::path::Path; +use askama::Template; use askama_axum::IntoResponse; -use templates::{hello::HelloResponse, index::GetIndexResponse}; +use axum::http::{StatusCode, Uri}; use tower_http::services::ServeDir; -async fn root() -> impl IntoResponse { - return GetIndexResponse {}.into_response(); +async fn fallback(uri: Uri) -> (StatusCode, String) { + (StatusCode::NOT_FOUND, format!("No route for {uri}")) } -async fn hello() -> impl IntoResponse { - return HelloResponse { - name: "Theo".to_string(), - } - .into_response(); +#[derive(Template)] +#[template(path = "index.html")] +pub struct GetIndexResponse; + +async fn root() -> impl IntoResponse { + GetIndexResponse {}.into_response() } pub fn get_router(assets_path: &Path) -> axum::Router { - let router = axum::Router::new() + axum::Router::new() .nest_service("/assets", ServeDir::new(assets_path)) .route("/", axum::routing::get(root)) - .route("/hello", axum::routing::get(hello)); - - router + .merge(templates::get_routes()) + .fallback(fallback) } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 0f11472..897ba73 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -9,6 +9,7 @@ async fn main() { let router = get_router(assets_path.as_path()); // TODO: select port based on available port (or ask in CLI) - let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + let listener = tokio::net::TcpListener::bind("localhost:3000").await.unwrap(); + println!("Listening on: http://{}", listener.local_addr().unwrap()); axum::serve(listener, router).await.unwrap(); } diff --git a/crates/app/src/templates/hello.rs b/crates/app/src/templates/hello.rs index 9ec4fb3..20321a4 100644 --- a/crates/app/src/templates/hello.rs +++ b/crates/app/src/templates/hello.rs @@ -1,7 +1,20 @@ use askama::Template; +use askama_axum::IntoResponse; +use axum::{routing, Router}; #[derive(Template)] #[template(path = "hello.html")] -pub struct HelloResponse { +struct HelloResponse { pub name: String, } + +async fn hello() -> impl IntoResponse { + HelloResponse { + name: "Theo".to_string(), + }.into_response() +} + +pub fn get_routes() -> Router { + Router::new() + .route("/", routing::get(hello)) +} diff --git a/crates/app/src/templates/index.rs b/crates/app/src/templates/index.rs deleted file mode 100644 index 49e09e7..0000000 --- a/crates/app/src/templates/index.rs +++ /dev/null @@ -1,5 +0,0 @@ -use askama::Template; - -#[derive(Template)] -#[template(path = "index.html")] -pub struct GetIndexResponse; diff --git a/crates/app/src/templates/mod.rs b/crates/app/src/templates/mod.rs index bb7cbb8..c0b91c0 100644 --- a/crates/app/src/templates/mod.rs +++ b/crates/app/src/templates/mod.rs @@ -1,2 +1,12 @@ -pub mod hello; -pub mod index; +use axum::Router; + +mod hello; +mod nav; +mod profile; + +pub fn get_routes() -> Router { + Router::new() + .nest("/hello", hello::get_routes()) + .nest("/nav", nav::get_routes()) + .nest("/profile", profile::get_routes()) +} diff --git a/crates/app/src/templates/nav.rs b/crates/app/src/templates/nav.rs new file mode 100644 index 0000000..5675ec7 --- /dev/null +++ b/crates/app/src/templates/nav.rs @@ -0,0 +1,65 @@ +use askama::Template; +use askama_axum::IntoResponse; +use axum::{extract::Query, routing, Router}; +use serde::Deserialize; + +struct MenuItem { + label: String, + id: String, + current: bool, +} + +#[derive(Deserialize)] +struct MenuParameters { + mobile: bool, +} + +#[derive(Template)] +#[template(path = "layout/nav/nav-menu-items.html")] +struct MenuResponse { + mobile: bool, + items: Vec, +} + +impl MenuResponse { + fn get_classes(&self, is_current_item: &bool) -> String { + let common_classes = match self.mobile { + true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(), + false => "inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium".to_string(), + }; + match (self.mobile, is_current_item) { + (true, true) => common_classes + " border-indigo-500 bg-indigo-50 text-indigo-700", + (true, false) => common_classes + " border-transparent text-gray-600 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-800", + (false, true) => common_classes + " border-indigo-500 text-gray-900", + (false, false) => common_classes + " border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700", + } + } +} + +async fn menu(Query(params): Query) -> impl IntoResponse { + MenuResponse { + mobile: params.mobile, + items: vec![ + MenuItem { + label: "Accueil".to_string(), + id: "home".to_string(), + current: true, + }, + MenuItem { + label: "À propos".to_string(), + id: "about".to_string(), + current: false, + }, + MenuItem { + label: "Contact".to_string(), + id: "contact".to_string(), + current: false, + }, + ], + }.into_response() +} + +pub fn get_routes() -> Router { + Router::new() + .route("/menu", routing::get(menu)) +} diff --git a/crates/app/src/templates/profile.rs b/crates/app/src/templates/profile.rs new file mode 100644 index 0000000..4b1d186 --- /dev/null +++ b/crates/app/src/templates/profile.rs @@ -0,0 +1,65 @@ +use askama::Template; +use askama_axum::IntoResponse; +use axum::{extract::Query, routing, Router}; +use serde::Deserialize; + +struct MenuItem { + label: String, + id: String, + current: bool, +} + +#[derive(Deserialize)] +struct MenuParameters { + mobile: bool, +} + +#[derive(Template)] +#[template(path = "layout/nav/profile-menu-items.html")] +struct MenuResponse { + mobile: bool, + items: Vec, +} + +impl MenuResponse { + fn get_classes(&self, is_current_item: &bool) -> String { + let common_classes = match self.mobile { + true => "block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800".to_string(), + false => "block px-4 py-2 text-sm text-gray-700".to_string(), + }; + match (self.mobile, is_current_item) { + (true, true) => common_classes + "", // ??? + (true, false) => common_classes + "", + (false, true) => common_classes + " bg-gray-100", + (false, false) => common_classes + "", + } + } +} + +async fn menu(Query(params): Query) -> impl IntoResponse { + MenuResponse { + mobile: params.mobile, + items: vec![ + MenuItem { + label: "Votre profil".to_string(), + id: "profile".to_string(), + current: false, + }, + MenuItem { + label: "Paramètres".to_string(), + id: "settings".to_string(), + current: false, + }, + MenuItem { + label: "Déconnexion".to_string(), + id: "logout".to_string(), + current: false, + }, + ], + }.into_response() +} + +pub fn get_routes() -> Router { + Router::new() + .route("/menu", routing::get(menu)) +} \ No newline at end of file diff --git a/crates/app/tailwind.config.js b/crates/app/tailwind.config.js new file mode 100644 index 0000000..601d56c --- /dev/null +++ b/crates/app/tailwind.config.js @@ -0,0 +1,12 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: [ + './templates/**/*.html', + './css/**/*.css', + ], + theme: { + extend: {}, + }, + plugins: [], +} + diff --git a/crates/app/templates/base.html b/crates/app/templates/base.html index 8c1715d..3a67442 100644 --- a/crates/app/templates/base.html +++ b/crates/app/templates/base.html @@ -1,13 +1,21 @@ - + {% block title %}{{ title }}{% endblock %} + + {% block head %}{% endblock %} - - {% block body %}{% endblock %} + +
+ {% block nav %} + {% include "layout/nav.html" %} + {% endblock %} + + {% block body %}{% endblock %} +
diff --git a/crates/app/templates/index.html b/crates/app/templates/index.html index 718e694..427de19 100644 --- a/crates/app/templates/index.html +++ b/crates/app/templates/index.html @@ -1,22 +1,26 @@ {% extends "base.html" %} - -{% block title %}Pharma Libre{% endblock %} - -{% block body %} -
+{% block title %}Pharma Libre{% endblock %} + +{% block body %} +
-

Pharma Libre

+
+

Dashboard

+
-
- Loading... +
+ +
+ Chargement ... +
diff --git a/crates/app/templates/layout/nav.html b/crates/app/templates/layout/nav.html new file mode 100644 index 0000000..872267f --- /dev/null +++ b/crates/app/templates/layout/nav.html @@ -0,0 +1,41 @@ + diff --git a/crates/app/templates/layout/nav/desktop/menu-items.html b/crates/app/templates/layout/nav/desktop/menu-items.html new file mode 100644 index 0000000..6fb9e25 --- /dev/null +++ b/crates/app/templates/layout/nav/desktop/menu-items.html @@ -0,0 +1,9 @@ + diff --git a/crates/app/templates/layout/nav/desktop/notifications-button.html b/crates/app/templates/layout/nav/desktop/notifications-button.html new file mode 100644 index 0000000..f11c45e --- /dev/null +++ b/crates/app/templates/layout/nav/desktop/notifications-button.html @@ -0,0 +1,6 @@ + diff --git a/crates/app/templates/layout/nav/desktop/profile-dropdown.html b/crates/app/templates/layout/nav/desktop/profile-dropdown.html new file mode 100644 index 0000000..73667f7 --- /dev/null +++ b/crates/app/templates/layout/nav/desktop/profile-dropdown.html @@ -0,0 +1,22 @@ + diff --git a/crates/app/templates/layout/nav/desktop/profile.html b/crates/app/templates/layout/nav/desktop/profile.html new file mode 100644 index 0000000..b0ceabc --- /dev/null +++ b/crates/app/templates/layout/nav/desktop/profile.html @@ -0,0 +1,27 @@ + +
+
+ +
+ + {% include "layout/nav/desktop/profile-dropdown.html" %} +
diff --git a/crates/app/templates/layout/nav/logo.html b/crates/app/templates/layout/nav/logo.html new file mode 100644 index 0000000..b7a5c3d --- /dev/null +++ b/crates/app/templates/layout/nav/logo.html @@ -0,0 +1,4 @@ +
+ Your Company + +
\ No newline at end of file diff --git a/crates/app/templates/layout/nav/mobile/menu-button.html b/crates/app/templates/layout/nav/mobile/menu-button.html new file mode 100644 index 0000000..c59e6e4 --- /dev/null +++ b/crates/app/templates/layout/nav/mobile/menu-button.html @@ -0,0 +1,43 @@ + + diff --git a/crates/app/templates/layout/nav/mobile/menu-items.html b/crates/app/templates/layout/nav/mobile/menu-items.html new file mode 100644 index 0000000..1bece64 --- /dev/null +++ b/crates/app/templates/layout/nav/mobile/menu-items.html @@ -0,0 +1,9 @@ + diff --git a/crates/app/templates/layout/nav/mobile/notifications-button.html b/crates/app/templates/layout/nav/mobile/notifications-button.html new file mode 100644 index 0000000..5525de9 --- /dev/null +++ b/crates/app/templates/layout/nav/mobile/notifications-button.html @@ -0,0 +1,6 @@ + diff --git a/crates/app/templates/layout/nav/mobile/profile-items.html b/crates/app/templates/layout/nav/mobile/profile-items.html new file mode 100644 index 0000000..9f84346 --- /dev/null +++ b/crates/app/templates/layout/nav/mobile/profile-items.html @@ -0,0 +1,9 @@ +
+ Chargement ... +
diff --git a/crates/app/templates/layout/nav/mobile/profile.html b/crates/app/templates/layout/nav/mobile/profile.html new file mode 100644 index 0000000..03851b7 --- /dev/null +++ b/crates/app/templates/layout/nav/mobile/profile.html @@ -0,0 +1,11 @@ +
+ +
+
+
Tom Cook
+
tom@example.com
+
diff --git a/crates/app/templates/layout/nav/nav-menu-items.html b/crates/app/templates/layout/nav/nav-menu-items.html new file mode 100644 index 0000000..92bb706 --- /dev/null +++ b/crates/app/templates/layout/nav/nav-menu-items.html @@ -0,0 +1,9 @@ +{% for item in items %} + + {{ item.label }} + +{% endfor %} \ No newline at end of file diff --git a/crates/app/templates/layout/nav/notifications-icon.html b/crates/app/templates/layout/nav/notifications-icon.html new file mode 100644 index 0000000..7f645d7 --- /dev/null +++ b/crates/app/templates/layout/nav/notifications-icon.html @@ -0,0 +1,16 @@ + +View notifications + \ No newline at end of file diff --git a/crates/app/templates/layout/nav/profile-menu-items.html b/crates/app/templates/layout/nav/profile-menu-items.html new file mode 100644 index 0000000..95b0064 --- /dev/null +++ b/crates/app/templates/layout/nav/profile-menu-items.html @@ -0,0 +1,11 @@ +{% for item in items %} + + {{ item.label }} + +{% endfor %}