feat: add unified styling with style.css route

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-29 12:06:32 -03:00
parent e056678799
commit 47fd796d50

View File

@@ -34,6 +34,7 @@ pub fn add_routes(app: axum::Router<AppState>) -> axum::Router<AppState> {
app
.route("/", axum::routing::get(list_items))
.route("/item/{item_id}", axum::routing::get(show_item))
.route("/style.css", axum::routing::get(style_css))
}
async fn list_items(
@@ -87,12 +88,7 @@ fn build_item_list(conn: &Connection, params: &ListQueryParams, columns: &[Colum
let mut html = String::new();
html.push_str("<html><head><title>Items</title>");
html.push_str("<style>");
html.push_str("table { border-collapse: collapse; width: 100%; }");
html.push_str("th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }");
html.push_str("th { background-color: #f2f2f2; }");
html.push_str("tr:nth-child(even) { background-color: #f9f9f9; }");
html.push_str("</style>");
html.push_str("<link rel=\"stylesheet\" href=\"/style.css\">");
html.push_str("</head><body>");
html.push_str("<h1>Items</h1>");
html.push_str("<p><a href=\"/swagger\">API Documentation</a></p>");
@@ -191,6 +187,55 @@ fn build_item_list(conn: &Connection, params: &ListQueryParams, columns: &[Colum
Ok(html)
}
async fn style_css() -> &'static str {
r#"
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
h1, h2 {
color: #333;
}
table {
border-collapse: collapse;
width: 100%;
background-color: white;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #f2f2f2;
position: sticky;
top: 0;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
tr:hover {
background-color: #f1f1f1;
}
a {
color: #0066cc;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.pagination {
margin: 20px 0;
}
.actions {
white-space: nowrap;
}
"#
}
async fn show_item(
State(state): State<AppState>,
Path(id): Path<i64>,
@@ -215,7 +260,9 @@ fn build_item_details(conn: &Connection, id: i64) -> Result<String> {
let metas = db::get_item_meta(conn, &item)?;
let mut html = String::new();
html.push_str("<html><head><title>Item Details</title></head><body>");
html.push_str("<html><head><title>Item Details</title>");
html.push_str("<link rel=\"stylesheet\" href=\"/style.css\">");
html.push_str("</head><body>");
html.push_str(&format!("<h1>Item #{}</h1>", id));
html.push_str("<table>");
html.push_str(&format!("<tr><td>ID:</td><td>{}</td></tr>", item.id.unwrap_or(0)));