Skip to content

Commit

Permalink
css
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Nov 21, 2024
1 parent 3529cdb commit bcc6d34
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 43 deletions.
12 changes: 5 additions & 7 deletions src/web/controllers/home.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -15,5 +10,8 @@ struct HomeTemplate {
}

pub async fn home(State(state): State<AppState>) -> impl IntoResponse {
HomeTemplate { alert: state.alert }.into_response()
HomeTemplate {
alert: state.alert.lock().unwrap().clone(),
}
.into_response()
}
2 changes: 1 addition & 1 deletion src/web/controllers/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn show(State(state): State<AppState>, query: Query<QueryName>) -> imp
};

QueryTemplate {
alert: state.alert,
alert: state.alert.lock().unwrap().clone(),
query_name,
query_data: rows,
}
Expand Down
16 changes: 7 additions & 9 deletions src/web/routes.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,11 +10,14 @@ use tower_http::services::ServeDir;
#[derive(Clone, Debug)]
pub struct AppState {
pub pool: PgPool,
pub alert: Option<String>,
pub alert: Arc<Mutex<Option<String>>>,
}

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();

Expand Down
1 change: 0 additions & 1 deletion templates/_query_selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<option value="unused_indexes">unused_indexes</option>
<option value="duplicate_indexes">duplicate_indexes</option>
<option value="vacuum_stats">vacuum_stats</option>
<option value="kill_pid">kill_pid</option>
<option value="buffercache_stats">buffercache_stats</option>
<option value="buffercache_usage">buffercache_usage</option>
<option value="ssl_used">ssl_used</option>
Expand Down
22 changes: 22 additions & 0 deletions templates/_result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table class="w-full font-mono border-collapse border my-5">
<thead class="bg-gray-300">
{% if query_data.len() > 0 %}
{% for (key, _) in query_data[0].as_object().unwrap() %}
<th class="p-2 border text-left">{{ key }}</th>
{% endfor %}
</thead>
<tbody>
{% for row in query_data %}
<tr class="hover:bg-gray-400 hover:text-white">
{% for (_, value) in row.as_object().unwrap() %}
<td class="p-1 border">{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
{% else %}
<tr>
<td>No data</td>
</tr>
{% endif %}
</tbody>
</table>
4 changes: 2 additions & 2 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title>Pg Extras</title>
</head>

<body>
<!-- <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> -->
<body class="p-5 text-xs">
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="/assets/styles.css">
{% if let Some(alert) = alert %}
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4" role="alert">
Expand Down
27 changes: 4 additions & 23 deletions templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,11 @@

{% include "_query_selector.html" %}

<h2>{{ query_name }}</h1>
<h1 class="font-bold text-xl my-5">
{{ query_name }}
</h1>

<table>
<thead>
{% if query_data.len() > 0 %}
<tr>
{% for (key, _) in query_data[0].as_object().unwrap() %}
<th>{{ key }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in query_data %}
<tr>
{% for (_, value) in row.as_object().unwrap() %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
{% else %}
<tr><td>No data</td></tr>
{% endif %}
</tbody>
</table>
{% include "_result.html" %}

{% endblock %}

0 comments on commit bcc6d34

Please sign in to comment.