diff --git a/src/web/controllers/home.rs b/src/web/controllers/home.rs index c3cf687..3f05a5e 100644 --- a/src/web/controllers/home.rs +++ b/src/web/controllers/home.rs @@ -1,11 +1,6 @@ use crate::web::routes::AppState; use askama_axum::Template; -use axum::{ - extract::{Path, State}, - http::HeaderMap, - response::IntoResponse, - Json, -}; +use axum::{extract::State, http::HeaderMap, response::IntoResponse}; use eyre::Result; #[derive(Template)] @@ -15,5 +10,8 @@ struct HomeTemplate { } pub async fn home(State(state): State) -> impl IntoResponse { - HomeTemplate { alert: state.alert }.into_response() + HomeTemplate { + alert: state.alert.lock().unwrap().clone(), + } + .into_response() } diff --git a/src/web/controllers/queries.rs b/src/web/controllers/queries.rs index f874c29..c768006 100644 --- a/src/web/controllers/queries.rs +++ b/src/web/controllers/queries.rs @@ -43,7 +43,7 @@ pub async fn show(State(state): State, query: Query) -> imp }; QueryTemplate { - alert: state.alert, + alert: state.alert.lock().unwrap().clone(), query_name, query_data: rows, } diff --git a/src/web/routes.rs b/src/web/routes.rs index ecbae80..97d36c6 100644 --- a/src/web/routes.rs +++ b/src/web/routes.rs @@ -1,10 +1,5 @@ -use axum::{ - body::Body, - http::{HeaderMap, HeaderValue, Response, StatusCode}, - response::IntoResponse, - routing::{delete, get, post, put}, - Router, -}; +use axum::{routing::get, Router}; +use std::sync::{Arc, Mutex}; use tower_http::trace::{self, TraceLayer}; use tracing::Level; @@ -15,11 +10,14 @@ use tower_http::services::ServeDir; #[derive(Clone, Debug)] pub struct AppState { pub pool: PgPool, - pub alert: Option, + pub alert: Arc>>, } pub async fn app(pool: PgPool) -> Router { - let state = AppState { pool, alert: None }; + let state = AppState { + pool, + alert: Arc::new(Mutex::new(None)), + }; tracing_subscriber::fmt::init(); diff --git a/templates/_query_selector.html b/templates/_query_selector.html index 07e7004..e682c33 100644 --- a/templates/_query_selector.html +++ b/templates/_query_selector.html @@ -30,7 +30,6 @@ - diff --git a/templates/_result.html b/templates/_result.html new file mode 100644 index 0000000..ff6f63a --- /dev/null +++ b/templates/_result.html @@ -0,0 +1,22 @@ + + + {% if query_data.len() > 0 %} + {% for (key, _) in query_data[0].as_object().unwrap() %} + + {% endfor %} + + + {% for row in query_data %} + + {% for (_, value) in row.as_object().unwrap() %} + + {% endfor %} + + {% endfor %} + {% else %} + + + + {% endif %} + +
{{ key }}
{{ value }}
No data
\ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html index f363099..f9fb467 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,8 +5,8 @@ Pg Extras - - + + {% if let Some(alert) = alert %}