Spaces:
Running
Running
File size: 6,300 Bytes
3bcb678 |
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 |
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 `<span class="px-2 py-1 rounded text-xs ${styles[status]}">${status.charAt(0).toUpperCase() + status.slice(1)}</span>`;
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
text-align: left;
padding: 12px;
border-bottom: 1px solid #334155;
color: #94a3b8;
font-size: 12px;
text-transform: uppercase;
cursor: pointer;
user-select: none;
}
th:hover {
color: #e2e8f0;
background: rgba(255,255,255,0.02);
}
td {
padding: 12px;
border-bottom: 1px solid #1e293b;
font-size: 14px;
}
tr:hover td {
background: rgba(255,255,255,0.02);
}
.sort-icon {
margin-left: 4px;
opacity: 0.5;
}
</style>
<div style="overflow-x: auto;">
<table>
<thead>
<tr>
<th onclick="this.getRootNode().host.sort('id')">
ID ${this.sortColumn === 'id' ? (this.sortDirection === 'asc' ? 'β' : 'β') : ''}
</th>
<th onclick="this.getRootNode().host.sort('operation')">
Operation ${this.sortColumn === 'operation' ? (this.sortDirection === 'asc' ? 'β' : 'β') : ''}
</th>
<th onclick="this.getRootNode().host.sort('timestamp')">
Timestamp ${this.sortColumn === 'timestamp' ? (this.sortDirection === 'asc' ? 'β' : 'β') : ''}
</th>
<th onclick="this.getRootNode().host.sort('duration')">
Duration ${this.sortColumn === 'duration' ? (this.sortDirection === 'asc' ? 'β' : 'β') : ''}
</th>
<th onclick="this.getRootNode().host.sort('status')">
Status ${this.sortColumn === 'status' ? (this.sortDirection === 'asc' ? 'β' : 'β') : ''}
</th>
</tr>
</thead>
<tbody>
${this.data.map(row => `
<tr>
<td class="font-mono text-slate-400">${row.id}</td>
<td class="text-white">${row.operation}</td>
<td class="text-slate-400">${new Date(row.timestamp).toLocaleString()}</td>
<td class="text-slate-300">${row.duration}ms</td>
<td>${this.getStatusBadge(row.status)}</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
}
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); |