The only table in this is 'documents', but its not seeming to connect.
Browse files- api/tables.json +10 -0
- components/documents-table.js +52 -0
- index.html +8 -7
- script.js +11 -14
api/tables.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```json
|
| 2 |
+
{
|
| 3 |
+
"tables": [
|
| 4 |
+
{
|
| 5 |
+
"table_name": "documents",
|
| 6 |
+
"table_schema": "Contains all document records with metadata and content"
|
| 7 |
+
}
|
| 8 |
+
]
|
| 9 |
+
}
|
| 10 |
+
```
|
components/documents-table.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class DocumentsTable extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
table {
|
| 7 |
+
width: 100%;
|
| 8 |
+
border-collapse: collapse;
|
| 9 |
+
}
|
| 10 |
+
th, td {
|
| 11 |
+
padding: 12px 16px;
|
| 12 |
+
text-align: left;
|
| 13 |
+
border-bottom: 1px solid #e5e7eb;
|
| 14 |
+
}
|
| 15 |
+
th {
|
| 16 |
+
background-color: #f9fafb;
|
| 17 |
+
font-weight: 600;
|
| 18 |
+
color: #374151;
|
| 19 |
+
}
|
| 20 |
+
tr:hover {
|
| 21 |
+
background-color: #f3f4f6;
|
| 22 |
+
}
|
| 23 |
+
</style>
|
| 24 |
+
<table>
|
| 25 |
+
<thead>
|
| 26 |
+
<tr>
|
| 27 |
+
<th>ID</th>
|
| 28 |
+
<th>Title</th>
|
| 29 |
+
<th>Type</th>
|
| 30 |
+
<th>Created</th>
|
| 31 |
+
</tr>
|
| 32 |
+
</thead>
|
| 33 |
+
<tbody>
|
| 34 |
+
<tr>
|
| 35 |
+
<td>1</td>
|
| 36 |
+
<td>Research Paper 1</td>
|
| 37 |
+
<td>PDF</td>
|
| 38 |
+
<td>2023-05-15</td>
|
| 39 |
+
</tr>
|
| 40 |
+
<tr>
|
| 41 |
+
<td>2</td>
|
| 42 |
+
<td>Study Notes</td>
|
| 43 |
+
<td>DOCX</td>
|
| 44 |
+
<td>2023-06-22</td>
|
| 45 |
+
</tr>
|
| 46 |
+
</tbody>
|
| 47 |
+
</table>
|
| 48 |
+
`;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
customElements.define('documents-table', DocumentsTable);
|
index.html
CHANGED
|
@@ -68,15 +68,15 @@
|
|
| 68 |
|
| 69 |
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
| 70 |
<div class="px-6 py-4 border-b border-gray-200 bg-gray-50">
|
| 71 |
-
|
| 72 |
-
|
| 73 |
<div class="divide-y divide-gray-200">
|
| 74 |
-
<!--
|
| 75 |
-
|
| 76 |
<div id="loading" class="p-6 text-center text-gray-500">
|
| 77 |
<i data-feather="loader" class="animate-spin inline-block"></i>
|
| 78 |
-
<span class="ml-2">Loading
|
| 79 |
-
|
| 80 |
</div>
|
| 81 |
</div>
|
| 82 |
</div>
|
|
@@ -93,6 +93,7 @@
|
|
| 93 |
});
|
| 94 |
</script>
|
| 95 |
<script src="script.js"></script>
|
| 96 |
-
<script src="
|
|
|
|
| 97 |
</body>
|
| 98 |
</html>
|
|
|
|
| 68 |
|
| 69 |
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
| 70 |
<div class="px-6 py-4 border-b border-gray-200 bg-gray-50">
|
| 71 |
+
<h2 class="text-lg font-semibold text-gray-800">Documents Table</h2>
|
| 72 |
+
</div>
|
| 73 |
<div class="divide-y divide-gray-200">
|
| 74 |
+
<!-- Documents table will be dynamically inserted here -->
|
| 75 |
+
</div>
|
| 76 |
<div id="loading" class="p-6 text-center text-gray-500">
|
| 77 |
<i data-feather="loader" class="animate-spin inline-block"></i>
|
| 78 |
+
<span class="ml-2">Loading documents...</span>
|
| 79 |
+
</div>
|
| 80 |
</div>
|
| 81 |
</div>
|
| 82 |
</div>
|
|
|
|
| 93 |
});
|
| 94 |
</script>
|
| 95 |
<script src="script.js"></script>
|
| 96 |
+
<script src="components/documents-table.js"></script>
|
| 97 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 98 |
</body>
|
| 99 |
</html>
|
script.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
|
| 2 |
-
//
|
| 3 |
-
const
|
| 4 |
-
{ table_name: '
|
| 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 |
-
//
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
} catch (error) {
|
| 18 |
console.error('Error fetching tables:', error);
|
| 19 |
-
showError('Failed to fetch tables. Using
|
| 20 |
-
return
|
| 21 |
}
|
| 22 |
}
|
| 23 |
// Function to display tables in UI
|
|
|
|
| 1 |
|
| 2 |
+
// Database tables
|
| 3 |
+
const dbTables = [
|
| 4 |
+
{ table_name: 'documents', table_schema: 'Stores all document records' }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
];
|
| 6 |
+
// Function to fetch tables
|
|
|
|
| 7 |
async function fetchTables() {
|
| 8 |
try {
|
| 9 |
+
// Replace with your actual database connection logic
|
| 10 |
+
const response = await fetch('/api/tables');
|
| 11 |
+
if (!response.ok) throw new Error('Network response was not ok');
|
| 12 |
+
const data = await response.json();
|
| 13 |
+
return data.tables || dbTables; // Fallback to default if no tables returned
|
| 14 |
} catch (error) {
|
| 15 |
console.error('Error fetching tables:', error);
|
| 16 |
+
showError('Failed to fetch tables. Using default table.');
|
| 17 |
+
return dbTables;
|
| 18 |
}
|
| 19 |
}
|
| 20 |
// Function to display tables in UI
|