-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_report_template.html
More file actions
128 lines (115 loc) · 6.43 KB
/
database_report_template.html
File metadata and controls
128 lines (115 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Database Panel</title>
<style>
body {{font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.6; color: #333; background-color: #f4f4f4; margin: 0; padding: 20px;}}
h1, h2 {{color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px;}}
.container {{max-width: 1200px; margin: auto; background: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0,0,0,0.1); border-radius: 8px;}}
table {{width: 100%; border-collapse: collapse; margin-bottom: 30px;}}
th, td {{padding: 12px; border: 1px solid #ddd; text-align: left; word-break: break-word;}}
th {{background-color: #3498db; color: white;}}
tr:nth-child(even) {{background-color: #f2f2f2;}}
.footer {{text-align: center; margin-top: 30px; color: #777; font-size: 0.9em;}}
.table-wrapper {{overflow-x: auto;}}
.delete-btn {{background-color: #e74c3c; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer;}}
.delete-btn:hover {{background-color: #c0392b;}}
.admin-section {{background-color: #ecf0f1; padding: 20px; border-radius: 8px; margin-bottom: 30px;}}
.admin-section textarea, .admin-section input, .admin-section select {{width: calc(100% - 24px); padding: 10px; margin-bottom: 10px; border-radius: 4px; border: 1px solid #bdc3c7;}}
.admin-section button {{background-color: #2ecc71; color: white; border: none; padding: 10px 15px; border-radius: 4px; cursor: pointer; font-size: 16px;}}
.admin-section button:hover {{background-color: #27ae60;}}
#status-message {{margin-top: 15px; padding: 10px; border-radius: 4px; display: none;}}
.status-success {{background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb;}}
.status-error {{background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb;}}
</style>
</head>
<body>
<div class="container">
<h1>Admin Database Panel</h1>
<p class="footer">Generated on: {generation_date}</p>
<div class="admin-section">
<h2>⚙️ Database Control</h2>
<label for="db-selector">Select Database:</label>
<select id="db-selector" onchange="switchDatabase()">
{db_options}
</select>
</div>
<div id="add-law-form" class="admin-section">
<h2>➕ Add New Law to '{current_db_name}'</h2>
<form onsubmit="addLaw(event)">
<textarea id="legal-text" rows="10" placeholder="Paste the full legal text here..."></textarea>
<input type="text" id="category" placeholder="Enter category (e.g., Civil, Criminal)" value="Manual">
<button type="submit">Add Law to Database</button>
</form>
<div id="status-message"></div>
</div>
{sections}
</div>
<script>
const CURRENT_DB_KEY = new URLSearchParams(window.location.search).get('db_key') || '{default_db_key}';
// Set dropdown to current DB
document.getElementById('db-selector').value = CURRENT_DB_KEY;
function switchDatabase() {{
const selectedDbKey = document.getElementById('db-selector').value;
window.location.href = window.location.pathname + '?db_key=' + selectedDbKey;
}}
async function addLaw(event) {{
event.preventDefault();
const legalText = document.getElementById('legal-text').value;
const category = document.getElementById('category').value;
const statusMessage = document.getElementById('status-message');
statusMessage.style.display = 'block';
statusMessage.className = '';
statusMessage.textContent = 'Processing...';
try {{
const response = await fetch('/admin/add_law', {{
method: 'POST',
headers: {{ 'Content-Type': 'application/json' }},
body: JSON.stringify({{ legal_text: legalText, category: category, db_key: CURRENT_DB_KEY }})
}});
if (response.ok) {{
statusMessage.className = 'status-success';
statusMessage.textContent = 'Law added successfully! The page will now reload.';
document.getElementById('legal-text').value = '';
document.getElementById('category').value = 'Manual';
setTimeout(() => window.location.reload(), 2000);
}} else {{
const error = await response.json();
statusMessage.className = 'status-error';
statusMessage.textContent = `Error: ${{error.detail || 'Unknown error'}}`;
}}
}} catch (e) {{
statusMessage.className = 'status-error';
statusMessage.textContent = 'A network error occurred. Is the admin server running at http://localhost:8001?';
}}
}}
async function deleteLaw(lawId) {{
if (!confirm(`Are you sure you want to delete law with ID: ${{lawId}}?`)) {{
return;
}}
const statusMessage = document.getElementById('status-message');
statusMessage.style.display = 'block';
statusMessage.textContent = 'Deleting...';
try {{
const response = await fetch(`/admin/delete_law/${{lawId}}?db_key=${{CURRENT_DB_KEY}}`, {{
method: 'DELETE'
}});
if (response.ok) {{
statusMessage.className = 'status-success';
statusMessage.textContent = 'Law deleted successfully! The page will now reload.';
setTimeout(() => window.location.reload(), 2000);
}} else {{
const error = await response.json();
statusMessage.className = 'status-error';
statusMessage.textContent = `Error: ${{error.detail || 'Unknown error'}}`;
}}
}} catch (e) {{
statusMessage.className = 'status-error';
statusMessage.textContent = 'A network error occurred. Is the admin server running at http://localhost:8001?';
}}
}}
</script>
</body>
</html>