Clients UI: show several sessions of one user
- API: /api/v1/stats returns sessions_count and sessions per client - UI: badge "xN", "N devices", expandable session list, Active Sessions KPI - deploy/ui-dist rebuilt, docs: plan, summary, API reference, UI architecture Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4815821f17
commit
1bbf9b7cc1
24 files changed
+229
-19
No files matched your search
@@ -0,0 +1,12 @@
|
||||
// Multi-session helpers for the Clients page
|
||||
|
||||
// Badge "xN" is shown only when a client has more than one session
|
||||
export const sessionsBadge = (c) => (c.sessions_count > 1 ? `×${c.sessions_count}` : null);
|
||||
|
||||
// Toggle a client in the set of expanded rows (returns a new array)
|
||||
export const toggleExpanded = (expanded, name) =>
|
||||
expanded.includes(name) ? expanded.filter(n => n !== name) : [...expanded, name];
|
||||
|
||||
// Sessions to render under a client row: only when expanded and there is more than one
|
||||
export const visibleSessions = (c, expanded) =>
|
||||
(c.sessions_count > 1 && expanded.includes(c.common_name)) ? (c.sessions || []) : [];
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { sessionsBadge, toggleExpanded, visibleSessions } from './sessions';
|
||||
|
||||
describe('multi-session display', () => {
|
||||
const multi = { common_name: 'alice', sessions_count: 2, sessions: [{ real_address: 'a' }, { real_address: 'b' }] };
|
||||
const single = { common_name: 'bob', sessions_count: 1, sessions: [{ real_address: 'c' }] };
|
||||
|
||||
it('shows the badge only for more than one session', () => {
|
||||
expect(sessionsBadge(multi)).toBe('×2');
|
||||
expect(sessionsBadge(single)).toBeNull();
|
||||
expect(sessionsBadge({ common_name: 'old' })).toBeNull();
|
||||
});
|
||||
|
||||
it('expands and collapses the session list on click', () => {
|
||||
expect(visibleSessions(multi, [])).toEqual([]);
|
||||
const open = toggleExpanded([], 'alice');
|
||||
expect(visibleSessions(multi, open)).toHaveLength(2);
|
||||
expect(visibleSessions(multi, toggleExpanded(open, 'alice'))).toEqual([]);
|
||||
expect(visibleSessions(single, ['bob'])).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -12,6 +12,10 @@
|
||||
<div class="stat-value">{{ stats.activeClients }}</div>
|
||||
<div class="stat-label">Active Clients</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ stats.totalSessions }}</div>
|
||||
<div class="stat-label">Active Sessions</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-3">
|
||||
@@ -78,17 +82,24 @@
|
||||
{{ group.status }} Clients
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="c in group.items" :key="c.common_name">
|
||||
<template v-for="c in group.items" :key="c.common_name">
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#" @click.prevent="openHistory(c.common_name)" class="client-link">
|
||||
{{ c.common_name }} <i class="fas fa-chart-area ms-1 small opacity-50"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="small text-muted">{{ c.real_address || '-' }}</td>
|
||||
<td class="small text-muted">{{ c.sessions_count > 1 ? `${c.sessions_count} devices` : (c.real_address || '-') }}</td>
|
||||
<td>
|
||||
<span class="status-badge" :class="c.status === 'Active' ? 'status-active' : 'status-disconnected'">
|
||||
{{ c.status }}
|
||||
</span>
|
||||
<button v-if="sessionsBadge(c)" type="button" class="btn btn-sm btn-outline-secondary ms-2 py-0 px-1"
|
||||
:aria-expanded="expanded.includes(c.common_name)" :title="'Show sessions'"
|
||||
@click="expanded = toggleExpanded(expanded, c.common_name)">
|
||||
{{ sessionsBadge(c) }}
|
||||
<i class="fas ms-1 small" :class="expanded.includes(c.common_name) ? 'fa-chevron-up' : 'fa-chevron-down'"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="font-monospace small">{{ formatBytes(c.total_bytes_received) }}</td>
|
||||
<td class="font-monospace small">{{ formatBytes(c.total_bytes_sent) }}</td>
|
||||
@@ -109,6 +120,15 @@
|
||||
|
||||
<td class="small text-muted">{{ formatDate(c.last_activity) }}</td>
|
||||
</tr>
|
||||
<tr v-for="(sess, i) in visibleSessions(c, expanded)" :key="`${c.common_name}-s${i}`" class="session-row">
|
||||
<td class="small text-muted ps-4"><i class="fas fa-level-up-alt fa-rotate-90 me-2 opacity-50"></i>Session {{ i + 1 }}</td>
|
||||
<td class="small text-muted">{{ sess.real_address || '-' }}</td>
|
||||
<td class="small text-muted" colspan="2">Since {{ formatDate(sess.connected_since) }}</td>
|
||||
<td class="font-monospace small">Down {{ sess.received_mb }} MB</td>
|
||||
<td class="font-monospace small">Up {{ sess.sent_mb }} MB</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</tbody>
|
||||
@@ -125,6 +145,7 @@ import { useApi } from '../composables/useApi';
|
||||
import { useFormatters } from '../composables/useFormatters';
|
||||
import HistoryModal from '../components/HistoryModal.vue';
|
||||
import { useAppConfig } from '../composables/useAppConfig';
|
||||
import { sessionsBadge, toggleExpanded, visibleSessions } from '../utils/sessions';
|
||||
|
||||
const { fetchStats } = useApi();
|
||||
const { formatBytes, formatRate, parseServerDate } = useFormatters();
|
||||
@@ -137,6 +158,7 @@ const searchQuery = ref('');
|
||||
const hideDisconnected = ref(false);
|
||||
const currentSort = ref('sent');
|
||||
const historyModal = ref(null);
|
||||
const expanded = ref([]); // CNs with an open session list; survives auto-refresh
|
||||
|
||||
let intervalId = null;
|
||||
|
||||
@@ -144,14 +166,16 @@ const stats = computed(() => {
|
||||
let totalReceived = 0;
|
||||
let totalSent = 0;
|
||||
let activeClients = 0;
|
||||
let totalSessions = 0;
|
||||
|
||||
clients.value.forEach(c => {
|
||||
totalReceived += c.total_bytes_received || 0;
|
||||
totalSent += c.total_bytes_sent || 0;
|
||||
if (c.status === 'Active') activeClients++;
|
||||
totalSessions += c.sessions_count || 0;
|
||||
});
|
||||
|
||||
return { totalReceived, totalSent, activeClients };
|
||||
return { totalReceived, totalSent, activeClients, totalSessions };
|
||||
});
|
||||
|
||||
const filteredClients = computed(() => {
|
||||
|
||||
Reference in new issue
Block a user