add shutters page first work

This commit is contained in:
Romulus21
2025-03-09 00:28:14 +01:00
parent 298ed6a6c9
commit c10fd3aa51
8 changed files with 432 additions and 4 deletions

308
Cargo.lock generated
View File

@@ -123,6 +123,12 @@ dependencies = [
"num-traits",
]
[[package]]
name = "atomic-waker"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "attribute-derive"
version = "0.9.2"
@@ -491,6 +497,16 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@@ -799,6 +815,21 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
@@ -981,6 +1012,25 @@ dependencies = [
"web-sys",
]
[[package]]
name = "h2"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5017294ff4bb30944501348f6f8e42e6ad28f42c8bbef7a74029aff064a4e3c2"
dependencies = [
"atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "half"
version = "2.4.1"
@@ -1134,9 +1184,9 @@ dependencies = [
[[package]]
name = "http"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
dependencies = [
"bytes",
"fnv",
@@ -1193,6 +1243,7 @@ dependencies = [
"bytes",
"futures-channel",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
@@ -1201,6 +1252,40 @@ dependencies = [
"pin-project-lite",
"smallvec",
"tokio",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.27.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2"
dependencies = [
"futures-util",
"http",
"hyper",
"hyper-util",
"rustls 0.23.12",
"rustls-pki-types",
"tokio",
"tokio-rustls 0.26.0",
"tower-service",
]
[[package]]
name = "hyper-tls"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
dependencies = [
"bytes",
"http-body-util",
"hyper",
"hyper-util",
"native-tls",
"tokio",
"tokio-native-tls",
"tower-service",
]
[[package]]
@@ -1210,13 +1295,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http",
"http-body",
"hyper",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
"tracing",
]
[[package]]
@@ -1895,6 +1983,23 @@ dependencies = [
"version_check",
]
[[package]]
name = "native-tls"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e"
dependencies = [
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]]
name = "nom"
version = "7.1.3"
@@ -2003,6 +2108,50 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "openssl"
version = "0.10.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e14130c6a98cd258fdcb0fb6d744152343ff729cbfcb28c656a9d12b999fbcd"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.76",
]
[[package]]
name = "openssl-probe"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
[[package]]
name = "openssl-sys"
version = "0.9.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bb61ea9811cc39e3c2069f40b8b8e2e70d8569b361f879786cc7ed48b777cdd"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "overload"
version = "0.1.1"
@@ -2377,6 +2526,49 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "reqwest"
version = "0.12.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f"
dependencies = [
"base64 0.22.1",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"http-body-util",
"hyper",
"hyper-rustls",
"hyper-tls",
"hyper-util",
"ipnet",
"js-sys",
"log",
"mime",
"native-tls",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls-pemfile 2.1.3",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper 1.0.1",
"system-configuration",
"tokio",
"tokio-native-tls",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows-registry",
]
[[package]]
name = "resolv-conf"
version = "0.7.0"
@@ -2465,6 +2657,7 @@ dependencies = [
"leptos_router",
"mail-send",
"regex",
"reqwest",
"serde",
"sqlx",
"tokio",
@@ -2594,6 +2787,15 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@@ -2610,6 +2812,29 @@ dependencies = [
"untrusted 0.9.0",
]
[[package]]
name = "security-framework"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "self_cell"
version = "1.0.4"
@@ -3202,6 +3427,30 @@ name = "sync_wrapper"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394"
dependencies = [
"futures-core",
]
[[package]]
name = "system-configuration"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
dependencies = [
"bitflags",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "tempfile"
@@ -3319,6 +3568,16 @@ dependencies = [
"syn 2.0.76",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.24.1"
@@ -3533,6 +3792,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "typed-builder"
version = "0.18.2"
@@ -3679,6 +3944,15 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@@ -3846,6 +4120,36 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-registry"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0"
dependencies = [
"windows-result",
"windows-strings",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-result"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-strings"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
dependencies = [
"windows-result",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.48.0"

View File

@@ -18,6 +18,7 @@ sqlx = { version = "0.8", features = [
"mysql",
"chrono",
], optional = true }
reqwest = { version = "0.12", features = ["json"] }
mail-send = { version = "0.4.7", optional = true }
regex = { version = "1.10", optional = true }

View File

@@ -2,6 +2,11 @@
@tailwind components;
@tailwind utilities;
body {
@apply dark:bg-prim dark:text-second
}
.active-link {
@apply text-third border-b;
}

View File

@@ -13,7 +13,7 @@ pub fn App() -> impl IntoView {
<Title text="Bienvenue à la maison"/>
<div class="dark:bg-prim dark:text-second h-screen flex flex-col">
<div class="h-screen flex flex-col">
<Router>
<Navigation />
<main class="flex-1">
@@ -22,6 +22,7 @@ pub fn App() -> impl IntoView {
<Route path="/liens" view=move || view! { <Links/> }/>
<Route path="/formulaire" view=move || view! { <FormValues/> }/>
<Route path="/donnees" view=move || view! { <Data/> }/>
<Route path="/volets" view=move || view! { <Shutters/> }/>
//<Route path="/*any" view=move || view! { <NotFound/> }/>
</Routes>
</main>
@@ -49,6 +50,9 @@ pub fn Navigation() -> impl IntoView {
<a href="/donnees"
class="hover:text-third hover:border-b border-third inline-block transition-colors"
class:active-link=move || location.pathname.get() == "/donnees">Données</a>
<a href="/volets"
class="hover:text-third hover:border-b border-third inline-block transition-colors"
class:active-link=move || location.pathname.get() == "/volets">Volets</a>
</nav>
}
}

View File

@@ -1,7 +1,9 @@
mod data;
mod link;
mod value;
mod shutters;
pub use data::*;
pub use link::*;
pub use value::*;
pub use shutters::*;

111
src/routes/shutters.rs Normal file
View File

@@ -0,0 +1,111 @@
use leptos::*;
use leptos_meta::*;
use reqwest::Client;
use serde::Serialize;
#[derive(Serialize)]
struct Params {
command: String,
shadeId: i32,
}
#[component]
pub fn Shutters() -> impl IntoView {
view! {
<Title text="Volets"/>
<div class="flex flex-wrap justify-center gap-2">
<Shutter name="Cuisine".to_string() shade_id=6 />
<Shutter name="Porte fenêtre".to_string() shade_id=2 />
<Shutter name="Salon fenêtre".to_string() shade_id=4 />
<Shutter name="Salon vidéo".to_string() shade_id=5 />
<Shutter name="Bureau".to_string() shade_id=1 />
</div>
}
}
#[component]
pub fn Shutter(name: String, shade_id: i32) -> impl IntoView {
let (response, set_response) = create_signal(None::<String>);
let move_up = create_action(move |_| async move {
let client = Client::new();
let params = Params {
command: "up".to_string(),
shadeId: shade_id,
};
let url = "http://192.168.3.34/shadeCommand";
match client.put(url).json(&params).send().await {
Ok(resp) => {
let text = resp.text().await.unwrap_or("Réponse vide".to_string());
set_response.set(Some(text));
}
Err(e) => {
set_response.set(Some(format!("Erreur: {:?}", e)));
}
}
});
let move_my = create_action(move |_| async move {
let client = Client::new();
let params = Params {
command: "my".to_string(),
shadeId: shade_id,
};
let url = "http://192.168.3.34/shadeCommand";
match client.put(url).json(&params).send().await {
Ok(resp) => {
let text = resp.text().await.unwrap_or("Réponse vide".to_string());
set_response.set(Some(text));
}
Err(e) => {
set_response.set(Some(format!("Erreur: {:?}", e)));
}
}
});
let move_down = create_action(move |_| async move {
let client = Client::new();
let params = Params {
command: "down".to_string(),
shadeId: shade_id,
};
let url = "http://192.168.3.34/shadeCommand";
match client.put(url).json(&params).send().await {
Ok(resp) => {
let text = resp.text().await.unwrap_or("Réponse vide".to_string());
set_response.set(Some(text));
}
Err(e) => {
set_response.set(Some(format!("Erreur: {:?}", e)));
}
}
});
view! {
<div class="bg-prim-light rounded-lg w-48 px-3">
<div class="text-2xl text-center">{name}</div>
<div class="flex justify-between bg-second-dark rounded *:flex-1 *:transition">
<button on:click=move |_| move_up.dispatch(()) class="hover:text-third focus:text-third-light">
<Arrow class="-rotate-90 w-8 inline".to_string() />
</button>
<button on:click=move |_| move_my.dispatch(()) class="hover:text-third focus:text-third-light">"My"</button>
<button on:click=move |_| move_down.dispatch(()) class="hover:text-third focus:text-third-light">
<Arrow class="rotate-90 w-8 inline".to_string() />
</button>
</div>
</div>
}
}
#[component]
pub fn Arrow(class: String) -> impl IntoView {
view! {
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" class=format!("{}", class)>
<path fill="currentColor" d="M6.23 20.23L8 22l10-10L8 2L6.23 3.77L14.46 12z"/>
</svg>
}
}

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,7 @@ module.exports = {
content: {
files: ["*.html", "./src/**/*.rs"],
},
safelist: ['rotate-90', '-rotate-90'],
theme: {
extend: {
colors: {