diff --git a/src/dashboard.rs b/src/dashboard.rs index a4b29a5..aa02d2b 100644 --- a/src/dashboard.rs +++ b/src/dashboard.rs @@ -18,14 +18,14 @@ use serde_yaml; #[derive(Deserialize)] pub struct Dashboard { - title: String, - graphs: Vec, + pub title: String, + pub graphs: Vec, } #[derive(Deserialize)] pub struct Graph { - title: String, - query: String, + pub title: String, + pub query: String, } pub fn read_dashboard_list(path: &Path) -> anyhow::Result> { diff --git a/src/main.rs b/src/main.rs index e540093..890f255 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use anyhow; use async_io::Async; -use axum::{self, routing::*, Router}; +use axum::{self, extract::State, routing::*, Router}; use clap::{self, Parser}; use smol_macros::main; @@ -39,12 +39,12 @@ main! { let args = Cli::parse(); let config = std::sync::Arc::new(dashboard::read_dashboard_list(args.config.as_path())?); let router = Router::new() - .with_state(config) // JSON api endpoints .nest("/api", routes::mk_api_routes()) // HTMX ui component endpoints .nest("/ui", routes::mk_ui_routes()) - .route("/", get(routes::index)); + .route("/", get(routes::index).with_state(config.clone())) + .with_state(State(config.clone())); let socket_addr = args.listen.unwrap_or("127.0.0.1:3000".parse()?); // TODO(jwall): Take this from clap arguments let listener = Async::::bind(socket_addr)?; diff --git a/src/routes.rs b/src/routes.rs index 81f17e3..167a7f8 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -20,12 +20,12 @@ use crate::dashboard::Dashboard; type Config = State>>; -pub fn mk_api_routes() -> Router { +pub fn mk_api_routes() -> Router { // Query routes Router::new() } -pub fn mk_ui_routes() -> Router { +pub fn mk_ui_routes() -> Router { Router::new() } @@ -43,10 +43,15 @@ pub async fn index(State(config): Config) -> Markup { } pub async fn app(State(config): Config) -> Markup { + let titles = config.iter().map(|d| d.title.clone()).collect::>(); html! { div { // Header menu - div { } + ul { + @for title in &titles { + li { (title) } + } + } // dashboard display div { } }