podmanager 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1838 @@
1
+ const state = {
2
+ activeView: 'dashboard',
3
+ systemInfo: null,
4
+ dfInfo: [],
5
+ containers: [],
6
+ pods: [],
7
+ images: [],
8
+ volumes: [],
9
+ networks: [],
10
+ events: [],
11
+ loading: {
12
+ containers: true,
13
+ pods: true,
14
+ images: true,
15
+ volumes: true,
16
+ networks: true
17
+ },
18
+ expandedRows: new Set(),
19
+ refreshTimer: null,
20
+ refreshInterval: 5000,
21
+ activeLogStream: null,
22
+ activePullStream: null,
23
+ containerFilter: { search: '', status: 'all' },
24
+ podFilter: { search: '' },
25
+ imageFilter: { search: '' },
26
+ volumeFilter: { search: '' },
27
+ networkFilter: { search: '' },
28
+ eventFilter: { search: '' },
29
+ logsConfig: {
30
+ containerId: null,
31
+ containerName: '',
32
+ autoscroll: true,
33
+ timestamps: false
34
+ }
35
+ };
36
+
37
+ function toggleRowDetails(rowId, btnElement) {
38
+ const row = document.getElementById(rowId);
39
+ if (!row) return;
40
+ const willOpen = !row.classList.contains('open');
41
+ if (willOpen) {
42
+ state.expandedRows.add(rowId);
43
+ row.classList.add('open');
44
+ } else {
45
+ state.expandedRows.delete(rowId);
46
+ row.classList.remove('open');
47
+ }
48
+ const btn = btnElement || document.querySelector(`button[data-target-row="${rowId}"]`);
49
+ if (btn) {
50
+ btn.classList.toggle('expanded', willOpen);
51
+ btn.setAttribute('aria-expanded', String(willOpen));
52
+ }
53
+ }
54
+
55
+ document.addEventListener('click', (e) => {
56
+ if (window.innerWidth > 1024) return;
57
+
58
+ if (e.target.closest('.action-trigger-btn') ||
59
+ e.target.closest('.floating-action-menu') ||
60
+ e.target.closest('a') ||
61
+ e.target.closest('.item-id') ||
62
+ e.target.closest('input') ||
63
+ e.target.closest('select')) {
64
+ return;
65
+ }
66
+ const rowItem = e.target.closest('tr.table-row-item');
67
+ if (!rowItem) return;
68
+
69
+ const expandBtn = rowItem.querySelector('.btn-expand-row');
70
+ if (expandBtn) {
71
+ const rowId = expandBtn.getAttribute('data-target-row');
72
+ if (rowId) {
73
+ toggleRowDetails(rowId, expandBtn);
74
+ }
75
+ }
76
+ });
77
+
78
+ let activeDropdownContext = null;
79
+
80
+ function openFloatingDropdown(type, id, triggerBtn, event) {
81
+ if (event) {
82
+ event.preventDefault();
83
+ event.stopPropagation();
84
+ }
85
+ const menu = document.getElementById('floating-action-dropdown');
86
+ if (!menu) return;
87
+
88
+ const rawId = decodeURIComponent(id);
89
+
90
+ if (activeDropdownContext &&
91
+ (activeDropdownContext.id === id || activeDropdownContext.id === rawId) &&
92
+ activeDropdownContext.type === type &&
93
+ menu.style.display !== 'none') {
94
+ closeFloatingDropdown();
95
+ return;
96
+ }
97
+
98
+ const items = getActionMenuItems(type, id);
99
+ if (!items) {
100
+ console.warn('No action menu items found for:', type, id);
101
+ return;
102
+ }
103
+
104
+ menu.innerHTML = items;
105
+ menu.style.display = 'flex';
106
+ menu.style.visibility = 'hidden';
107
+ menu._openedAt = Date.now();
108
+
109
+ const rect = triggerBtn.getBoundingClientRect();
110
+ const menuWidth = menu.offsetWidth || 180;
111
+ const menuHeight = menu.offsetHeight || 190;
112
+
113
+ let top = rect.bottom + 4;
114
+ if (top + menuHeight > window.innerHeight - 8) {
115
+ top = Math.max(8, rect.top - menuHeight - 4);
116
+ }
117
+
118
+ let left = rect.right - menuWidth;
119
+ if (left < 8) left = 8;
120
+ if (left + menuWidth > window.innerWidth - 8) {
121
+ left = window.innerWidth - menuWidth - 8;
122
+ }
123
+
124
+ menu.style.top = `${top}px`;
125
+ menu.style.left = `${left}px`;
126
+ menu.style.visibility = 'visible';
127
+
128
+ if (activeDropdownContext && activeDropdownContext.triggerBtn) {
129
+ activeDropdownContext.triggerBtn.setAttribute('aria-expanded', 'false');
130
+ }
131
+ activeDropdownContext = { type, id, triggerBtn };
132
+ triggerBtn.setAttribute('aria-expanded', 'true');
133
+ }
134
+
135
+ function closeFloatingDropdown() {
136
+ const menu = document.getElementById('floating-action-dropdown');
137
+ if (menu) {
138
+ menu.style.display = 'none';
139
+ }
140
+ if (activeDropdownContext && activeDropdownContext.triggerBtn) {
141
+ activeDropdownContext.triggerBtn.setAttribute('aria-expanded', 'false');
142
+ }
143
+ activeDropdownContext = null;
144
+ }
145
+
146
+ function getActionMenuItems(type, id) {
147
+ const rawId = decodeURIComponent(id);
148
+
149
+ if (type === 'container') {
150
+ const c = state.containers.find(item => item.Id === id || item.Id === rawId || item.id === id || item.id === rawId || (item.Names && item.Names.includes(id)));
151
+ if (!c) return '';
152
+ const cId = c.Id || c.id;
153
+ const name = c.Names?.[0] || shortId(cId);
154
+ const isRunning = (c.State || '').toLowerCase() === 'running';
155
+ const isPaused = (c.State || '').toLowerCase() === 'paused';
156
+ const safeName = escapeHtml(name);
157
+
158
+ return `
159
+ ${isRunning ? `
160
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionContainer('${cId}', 'stop');">
161
+ <svg viewBox="0 0 24 24"><rect x="6" y="6" width="12" height="12"></rect></svg>
162
+ <span>Stop Container</span>
163
+ </button>
164
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionContainer('${cId}', 'restart');">
165
+ <svg viewBox="0 0 24 24"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg>
166
+ <span>Restart Container</span>
167
+ </button>
168
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); openExecModal('${cId}', '${safeName}');">
169
+ <svg viewBox="0 0 24 24"><polyline points="4 17 10 11 4 5"></polyline><line x1="12" y1="19" x2="20" y2="19"></line></svg>
170
+ <span>Exec Shell</span>
171
+ </button>
172
+ ` : isPaused ? `
173
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionContainer('${cId}', 'unpause');">
174
+ <svg viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
175
+ <span>Resume Container</span>
176
+ </button>
177
+ ` : `
178
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionContainer('${cId}', 'start');">
179
+ <svg viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
180
+ <span>Start Container</span>
181
+ </button>
182
+ `}
183
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); viewContainerLogs('${cId}', '${safeName}');">
184
+ <svg viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line></svg>
185
+ <span>View Logs</span>
186
+ </button>
187
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); inspectItem('container', '${cId}');">
188
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
189
+ <span>Inspect JSON</span>
190
+ </button>
191
+ <div class="dropdown-divider"></div>
192
+ <button type="button" class="dropdown-item danger" onclick="closeFloatingDropdown(); confirmDeleteContainer('${cId}', '${safeName}');">
193
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
194
+ <span>Delete Container</span>
195
+ </button>
196
+ `;
197
+ }
198
+
199
+ if (type === 'pod') {
200
+ const p = state.pods.find(item => item.Id === id || item.Id === rawId || item.id === id || item.Name === id || item.Name === rawId);
201
+ if (!p) return '';
202
+ const pId = p.Id || p.id;
203
+ const isRunning = (p.Status || '').toLowerCase() === 'running';
204
+ const safeName = escapeHtml(p.Name || shortId(pId));
205
+
206
+ return `
207
+ ${isRunning ? `
208
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionPod('${pId}', 'stop');">
209
+ <svg viewBox="0 0 24 24"><rect x="6" y="6" width="12" height="12"></rect></svg>
210
+ <span>Stop Pod</span>
211
+ </button>
212
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionPod('${pId}', 'restart');">
213
+ <svg viewBox="0 0 24 24"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg>
214
+ <span>Restart Pod</span>
215
+ </button>
216
+ ` : `
217
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); actionPod('${pId}', 'start');">
218
+ <svg viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
219
+ <span>Start Pod</span>
220
+ </button>
221
+ `}
222
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); inspectItem('pod', '${pId}');">
223
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
224
+ <span>Inspect JSON</span>
225
+ </button>
226
+ <div class="dropdown-divider"></div>
227
+ <button type="button" class="dropdown-item danger" onclick="closeFloatingDropdown(); confirmDeletePod('${pId}', '${safeName}');">
228
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
229
+ <span>Delete Pod</span>
230
+ </button>
231
+ `;
232
+ }
233
+
234
+ if (type === 'image') {
235
+ const img = state.images.find(item => item.Id === id || item.Id === rawId || item.id === id || item.id === rawId);
236
+ if (!img) return '';
237
+ const imgId = img.Id || img.id;
238
+ const repo = img.Repositories?.[0] || img.Repository || (img.Names?.[0]?.split(':')[0]) || '<none>';
239
+ const tag = img.Tag || (img.Names?.[0]?.split(':')[1]) || 'latest';
240
+ const imageRef = `${repo}:${tag}`;
241
+
242
+ return `
243
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); openCreateContainerModal('${escapeHtml(imageRef)}');">
244
+ <svg viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
245
+ <span>Run Container</span>
246
+ </button>
247
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); inspectItem('image', '${imgId}');">
248
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
249
+ <span>Inspect JSON</span>
250
+ </button>
251
+ <div class="dropdown-divider"></div>
252
+ <button type="button" class="dropdown-item danger" onclick="closeFloatingDropdown(); confirmDeleteImage('${imgId}', '${escapeHtml(repo)}');">
253
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
254
+ <span>Delete Image</span>
255
+ </button>
256
+ `;
257
+ }
258
+
259
+ if (type === 'volume') {
260
+ const v = state.volumes.find(item => item.Name === id || item.Name === rawId || item.name === id || item.name === rawId);
261
+ if (!v) return '';
262
+ const volName = v.Name || v.name;
263
+ return `
264
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); inspectItem('volume', '${encodeURIComponent(volName)}');">
265
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
266
+ <span>Inspect JSON</span>
267
+ </button>
268
+ <div class="dropdown-divider"></div>
269
+ <button type="button" class="dropdown-item danger" onclick="closeFloatingDropdown(); deleteVolume('${encodeURIComponent(volName)}');">
270
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
271
+ <span>Delete Volume</span>
272
+ </button>
273
+ `;
274
+ }
275
+
276
+ if (type === 'network') {
277
+ const n = state.networks.find(item => item.name === id || item.id === id || item.name === rawId || item.id === rawId || item.Name === id || item.Name === rawId);
278
+ if (!n) return '';
279
+ const netName = n.name || n.Name;
280
+ return `
281
+ <button type="button" class="dropdown-item" onclick="closeFloatingDropdown(); inspectItem('network', '${encodeURIComponent(netName)}');">
282
+ <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
283
+ <span>Inspect JSON</span>
284
+ </button>
285
+ ${netName !== 'podman' ? `
286
+ <div class="dropdown-divider"></div>
287
+ <button type="button" class="dropdown-item danger" onclick="closeFloatingDropdown(); deleteNetwork('${encodeURIComponent(netName)}');">
288
+ <svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
289
+ <span>Delete Network</span>
290
+ </button>
291
+ ` : ''}
292
+ `;
293
+ }
294
+
295
+ return '';
296
+ }
297
+
298
+ document.addEventListener('click', (e) => {
299
+ const menu = document.getElementById('floating-action-dropdown');
300
+ if (!menu || menu.style.display === 'none') return;
301
+ if (e.target.closest && (e.target.closest('#floating-action-dropdown') || e.target.closest('.action-trigger-btn'))) {
302
+ return;
303
+ }
304
+ closeFloatingDropdown();
305
+ });
306
+
307
+ document.addEventListener('keydown', (e) => {
308
+ if (e.key === 'Escape') closeFloatingDropdown();
309
+ });
310
+
311
+ window.addEventListener('resize', closeFloatingDropdown);
312
+
313
+ const formatBytes = (bytes, decimals = 2) => {
314
+ if (!+bytes) return '0 B';
315
+ const k = 1024;
316
+ const dm = decimals < 0 ? 0 : decimals;
317
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
318
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
319
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
320
+ };
321
+
322
+ const formatTime = (timestamp) => {
323
+ if (!timestamp) return '-';
324
+ const date = typeof timestamp === 'number' ? new Date(timestamp * 1000) : new Date(timestamp);
325
+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
326
+ };
327
+
328
+ const shortId = (id) => (id ? id.substring(0, 12) : '-');
329
+
330
+ function showToast(title, message = '', type = 'info') {
331
+ const container = document.getElementById('toast-container');
332
+ if (!container) return;
333
+
334
+ const toast = document.createElement('div');
335
+ toast.className = `toast toast-${type}`;
336
+ toast.innerHTML = `
337
+ <div class="toast-content">
338
+ <div class="toast-title">${escapeHtml(title)}</div>
339
+ ${message ? `<div class="toast-msg">${escapeHtml(message)}</div>` : ''}
340
+ </div>
341
+ <button class="modal-close" style="padding:2px;" onclick="this.parentElement.remove()">
342
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
343
+ </button>
344
+ `;
345
+ container.appendChild(toast);
346
+
347
+ setTimeout(() => {
348
+ toast.style.opacity = '0';
349
+ toast.style.transition = 'opacity 0.3s ease';
350
+ setTimeout(() => toast.remove(), 300);
351
+ }, 4500);
352
+ }
353
+
354
+ function escapeHtml(str) {
355
+ if (!str) return '';
356
+ return String(str)
357
+ .replace(/&/g, '&amp;')
358
+ .replace(/</g, '&lt;')
359
+ .replace(/>/g, '&gt;')
360
+ .replace(/"/g, '&quot;')
361
+ .replace(/'/g, '&#039;');
362
+ }
363
+
364
+ function openModal(modalId) {
365
+ const modal = document.getElementById(modalId);
366
+ if (modal) {
367
+ modal.classList.add('open');
368
+ }
369
+ }
370
+
371
+ function closeModal(modalId) {
372
+ const modal = document.getElementById(modalId);
373
+ if (modal) {
374
+ modal.classList.remove('open');
375
+ if (modalId === 'logs-modal' && state.activeLogStream) {
376
+ state.activeLogStream.close();
377
+ state.activeLogStream = null;
378
+ }
379
+ }
380
+ }
381
+
382
+ function switchView(viewName, updateUrl = true) {
383
+ const validViews = ['dashboard', 'containers', 'pods', 'images', 'volumes', 'networks', 'events'];
384
+ if (!validViews.includes(viewName)) {
385
+ viewName = 'dashboard';
386
+ }
387
+ state.activeView = viewName;
388
+ document.querySelectorAll('.view-section').forEach(el => el.classList.remove('active'));
389
+ document.querySelectorAll('.nav-link').forEach(el => el.classList.remove('active'));
390
+
391
+ const targetView = document.getElementById(`view-${viewName}`);
392
+ if (targetView) targetView.classList.add('active');
393
+
394
+ const navItem = document.querySelector(`.nav-link[data-view="${viewName}"]`);
395
+ if (navItem) navItem.classList.add('active');
396
+
397
+ const pageTitle = document.getElementById('page-title');
398
+ if (pageTitle) {
399
+ const titles = {
400
+ dashboard: 'Dashboard Overview',
401
+ containers: 'Containers Management',
402
+ pods: 'Pods Management',
403
+ images: 'Images Management',
404
+ volumes: 'Volumes Management',
405
+ networks: 'Networks Management',
406
+ events: 'Live System Events'
407
+ };
408
+ pageTitle.textContent = titles[viewName] || 'Podmanager';
409
+ }
410
+
411
+ if (updateUrl && window.history && window.history.pushState) {
412
+ const url = new URL(window.location);
413
+ if (viewName === 'dashboard') {
414
+ url.searchParams.delete('view');
415
+ } else {
416
+ url.searchParams.set('view', viewName);
417
+ }
418
+ window.history.pushState({ view: viewName }, '', url.pathname + url.search + url.hash);
419
+ }
420
+
421
+ if (viewName === 'events') {
422
+ renderEvents();
423
+ }
424
+
425
+ refreshData();
426
+ }
427
+
428
+ async function refreshData() {
429
+ const refreshIcon = document.getElementById('refresh-icon');
430
+ if (refreshIcon) refreshIcon.classList.add('spin');
431
+
432
+ try {
433
+ const [infoRes, dfRes, containersRes, podsRes, imagesRes, volumesRes, networksRes] = await Promise.all([
434
+ API.getSystemInfo().catch(e => null),
435
+ API.getSystemDf().catch(e => null),
436
+ API.getContainers().catch(e => null),
437
+ API.getPods().catch(e => null),
438
+ API.getImages().catch(e => null),
439
+ API.getVolumes().catch(e => null),
440
+ API.getNetworks().catch(e => null)
441
+ ]);
442
+
443
+ if (infoRes?.data) state.systemInfo = infoRes.data;
444
+ if (dfRes?.data) state.dfInfo = dfRes.data;
445
+ if (containersRes?.data) {
446
+ state.containers = containersRes.data;
447
+ state.loading.containers = false;
448
+ }
449
+ if (podsRes?.data) {
450
+ state.pods = podsRes.data;
451
+ state.loading.pods = false;
452
+ }
453
+ if (imagesRes?.data) {
454
+ state.images = imagesRes.data;
455
+ state.loading.images = false;
456
+ }
457
+ if (volumesRes?.data) {
458
+ state.volumes = volumesRes.data;
459
+ state.loading.volumes = false;
460
+ }
461
+ if (networksRes?.data) {
462
+ state.networks = networksRes.data;
463
+ state.loading.networks = false;
464
+ }
465
+
466
+ updateBadges();
467
+
468
+ if (state.activeView === 'dashboard') {
469
+ renderDashboard();
470
+ } else if (state.activeView === 'containers') {
471
+ renderContainers();
472
+ } else if (state.activeView === 'pods') {
473
+ renderPods();
474
+ } else if (state.activeView === 'images') {
475
+ renderImages();
476
+ } else if (state.activeView === 'volumes') {
477
+ renderVolumes();
478
+ } else if (state.activeView === 'networks') {
479
+ renderNetworks();
480
+ } else if (state.activeView === 'events') {
481
+ renderEvents();
482
+ }
483
+
484
+ updateSystemStatus(true);
485
+ } catch (err) {
486
+ console.error('Failed to refresh data:', err);
487
+ updateSystemStatus(false);
488
+ } finally {
489
+ if (refreshIcon) refreshIcon.classList.remove('spin');
490
+ }
491
+ }
492
+
493
+ function updateBadges() {
494
+ const dBadge = document.getElementById('badge-dashboard');
495
+ const cBadge = document.getElementById('badge-containers');
496
+ const pBadge = document.getElementById('badge-pods');
497
+ const iBadge = document.getElementById('badge-images');
498
+ const vBadge = document.getElementById('badge-volumes');
499
+ const nBadge = document.getElementById('badge-networks');
500
+ const eBadge = document.getElementById('badge-events');
501
+
502
+ const runningCount = state.containers.filter(c => c.State === 'running').length;
503
+
504
+ if (dBadge) {
505
+ dBadge.textContent = 'Live';
506
+ }
507
+
508
+ if (cBadge) {
509
+ cBadge.textContent = `${runningCount}/${state.containers.length}`;
510
+ cBadge.className = runningCount > 0 ? 'nav-badge active-count' : 'nav-badge';
511
+ }
512
+
513
+ if (pBadge) {
514
+ pBadge.textContent = state.pods.length;
515
+ }
516
+
517
+ if (iBadge) {
518
+ iBadge.textContent = state.images.length;
519
+ }
520
+
521
+ if (vBadge) {
522
+ vBadge.textContent = state.volumes.length;
523
+ }
524
+
525
+ if (nBadge) {
526
+ nBadge.textContent = state.networks.length;
527
+ }
528
+
529
+ if (eBadge) {
530
+ eBadge.textContent = state.events.length;
531
+ }
532
+ }
533
+
534
+ function updateSystemStatus(isOnline) {
535
+ const dot = document.getElementById('status-dot');
536
+ const text = document.getElementById('status-text');
537
+ if (dot && text) {
538
+ if (isOnline) {
539
+ dot.className = 'status-dot';
540
+ const version = state.systemInfo?.version?.Version || '';
541
+ text.textContent = version ? `Podman v${version} Connected` : 'Podman Connected';
542
+ } else {
543
+ dot.className = 'status-dot offline';
544
+ text.textContent = 'Connection Error';
545
+ }
546
+ }
547
+ }
548
+
549
+ function renderDashboard() {
550
+ const runningContainers = state.containers.filter(c => c.State === 'running').length;
551
+
552
+ document.getElementById('dash-stat-running').textContent = runningContainers;
553
+ document.getElementById('dash-stat-containers').textContent = state.containers.length;
554
+ document.getElementById('dash-stat-pods').textContent = state.pods.length;
555
+ document.getElementById('dash-stat-images').textContent = state.images.length;
556
+
557
+ const host = state.systemInfo?.host || {};
558
+ const ver = state.systemInfo?.version || {};
559
+ const store = state.systemInfo?.store || {};
560
+
561
+ document.getElementById('spec-podman-version').textContent = ver.Version || '-';
562
+ document.getElementById('spec-os-arch').textContent = `${host.os || ''} (${host.arch || ''})`;
563
+ document.getElementById('spec-distro').textContent = host.distribution ? `${host.distribution.distribution} ${host.distribution.version}` : '-';
564
+ document.getElementById('spec-kernel').textContent = host.kernel || '-';
565
+ document.getElementById('spec-cpus').textContent = host.cpus ? `${host.cpus} Cores` : '-';
566
+ document.getElementById('spec-mem').textContent = host.memTotal ? formatBytes(host.memTotal) : '-';
567
+ document.getElementById('spec-driver').textContent = store.graphDriverName || '-';
568
+
569
+ const rootlessBadge = document.getElementById('spec-rootless');
570
+ if (rootlessBadge) {
571
+ rootlessBadge.textContent = host.rootless ? 'Rootless Mode' : 'Root Mode';
572
+ rootlessBadge.className = host.rootless ? 'tag-badge rootless' : 'tag-badge';
573
+ }
574
+
575
+ const diskContainer = document.getElementById('dash-disk-list');
576
+ if (diskContainer && state.dfInfo.length > 0) {
577
+ diskContainer.innerHTML = state.dfInfo.map(item => `
578
+ <div class="disk-item">
579
+ <div class="disk-header">
580
+ <strong>${escapeHtml(item.Type)} (${item.TotalCount ?? item.Total ?? 0})</strong>
581
+ <span>${escapeHtml(item.Size || '0B')}</span>
582
+ </div>
583
+ <div class="disk-bar-bg">
584
+ <div class="disk-bar-fill" style="width: ${item.Active > 0 ? Math.min(100, Math.round((item.Active / (item.Total || 1)) * 100)) : 10}%;"></div>
585
+ </div>
586
+ <div class="disk-reclaimable">Reclaimable: ${escapeHtml(item.Reclaimable || '0B')}</div>
587
+ </div>
588
+ `).join('');
589
+ }
590
+ }
591
+
592
+ function renderTableSkeletons(type, count = 5) {
593
+ const rows = [];
594
+ for (let i = 0; i < count; i++) {
595
+ const varW = (base, mod) => base + ((i % 3) * mod);
596
+
597
+ if (type === 'containers') {
598
+ rows.push(`
599
+ <tr class="table-row-item skeleton-row">
600
+ <td><div class="skeleton skeleton-badge" style="width:65px;"></div></td>
601
+ <td>
602
+ <div class="skeleton-group">
603
+ <div class="skeleton skeleton-text" style="width:${varW(120, 15)}px;"></div>
604
+ <div class="skeleton skeleton-text skeleton-sub" style="width:${varW(75, 10)}px;"></div>
605
+ </div>
606
+ </td>
607
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:${varW(100, 20)}px;"></div></td>
608
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:${varW(80, 15)}px;"></div></td>
609
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:75px;"></div></td>
610
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:85px;"></div></td>
611
+ <td class="col-actions-header" style="text-align:right;">
612
+ <div class="skeleton skeleton-btn" style="margin-left:auto;"></div>
613
+ </td>
614
+ <td class="mobile-toggle-cell">
615
+ <div class="skeleton skeleton-icon" style="margin:0 auto;"></div>
616
+ </td>
617
+ </tr>
618
+ `);
619
+ } else if (type === 'pods') {
620
+ rows.push(`
621
+ <tr class="table-row-item skeleton-row">
622
+ <td><div class="skeleton skeleton-badge" style="width:65px;"></div></td>
623
+ <td>
624
+ <div class="skeleton-group">
625
+ <div class="skeleton skeleton-text" style="width:${varW(130, 20)}px;"></div>
626
+ <div class="skeleton skeleton-text skeleton-sub" style="width:${varW(70, 10)}px;"></div>
627
+ </div>
628
+ </td>
629
+ <td class="col-hide-tablet">
630
+ <div class="skeleton-group">
631
+ <div class="skeleton skeleton-badge" style="width:70px;"></div>
632
+ <div class="skeleton skeleton-text skeleton-sub" style="width:110px;"></div>
633
+ </div>
634
+ </td>
635
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:85px;"></div></td>
636
+ <td class="col-actions-header" style="text-align:right;">
637
+ <div class="skeleton skeleton-btn" style="margin-left:auto;"></div>
638
+ </td>
639
+ <td class="mobile-toggle-cell">
640
+ <div class="skeleton skeleton-icon" style="margin:0 auto;"></div>
641
+ </td>
642
+ </tr>
643
+ `);
644
+ } else if (type === 'images') {
645
+ rows.push(`
646
+ <tr class="table-row-item skeleton-row">
647
+ <td>
648
+ <div class="skeleton-group">
649
+ <div class="skeleton skeleton-text" style="width:${varW(140, 25)}px;"></div>
650
+ <div class="skeleton skeleton-text skeleton-sub" style="width:${varW(85, 10)}px;"></div>
651
+ </div>
652
+ </td>
653
+ <td><div class="skeleton skeleton-badge" style="width:45px;"></div></td>
654
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:55px;"></div></td>
655
+ <td class="col-hide-tablet"><div class="skeleton skeleton-badge" style="width:50px;"></div></td>
656
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:85px;"></div></td>
657
+ <td class="col-actions-header" style="text-align:right;">
658
+ <div class="skeleton skeleton-btn" style="margin-left:auto;"></div>
659
+ </td>
660
+ <td class="mobile-toggle-cell">
661
+ <div class="skeleton skeleton-icon" style="margin:0 auto;"></div>
662
+ </td>
663
+ </tr>
664
+ `);
665
+ } else if (type === 'volumes') {
666
+ rows.push(`
667
+ <tr class="table-row-item skeleton-row">
668
+ <td><div class="skeleton skeleton-text" style="width:${varW(130, 20)}px;"></div></td>
669
+ <td><div class="skeleton skeleton-badge" style="width:50px;"></div></td>
670
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:${varW(150, 30)}px;"></div></td>
671
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:85px;"></div></td>
672
+ <td class="col-actions-header" style="text-align:right;">
673
+ <div class="skeleton skeleton-btn" style="margin-left:auto;"></div>
674
+ </td>
675
+ <td class="mobile-toggle-cell">
676
+ <div class="skeleton skeleton-icon" style="margin:0 auto;"></div>
677
+ </td>
678
+ </tr>
679
+ `);
680
+ } else if (type === 'networks') {
681
+ rows.push(`
682
+ <tr class="table-row-item skeleton-row">
683
+ <td><div class="skeleton skeleton-text" style="width:${varW(110, 20)}px;"></div></td>
684
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:80px;"></div></td>
685
+ <td><div class="skeleton skeleton-badge" style="width:55px;"></div></td>
686
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:110px;"></div></td>
687
+ <td class="col-hide-tablet"><div class="skeleton skeleton-text" style="width:95px;"></div></td>
688
+ <td class="col-actions-header" style="text-align:right;">
689
+ <div class="skeleton skeleton-btn" style="margin-left:auto;"></div>
690
+ </td>
691
+ <td class="mobile-toggle-cell">
692
+ <div class="skeleton skeleton-icon" style="margin:0 auto;"></div>
693
+ </td>
694
+ </tr>
695
+ `);
696
+ }
697
+ }
698
+ return rows.join('');
699
+ }
700
+
701
+ function renderContainers() {
702
+ const tbody = document.getElementById('containers-tbody');
703
+ if (!tbody) return;
704
+
705
+ if (state.loading.containers) {
706
+ tbody.innerHTML = renderTableSkeletons('containers');
707
+ return;
708
+ }
709
+
710
+ const search = state.containerFilter.search.toLowerCase();
711
+ const status = state.containerFilter.status;
712
+
713
+ const filtered = state.containers.filter(c => {
714
+ const nameMatch = (c.Names?.[0] || '').toLowerCase().includes(search) ||
715
+ (c.Image || '').toLowerCase().includes(search) ||
716
+ (c.Id || '').toLowerCase().includes(search);
717
+ const statusMatch = status === 'all' || c.State === status;
718
+ return nameMatch && statusMatch;
719
+ });
720
+
721
+ if (filtered.length === 0) {
722
+ tbody.innerHTML = `
723
+ <tr>
724
+ <td colspan="8">
725
+ <div class="empty-state">
726
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"></rect><line x1="8" y1="21" x2="16" y2="21"></line><line x1="12" y1="17" x2="12" y2="21"></line></svg>
727
+ <div class="empty-state-title">No containers found</div>
728
+ <div class="empty-state-desc">No containers match your search or filter. Launch a container to get started.</div>
729
+ <button class="btn btn-primary" onclick="openCreateContainerModal()">
730
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
731
+ <span>Run Container</span>
732
+ </button>
733
+ </div>
734
+ </td>
735
+ </tr>
736
+ `;
737
+ return;
738
+ }
739
+
740
+ tbody.innerHTML = filtered.map(c => {
741
+ const name = c.Names?.[0] || shortId(c.Id);
742
+ const cShort = shortId(c.Id);
743
+ const rowId = `expand-c-${cShort}`;
744
+ const isExpanded = state.expandedRows.has(rowId);
745
+
746
+ return `
747
+ <tr class="table-row-item">
748
+ <td>
749
+ <span class="status-pill status-${c.State}">${c.State}</span>
750
+ </td>
751
+ <td>
752
+ <div class="item-name">${escapeHtml(name)}</div>
753
+ <span class="item-id" title="Click to copy ID" onclick="navigator.clipboard.writeText('${c.Id}'); showToast('Copied ID', '${cShort}', 'info');">${cShort}</span>
754
+ </td>
755
+ <td class="col-hide-tablet">
756
+ <span title="${escapeHtml(c.Image)}">${escapeHtml(c.Image)}</span>
757
+ </td>
758
+ <td class="col-hide-tablet">${formatPorts(c.Ports)}</td>
759
+ <td class="col-hide-tablet">${c.PodName ? `<span class="tag-badge rootless">${escapeHtml(c.PodName)}</span>` : '-'}</td>
760
+ <td class="col-hide-tablet" style="color:var(--text-secondary); font-size:12px;">${escapeHtml(c.Status)}</td>
761
+ <td class="col-actions-cell" style="text-align:right;">
762
+ <button type="button" class="btn btn-secondary btn-icon-only btn-sm action-trigger-btn" title="Actions" aria-label="Actions" aria-haspopup="true" aria-expanded="false" onclick="openFloatingDropdown('container', '${c.Id}', this, event)">
763
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg>
764
+ </button>
765
+ </td>
766
+ <td class="mobile-toggle-cell" style="text-align:center;">
767
+ <button type="button" class="btn-expand-row ${isExpanded ? 'expanded' : ''}" data-target-row="${rowId}" aria-label="Toggle details for ${escapeHtml(name)}" aria-expanded="${isExpanded}">
768
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>
769
+ </button>
770
+ </td>
771
+ </tr>
772
+ <tr class="expandable-details-row ${isExpanded ? 'open' : ''}" id="${rowId}">
773
+ <td colspan="8">
774
+ <div class="details-drawer-content">
775
+ <div class="drawer-grid">
776
+ <div class="drawer-field">
777
+ <span class="drawer-label">Image</span>
778
+ <span class="drawer-value">${escapeHtml(c.Image)}</span>
779
+ </div>
780
+ <div class="drawer-field">
781
+ <span class="drawer-label">Ports</span>
782
+ <span class="drawer-value">${formatPorts(c.Ports)}</span>
783
+ </div>
784
+ <div class="drawer-field">
785
+ <span class="drawer-label">Pod</span>
786
+ <span class="drawer-value">${c.PodName ? escapeHtml(c.PodName) : 'Standalone'}</span>
787
+ </div>
788
+ <div class="drawer-field">
789
+ <span class="drawer-label">Status / Uptime</span>
790
+ <span class="drawer-value">${escapeHtml(c.Status)}</span>
791
+ </div>
792
+ </div>
793
+ </div>
794
+ </td>
795
+ </tr>
796
+ `;
797
+ }).join('');
798
+ }
799
+
800
+ function formatPorts(ports) {
801
+ if (!ports || ports.length === 0) return '<span style="color:var(--text-tertiary);">-</span>';
802
+ return ports.map(p => {
803
+ const hostPort = p.host_port || p.HostPort;
804
+ const containerPort = p.container_port || p.ContainerPort;
805
+ const protocol = p.protocol || 'tcp';
806
+ if (hostPort) {
807
+ return `<a class="ports-badge" href="http://localhost:${hostPort}" target="_blank" title="Open port in browser">${hostPort}:${containerPort}/${protocol}</a>`;
808
+ }
809
+ return `<span class="ports-badge">${containerPort}/${protocol}</span>`;
810
+ }).join(' ');
811
+ }
812
+
813
+ function renderPods() {
814
+ const tbody = document.getElementById('pods-tbody');
815
+ if (!tbody) return;
816
+
817
+ if (state.loading.pods) {
818
+ tbody.innerHTML = renderTableSkeletons('pods');
819
+ return;
820
+ }
821
+
822
+ const search = state.podFilter.search.toLowerCase();
823
+ const filtered = state.pods.filter(p => {
824
+ return (p.Name || '').toLowerCase().includes(search) || (p.Id || '').toLowerCase().includes(search);
825
+ });
826
+
827
+ if (filtered.length === 0) {
828
+ tbody.innerHTML = `
829
+ <tr>
830
+ <td colspan="6">
831
+ <div class="empty-state">
832
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"></path><path d="M2 12h20"></path></svg>
833
+ <div class="empty-state-title">No pods found</div>
834
+ <div class="empty-state-desc">No pods match your search. Create a pod to group multiple containers together.</div>
835
+ <button class="btn btn-primary" onclick="openModal('create-pod-modal')">
836
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
837
+ <span>Create Pod</span>
838
+ </button>
839
+ </div>
840
+ </td>
841
+ </tr>
842
+ `;
843
+ return;
844
+ }
845
+
846
+ tbody.innerHTML = filtered.map(p => {
847
+ const isRunning = p.Status?.toLowerCase() === 'running';
848
+ const containerCount = p.Containers ? p.Containers.length : 0;
849
+ const pShort = shortId(p.Id);
850
+ const rowId = `expand-p-${pShort}`;
851
+ const isExpanded = state.expandedRows.has(rowId);
852
+ const containersSummary = p.Containers ? p.Containers.map(c => escapeHtml(c.Names || c.Name || '')).join(', ') : '';
853
+
854
+ return `
855
+ <tr class="table-row-item">
856
+ <td>
857
+ <span class="status-pill status-${isRunning ? 'running' : 'exited'}">${p.Status}</span>
858
+ </td>
859
+ <td>
860
+ <div class="item-name">${escapeHtml(p.Name)}</div>
861
+ <span class="item-id" title="Copy ID" onclick="navigator.clipboard.writeText('${p.Id}'); showToast('Copied Pod ID', '${pShort}', 'info');">${pShort}</span>
862
+ </td>
863
+ <td class="col-hide-tablet">
864
+ <span class="tag-badge rootless">${containerCount} Container${containerCount === 1 ? '' : 's'}</span>
865
+ <div style="font-size:11px; color:var(--text-tertiary); margin-top:4px;">
866
+ ${containersSummary}
867
+ </div>
868
+ </td>
869
+ <td class="col-hide-tablet" style="color:var(--text-secondary); font-size:12px;">${escapeHtml(p.Created || '-')}</td>
870
+ <td class="col-actions-cell" style="text-align:right;">
871
+ <button type="button" class="btn btn-secondary btn-icon-only btn-sm action-trigger-btn" title="Actions" aria-label="Actions" aria-haspopup="true" aria-expanded="false" onclick="openFloatingDropdown('pod', '${p.Id}', this, event)">
872
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg>
873
+ </button>
874
+ </td>
875
+ <td class="mobile-toggle-cell" style="text-align:center;">
876
+ <button type="button" class="btn-expand-row ${isExpanded ? 'expanded' : ''}" data-target-row="${rowId}" aria-label="Toggle details for ${escapeHtml(p.Name)}" aria-expanded="${isExpanded}">
877
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>
878
+ </button>
879
+ </td>
880
+ </tr>
881
+ <tr class="expandable-details-row ${isExpanded ? 'open' : ''}" id="${rowId}">
882
+ <td colspan="6">
883
+ <div class="details-drawer-content">
884
+ <div class="drawer-grid">
885
+ <div class="drawer-field">
886
+ <span class="drawer-label">Containers (${containerCount})</span>
887
+ <span class="drawer-value">${containersSummary || 'None'}</span>
888
+ </div>
889
+ <div class="drawer-field">
890
+ <span class="drawer-label">Created</span>
891
+ <span class="drawer-value">${escapeHtml(p.Created || '-')}</span>
892
+ </div>
893
+ </div>
894
+ </div>
895
+ </td>
896
+ </tr>
897
+ `;
898
+ }).join('');
899
+ }
900
+
901
+ function renderImages() {
902
+ const tbody = document.getElementById('images-tbody');
903
+ if (!tbody) return;
904
+
905
+ if (state.loading.images) {
906
+ tbody.innerHTML = renderTableSkeletons('images');
907
+ return;
908
+ }
909
+
910
+ const search = state.imageFilter.search.toLowerCase();
911
+ const filtered = state.images.filter(img => {
912
+ const repo = (img.Repositories?.[0] || img.Repository || '').toLowerCase();
913
+ const id = (img.Id || '').toLowerCase();
914
+ return repo.includes(search) || id.includes(search);
915
+ });
916
+
917
+ if (filtered.length === 0) {
918
+ tbody.innerHTML = `
919
+ <tr>
920
+ <td colspan="7">
921
+ <div class="empty-state">
922
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="16.5" y1="9.4" x2="7.5" y2="4.21"></line><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path><polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline><line x1="12" y1="22.08" x2="12" y2="12"></line></svg>
923
+ <div class="empty-state-title">No images found</div>
924
+ <div class="empty-state-desc">No container images match your search. Pull an image from a registry to get started.</div>
925
+ <button class="btn btn-primary" onclick="openModal('pull-image-modal')">
926
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
927
+ <span>Pull Image</span>
928
+ </button>
929
+ </div>
930
+ </td>
931
+ </tr>
932
+ `;
933
+ return;
934
+ }
935
+
936
+ tbody.innerHTML = filtered.map(img => {
937
+ const repo = img.Repositories?.[0] || img.Repository || '<none>';
938
+ const tag = img.Tag || (img.Names?.[0]?.split(':')[1]) || 'latest';
939
+ const size = img.Size ? (typeof img.Size === 'number' ? formatBytes(img.Size) : img.Size) : '-';
940
+ const containersInUse = img.Containers || 0;
941
+ const imgShort = shortId(img.Id);
942
+ const rowId = `expand-img-${imgShort}`;
943
+ const isExpanded = state.expandedRows.has(rowId);
944
+ const createdStr = img.Created ? (typeof img.Created === 'number' ? new Date(img.Created * 1000).toLocaleDateString() : img.Created) : '-';
945
+
946
+ return `
947
+ <tr class="table-row-item">
948
+ <td>
949
+ <div class="item-name">${escapeHtml(repo)}</div>
950
+ <span class="item-id" title="Copy ID" onclick="navigator.clipboard.writeText('${img.Id}'); showToast('Copied Image ID', '${imgShort}', 'info');">${imgShort}</span>
951
+ </td>
952
+ <td><span class="tag-badge rootless">${escapeHtml(tag)}</span></td>
953
+ <td class="col-hide-tablet">${escapeHtml(size)}</td>
954
+ <td class="col-hide-tablet">
955
+ ${containersInUse > 0
956
+ ? `<span class="tag-badge" style="background-color:var(--apple-green-soft); color:var(--apple-green);">${containersInUse} In Use</span>`
957
+ : `<span style="color:var(--text-tertiary); font-size:12px;">Unused</span>`}
958
+ </td>
959
+ <td class="col-hide-tablet" style="color:var(--text-secondary); font-size:12px;">${escapeHtml(createdStr)}</td>
960
+ <td class="col-actions-cell" style="text-align:right;">
961
+ <button type="button" class="btn btn-secondary btn-icon-only btn-sm action-trigger-btn" title="Actions" aria-label="Actions" aria-haspopup="true" aria-expanded="false" onclick="openFloatingDropdown('image', '${img.Id}', this, event)">
962
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg>
963
+ </button>
964
+ </td>
965
+ <td class="mobile-toggle-cell" style="text-align:center;">
966
+ <button type="button" class="btn-expand-row ${isExpanded ? 'expanded' : ''}" data-target-row="${rowId}" aria-label="Toggle details for ${escapeHtml(repo)}" aria-expanded="${isExpanded}">
967
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>
968
+ </button>
969
+ </td>
970
+ </tr>
971
+ <tr class="expandable-details-row ${isExpanded ? 'open' : ''}" id="${rowId}">
972
+ <td colspan="7">
973
+ <div class="details-drawer-content">
974
+ <div class="drawer-grid">
975
+ <div class="drawer-field">
976
+ <span class="drawer-label">Size</span>
977
+ <span class="drawer-value">${escapeHtml(size)}</span>
978
+ </div>
979
+ <div class="drawer-field">
980
+ <span class="drawer-label">In Use</span>
981
+ <span class="drawer-value">${containersInUse > 0 ? `${containersInUse} container(s)` : 'Unused'}</span>
982
+ </div>
983
+ <div class="drawer-field">
984
+ <span class="drawer-label">Created</span>
985
+ <span class="drawer-value">${escapeHtml(createdStr)}</span>
986
+ </div>
987
+ </div>
988
+ </div>
989
+ </td>
990
+ </tr>
991
+ `;
992
+ }).join('');
993
+ }
994
+
995
+ function renderVolumes() {
996
+ const tbody = document.getElementById('volumes-tbody');
997
+ if (!tbody) return;
998
+
999
+ if (state.loading.volumes) {
1000
+ tbody.innerHTML = renderTableSkeletons('volumes');
1001
+ return;
1002
+ }
1003
+
1004
+ const search = state.volumeFilter.search.toLowerCase();
1005
+ const filtered = state.volumes.filter(v => {
1006
+ return (v.Name || '').toLowerCase().includes(search) || (v.Driver || '').toLowerCase().includes(search);
1007
+ });
1008
+
1009
+ if (filtered.length === 0) {
1010
+ tbody.innerHTML = `
1011
+ <tr>
1012
+ <td colspan="6">
1013
+ <div class="empty-state">
1014
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path></svg>
1015
+ <div class="empty-state-title">No volumes found</div>
1016
+ <div class="empty-state-desc">No storage volumes match your search. Create a persistent volume for your application data.</div>
1017
+ <button class="btn btn-primary" onclick="openModal('create-volume-modal')">
1018
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
1019
+ <span>Create Volume</span>
1020
+ </button>
1021
+ </div>
1022
+ </td>
1023
+ </tr>
1024
+ `;
1025
+ return;
1026
+ }
1027
+
1028
+ tbody.innerHTML = filtered.map(v => {
1029
+ const volIdSafe = encodeURIComponent(v.Name).replace(/[^a-zA-Z0-9_-]/g, '_');
1030
+ const rowId = `expand-vol-${volIdSafe}`;
1031
+ const isExpanded = state.expandedRows.has(rowId);
1032
+
1033
+ return `
1034
+ <tr class="table-row-item">
1035
+ <td><strong>${escapeHtml(v.Name)}</strong></td>
1036
+ <td><span class="tag-badge rootless">${escapeHtml(v.Driver || 'local')}</span></td>
1037
+ <td class="col-hide-tablet" style="font-family:monospace; font-size:11px; color:var(--text-secondary);">${escapeHtml(v.MountPoint || '-')}</td>
1038
+ <td class="col-hide-tablet" style="color:var(--text-secondary); font-size:12px;">${escapeHtml(v.CreatedAt || '-')}</td>
1039
+ <td class="col-actions-cell" style="text-align:right;">
1040
+ <button type="button" class="btn btn-secondary btn-icon-only btn-sm action-trigger-btn" title="Actions" aria-label="Actions" aria-haspopup="true" aria-expanded="false" onclick="openFloatingDropdown('volume', '${encodeURIComponent(v.Name)}', this, event)">
1041
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg>
1042
+ </button>
1043
+ </td>
1044
+ <td class="mobile-toggle-cell" style="text-align:center;">
1045
+ <button type="button" class="btn-expand-row ${isExpanded ? 'expanded' : ''}" data-target-row="${rowId}" aria-label="Toggle details for ${escapeHtml(v.Name)}" aria-expanded="${isExpanded}">
1046
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>
1047
+ </button>
1048
+ </td>
1049
+ </tr>
1050
+ <tr class="expandable-details-row ${isExpanded ? 'open' : ''}" id="${rowId}">
1051
+ <td colspan="6">
1052
+ <div class="details-drawer-content">
1053
+ <div class="drawer-grid">
1054
+ <div class="drawer-field">
1055
+ <span class="drawer-label">Mountpoint</span>
1056
+ <span class="drawer-value" style="font-family:monospace; font-size:11px;">${escapeHtml(v.MountPoint || '-')}</span>
1057
+ </div>
1058
+ <div class="drawer-field">
1059
+ <span class="drawer-label">Created</span>
1060
+ <span class="drawer-value">${escapeHtml(v.CreatedAt || '-')}</span>
1061
+ </div>
1062
+ </div>
1063
+ </div>
1064
+ </td>
1065
+ </tr>
1066
+ `;
1067
+ }).join('');
1068
+ }
1069
+
1070
+ function renderNetworks() {
1071
+ const tbody = document.getElementById('networks-tbody');
1072
+ if (!tbody) return;
1073
+
1074
+ if (state.loading.networks) {
1075
+ tbody.innerHTML = renderTableSkeletons('networks');
1076
+ return;
1077
+ }
1078
+
1079
+ const search = state.networkFilter.search.toLowerCase();
1080
+ const filtered = state.networks.filter(n => {
1081
+ return (n.name || '').toLowerCase().includes(search) ||
1082
+ (n.driver || '').toLowerCase().includes(search) ||
1083
+ (n.id || '').toLowerCase().includes(search);
1084
+ });
1085
+
1086
+ if (filtered.length === 0) {
1087
+ tbody.innerHTML = `
1088
+ <tr>
1089
+ <td colspan="7">
1090
+ <div class="empty-state">
1091
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="16" y="16" width="6" height="6" rx="1"></rect><rect x="2" y="16" width="6" height="6" rx="1"></rect><rect x="9" y="2" width="6" height="6" rx="1"></rect><path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3"></path><path d="M12 12V8"></path></svg>
1092
+ <div class="empty-state-title">No networks found</div>
1093
+ <div class="empty-state-desc">No networks match your search. Create a custom network to isolate or connect containers.</div>
1094
+ <button class="btn btn-primary" onclick="openModal('create-network-modal')">
1095
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
1096
+ <span>Create Network</span>
1097
+ </button>
1098
+ </div>
1099
+ </td>
1100
+ </tr>
1101
+ `;
1102
+ return;
1103
+ }
1104
+
1105
+ tbody.innerHTML = filtered.map(n => {
1106
+ const subnets = n.subnets ? n.subnets.map(s => s.subnet).join(', ') : '-';
1107
+ const gateways = n.subnets ? n.subnets.map(s => s.gateway).filter(Boolean).join(', ') : '-';
1108
+ const nShort = shortId(n.id);
1109
+ const netIdSafe = encodeURIComponent(n.name).replace(/[^a-zA-Z0-9_-]/g, '_');
1110
+ const rowId = `expand-net-${netIdSafe}`;
1111
+ const isExpanded = state.expandedRows.has(rowId);
1112
+
1113
+ return `
1114
+ <tr class="table-row-item">
1115
+ <td><strong>${escapeHtml(n.name)}</strong></td>
1116
+ <td class="col-hide-tablet"><span class="item-id">${nShort}</span></td>
1117
+ <td><span class="tag-badge rootless">${escapeHtml(n.driver || 'bridge')}</span></td>
1118
+ <td class="col-hide-tablet" style="font-family:monospace; font-size:12px;">${escapeHtml(subnets)}</td>
1119
+ <td class="col-hide-tablet" style="font-family:monospace; font-size:12px;">${escapeHtml(gateways)}</td>
1120
+ <td class="col-actions-cell" style="text-align:right;">
1121
+ <button type="button" class="btn btn-secondary btn-icon-only btn-sm action-trigger-btn" title="Actions" aria-label="Actions" aria-haspopup="true" aria-expanded="false" onclick="openFloatingDropdown('network', '${encodeURIComponent(n.name)}', this, event)">
1122
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg>
1123
+ </button>
1124
+ </td>
1125
+ <td class="mobile-toggle-cell" style="text-align:center;">
1126
+ <button type="button" class="btn-expand-row ${isExpanded ? 'expanded' : ''}" data-target-row="${rowId}" aria-label="Toggle details for ${escapeHtml(n.name)}" aria-expanded="${isExpanded}">
1127
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"></polyline></svg>
1128
+ </button>
1129
+ </td>
1130
+ </tr>
1131
+ <tr class="expandable-details-row ${isExpanded ? 'open' : ''}" id="${rowId}">
1132
+ <td colspan="7">
1133
+ <div class="details-drawer-content">
1134
+ <div class="drawer-grid">
1135
+ <div class="drawer-field">
1136
+ <span class="drawer-label">Network ID</span>
1137
+ <span class="drawer-value" style="font-family:monospace; font-size:11px;">${nShort}</span>
1138
+ </div>
1139
+ <div class="drawer-field">
1140
+ <span class="drawer-label">Subnets</span>
1141
+ <span class="drawer-value" style="font-family:monospace; font-size:11px;">${escapeHtml(subnets)}</span>
1142
+ </div>
1143
+ <div class="drawer-field">
1144
+ <span class="drawer-label">Gateways</span>
1145
+ <span class="drawer-value" style="font-family:monospace; font-size:11px;">${escapeHtml(gateways)}</span>
1146
+ </div>
1147
+ </div>
1148
+ </div>
1149
+ </td>
1150
+ </tr>
1151
+ `;
1152
+ }).join('');
1153
+ }
1154
+
1155
+ async function loadEvents(force = false) {
1156
+ try {
1157
+ const res = await API.getEvents('24h');
1158
+ if (res?.data && Array.isArray(res.data)) {
1159
+ if (force || state.events.length === 0) {
1160
+ state.events = res.data;
1161
+ } else {
1162
+ const existingKeys = new Set(state.events.map(e => `${e.time || e.Time}_${e.timeNano || ''}_${e.ID || e.Name}_${e.Status || e.Action}`));
1163
+ for (const item of res.data) {
1164
+ const key = `${item.time || item.Time}_${item.timeNano || ''}_${item.ID || item.Name}_${item.Status || item.Action}`;
1165
+ if (!existingKeys.has(key)) {
1166
+ state.events.push(item);
1167
+ existingKeys.add(key);
1168
+ }
1169
+ }
1170
+ state.events.sort((a, b) => ((b.time || b.Time || 0) - (a.time || a.Time || 0)));
1171
+ }
1172
+ updateBadges();
1173
+ if (state.activeView === 'events') {
1174
+ renderEvents();
1175
+ }
1176
+ }
1177
+ } catch (err) {
1178
+ console.warn('Failed to load past events:', err);
1179
+ }
1180
+ }
1181
+
1182
+ function initEventStream() {
1183
+ try {
1184
+ const eventSource = new EventSource('/api/events/stream');
1185
+ eventSource.onmessage = (e) => {
1186
+ try {
1187
+ const item = JSON.parse(e.data);
1188
+ if (item && (item.Type || item.Action || item.Status)) {
1189
+ state.events.unshift(item);
1190
+ if (state.events.length > 250) state.events.pop();
1191
+ updateBadges();
1192
+ if (state.activeView === 'events') {
1193
+ renderEvents();
1194
+ }
1195
+ }
1196
+ } catch {}
1197
+ };
1198
+ eventSource.onerror = () => {
1199
+ };
1200
+ } catch (err) {
1201
+ console.warn('Events SSE not supported or blocked:', err);
1202
+ }
1203
+ }
1204
+
1205
+ function renderEvents() {
1206
+ const container = document.getElementById('events-container');
1207
+ if (!container) return;
1208
+
1209
+ const search = (state.eventFilter?.search || '').toLowerCase();
1210
+ const filtered = state.events.filter(ev => {
1211
+ if (!search) return true;
1212
+ const type = (ev.Type || '').toLowerCase();
1213
+ const action = (ev.Action || ev.Status || '').toLowerCase();
1214
+ const name = (ev.Name || ev.ID || '').toLowerCase();
1215
+ return type.includes(search) || action.includes(search) || name.includes(search);
1216
+ });
1217
+
1218
+ if (filtered.length === 0) {
1219
+ container.innerHTML = `
1220
+ <div class="empty-state">
1221
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline></svg>
1222
+ <div class="empty-state-title">No events found</div>
1223
+ <div class="empty-state-desc">Listening for Podman daemon activity (containers created, started, stopped, images pulled, etc.).</div>
1224
+ </div>
1225
+ `;
1226
+ return;
1227
+ }
1228
+
1229
+ container.innerHTML = filtered.map(ev => {
1230
+ const type = ev.Type || 'system';
1231
+ const action = ev.Action || ev.Status || 'event';
1232
+ const name = ev.Name || (ev.Image ? ev.Image.split('/').pop() : '') || (ev.ID ? shortId(ev.ID) : '-');
1233
+ const timestamp = ev.time || ev.Time;
1234
+ const timeStr = timestamp ? new Date(timestamp * 1000).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' }) : '-';
1235
+ const dateStr = timestamp ? new Date(timestamp * 1000).toLocaleDateString([], { month: 'short', day: 'numeric' }) : '';
1236
+
1237
+ let actionStyle = 'background-color:rgba(255,255,255,0.06); color:var(--text-secondary);';
1238
+ if (['start', 'create', 'pull'].includes(action)) {
1239
+ actionStyle = 'background-color:var(--apple-green-soft); color:var(--apple-green);';
1240
+ } else if (['died', 'die', 'kill', 'remove', 'rm'].includes(action)) {
1241
+ actionStyle = 'background-color:var(--apple-red-soft); color:var(--apple-red);';
1242
+ } else if (['stop', 'pause'].includes(action)) {
1243
+ actionStyle = 'background-color:var(--apple-yellow-soft); color:var(--apple-yellow);';
1244
+ }
1245
+
1246
+ return `
1247
+ <div style="padding:12px 18px; border-bottom:1px solid var(--border-subtle); display:flex; align-items:center; justify-content:space-between; gap:12px; font-size:13px;">
1248
+ <div style="display:flex; align-items:center; gap:10px; flex-wrap:wrap; min-width:0;">
1249
+ <span class="tag-badge rootless" style="text-transform:uppercase; font-size:10px; letter-spacing:0.5px;">${escapeHtml(type)}</span>
1250
+ <span class="tag-badge" style="${actionStyle}; font-weight:600;">${escapeHtml(action)}</span>
1251
+ <strong style="color:var(--text-primary); word-break:break-all;">${escapeHtml(name)}</strong>
1252
+ ${ev.ID ? `<span class="item-id" title="${escapeHtml(ev.ID)}">${shortId(ev.ID)}</span>` : ''}
1253
+ ${ev.ExitCode !== undefined || ev.ContainerExitCode !== undefined ? `<span style="font-size:11px; color:var(--text-tertiary);">(exit ${ev.ExitCode ?? ev.ContainerExitCode})</span>` : ''}
1254
+ </div>
1255
+ <div style="text-align:right; white-space:nowrap; flex-shrink:0;">
1256
+ <div style="font-size:12px; font-weight:500; color:var(--text-primary); font-family:ui-monospace, SFMono-Regular, monospace;">${timeStr}</div>
1257
+ <div style="font-size:10px; color:var(--text-tertiary);">${dateStr}</div>
1258
+ </div>
1259
+ </div>
1260
+ `;
1261
+ }).join('');
1262
+ }
1263
+
1264
+ async function actionContainer(id, action) {
1265
+ try {
1266
+ showToast('Executing...', `${action.toUpperCase()} container ${shortId(id)}`, 'info');
1267
+ if (action === 'start') await API.startContainer(id);
1268
+ else if (action === 'stop') await API.stopContainer(id);
1269
+ else if (action === 'restart') await API.restartContainer(id);
1270
+ else if (action === 'pause') await API.pauseContainer(id);
1271
+ else if (action === 'unpause') await API.unpauseContainer(id);
1272
+
1273
+ showToast('Success', `Container ${action} completed`, 'success');
1274
+ await refreshData();
1275
+ } catch (err) {
1276
+ showToast(`Failed to ${action} container`, err.message, 'error');
1277
+ }
1278
+ }
1279
+
1280
+ function confirmDeleteContainer(id, name) {
1281
+ if (confirm(`Are you sure you want to remove container "${name}" (${shortId(id)})?`)) {
1282
+ API.removeContainer(id, true)
1283
+ .then(() => {
1284
+ showToast('Container Removed', `Removed ${name}`, 'success');
1285
+ refreshData();
1286
+ })
1287
+ .catch(err => {
1288
+ showToast('Failed to Remove Container', err.message, 'error');
1289
+ });
1290
+ }
1291
+ }
1292
+
1293
+ async function actionPod(id, action) {
1294
+ try {
1295
+ showToast('Executing...', `${action.toUpperCase()} pod ${shortId(id)}`, 'info');
1296
+ if (action === 'start') await API.startPod(id);
1297
+ else if (action === 'stop') await API.stopPod(id);
1298
+ else if (action === 'restart') await API.restartPod(id);
1299
+
1300
+ showToast('Success', `Pod ${action} completed`, 'success');
1301
+ await refreshData();
1302
+ } catch (err) {
1303
+ showToast(`Failed to ${action} pod`, err.message, 'error');
1304
+ }
1305
+ }
1306
+
1307
+ function confirmDeletePod(id, name) {
1308
+ if (confirm(`Are you sure you want to delete pod "${name}"? Containers inside will also be removed.`)) {
1309
+ API.removePod(id, true)
1310
+ .then(() => {
1311
+ showToast('Pod Removed', `Removed ${name}`, 'success');
1312
+ refreshData();
1313
+ })
1314
+ .catch(err => {
1315
+ showToast('Failed to Remove Pod', err.message, 'error');
1316
+ });
1317
+ }
1318
+ }
1319
+
1320
+ function confirmDeleteImage(id, name) {
1321
+ if (confirm(`Are you sure you want to remove image "${name}"?`)) {
1322
+ API.removeImage(id, true)
1323
+ .then(() => {
1324
+ showToast('Image Removed', `Removed ${name}`, 'success');
1325
+ refreshData();
1326
+ })
1327
+ .catch(err => {
1328
+ showToast('Failed to Remove Image', err.message, 'error');
1329
+ });
1330
+ }
1331
+ }
1332
+
1333
+ function deleteVolume(name) {
1334
+ if (confirm(`Are you sure you want to delete volume "${decodeURIComponent(name)}"?`)) {
1335
+ API.removeVolume(name, true)
1336
+ .then(() => {
1337
+ showToast('Volume Removed', decodeURIComponent(name), 'success');
1338
+ refreshData();
1339
+ })
1340
+ .catch(err => {
1341
+ showToast('Failed to Remove Volume', err.message, 'error');
1342
+ });
1343
+ }
1344
+ }
1345
+
1346
+ function deleteNetwork(name) {
1347
+ if (confirm(`Are you sure you want to delete network "${decodeURIComponent(name)}"?`)) {
1348
+ API.removeNetwork(name)
1349
+ .then(() => {
1350
+ showToast('Network Removed', decodeURIComponent(name), 'success');
1351
+ refreshData();
1352
+ })
1353
+ .catch(err => {
1354
+ showToast('Failed to Remove Network', err.message, 'error');
1355
+ });
1356
+ }
1357
+ }
1358
+
1359
+ async function executePrune(type) {
1360
+ if (!confirm(`Are you sure you want to prune ${type}? This will delete unused data irreversibly.`)) {
1361
+ return;
1362
+ }
1363
+ try {
1364
+ showToast('Pruning...', `Pruning ${type}...`, 'info');
1365
+ const res = await API.pruneSystem(type);
1366
+ showToast('Prune Completed', res.stdout || 'Cleaned unused resources', 'success');
1367
+ closeModal('prune-modal');
1368
+ await refreshData();
1369
+ } catch (err) {
1370
+ showToast('Prune Failed', err.message, 'error');
1371
+ }
1372
+ }
1373
+
1374
+ async function inspectItem(type, id) {
1375
+ openModal('inspect-modal');
1376
+ const inspectTitle = document.getElementById('inspect-modal-title');
1377
+ const inspectViewer = document.getElementById('inspect-content');
1378
+
1379
+ inspectTitle.textContent = `Inspect ${type.toUpperCase()}: ${decodeURIComponent(id)}`;
1380
+ inspectViewer.textContent = 'Loading details...';
1381
+
1382
+ try {
1383
+ let data;
1384
+ if (type === 'container') data = (await API.inspectContainer(id)).data;
1385
+ else if (type === 'pod') data = (await API.inspectPod(id)).data;
1386
+ else if (type === 'image') data = (await API.inspectImage(id)).data;
1387
+ else if (type === 'volume') data = (await API.inspectVolume(id)).data;
1388
+ else if (type === 'network') data = (await API.inspectNetwork(id)).data;
1389
+
1390
+ inspectViewer.textContent = JSON.stringify(data, null, 2);
1391
+ } catch (err) {
1392
+ inspectViewer.textContent = `Error loading inspection data:\n${err.message}`;
1393
+ }
1394
+ }
1395
+
1396
+ function viewContainerLogs(id, name) {
1397
+ state.logsConfig.containerId = id;
1398
+ state.logsConfig.containerName = name;
1399
+ openModal('logs-modal');
1400
+ document.getElementById('logs-modal-title').textContent = `Logs: ${name}`;
1401
+
1402
+ const autoBtn = document.getElementById('btn-logs-autoscroll');
1403
+ if (autoBtn) autoBtn.classList.toggle('active', state.logsConfig.autoscroll);
1404
+ const timeBtn = document.getElementById('btn-logs-timestamps');
1405
+ if (timeBtn) timeBtn.classList.toggle('active', state.logsConfig.timestamps);
1406
+
1407
+ restartLogsStream();
1408
+ }
1409
+
1410
+ function restartLogsStream() {
1411
+ const viewer = document.getElementById('logs-viewer');
1412
+ if (!viewer) return;
1413
+ const id = state.logsConfig.containerId;
1414
+ if (!id) return;
1415
+
1416
+ viewer.textContent = 'Streaming logs...\n';
1417
+
1418
+ if (state.activeLogStream) {
1419
+ state.activeLogStream.close();
1420
+ state.activeLogStream = null;
1421
+ }
1422
+
1423
+ const tail = document.getElementById('logs-tail-select')?.value || 100;
1424
+ const timestamps = state.logsConfig.timestamps;
1425
+
1426
+ try {
1427
+ const sse = new EventSource(`/api/containers/${id}/logs/stream?tail=${tail}&timestamps=${timestamps}`);
1428
+ state.activeLogStream = sse;
1429
+
1430
+ sse.onmessage = (e) => {
1431
+ try {
1432
+ const item = JSON.parse(e.data);
1433
+ if (item.log) {
1434
+ viewer.textContent += item.log + '\n';
1435
+ if (state.logsConfig.autoscroll) {
1436
+ viewer.scrollTop = viewer.scrollHeight;
1437
+ }
1438
+ }
1439
+ } catch {}
1440
+ };
1441
+
1442
+ sse.addEventListener('end', () => {
1443
+ viewer.textContent += '\n[Log stream closed]\n';
1444
+ sse.close();
1445
+ state.activeLogStream = null;
1446
+ });
1447
+
1448
+ sse.onerror = () => {
1449
+ API.getContainerLogs(id, tail, timestamps).then(res => {
1450
+ viewer.textContent = res.logs || 'No logs available.';
1451
+ if (state.logsConfig.autoscroll) {
1452
+ viewer.scrollTop = viewer.scrollHeight;
1453
+ }
1454
+ }).catch(err => {
1455
+ viewer.textContent = `Error fetching logs: ${err.message}`;
1456
+ });
1457
+ sse.close();
1458
+ state.activeLogStream = null;
1459
+ };
1460
+ } catch (err) {
1461
+ viewer.textContent = `Log viewer error: ${err.message}`;
1462
+ }
1463
+ }
1464
+
1465
+ function toggleLogsAutoscroll() {
1466
+ state.logsConfig.autoscroll = !state.logsConfig.autoscroll;
1467
+ const btn = document.getElementById('btn-logs-autoscroll');
1468
+ if (btn) {
1469
+ btn.classList.toggle('active', state.logsConfig.autoscroll);
1470
+ }
1471
+ if (state.logsConfig.autoscroll) {
1472
+ const viewer = document.getElementById('logs-viewer');
1473
+ if (viewer) viewer.scrollTop = viewer.scrollHeight;
1474
+ }
1475
+ }
1476
+
1477
+ function toggleLogsTimestamps() {
1478
+ state.logsConfig.timestamps = !state.logsConfig.timestamps;
1479
+ const btn = document.getElementById('btn-logs-timestamps');
1480
+ if (btn) {
1481
+ btn.classList.toggle('active', state.logsConfig.timestamps);
1482
+ }
1483
+ restartLogsStream();
1484
+ }
1485
+
1486
+ function copyLogsToClipboard() {
1487
+ const viewer = document.getElementById('logs-viewer');
1488
+ if (!viewer) return;
1489
+ navigator.clipboard.writeText(viewer.textContent).then(() => {
1490
+ showToast('Copied to Clipboard', 'Container logs copied', 'info');
1491
+ }).catch(() => {
1492
+ showToast('Copy Failed', 'Unable to copy logs', 'error');
1493
+ });
1494
+ }
1495
+
1496
+ function clearLogsViewer() {
1497
+ const viewer = document.getElementById('logs-viewer');
1498
+ if (viewer) viewer.textContent = '';
1499
+ }
1500
+
1501
+ let activeExecContainerId = null;
1502
+ function openExecModal(id, name) {
1503
+ activeExecContainerId = id;
1504
+ openModal('exec-modal');
1505
+ document.getElementById('exec-modal-title').textContent = `Execute Command: ${name}`;
1506
+ document.getElementById('exec-cmd-input').value = '';
1507
+ document.getElementById('exec-output').textContent = 'Enter a command above and press Run (e.g. uname -a, ps aux, ls -la, env)...';
1508
+ }
1509
+
1510
+ async function runContainerExec() {
1511
+ if (!activeExecContainerId) return;
1512
+ const cmd = document.getElementById('exec-cmd-input').value.trim();
1513
+ if (!cmd) return;
1514
+
1515
+ const outputBox = document.getElementById('exec-output');
1516
+ outputBox.textContent = `Running: ${cmd}...\n`;
1517
+
1518
+ try {
1519
+ const res = await API.execContainer(activeExecContainerId, cmd);
1520
+ outputBox.textContent = (res.stdout || '') + (res.stderr ? '\n[STDERR]:\n' + res.stderr : '');
1521
+ if (!res.stdout && !res.stderr) {
1522
+ outputBox.textContent = '[Command completed with empty output]';
1523
+ }
1524
+ } catch (err) {
1525
+ outputBox.textContent = `Execution failed:\n${err.message}`;
1526
+ }
1527
+ }
1528
+
1529
+ function openCreateContainerModal(prefillImage = '') {
1530
+ openModal('create-container-modal');
1531
+ if (prefillImage) {
1532
+ document.getElementById('create-image-input').value = prefillImage;
1533
+ }
1534
+ }
1535
+
1536
+ async function handleCreateContainer(e) {
1537
+ e.preventDefault();
1538
+ const btn = document.getElementById('btn-submit-create-container');
1539
+ btn.disabled = true;
1540
+ btn.textContent = 'Launching Container...';
1541
+
1542
+ const payload = {
1543
+ image: document.getElementById('create-image-input').value.trim(),
1544
+ name: document.getElementById('create-name-input').value.trim(),
1545
+ ports: document.getElementById('create-ports-input').value.trim(),
1546
+ envs: document.getElementById('create-envs-input').value.trim(),
1547
+ volumes: document.getElementById('create-volumes-input').value.trim(),
1548
+ cmd: document.getElementById('create-cmd-input').value.trim(),
1549
+ restart: document.getElementById('create-restart-select').value,
1550
+ autoRemove: document.getElementById('create-autoremove-check').checked
1551
+ };
1552
+
1553
+ try {
1554
+ const result = await API.createContainer(payload);
1555
+ showToast('Container Launched', `ID: ${shortId(result.containerId)}`, 'success');
1556
+ closeModal('create-container-modal');
1557
+ e.target.reset();
1558
+ await refreshData();
1559
+ } catch (err) {
1560
+ showToast('Launch Failed', err.message, 'error');
1561
+ } finally {
1562
+ btn.disabled = false;
1563
+ btn.textContent = 'Run Container';
1564
+ }
1565
+ }
1566
+
1567
+ async function handleCreatePod(e) {
1568
+ e.preventDefault();
1569
+ const name = document.getElementById('create-pod-name').value.trim();
1570
+ const ports = document.getElementById('create-pod-ports').value.trim();
1571
+
1572
+ try {
1573
+ await API.createPod({ name, ports });
1574
+ showToast('Pod Created', name || 'New Pod', 'success');
1575
+ closeModal('create-pod-modal');
1576
+ e.target.reset();
1577
+ await refreshData();
1578
+ } catch (err) {
1579
+ showToast('Failed to Create Pod', err.message, 'error');
1580
+ }
1581
+ }
1582
+
1583
+ function handlePullImage(e) {
1584
+ e.preventDefault();
1585
+ const image = document.getElementById('pull-image-input').value.trim();
1586
+ if (!image) return;
1587
+
1588
+ const outputBox = document.getElementById('pull-output');
1589
+ outputBox.style.display = 'block';
1590
+ outputBox.textContent = `Starting pull for ${image}...\n`;
1591
+
1592
+ const btn = document.getElementById('btn-submit-pull');
1593
+ btn.disabled = true;
1594
+ btn.textContent = 'Pulling...';
1595
+
1596
+ try {
1597
+ const sse = new EventSource(`/api/images/pull-stream?image=${encodeURIComponent(image)}`);
1598
+ sse.onmessage = (event) => {
1599
+ try {
1600
+ const data = JSON.parse(event.data);
1601
+ if (data.text) {
1602
+ outputBox.textContent += data.text;
1603
+ outputBox.scrollTop = outputBox.scrollHeight;
1604
+ }
1605
+ } catch {}
1606
+ };
1607
+
1608
+ sse.addEventListener('complete', () => {
1609
+ outputBox.textContent += '\nImage pull completed successfully!\n';
1610
+ showToast('Image Pulled', image, 'success');
1611
+ btn.disabled = false;
1612
+ btn.textContent = 'Pull Image';
1613
+ sse.close();
1614
+ refreshData();
1615
+ });
1616
+
1617
+ sse.addEventListener('error', (event) => {
1618
+ try {
1619
+ const data = JSON.parse(event.data);
1620
+ outputBox.textContent += `\nError pulling image: ${data.error}\n`;
1621
+ showToast('Pull Failed', data.error, 'error');
1622
+ } catch {
1623
+ outputBox.textContent += '\nConnection to pull stream closed or failed.\n';
1624
+ }
1625
+ btn.disabled = false;
1626
+ btn.textContent = 'Pull Image';
1627
+ sse.close();
1628
+ });
1629
+ } catch (err) {
1630
+ outputBox.textContent += `\nError: ${err.message}\n`;
1631
+ btn.disabled = false;
1632
+ btn.textContent = 'Pull Image';
1633
+ }
1634
+ }
1635
+
1636
+ async function handleCreateVolume(e) {
1637
+ e.preventDefault();
1638
+ const name = document.getElementById('create-vol-name').value.trim();
1639
+ const driver = document.getElementById('create-vol-driver').value.trim();
1640
+
1641
+ try {
1642
+ await API.createVolume(name, driver);
1643
+ showToast('Volume Created', name, 'success');
1644
+ closeModal('create-volume-modal');
1645
+ e.target.reset();
1646
+ await refreshData();
1647
+ } catch (err) {
1648
+ showToast('Failed to Create Volume', err.message, 'error');
1649
+ }
1650
+ }
1651
+
1652
+ async function handleCreateNetwork(e) {
1653
+ e.preventDefault();
1654
+ const name = document.getElementById('create-net-name').value.trim();
1655
+ const driver = document.getElementById('create-net-driver').value.trim() || 'bridge';
1656
+ const subnet = document.getElementById('create-net-subnet').value.trim() || undefined;
1657
+ const gateway = document.getElementById('create-net-gateway').value.trim() || undefined;
1658
+
1659
+ try {
1660
+ await API.createNetwork({ name, driver, subnet, gateway });
1661
+ showToast('Network Created', name, 'success');
1662
+ closeModal('create-network-modal');
1663
+ e.target.reset();
1664
+ await refreshData();
1665
+ } catch (err) {
1666
+ showToast('Failed to Create Network', err.message, 'error');
1667
+ }
1668
+ }
1669
+
1670
+ function setupAutoRefresh() {
1671
+ const select = document.getElementById('refresh-interval-select');
1672
+ if (!select) return;
1673
+
1674
+ const updateInterval = () => {
1675
+ if (state.refreshTimer) clearInterval(state.refreshTimer);
1676
+ const val = parseInt(select.value, 10);
1677
+ state.refreshInterval = val;
1678
+ if (val > 0) {
1679
+ state.refreshTimer = setInterval(() => {
1680
+ refreshData();
1681
+ }, val);
1682
+ }
1683
+ };
1684
+
1685
+ select.addEventListener('change', updateInterval);
1686
+ updateInterval();
1687
+ }
1688
+
1689
+ function toggleMobileSidebar(open) {
1690
+ const sidebar = document.getElementById('sidebar');
1691
+ const backdrop = document.getElementById('sidebar-backdrop');
1692
+ const toggleBtn = document.getElementById('btn-menu-toggle');
1693
+
1694
+ const shouldOpen = typeof open === 'boolean' ? open : !sidebar?.classList.contains('mobile-open');
1695
+ if (sidebar) {
1696
+ sidebar.classList.toggle('mobile-open', shouldOpen);
1697
+ }
1698
+ if (backdrop) {
1699
+ backdrop.classList.toggle('active', shouldOpen);
1700
+ }
1701
+ if (toggleBtn) {
1702
+ toggleBtn.setAttribute('aria-expanded', String(shouldOpen));
1703
+ }
1704
+ if (shouldOpen) {
1705
+ document.body.style.overflow = 'hidden';
1706
+ } else {
1707
+ document.body.style.overflow = '';
1708
+ }
1709
+ }
1710
+
1711
+ document.addEventListener('DOMContentLoaded', () => {
1712
+ document.getElementById('btn-menu-toggle')?.addEventListener('click', () => toggleMobileSidebar());
1713
+ document.getElementById('btn-sidebar-close')?.addEventListener('click', () => toggleMobileSidebar(false));
1714
+ document.getElementById('sidebar-backdrop')?.addEventListener('click', () => toggleMobileSidebar(false));
1715
+
1716
+ document.querySelectorAll('.nav-link[data-view]').forEach(link => {
1717
+ const handleNav = (e) => {
1718
+ e.preventDefault();
1719
+ switchView(link.getAttribute('data-view'));
1720
+ toggleMobileSidebar(false);
1721
+ };
1722
+
1723
+ link.addEventListener('click', handleNav);
1724
+ link.addEventListener('keydown', (e) => {
1725
+ if (e.key === 'Enter' || e.key === ' ') {
1726
+ handleNav(e);
1727
+ }
1728
+ });
1729
+ });
1730
+
1731
+ document.addEventListener('keydown', (e) => {
1732
+ if (e.key === 'Escape') {
1733
+ closeFloatingDropdown();
1734
+ const openModalEl = document.querySelector('.modal-overlay.open');
1735
+ if (openModalEl) {
1736
+ closeModal(openModalEl.id);
1737
+ } else {
1738
+ toggleMobileSidebar(false);
1739
+ }
1740
+ }
1741
+ });
1742
+
1743
+ document.getElementById('btn-refresh-manual')?.addEventListener('click', () => {
1744
+ refreshData();
1745
+ });
1746
+
1747
+ setupAutoRefresh();
1748
+
1749
+ document.getElementById('container-search')?.addEventListener('input', (e) => {
1750
+ state.containerFilter.search = e.target.value;
1751
+ renderContainers();
1752
+ });
1753
+
1754
+ document.querySelectorAll('#container-status-segmented .segment-btn').forEach(btn => {
1755
+ btn.addEventListener('click', () => {
1756
+ document.querySelectorAll('#container-status-segmented .segment-btn').forEach(b => {
1757
+ b.classList.remove('active');
1758
+ b.setAttribute('aria-selected', 'false');
1759
+ });
1760
+ btn.classList.add('active');
1761
+ btn.setAttribute('aria-selected', 'true');
1762
+ state.containerFilter.status = btn.dataset.status || 'all';
1763
+ renderContainers();
1764
+ });
1765
+ });
1766
+
1767
+ document.getElementById('container-status-filter')?.addEventListener('change', (e) => {
1768
+ state.containerFilter.status = e.target.value;
1769
+ renderContainers();
1770
+ });
1771
+
1772
+ document.getElementById('pod-search')?.addEventListener('input', (e) => {
1773
+ state.podFilter.search = e.target.value;
1774
+ renderPods();
1775
+ });
1776
+
1777
+ document.getElementById('image-search')?.addEventListener('input', (e) => {
1778
+ state.imageFilter.search = e.target.value;
1779
+ renderImages();
1780
+ });
1781
+
1782
+ document.getElementById('volume-search')?.addEventListener('input', (e) => {
1783
+ state.volumeFilter.search = e.target.value;
1784
+ renderVolumes();
1785
+ });
1786
+
1787
+ document.getElementById('network-search')?.addEventListener('input', (e) => {
1788
+ state.networkFilter.search = e.target.value;
1789
+ renderNetworks();
1790
+ });
1791
+
1792
+ document.getElementById('event-search')?.addEventListener('input', (e) => {
1793
+ state.eventFilter.search = e.target.value;
1794
+ renderEvents();
1795
+ });
1796
+
1797
+ document.getElementById('form-create-container')?.addEventListener('submit', handleCreateContainer);
1798
+ document.getElementById('form-create-pod')?.addEventListener('submit', handleCreatePod);
1799
+ document.getElementById('form-pull-image')?.addEventListener('submit', handlePullImage);
1800
+ document.getElementById('form-create-volume')?.addEventListener('submit', handleCreateVolume);
1801
+ document.getElementById('form-create-network')?.addEventListener('submit', handleCreateNetwork);
1802
+
1803
+ document.getElementById('btn-run-exec')?.addEventListener('click', runContainerExec);
1804
+ document.getElementById('exec-cmd-input')?.addEventListener('keydown', (e) => {
1805
+ if (e.key === 'Enter') runContainerExec();
1806
+ });
1807
+
1808
+ document.getElementById('btn-copy-inspect')?.addEventListener('click', () => {
1809
+ const text = document.getElementById('inspect-content').textContent;
1810
+ navigator.clipboard.writeText(text);
1811
+ showToast('Copied to Clipboard', 'Inspection JSON copied', 'info');
1812
+ });
1813
+
1814
+ document.querySelectorAll('.modal-overlay').forEach(overlay => {
1815
+ overlay.addEventListener('click', (e) => {
1816
+ if (e.target === overlay) {
1817
+ closeModal(overlay.id);
1818
+ }
1819
+ });
1820
+ });
1821
+
1822
+ window.addEventListener('popstate', () => {
1823
+ const params = new URLSearchParams(window.location.search);
1824
+ const viewFromQuery = params.get('view');
1825
+ const viewFromHash = window.location.hash ? window.location.hash.replace(/^#\/?/, '') : null;
1826
+ const target = viewFromQuery || viewFromHash || 'dashboard';
1827
+ switchView(target, false);
1828
+ });
1829
+
1830
+ const initialParams = new URLSearchParams(window.location.search);
1831
+ const initialViewQuery = initialParams.get('view');
1832
+ const initialViewHash = window.location.hash ? window.location.hash.replace(/^#\/?/, '') : null;
1833
+ const initialView = initialViewQuery || initialViewHash || 'dashboard';
1834
+
1835
+ switchView(initialView, false);
1836
+ loadEvents();
1837
+ initEventStream();
1838
+ });