Add clickable Online/Offline filters in sidebar
This commit is contained in:
@@ -642,6 +642,18 @@
|
||||
// Load connected machines (Access tab)
|
||||
let machines = [];
|
||||
let selectedMachine = null;
|
||||
let currentFilter = 'all'; // 'all', 'online', 'offline'
|
||||
|
||||
// Setup filter click handlers
|
||||
document.querySelectorAll('.sidebar-item[data-filter]').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
currentFilter = item.dataset.filter;
|
||||
// Update active state
|
||||
document.querySelectorAll('.sidebar-item[data-filter]').forEach(i => i.classList.remove('active'));
|
||||
item.classList.add('active');
|
||||
renderMachinesList();
|
||||
});
|
||||
});
|
||||
|
||||
async function loadMachines() {
|
||||
try {
|
||||
@@ -664,12 +676,23 @@
|
||||
function renderMachinesList() {
|
||||
const container = document.getElementById("machinesList");
|
||||
|
||||
if (machines.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state"><h3>No machines</h3><p>Install the agent on a machine to see it here</p></div>';
|
||||
// Filter machines based on current filter
|
||||
let filteredMachines = machines;
|
||||
if (currentFilter === 'online') {
|
||||
filteredMachines = machines.filter(m => m.is_online);
|
||||
} else if (currentFilter === 'offline') {
|
||||
filteredMachines = machines.filter(m => !m.is_online);
|
||||
}
|
||||
|
||||
if (filteredMachines.length === 0) {
|
||||
const msg = currentFilter === 'all' ? 'Install the agent on a machine to see it here' :
|
||||
currentFilter === 'online' ? 'No machines are currently online' :
|
||||
'No machines are currently offline';
|
||||
container.innerHTML = '<div class="empty-state"><h3>No machines</h3><p>' + msg + '</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '<div style="padding: 12px;">' + machines.map(m => {
|
||||
container.innerHTML = '<div style="padding: 12px;">' + filteredMachines.map(m => {
|
||||
const started = new Date(m.started_at).toLocaleString();
|
||||
const isSelected = selectedMachine?.id === m.id;
|
||||
const statusColor = m.is_online ? 'hsl(142, 76%, 50%)' : 'hsl(0, 0%, 50%)';
|
||||
|
||||
Reference in New Issue
Block a user