class DataTable extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.data = []; this.sortColumn = null; this.sortDirection = 'asc'; } connectedCallback() { this.generateData(); this.render(); this.attachEvents(); } generateData() { const operations = [ 'Inference Request', 'Model Update', 'Data Preprocessing', 'API Call', 'Cache Miss', 'Authentication', 'Validation Check', 'Batch Processing' ]; const statuses = ['success', 'pending', 'error']; for (let i = 0; i < 20; i++) { this.data.push({ id: `OP-${10000 + i}`, operation: operations[Math.floor(Math.random() * operations.length)], timestamp: new Date(Date.now() - Math.random() * 3600000).toISOString(), duration: Math.floor(Math.random() * 500 + 10), status: statuses[Math.floor(Math.random() * statuses.length)] }); } } sort(column) { if (this.sortColumn === column) { this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc'; } else { this.sortColumn = column; this.sortDirection = 'asc'; } this.data.sort((a, b) => { let valA = a[column]; let valB = b[column]; if (typeof valA === 'string') valA = valA.toLowerCase(); if (typeof valB === 'string') valB = valB.toLowerCase(); if (valA < valB) return this.sortDirection === 'asc' ? -1 : 1; if (valA > valB) return this.sortDirection === 'asc' ? 1 : -1; return 0; }); this.render(); } getStatusBadge(status) { const styles = { success: 'bg-green-900/50 text-green-400', pending: 'bg-yellow-900/50 text-yellow-400', error: 'bg-red-900/50 text-red-400' }; return `${status.charAt(0).toUpperCase() + status.slice(1)}`; } render() { this.shadowRoot.innerHTML = `
${this.data.map(row => ` `).join('')}
ID ${this.sortColumn === 'id' ? (this.sortDirection === 'asc' ? '↑' : '↓') : ''} Operation ${this.sortColumn === 'operation' ? (this.sortDirection === 'asc' ? '↑' : '↓') : ''} Timestamp ${this.sortColumn === 'timestamp' ? (this.sortDirection === 'asc' ? '↑' : '↓') : ''} Duration ${this.sortColumn === 'duration' ? (this.sortDirection === 'asc' ? '↑' : '↓') : ''} Status ${this.sortColumn === 'status' ? (this.sortDirection === 'asc' ? '↑' : '↓') : ''}
${row.id} ${row.operation} ${new Date(row.timestamp).toLocaleString()} ${row.duration}ms ${this.getStatusBadge(row.status)}
`; } attachEvents() { // Add new data periodically setInterval(() => { const operations = ['Inference Request', 'Model Update', 'Data Preprocessing', 'API Call']; const statuses = ['success', 'pending', 'error']; this.data.unshift({ id: `OP-${10000 + this.data.length}`, operation: operations[Math.floor(Math.random() * operations.length)], timestamp: new Date().toISOString(), duration: Math.floor(Math.random() * 500 + 10), status: statuses[Math.floor(Math.random() * statuses.length)] }); if (this.data.length > 50) { this.data.pop(); } this.render(); }, 3000); } } customElements.define('data-table', DataTable);