File size: 5,814 Bytes
5b56a40
12721c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fda380d
 
 
 
2d16b75
 
 
 
 
 
 
fda380d
 
 
 
 
 
 
 
 
 
 
 
 
083e043
 
fda380d
 
 
 
 
 
 
 
 
 
083e043
fda380d
 
3fa49b3
083e043
 
 
 
 
 
 
 
 
 
 
fda380d
083e043
 
 
fda380d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
083e043
 
 
 
 
fda380d
083e043
 
 
 
 
 
 
 
 
 
 
12721c7
 
 
 
 
 
083e043
5b56a40
083e043
 
fda380d
083e043
 
fda380d
0ba9d46
5b56a40
 
083e043
 
 
 
 
5b56a40
 
083e043
5b56a40
 
 
 
 
 
 
 
 
 
 
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

// Browser compatibility test
function testCompatibility() {
    const requiredFeatures = {
        'Promise': window.Promise,
        'fetch': window.fetch,
        'Web Components': window.customElements,
        'Shadow DOM': 'attachShadow' in Element.prototype,
        'ES6 Modules': 'noModule' in HTMLScriptElement.prototype,
        'CSS Variables': window.CSS && CSS.supports('color', 'var(--test)')
    };

    const missingFeatures = Object.entries(requiredFeatures)
        .filter(([_, supported]) => !supported)
        .map(([name]) => name);

    if (missingFeatures.length > 0) {
        const warning = document.createElement('div');
        warning.className = 'compatibility-warning';
        warning.innerHTML = `
            <div class="warning-content">
                <h3>⚠️ Compatibility Warning</h3>
                <p>Your browser is missing these required features:</p>
                <ul>${missingFeatures.map(f => `<li>${f}</li>`).join('')}</ul>
                <p>Please update your browser or use a modern alternative like Chrome, Firefox, or Edge.</p>
            </div>
        `;
        document.body.prepend(warning);
        return false;
    }
    return true;
}
// Database tables with more complete default data
const dbTables = [
    { 
        table_name: 'documents', 
        table_schema: 'Stores document metadata including OCR processing info',
        row_count: 50430,
        columns: [
            'id', 'doc_id', 'file_path', 'file_type', 'content',
            'file_hash', 'processing_time_seconds', 'file_size_bytes',
            'ocr_date'
        ]
    },
    { 
        table_name: 'users', 
        table_schema: 'Contains user account information and permissions',
        row_count: 15
    },
    { 
        table_name: 'sessions', 
        table_schema: 'Tracks active user sessions and login history',
        row_count: 28
    }
];
// Function to fetch tables with better error handling
async function fetchTables() {
    try {
        // First try local fallback
        const localResponse = await fetch('/api/tables.json');
        if (localResponse.ok) {
            const data = await localResponse.json();
            return data.tables || dbTables;
        }
        
        // If local fails, use default data
        console.warn('Using default table data - local API not available');
        return dbTables;
    } catch (error) {
        console.error('Table fetch error:', error);
        showError('Using default table data - could not connect to API');
        return dbTables;
    }
}
// Function to display tables in UI
function displayTables(tables) {
    const tablesContainer = document.querySelector('.divide-y');
    if (!tablesContainer) return;

    tablesContainer.innerHTML = '';
    
    tables.forEach(table => {
        const tableElement = document.createElement('div');
        tableElement.className = 'p-6 hover:bg-gray-50 transition cursor-pointer group';
        tableElement.innerHTML = `
            <div class="flex justify-between items-center">
                <div>
                    <div class="flex items-center space-x-3">
                        <div class="bg-indigo-100 p-2 rounded-lg">
                            <i data-feather="database" class="text-indigo-600 w-4 h-4"></i>
                        </div>
                        <div>
                            <h3 class="font-medium text-gray-800">${table.table_name}</h3>
                            <p class="text-sm text-gray-500">${table.table_schema || 'No description available'}</p>
                        </div>
                    </div>
                </div>
                <div class="flex items-center space-x-4">
                    <span class="text-xs bg-gray-100 px-2 py-1 rounded text-gray-600">
                        ${table.row_count || '?'} rows
                    </span>
                    <i data-feather="chevron-right" class="text-gray-400 group-hover:text-indigo-500 transition"></i>
                </div>
            </div>
        `;
        tablesContainer.appendChild(tableElement);
    });
feather.replace();
}

// Function to show error message
function showError(message) {
    const errorElement = document.createElement('div');
    errorElement.className = 'bg-red-50 text-red-600 p-4 rounded-lg mb-6';
    errorElement.textContent = message;
    document.querySelector('.max-w-4xl').prepend(errorElement);
}
// Initialize the application
document.addEventListener('DOMContentLoaded', async () => {
    // Check compatibility first
    if (!testCompatibility()) {
        console.error('Browser missing required features');
        return;
    }
console.log('Application initialized');
    
    const loading = document.getElementById('loading');
    try {
        const tables = await fetchTables();
        displayTables(tables);
    } catch (error) {
        console.error('Initialization error:', error);
        showError('Using default table data - could not initialize');
        displayTables(dbTables);
    } finally {
        if (loading) loading.style.display = 'none';
    }
});
// Search functionality
document.getElementById('searchInput')?.addEventListener('input', function(e) {
    const searchTerm = e.target.value.toLowerCase();
    const tablesContainer = document.querySelector('.divide-y');
    if (!tablesContainer) return;
    
    const allTables = tablesContainer.querySelectorAll('div.p-6');
    allTables.forEach(table => {
        const name = table.querySelector('h3').textContent.toLowerCase();
        const desc = table.querySelector('p').textContent.toLowerCase();
        if (name.includes(searchTerm) || desc.includes(searchTerm)) {
            table.style.display = 'block';
        } else {
            table.style.display = 'none';
        }
    });
});