chore: update backends output for config files changes
This commit is contained in:
parent
30b5b4797e
commit
3d9c28f7f7
@ -927,6 +927,159 @@ async fn submit_field_handler(
|
||||
(StatusCode::OK, headers, Json(json!({"success": true})))
|
||||
}
|
||||
|
||||
/// Render success HTML for normal (non-roundtrip) mode
|
||||
#[cfg(feature = "web")]
|
||||
fn render_success_html(results: &HashMap<String, Value>) -> String {
|
||||
let field_count = results.len();
|
||||
|
||||
let fields_html = if field_count > 0 {
|
||||
let mut html = String::from("<div style='margin: 20px 0;'>");
|
||||
html.push_str("<h3 style='margin: 0 0 10px 0;'>📋 Form Results:</h3>");
|
||||
html.push_str("<div style='background: #1e1e1e; padding: 15px; border-radius: 4px; font-family: monospace; max-height: 400px; overflow-y: auto;'>");
|
||||
|
||||
let mut sorted_fields: Vec<_> = results.iter().collect();
|
||||
sorted_fields.sort_by_key(|(k, _)| k.as_str());
|
||||
|
||||
for (field_name, value) in sorted_fields {
|
||||
let value_str = match value {
|
||||
Value::String(s) => s.clone(),
|
||||
Value::Number(n) => n.to_string(),
|
||||
Value::Bool(b) => b.to_string(),
|
||||
Value::Array(arr) => {
|
||||
let items: Vec<String> = arr
|
||||
.iter()
|
||||
.map(|v| match v {
|
||||
Value::String(s) => s.clone(),
|
||||
other => other.to_string(),
|
||||
})
|
||||
.collect();
|
||||
format!("[{}]", items.join(", "))
|
||||
}
|
||||
Value::Null => "(empty)".to_string(),
|
||||
Value::Object(_) => "{...}".to_string(),
|
||||
};
|
||||
|
||||
html.push_str(&format!(
|
||||
r#"<div style="margin: 8px 0; padding: 8px; background: #2d2d30; border-radius: 3px;">
|
||||
<div style="color: #dcdcaa; font-weight: bold;">{}</div>
|
||||
<div style="margin-left: 15px; color: #4ec9b0; margin-top: 4px;">{}</div>
|
||||
</div>"#,
|
||||
html_escape(field_name),
|
||||
html_escape(&value_str)
|
||||
));
|
||||
}
|
||||
|
||||
html.push_str("</div></div>");
|
||||
html
|
||||
} else {
|
||||
String::from("<p style='color: #808080;'>No fields submitted</p>")
|
||||
};
|
||||
|
||||
format!(
|
||||
r#"<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Form Submitted Successfully</title>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
body {{
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: #1e1e1e;
|
||||
color: #d4d4d4;
|
||||
margin: 0;
|
||||
padding: 40px 20px;
|
||||
}}
|
||||
.container {{
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
background: #252526;
|
||||
padding: 40px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
|
||||
}}
|
||||
h1 {{
|
||||
color: #4ec9b0;
|
||||
margin: 0 0 10px 0;
|
||||
}}
|
||||
.header {{
|
||||
border-bottom: 2px solid #007acc;
|
||||
padding-bottom: 20px;
|
||||
margin-bottom: 30px;
|
||||
}}
|
||||
.stat-row {{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
background: #1e1e1e;
|
||||
border-radius: 4px;
|
||||
}}
|
||||
.actions {{
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #3e3e42;
|
||||
}}
|
||||
.btn {{
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
margin: 5px;
|
||||
background: #007acc;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}}
|
||||
.btn:hover {{
|
||||
background: #005a9e;
|
||||
}}
|
||||
.auto-close {{
|
||||
color: #808080;
|
||||
font-size: 12px;
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
}}
|
||||
</style>
|
||||
<script>
|
||||
let countdown = 30;
|
||||
function updateCountdown() {{
|
||||
document.getElementById('countdown').textContent = countdown;
|
||||
countdown--;
|
||||
if (countdown < 0) {{
|
||||
window.close();
|
||||
}}
|
||||
}}
|
||||
setInterval(updateCountdown, 1000);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>✅ Form Submitted Successfully!</h1>
|
||||
</div>
|
||||
|
||||
<div class="stat-row">
|
||||
<span>📊 <strong>Fields Submitted:</strong></span>
|
||||
<span>{} fields</span>
|
||||
</div>
|
||||
|
||||
{}
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn" onclick="window.location.reload()">🔄 Submit Another</button>
|
||||
<button class="btn" onclick="window.close()">❌ Close</button>
|
||||
</div>
|
||||
|
||||
<div class="auto-close">
|
||||
⏱️ This window will auto-close in <span id="countdown">30</span> seconds...
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>"#,
|
||||
field_count, fields_html
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
async fn submit_complete_form_handler(
|
||||
State(state): State<Arc<WebFormState>>,
|
||||
@ -995,17 +1148,16 @@ async fn submit_complete_form_handler(
|
||||
.body(Body::from(html))
|
||||
.unwrap()
|
||||
} else {
|
||||
// Normal mode: return JSON success
|
||||
// Normal mode: return HTML success page
|
||||
use axum::body::Body;
|
||||
use axum::response::Response;
|
||||
|
||||
let html = render_success_html(&all_results);
|
||||
|
||||
Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("HX-Trigger", "formComplete")
|
||||
.body(Body::from(
|
||||
serde_json::to_string(&json!({"success": true})).unwrap(),
|
||||
))
|
||||
.header("Content-Type", "text/html; charset=utf-8")
|
||||
.body(Body::from(html))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,28 +96,25 @@ impl RoundtripSummary {
|
||||
|
||||
output.push('\n');
|
||||
output.push_str("╔════════════════════════════════════════════════════════════╗\n");
|
||||
output.push_str("║ ✅ Configuration Saved Successfully! ║\n");
|
||||
output.push_str("╠════════════════════════════════════════════════════════════╣\n");
|
||||
output.push_str(&format!(
|
||||
"║ 📄 File: {:<48} ║\n",
|
||||
truncate(&self.output_path, 48)
|
||||
));
|
||||
output.push_str(" ✅ Configuration Saved Successfully!\n");
|
||||
output.push_str("════════════════════════════════════════════════════════════\n");
|
||||
output.push_str(&format!(" 📄 File: {}\n", self.output_path));
|
||||
|
||||
if let Some(passed) = self.validation_passed {
|
||||
let status = if passed { "✓ PASSED" } else { "✗ FAILED" };
|
||||
output.push_str(&format!("║ ✓ Validation: {:<43} ║\n", status));
|
||||
output.push_str(&format!(" ✓ Validation: {}\n", status));
|
||||
}
|
||||
|
||||
output.push_str(&format!(
|
||||
"║ 📊 Fields: {}/{} changed, {} unchanged{:<18} ║\n",
|
||||
self.changed_fields, self.total_fields, self.unchanged_fields, ""
|
||||
" 📊 Fields: {}/{} changed, {} unchanged\n",
|
||||
self.changed_fields, self.total_fields, self.unchanged_fields
|
||||
));
|
||||
|
||||
output.push_str("╠════════════════════════════════════════════════════════════╣\n");
|
||||
output.push_str("════════════════════════════════════════════════════════════\n");
|
||||
|
||||
// Show changes
|
||||
if self.changed_fields > 0 {
|
||||
output.push_str("║ 📋 What Changed: ║\n");
|
||||
output.push_str(" 📋 What Changed:\n");
|
||||
|
||||
let mut shown = 0;
|
||||
for change in &self.changes {
|
||||
@ -128,30 +125,29 @@ impl RoundtripSummary {
|
||||
if !verbose && shown >= 10 {
|
||||
let remaining = self.changed_fields - shown;
|
||||
output.push_str(&format!(
|
||||
"║ ... and {} more changes (use --verbose to see all){:<4} ║\n",
|
||||
remaining, ""
|
||||
" ... and {} more changes (use --verbose to see all)\n",
|
||||
remaining
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
let line = format!(
|
||||
" ├─ {}: {} → {}",
|
||||
output.push_str(&format!(
|
||||
" ├─ {}: {} → {}\n",
|
||||
change.field_name,
|
||||
truncate(&change.old_value, 15),
|
||||
truncate(&change.new_value, 15)
|
||||
);
|
||||
output.push_str(&format!("║ {:<58} ║\n", truncate(&line, 58)));
|
||||
truncate(&change.old_value, 20),
|
||||
truncate(&change.new_value, 20)
|
||||
));
|
||||
shown += 1;
|
||||
}
|
||||
} else {
|
||||
output.push_str("║ 📋 No changes made ║\n");
|
||||
output.push_str(" 📋 No changes made\n");
|
||||
}
|
||||
|
||||
output.push_str("╠════════════════════════════════════════════════════════════╣\n");
|
||||
output.push_str("║ 💡 Next Steps: ║\n");
|
||||
output.push_str("║ • Review: cat config.ncl ║\n");
|
||||
output.push_str("║ • Apply CI tools: ./setup-ci.sh ║\n");
|
||||
output.push_str("║ • Re-configure: ./ci-configure.sh ║\n");
|
||||
output.push_str("════════════════════════════════════════════════════════════\n");
|
||||
output.push_str(" 💡 Next Steps:\n");
|
||||
output.push_str(" • Review: cat config.ncl\n");
|
||||
output.push_str(" • Apply CI tools: ./setup-ci.sh\n");
|
||||
output.push_str(" • Re-configure: ./ci-configure.sh\n");
|
||||
output.push_str("╚════════════════════════════════════════════════════════════╝\n");
|
||||
output.push('\n');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user