From e8edef93bfd9679256d82176cf31a358eb41492b Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 7 Feb 2024 13:37:43 -0600 Subject: [PATCH] dev: sketch out basic elements for graph placement --- src/routes.rs | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/routes.rs b/src/routes.rs index f7c4d5a..bc003b4 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -21,7 +21,7 @@ use axum::{ use maud::{html, Markup, PreEscaped}; use tracing::debug; -use crate::dashboard::Dashboard; +use crate::dashboard::{Dashboard, Graph}; use crate::query::{to_samples, QueryResult}; type Config = State>>; @@ -58,17 +58,46 @@ pub fn mk_api_routes(config: Arc>) -> Router { ) } -pub async fn dash_ui(State(config): State, Path(idx): Path) -> Markup { +pub fn graph_component(graph: &Graph) -> Markup { html!( - "TODO(jwall): Fill this in" + div { + h2 { (graph.title) } + div { "data/graph goes here" } + } + ) +} + +pub async fn graph_ui( + State(config): State, + Path((dash_idx, graph_idx)): Path<(usize, usize)>, +) -> Markup { + let graph = config + .get(dash_idx) + .expect("No such dashboard") + .graphs + .get(graph_idx) + .expect("No such graph"); + graph_component(graph) +} + +pub async fn dash_ui(State(config): State, Path(idx): Path) -> Markup { + // TODO(zaphar): Should do better http error reporting here. + let dash = config.get(idx).expect("No such dashboard"); + html!( + h1 { (dash.title) } + @for graph in &dash.graphs { + (graph_component(graph)) + } ) } pub fn mk_ui_routes(config: Arc>) -> Router { - Router::new().route( - "/dash/:idx", - get(dash_ui).with_state(State(config)) - ) + Router::new() + .route("/dash/:idx", get(dash_ui).with_state(State(config.clone()))) + .route( + "/dash/:dash_idx/graph/:graph_idx", + get(graph_ui).with_state(State(config)), + ) } pub async fn index(State(config): State) -> Markup {