diff --git a/src/main.rs b/src/main.rs index 8abd933..fac843b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,10 @@ async fn main() -> anyhow::Result<()> { .nest("/api", routes::mk_api_routes(config.clone())) // HTMX ui component endpoints .nest("/ui", routes::mk_ui_routes(config.clone())) + .route( + "/embed/dash/:dash_idx/graph/:graph_idx", + get(routes::graph_embed).with_state(State(config.clone())), + ) .route("/dash/:dash_idx", get(routes::dashboard_direct)) .route("/", get(routes::index).with_state(State(config.clone()))) .layer(TraceLayer::new_for_http()) diff --git a/src/routes.rs b/src/routes.rs index b8c59e7..196ce9a 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -135,6 +135,31 @@ pub fn mk_ui_routes(config: Arc>) -> Router { ) } +fn graph_lib_prelude() -> Markup { + html! { + script src="/js/plotly.js" { } + script defer src="/js/lib.js" { } + link rel="stylesheet" href="/static/site.css" { } + } +} + +pub async fn graph_embed( + State(config): State, + Path((dash_idx, graph_idx)): Path<(usize, usize)>, +) -> Markup { + html! { + html { + head { + title { ("Heracles - Prometheus Unshackled") } + } + body { + (graph_lib_prelude()) + (graph_ui(State(config.clone()), Path((dash_idx, graph_idx))).await) + } + } + } +} + async fn index_html(config: Config, dash_idx: Option) -> Markup { html! { html { @@ -142,10 +167,8 @@ async fn index_html(config: Config, dash_idx: Option) -> Markup { title { ("Heracles - Prometheus Unshackled") } } body { - script src="/js/plotly.js" { } script src="/js/htmx.js" { } - script defer src="/js/lib.js" { } - link rel="stylesheet" href="/static/site.css" { } + (graph_lib_prelude()) (app(State(config.clone()), dash_idx).await) } } @@ -156,10 +179,7 @@ pub async fn index(State(config): State) -> Markup { index_html(config, None).await } -pub async fn dashboard_direct( - State(config): State, - Path(dash_idx): Path, -) -> Markup { +pub async fn dashboard_direct(State(config): State, Path(dash_idx): Path) -> Markup { index_html(config, Some(dash_idx)).await } @@ -222,7 +242,11 @@ pub fn mk_js_routes(config: Arc>) -> Router { pub fn mk_static_routes(config: Arc>) -> Router { Router::new() - .route("/site.css", get(|| async { return include_str!("../static/site.css"); })) + .route( + "/site.css", + get(|| async { + return include_str!("../static/site.css"); + }), + ) .with_state(State(config)) } -