The connection isn't working.
Browse files
script.js
CHANGED
|
@@ -1,35 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
async function fetchTables() {
|
| 12 |
try {
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
'Content-Type': 'application/json',
|
| 17 |
-
},
|
| 18 |
-
body: JSON.stringify(dbConfig)
|
| 19 |
-
});
|
| 20 |
-
|
| 21 |
-
if (!response.ok) {
|
| 22 |
-
throw new Error('Failed to fetch tables');
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
return await response.json();
|
| 26 |
} catch (error) {
|
| 27 |
console.error('Error fetching tables:', error);
|
| 28 |
-
showError('Failed to fetch tables.
|
| 29 |
-
return
|
| 30 |
}
|
| 31 |
}
|
| 32 |
-
|
| 33 |
// Function to display tables in UI
|
| 34 |
function displayTables(tables) {
|
| 35 |
const tablesContainer = document.querySelector('.divide-y');
|
|
@@ -62,24 +52,36 @@ function showError(message) {
|
|
| 62 |
errorElement.textContent = message;
|
| 63 |
document.querySelector('.max-w-4xl').prepend(errorElement);
|
| 64 |
}
|
| 65 |
-
|
| 66 |
// Initialize the application
|
| 67 |
document.addEventListener('DOMContentLoaded', async () => {
|
| 68 |
console.log('Application initialized');
|
| 69 |
|
|
|
|
| 70 |
try {
|
| 71 |
const tables = await fetchTables();
|
| 72 |
displayTables(tables);
|
| 73 |
} catch (error) {
|
| 74 |
console.error('Initialization error:', error);
|
| 75 |
-
showError('Failed to initialize application');
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
});
|
| 78 |
// Search functionality
|
| 79 |
document.getElementById('searchInput')?.addEventListener('input', function(e) {
|
| 80 |
const searchTerm = e.target.value.toLowerCase();
|
| 81 |
-
|
|
|
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// Mock database tables for demo
|
| 3 |
+
const mockTables = [
|
| 4 |
+
{ table_name: 'users', table_schema: 'Stores user account information' },
|
| 5 |
+
{ table_name: 'sessions', table_schema: 'User login sessions' },
|
| 6 |
+
{ table_name: 'experiments', table_schema: 'Research experiment data' },
|
| 7 |
+
{ table_name: 'participants', table_schema: 'Study participants information' },
|
| 8 |
+
{ table_name: 'results', table_schema: 'Experiment results data' }
|
| 9 |
+
];
|
| 10 |
+
|
| 11 |
+
// Function to fetch tables from mock data
|
| 12 |
async function fetchTables() {
|
| 13 |
try {
|
| 14 |
+
// Simulate network delay
|
| 15 |
+
await new Promise(resolve => setTimeout(resolve, 800));
|
| 16 |
+
return mockTables;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
} catch (error) {
|
| 18 |
console.error('Error fetching tables:', error);
|
| 19 |
+
showError('Failed to fetch tables. Using demo data.');
|
| 20 |
+
return mockTables.slice(0, 3); // Return partial data on error
|
| 21 |
}
|
| 22 |
}
|
|
|
|
| 23 |
// Function to display tables in UI
|
| 24 |
function displayTables(tables) {
|
| 25 |
const tablesContainer = document.querySelector('.divide-y');
|
|
|
|
| 52 |
errorElement.textContent = message;
|
| 53 |
document.querySelector('.max-w-4xl').prepend(errorElement);
|
| 54 |
}
|
|
|
|
| 55 |
// Initialize the application
|
| 56 |
document.addEventListener('DOMContentLoaded', async () => {
|
| 57 |
console.log('Application initialized');
|
| 58 |
|
| 59 |
+
const loading = document.getElementById('loading');
|
| 60 |
try {
|
| 61 |
const tables = await fetchTables();
|
| 62 |
displayTables(tables);
|
| 63 |
} catch (error) {
|
| 64 |
console.error('Initialization error:', error);
|
| 65 |
+
showError('Failed to initialize application. Using demo data.');
|
| 66 |
+
displayTables(mockTables);
|
| 67 |
+
} finally {
|
| 68 |
+
if (loading) loading.style.display = 'none';
|
| 69 |
}
|
| 70 |
});
|
| 71 |
// Search functionality
|
| 72 |
document.getElementById('searchInput')?.addEventListener('input', function(e) {
|
| 73 |
const searchTerm = e.target.value.toLowerCase();
|
| 74 |
+
const tablesContainer = document.querySelector('.divide-y');
|
| 75 |
+
if (!tablesContainer) return;
|
| 76 |
|
| 77 |
+
const allTables = tablesContainer.querySelectorAll('div.p-6');
|
| 78 |
+
allTables.forEach(table => {
|
| 79 |
+
const name = table.querySelector('h3').textContent.toLowerCase();
|
| 80 |
+
const desc = table.querySelector('p').textContent.toLowerCase();
|
| 81 |
+
if (name.includes(searchTerm) || desc.includes(searchTerm)) {
|
| 82 |
+
table.style.display = 'block';
|
| 83 |
+
} else {
|
| 84 |
+
table.style.display = 'none';
|
| 85 |
+
}
|
| 86 |
+
});
|
| 87 |
+
});
|