From eb359621f09ae8b3c1a6f3167daf392e9eeea97f Mon Sep 17 00:00:00 2001 From: Jacob Morgan Date: Sat, 20 Apr 2024 17:18:17 +0200 Subject: [PATCH] Add settings page styling and functionality in CSS and Rust files. Incomplete page at /settings but working example. Want to refactor to less manual effort before completing. --- assets/style.css | 33 +++++++++++++++++++++ src/site/app.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/assets/style.css b/assets/style.css index 5d2967b..0f0813f 100644 --- a/assets/style.css +++ b/assets/style.css @@ -70,3 +70,36 @@ .workload-version, .workload-image, .workload-namespace, .workload-last-scanned, .workload-latest-version { margin-top: 10px; } + + +.settings-page { + background-color: #F0F0F0; + padding: 20px; + border-radius: 8px; + margin: 20px auto; + width: 80%; + box-shadow: 0 4px 8px rgba(0,0,0,0.1); +} + +.settings-section { + margin-bottom: 20px; +} + +.settings-section-header { + font-weight: bold; + font-size: 1.5em; + color: #333; + margin-bottom: 10px; +} + +.settings-item { + margin-top: 5px; +} + +.settings-item-key { + font-weight: bold; +} + +.settings-item-value { + margin-left: 10px; +} diff --git a/src/site/app.rs b/src/site/app.rs index ccd2b06..173830a 100644 --- a/src/site/app.rs +++ b/src/site/app.rs @@ -2,7 +2,9 @@ use dioxus::prelude::*; use dioxus::prelude::ServerFnError; +use serde_derive::{Deserialize, Serialize}; use wasm_bindgen_futures::spawn_local; +use crate::config::{GitopsConfig, Notifications, Settings, System}; use crate::models; use crate::models::models::Workload; @@ -14,8 +16,15 @@ enum Route { Home {}, #[route("/refresh-all")] RefreshAll {}, + #[route("/settings")] + SettingsPage {}, } +#[derive(Debug, Deserialize, Clone)] +#[allow(unused)] +pub struct AppSettings { + pub settings: Settings, +} #[derive(PartialEq, Clone,Props)] @@ -32,6 +41,62 @@ async fn get_all_workloads() -> Result { } + +#[component] +fn SettingsCard(props: AppSettings) -> Element { + rsx! { + div { + class: "settings-section", + } + } +} + +#[component] +fn SettingsPage() -> Element { + let settings_context = use_context::>(); + let settings = settings_context.read(); + rsx! { + div { + class: "settings-page", + div { + class: "settings-section", + div { class: "settings-section-header", "System Settings" }, + div { class: "settings-item", + span { class: "settings-item-key", "Schedule: " }, + span { class: "settings-item-value", "{settings.settings.system.schedule}" } + }, + div { class: "settings-item", + span { class: "settings-item-key", "Data Directory: " }, + span { class: "settings-item-value", "{settings.settings.system.data_dir}" } + }, + div { class: "settings-item", + span { class: "settings-item-key", "Run at Startup: " }, + span { class: "settings-item-value", "{settings.settings.system.run_at_startup}" } + } + }, + div { + class: "settings-section", + div { class: "settings-section-header", "Gitops Settings" }, + for gitops in settings.clone().settings.gitops.unwrap().iter() { + div { class: "settings-item", + span { class: "settings-item-key", "Name: " } + span { class: "settings-item-value", "{gitops.name}" } + } + div { class: "settings-item", + span { class: "settings-item-key", "Repository URL: " } + span { class: "settings-item-value", "{gitops.repository_url}" } + } + } + + } + + }, + } +} + + + + #[component] fn Home() -> Element { let workloads = use_server_future(get_all)?; @@ -130,6 +195,13 @@ fn WorkloadCard(props: WorkloadCardProps) -> Element { pub fn App() -> Element { println!("App started"); + use_context_provider(|| Signal::new(AppSettings { settings: Settings::new().unwrap_or_else( + |err| { + log::error!("Failed to load settings: {}", err); + panic!("Failed to load settings: {}", err); + } + ) })); + //load config rsx! { Router:: {} } } @@ -204,6 +276,7 @@ fn All() -> Element { } + #[server] async fn upgrade_workload(workload: Workload) -> Result<(), ServerFnError> { log::info!("upgrade_workload: {:?}", workload); @@ -239,6 +312,8 @@ async fn refresh_all() -> Result<(), ServerFnError> { #[server] async fn get_all() -> Result, ServerFnError> { use crate::database::client::return_all_workloads; + let settings_context = consume_context::>(); + log::info!("settings_context: {:?}", settings_context); let workloads = return_all_workloads(); log::info!("get_all_workloads: {:?}", workloads); Ok(workloads.unwrap())