Compare commits

..

No commits in common. "782cca41a0b44ea8ac68c696f73d5491197a933b" and "2f15472d62cf823cb93da83e78afcaf875dbfd45" have entirely different histories.

2 changed files with 10 additions and 39 deletions

View File

@ -90,10 +90,6 @@ async fn main() -> anyhow::Result<()> {
.nest("/api", routes::mk_api_routes(config.clone())) .nest("/api", routes::mk_api_routes(config.clone()))
// HTMX ui component endpoints // HTMX ui component endpoints
.nest("/ui", routes::mk_ui_routes(config.clone())) .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("/dash/:dash_idx", get(routes::dashboard_direct))
.route("/", get(routes::index).with_state(State(config.clone()))) .route("/", get(routes::index).with_state(State(config.clone())))
.layer(TraceLayer::new_for_http()) .layer(TraceLayer::new_for_http())

View File

@ -77,10 +77,9 @@ pub fn mk_api_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
pub fn graph_component(dash_idx: usize, graph_idx: usize, graph: &Graph) -> Markup { pub fn graph_component(dash_idx: usize, graph_idx: usize, graph: &Graph) -> Markup {
let graph_id = format!("graph-{}-{}", dash_idx, graph_idx); let graph_id = format!("graph-{}-{}", dash_idx, graph_idx);
let graph_data_uri = format!("/api/dash/{}/graph/{}", dash_idx, graph_idx); let graph_data_uri = format!("/api/dash/{}/graph/{}", dash_idx, graph_idx);
let graph_embed_uri = format!("/embed/dash/{}/graph/{}", dash_idx, graph_idx);
html!( html!(
div { div {
h2 { (graph.title) " - " a href=(graph_embed_uri) { "embed url" } } h2 { (graph.title) }
@if graph.d3_tick_format.is_some() { @if graph.d3_tick_format.is_some() {
timeseries-graph uri=(graph_data_uri) id=(graph_id) d3-tick-format=(graph.d3_tick_format.as_ref().unwrap()) { } timeseries-graph uri=(graph_data_uri) id=(graph_id) d3-tick-format=(graph.d3_tick_format.as_ref().unwrap()) { }
} @else { } @else {
@ -136,31 +135,6 @@ pub fn mk_ui_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
) )
} }
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<Config>,
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<usize>) -> Markup { async fn index_html(config: Config, dash_idx: Option<usize>) -> Markup {
html! { html! {
html { html {
@ -168,8 +142,10 @@ async fn index_html(config: Config, dash_idx: Option<usize>) -> Markup {
title { ("Heracles - Prometheus Unshackled") } title { ("Heracles - Prometheus Unshackled") }
} }
body { body {
script src="/js/plotly.js" { }
script src="/js/htmx.js" { } script src="/js/htmx.js" { }
(graph_lib_prelude()) script defer src="/js/lib.js" { }
link rel="stylesheet" href="/static/site.css" { }
(app(State(config.clone()), dash_idx).await) (app(State(config.clone()), dash_idx).await)
} }
} }
@ -180,7 +156,10 @@ pub async fn index(State(config): State<Config>) -> Markup {
index_html(config, None).await index_html(config, None).await
} }
pub async fn dashboard_direct(State(config): State<Config>, Path(dash_idx): Path<usize>) -> Markup { pub async fn dashboard_direct(
State(config): State<Config>,
Path(dash_idx): Path<usize>,
) -> Markup {
index_html(config, Some(dash_idx)).await index_html(config, Some(dash_idx)).await
} }
@ -243,11 +222,7 @@ pub fn mk_js_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
pub fn mk_static_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> { pub fn mk_static_routes(config: Arc<Vec<Dashboard>>) -> Router<Config> {
Router::new() Router::new()
.route( .route("/site.css", get(|| async { return include_str!("../static/site.css"); }))
"/site.css",
get(|| async {
return include_str!("../static/site.css");
}),
)
.with_state(State(config)) .with_state(State(config))
} }