Skip to content

Commit

Permalink
Add settings page styling and functionality in CSS and Rust files. In…
Browse files Browse the repository at this point in the history
…complete page at /settings but working example. Want to refactor to less manual effort before completing.
  • Loading branch information
slackspace-io committed Apr 20, 2024
1 parent b9cf84d commit eb35962
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
33 changes: 33 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
75 changes: 75 additions & 0 deletions src/site/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)]
Expand All @@ -32,6 +41,62 @@ async fn get_all_workloads() -> Result<String, ServerFnError> {
}



#[component]
fn SettingsCard(props: AppSettings) -> Element {
rsx! {
div {
class: "settings-section",
}
}
}

#[component]
fn SettingsPage() -> Element {
let settings_context = use_context::<Signal<AppSettings>>();
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)?;
Expand Down Expand Up @@ -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::<Route> {} }
}

Expand Down Expand Up @@ -204,6 +276,7 @@ fn All() -> Element {
}



#[server]
async fn upgrade_workload(workload: Workload) -> Result<(), ServerFnError> {
log::info!("upgrade_workload: {:?}", workload);
Expand Down Expand Up @@ -239,6 +312,8 @@ async fn refresh_all() -> Result<(), ServerFnError> {
#[server]
async fn get_all() -> Result<Vec<Workload>, ServerFnError> {
use crate::database::client::return_all_workloads;
let settings_context = consume_context::<Signal<AppSettings>>();
log::info!("settings_context: {:?}", settings_context);
let workloads = return_all_workloads();
log::info!("get_all_workloads: {:?}", workloads);
Ok(workloads.unwrap())
Expand Down

0 comments on commit eb35962

Please sign in to comment.