Spaces:
Sleeping
Sleeping
File size: 9,483 Bytes
0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 23af55d d72816f 23af55d d72816f 23af55d d72816f 23af55d d72816f 23af55d d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 23af55d 0c30f00 d72816f 23af55d d72816f 23af55d d72816f 23af55d d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 23af55d d72816f 23af55d 0c30f00 d72816f b49d66f d72816f f21967a d72816f f21967a d72816f b49d66f 7296d4a d72816f 7296d4a 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 0c30f00 d72816f 23af55d d72816f 0c30f00 b49d66f d72816f b49d66f d72816f b49d66f d72816f b49d66f d72816f b49d66f d72816f 7296d4a d72816f 7296d4a d72816f b49d66f d72816f 0c30f00 651af0e |
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Database Viewer</title>
<style>
:root {
--primary-color: #6366f1;
--primary-hover: #4f46e5;
--bg-color: #f3f4f6;
--sidebar-bg: #ffffff;
--text-color: #1f2937;
--border-color: #e5e7eb;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
background-color: var(--bg-color);
color: var(--text-color);
display: flex;
height: 100vh;
overflow: hidden;
}
/* Sidebar */
#sidebar {
width: 250px;
background-color: var(--sidebar-bg);
border-right: 1px solid var(--border-color);
display: flex;
flex-direction: column;
padding: 1rem;
overflow-y: auto;
}
#sidebar h2 {
font-size: 1.25rem;
margin-bottom: 1rem;
color: var(--primary-color);
}
.table-list {
list-style: none;
padding: 0;
margin: 0;
}
.table-item {
padding: 0.75rem 1rem;
margin-bottom: 0.5rem;
border-radius: 0.375rem;
cursor: pointer;
transition: background-color 0.2s;
font-weight: 500;
}
.table-item:hover {
background-color: #eff6ff;
color: var(--primary-color);
}
.table-item.active {
background-color: var(--primary-color);
color: white;
}
/* Main Content */
#main-content {
flex: 1;
display: flex;
flex-direction: column;
padding: 1.5rem;
overflow: hidden;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
h1 {
font-size: 1.5rem;
margin: 0;
}
/* Table Container */
#table-container {
flex: 1;
background: white;
border-radius: 0.5rem;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
overflow: auto;
position: relative;
}
table {
width: 100%;
border-collapse: collapse;
white-space: nowrap;
}
th, td {
padding: 0.75rem 1rem;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
th {
background-color: #f9fafb;
font-weight: 600;
position: sticky;
top: 0;
z-index: 10;
}
tr:hover {
background-color: #f9fafb;
}
/* Pagination */
#pagination {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
padding: 0.5rem;
background: white;
border-radius: 0.5rem;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}
.btn {
padding: 0.5rem 1rem;
border: 1px solid var(--border-color);
background-color: white;
border-radius: 0.375rem;
cursor: pointer;
transition: all 0.2s;
}
.btn:hover:not(:disabled) {
background-color: #f3f4f6;
border-color: #d1d5db;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
#page-info {
font-size: 0.875rem;
color: #6b7280;
}
/* Loading & Empty States */
.loading, .empty {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
color: #6b7280;
font-size: 1.125rem;
}
</style>
</head>
<body>
<div id="sidebar">
<h2>Tables</h2>
<ul id="table-list" class="table-list">
<!-- Tables will be injected here -->
</ul>
</div>
<div id="main-content">
<header>
<h1 id="current-table-name">Select a Table</h1>
<div id="pagination-controls" style="display: none;">
<!-- Pagination controls -->
</div>
</header>
<div id="table-container">
<div class="empty">Select a table from the sidebar to view data.</div>
</div>
<div id="pagination" style="display: none;">
<button id="prev-btn" class="btn">Previous</button>
<span id="page-info">Page 1 of 1</span>
<button id="next-btn" class="btn">Next</button>
</div>
</div>
<script>
const API_BASE = '/api/schema';
let currentTable = null;
let currentPage = 1;
let totalPages = 1;
const perPage = 50;
// DOM Elements
const tableListEl = document.getElementById('table-list');
const currentTableNameEl = document.getElementById('current-table-name');
const tableContainerEl = document.getElementById('table-container');
const paginationEl = document.getElementById('pagination');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const pageInfoEl = document.getElementById('page-info');
// Initialize
async function init() {
try {
const response = await fetch(`${API_BASE}/tables`);
const tables = await response.json();
renderTableList(tables);
} catch (error) {
console.error('Failed to fetch tables:', error);
tableContainerEl.innerHTML = '<div class="empty">Error loading tables.</div>';
}
}
function renderTableList(tables) {
tableListEl.innerHTML = tables.map(table => `
<li class="table-item" onclick="loadTable('${table}')">${table}</li>
`).join('');
}
async function loadTable(tableName, page = 1) {
currentTable = tableName;
currentPage = page;
// Update UI
document.querySelectorAll('.table-item').forEach(el => {
el.classList.toggle('active', el.textContent === tableName);
});
currentTableNameEl.textContent = tableName;
tableContainerEl.innerHTML = '<div class="loading">Loading...</div>';
paginationEl.style.display = 'none';
try {
const response = await fetch(`${API_BASE}/table/${tableName}?page=${page}&per_page=${perPage}`);
const data = await response.json();
renderTableData(data);
} catch (error) {
console.error(`Failed to fetch data for ${tableName}:`, error);
tableContainerEl.innerHTML = `<div class="empty">Error loading data for ${tableName}.</div>`;
}
}
function renderTableData(data) {
if (!data.data || data.data.length === 0) {
tableContainerEl.innerHTML = '<div class="empty">No data found in this table.</div>';
paginationEl.style.display = 'none';
return;
}
// Calculate pagination
totalPages = Math.ceil(data.total / data.per_page);
updatePaginationUI(data.total);
// Build Table
const columns = data.columns;
const rows = data.data;
let html = '<table><thead><tr>';
columns.forEach(col => {
html += `<th>${col}</th>`;
});
html += '</tr></thead><tbody>';
rows.forEach(row => {
html += '<tr>';
columns.forEach(col => {
let val = row[col];
if (val === null) val = '<span style="color: #9ca3af;">null</span>';
else if (typeof val === 'object') val = JSON.stringify(val);
html += `<td>${val}</td>`;
});
html += '</tr>';
});
html += '</tbody></table>';
tableContainerEl.innerHTML = html;
}
function updatePaginationUI(totalItems) {
if (totalItems === 0) {
paginationEl.style.display = 'none';
return;
}
paginationEl.style.display = 'flex';
pageInfoEl.textContent = `Page ${currentPage} of ${totalPages} (${totalItems} items)`;
prevBtn.disabled = currentPage <= 1;
nextBtn.disabled = currentPage >= totalPages;
}
// Event Listeners
prevBtn.addEventListener('click', () => {
if (currentPage > 1) loadTable(currentTable, currentPage - 1);
});
nextBtn.addEventListener('click', () => {
if (currentPage < totalPages) loadTable(currentTable, currentPage + 1);
});
// Start
init();
</script>
</body>
</html> |