From 4cd7f94ef269d0a14deb9636431849c441fa1138 Mon Sep 17 00:00:00 2001
From: Romulus21
Date: Sun, 12 Apr 2026 15:26:28 +0200
Subject: [PATCH] ajout de l'option dashboard pour afficher les liens
importants sur home
---
...0412150652_add_dashboard_to_links.down.sql | 1 +
...260412150652_add_dashboard_to_links.up.sql | 1 +
src/app.rs | 7 ---
src/models/link.rs | 15 +++--
src/routes/home.rs | 57 +++++++++++++++++++
src/routes/link.rs | 26 +++++++--
src/routes/mod.rs | 2 +
7 files changed, 94 insertions(+), 15 deletions(-)
create mode 100644 migrations/20260412150652_add_dashboard_to_links.down.sql
create mode 100644 migrations/20260412150652_add_dashboard_to_links.up.sql
create mode 100644 src/routes/home.rs
diff --git a/migrations/20260412150652_add_dashboard_to_links.down.sql b/migrations/20260412150652_add_dashboard_to_links.down.sql
new file mode 100644
index 0000000..a2ad9fa
--- /dev/null
+++ b/migrations/20260412150652_add_dashboard_to_links.down.sql
@@ -0,0 +1 @@
+ALTER TABLE links DROP COLUMN dashboard;
diff --git a/migrations/20260412150652_add_dashboard_to_links.up.sql b/migrations/20260412150652_add_dashboard_to_links.up.sql
new file mode 100644
index 0000000..32a3ad1
--- /dev/null
+++ b/migrations/20260412150652_add_dashboard_to_links.up.sql
@@ -0,0 +1 @@
+ALTER TABLE links ADD COLUMN dashboard BOOLEAN NOT NULL DEFAULT FALSE;
diff --git a/src/app.rs b/src/app.rs
index 42d22f2..226e0bf 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -59,13 +59,6 @@ pub fn Navigation() -> impl IntoView {
}
}
-#[component]
-pub fn Home() -> impl IntoView {
- view! {
- Home
- }
-}
-
#[component]
pub fn NotFound() -> impl IntoView {
view! {
diff --git a/src/models/link.rs b/src/models/link.rs
index d3d6825..87b1048 100644
--- a/src/models/link.rs
+++ b/src/models/link.rs
@@ -7,6 +7,7 @@ pub struct Link {
pub name: String,
pub icon: String,
pub alternate_link: String,
+ pub dashboard: bool,
position: i64,
created_at: String,
}
@@ -18,13 +19,15 @@ impl Link {
link: String,
icon: String,
alternate_link: String,
+ dashboard: bool,
) -> Result {
sqlx::query!(
- "INSERT INTO links (name, link, icon, alternate_link, position, created_at) VALUES (?, ?, ?, ?, (SELECT COALESCE(MAX(position) + 1, 1) FROM links lin), ?)",
+ "INSERT INTO links (name, link, icon, alternate_link, dashboard, position, created_at) VALUES (?, ?, ?, ?, ?, (SELECT COALESCE(MAX(position) + 1, 1) FROM links lin), ?)",
name,
link,
icon,
alternate_link,
+ dashboard,
chrono::Local::now().naive_local(),
)
.execute(crate::database::get_db())
@@ -34,7 +37,7 @@ impl Link {
#[cfg(feature = "ssr")]
pub async fn get_all() -> Result, sqlx::Error> {
sqlx::query!(
- "SELECT id, name, link, icon, alternate_link, position, created_at FROM links ORDER BY position"
+ "SELECT id, name, link, icon, alternate_link, dashboard, position, created_at FROM links ORDER BY position"
)
.map(|x| Self {
id: x.id,
@@ -42,6 +45,7 @@ impl Link {
link: x.link,
icon: x.icon,
alternate_link: x.alternate_link,
+ dashboard: x.dashboard != 0,
position: x.position,
created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(),
})
@@ -55,7 +59,7 @@ impl Link {
direction: String,
) -> Result {
let link = sqlx::query!(
- "SELECT id, name, link, icon, alternate_link, position, created_at FROM links WHERE id = ?",
+ "SELECT id, name, link, icon, alternate_link, dashboard, position, created_at FROM links WHERE id = ?",
link_id
)
.map(|x| Self {
@@ -64,6 +68,7 @@ impl Link {
link: x.link,
icon: x.icon,
alternate_link: x.alternate_link,
+ dashboard: x.dashboard != 0,
position: x.position,
created_at: x.created_at.format("%d/%m/%Y %H:%M").to_string(),
})
@@ -108,13 +113,15 @@ impl Link {
link: String,
icon: String,
alternate_link: String,
+ dashboard: bool,
) -> Result {
sqlx::query!(
- "UPDATE links SET name = ?, link = ?, icon = ?, alternate_link = ? WHERE id = ?",
+ "UPDATE links SET name = ?, link = ?, icon = ?, alternate_link = ?, dashboard = ? WHERE id = ?",
name,
link,
icon,
alternate_link,
+ dashboard,
id
)
.execute(crate::database::get_db())
diff --git a/src/routes/home.rs b/src/routes/home.rs
new file mode 100644
index 0000000..7b07452
--- /dev/null
+++ b/src/routes/home.rs
@@ -0,0 +1,57 @@
+use leptos::*;
+use leptos_meta::*;
+
+#[server(GetDashboardLinksAction, "/api", "GetJson")]
+#[tracing::instrument]
+pub async fn get_dashboard_links() -> Result, ServerFnError> {
+ crate::models::Link::get_all()
+ .await
+ .map(|links| links.into_iter().filter(|l| l.dashboard).collect())
+ .map_err(|x| {
+ let err = format!("Error while fetching dashboard links: {x:?}");
+ tracing::error!("{err}");
+ ServerFnError::ServerError("Could not fetch dashboard links, try again later".into())
+ })
+}
+
+#[component]
+pub fn Home() -> impl IntoView {
+ let links = create_resource(|| (), |_| async move { get_dashboard_links().await });
+
+ view! {
+
+
}>
+ "Something went wrong." }
+ }>
+ {move || links.get().map(move |x| x.map(move |c| {
+ view! {
+ }
+ }/>
+ }
+ }))}
+
+
+
+ }
+}
+
+#[component]
+fn DashboardLink(link: crate::models::Link) -> impl IntoView {
+ view! {
+
+
+
+ {link.name.clone()}
+
+
+ }
+}
diff --git a/src/routes/link.rs b/src/routes/link.rs
index bab111c..aaeea51 100644
--- a/src/routes/link.rs
+++ b/src/routes/link.rs
@@ -13,8 +13,8 @@ pub async fn get_links() -> Result, ServerFnError> {
}
#[server(LinkAction, "/api")]
-pub async fn add_value(name: String, link: String, icon: String, alternate_link: String) -> Result<(), ServerFnError> {
- crate::models::Link::insert(name, link, icon, alternate_link)
+pub async fn add_value(name: String, link: String, icon: String, alternate_link: String, dashboard: bool) -> Result<(), ServerFnError> {
+ crate::models::Link::insert(name, link, icon, alternate_link, dashboard)
.await
.map(|_| ())
.map_err(|x| {
@@ -120,7 +120,7 @@ fn Link(
) -> impl IntoView {
view! {
-
Result<(), ServerFnError> {
- crate::models::Link::update(id, name, link, icon, alternate_link)
+ crate::models::Link::update(id, name, link, icon, alternate_link, dashboard)
.await
.map(|_| ())
.map_err(|x| {
@@ -235,6 +236,8 @@ fn LinkFormModal(
let (icon, set_icon) = create_signal(link.as_ref().map(|x| x.icon.clone()).unwrap_or_default());
let (alternate_link, set_alternate_link) =
create_signal(link.as_ref().map(|x| x.alternate_link.clone()).unwrap_or_default());
+ let (dashboard, set_dashboard) =
+ create_signal(link.as_ref().map(|x| x.dashboard).unwrap_or(false));
let link_id = link.as_ref().map(|x| x.id.to_string());
view! {
@@ -257,6 +260,8 @@ fn LinkFormModal(
set_icon=set_icon
alternate_link=alternate_link
set_alternate_link=set_alternate_link
+ dashboard=dashboard
+ set_dashboard=set_dashboard
/>
@@ -273,6 +278,8 @@ fn LinkFormModal(
set_icon=set_icon
alternate_link=alternate_link
set_alternate_link=set_alternate_link
+ dashboard=dashboard
+ set_dashboard=set_dashboard
/>
@@ -293,6 +300,8 @@ fn LinkFormFields(
set_icon: WriteSignal,
alternate_link: ReadSignal,
set_alternate_link: WriteSignal,
+ dashboard: ReadSignal,
+ set_dashboard: WriteSignal,
) -> impl IntoView {
view! {
@@ -332,6 +341,15 @@ fn LinkFormFields(
on:input=move |ev| set_icon.set(event_target_value(&ev))
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-full" />
+
+
+
}
}
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index e98346e..d3eb725 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -1,5 +1,7 @@
+mod home;
mod link;
mod shutters;
+pub use home::*;
pub use link::*;
pub use shutters::*;