mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 12:39:50 -04:00
Merge pull request #20 from zaphar/embeddable_graphs
feat: URL for embedded graphs.
This commit is contained in:
commit
e1e0d17657
@ -90,6 +90,10 @@ 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())
|
||||||
|
@ -135,6 +135,31 @@ 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 {
|
||||||
@ -142,10 +167,8 @@ 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" { }
|
||||||
script defer src="/js/lib.js" { }
|
(graph_lib_prelude())
|
||||||
link rel="stylesheet" href="/static/site.css" { }
|
|
||||||
(app(State(config.clone()), dash_idx).await)
|
(app(State(config.clone()), dash_idx).await)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,10 +179,7 @@ pub async fn index(State(config): State<Config>) -> Markup {
|
|||||||
index_html(config, None).await
|
index_html(config, None).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn dashboard_direct(
|
pub async fn dashboard_direct(State(config): State<Config>, Path(dash_idx): Path<usize>) -> Markup {
|
||||||
State(config): State<Config>,
|
|
||||||
Path(dash_idx): Path<usize>,
|
|
||||||
) -> Markup {
|
|
||||||
index_html(config, Some(dash_idx)).await
|
index_html(config, Some(dash_idx)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +242,11 @@ 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("/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))
|
.with_state(State(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user