rwda ui implementation

This commit is contained in:
Timur Gordon
2025-04-22 15:36:40 +02:00
parent 34594b95fa
commit 6060831f61
15 changed files with 2690 additions and 27 deletions

View File

@@ -122,37 +122,57 @@ pub fn render_template(
template_name: &str,
ctx: &Context,
) -> Result<HttpResponse, Error> {
println!("DEBUG: Attempting to render template: {}", template_name);
// Print all context keys for debugging
let mut keys = Vec::new();
for (key, _) in ctx.clone().into_json().as_object().unwrap().iter() {
keys.push(key.clone());
}
println!("DEBUG: Context keys: {:?}", keys);
match tmpl.render(template_name, ctx) {
Ok(content) => Ok(HttpResponse::Ok().content_type("text/html").body(content)),
Ok(content) => {
println!("DEBUG: Successfully rendered template: {}", template_name);
Ok(HttpResponse::Ok().content_type("text/html").body(content))
},
Err(e) => {
// Log the error
println!("DEBUG: Template rendering error for {}: {}", template_name, e);
log::error!("Template rendering error: {}", e);
log::error!("Error details: {:?}", e);
log::error!("Context: {:?}", ctx);
// Create a context for the error template
let mut error_ctx = Context::new();
error_ctx.insert("error", &format!("Template rendering error: {}", e));
error_ctx.insert("error_details", &format!("{:?}", e));
error_ctx.insert("error_location", &template_name);
// Create a simple error response instead of trying to render the error template
let error_html = format!(
r#"<!DOCTYPE html>
<html>
<head>
<title>Template Error</title>
<style>
body {{ font-family: Arial, sans-serif; margin: 40px; }}
.error-container {{ border: 1px solid #dc3545; padding: 20px; border-radius: 5px; }}
h1 {{ color: #dc3545; }}
pre {{ background-color: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; }}
</style>
</head>
<body>
<div class="error-container">
<h1>Template Rendering Error</h1>
<p><strong>Template:</strong> {}</p>
<p><strong>Error:</strong></p>
<pre>{}</pre>
<p><a href="/">Return to Home</a></p>
</div>
</body>
</html>"#,
template_name,
e
);
// Try to render the error template
match tmpl.render("error.html", &error_ctx) {
Ok(error_page) => {
// Return the error page with a 500 status code
Ok(HttpResponse::InternalServerError()
.content_type("text/html")
.body(error_page))
}
Err(render_err) => {
// If we can't render the error template, log it and return a basic error
log::error!("Error rendering error template: {}", render_err);
Err(error::ErrorInternalServerError(format!(
"Template rendering error: {}. Failed to render error page: {}",
e, render_err
)))
}
}
println!("DEBUG: Returning simple error page");
Ok(HttpResponse::InternalServerError()
.content_type("text/html")
.body(error_html))
}
}
}