feat: implement virtual machine listing page with batch selection and contextual actions

This commit is contained in:
Rizqi 2026-06-23 13:00:46 +07:00
parent 2e1c33c182
commit 7786f08adc
2 changed files with 416 additions and 5 deletions

View File

@ -336,6 +336,160 @@
::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 10px; } ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); } ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }
/* ── Toast Notifications ── */
.toast-container {
position: fixed; bottom: 24px; right: 24px; z-index: 10000;
display: flex; flex-direction: column-reverse; gap: 10px;
pointer-events: none;
}
.toast {
pointer-events: auto;
background: rgba(18, 22, 35, 0.95);
backdrop-filter: blur(24px);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 14px 20px;
min-width: 300px; max-width: 420px;
display: flex; align-items: center; gap: 12px;
font-size: 13.5px; font-weight: 500;
box-shadow: 0 12px 40px rgba(0,0,0,0.5);
transform: translateX(120%);
animation: toast-in .35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast.removing { animation: toast-out .25s ease-in forwards; }
@keyframes toast-in { to { transform: translateX(0); } }
@keyframes toast-out { to { transform: translateX(120%); opacity: 0; } }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.toast-msg { color: var(--text-secondary); font-size: 12.5px; }
.toast-close {
background: none; border: none; color: var(--text-muted); cursor: pointer;
padding: 4px; border-radius: 4px; line-height: 1; flex-shrink: 0;
}
.toast-close:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--accent-2); }
.toast-warning { border-left: 3px solid var(--warning); }
/* ── Command Palette ── */
.cmd-overlay {
position: fixed; inset: 0; z-index: 20000;
background: rgba(0,0,0,0.6);
backdrop-filter: blur(6px);
display: none; align-items: flex-start; justify-content: center;
padding-top: min(20vh, 180px);
}
.cmd-overlay.open { display: flex; }
.cmd-palette {
width: 560px; max-width: 90vw;
background: rgba(18, 22, 35, 0.98);
border: 1px solid var(--border-bright);
border-radius: var(--radius);
box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(99,102,241,0.1);
overflow: hidden;
animation: cmd-in .2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cmd-in { from { opacity:0; transform:scale(0.96) translateY(-10px); } to { opacity:1; transform:scale(1) translateY(0); } }
.cmd-input-wrap {
display: flex; align-items: center; gap: 12px;
padding: 16px 20px;
border-bottom: 1px solid var(--border);
}
.cmd-input-wrap svg { flex-shrink: 0; color: var(--text-muted); }
.cmd-input {
flex: 1; background: none; border: none; outline: none;
color: var(--text-primary); font-size: 15px; font-family: inherit;
}
.cmd-input::placeholder { color: var(--text-muted); }
.cmd-hint {
font-size: 11px; color: var(--text-muted); padding: 8px 20px 4px;
font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
}
.cmd-list {
max-height: 340px; overflow-y: auto;
padding: 8px 8px;
}
.cmd-item {
display: flex; align-items: center; gap: 12px;
padding: 10px 14px; border-radius: var(--radius-sm);
cursor: pointer; color: var(--text-secondary);
font-size: 13.5px; font-weight: 500;
transition: all .12s ease;
}
.cmd-item:hover, .cmd-item.active {
background: rgba(99, 102, 241, 0.1);
color: var(--text-primary);
}
.cmd-item.active { border: 1px solid rgba(99, 102, 241, 0.2); }
.cmd-item-icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.cmd-item-label { flex: 1; }
.cmd-item-kbd {
font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace;
background: rgba(255,255,255,0.04); padding: 2px 6px; border-radius: 4px;
border: 1px solid rgba(255,255,255,0.06);
}
.cmd-footer {
padding: 10px 20px; border-top: 1px solid var(--border);
font-size: 11px; color: var(--text-muted); display: flex; gap: 16px;
}
.cmd-footer kbd {
font-family: 'JetBrains Mono', monospace; font-size: 10px;
background: rgba(255,255,255,0.04); padding: 2px 5px; border-radius: 3px;
border: 1px solid rgba(255,255,255,0.08); margin: 0 2px;
}
/* ── Copy Tooltip ── */
.copy-feedback {
position: fixed; z-index: 15000;
background: var(--success); color: #fff;
font-size: 12px; font-weight: 600;
padding: 4px 10px; border-radius: 6px;
pointer-events: none;
animation: copy-pop .4s ease forwards;
}
@keyframes copy-pop {
0% { opacity: 0; transform: translateY(4px) scale(0.9); }
30% { opacity: 1; transform: translateY(-6px) scale(1); }
100% { opacity: 0; transform: translateY(-18px) scale(0.95); }
}
/* ── Skeleton Loading ── */
.skeleton {
background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%);
background-size: 200% 100%;
animation: shimmer 1.5s ease-in-out infinite;
border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 24px;
box-shadow: var(--shadow);
}
.skeleton-line { height: 14px; margin-bottom: 10px; border-radius: 6px; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-line.h-20 { height: 20px; }
.skeleton-line.h-8 { height: 8px; margin-bottom: 14px; }
.skeleton-block { height: 48px; margin-bottom: 12px; border-radius: var(--radius-sm); }
/* ── Keyboard Shortcut Hints ── */
.kbd-hint {
display: inline-block;
font-family: 'JetBrains Mono', monospace;
font-size: 10px; font-weight: 600;
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08);
padding: 1px 5px; border-radius: 3px;
color: var(--text-muted);
margin-left: 6px; vertical-align: middle;
}
</style> </style>
{% block head %}{% endblock %} {% block head %}{% endblock %}
</head> </head>
@ -403,17 +557,174 @@
<main class="main" {% if not session.get('host') %}style="margin-left:0; align-items:center; justify-content:center;"{% else %}style="min-height:100vh;"{% endif %}> <main class="main" {% if not session.get('host') %}style="margin-left:0; align-items:center; justify-content:center;"{% else %}style="min-height:100vh;"{% endif %}>
{% with messages = get_flashed_messages(with_categories=true) %} {% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %} {% if messages %}
<div style="padding:16px 32px 0"> <div id="flashData" style="display:none;">{{ messages|tojson }}</div>
{% for cat, msg in messages %}
<div class="alert alert-{{ cat }}">{{ msg }}</div>
{% endfor %}
</div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </main>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<!-- Command Palette -->
<div class="cmd-overlay" id="cmdOverlay">
<div class="cmd-palette">
<div class="cmd-input-wrap">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<input class="cmd-input" id="cmdInput" type="text" placeholder="Type a command or search…" autocomplete="off" />
</div>
<div class="cmd-hint">Commands</div>
<div class="cmd-list" id="cmdList"></div>
<div class="cmd-footer">
<span><kbd>↑↓</kbd> Navigate</span>
<span><kbd></kbd> Select</span>
<span><kbd>Esc</kbd> Close</span>
</div>
</div>
</div>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
<!-- Global Scripts -->
<script>
(function() {
// ── Toast System ─────────────────────────────────────────────────────────
const toastIcons = { success: '✓', error: '✕', info: '', warning: '⚠' };
window.showToast = function(type, title, msg, duration) {
duration = duration || 4000;
const c = document.getElementById('toastContainer');
const el = document.createElement('div');
el.className = 'toast toast-' + type;
el.innerHTML = '<span class="toast-icon">' + (toastIcons[type] || '') + '</span>'
+ '<div class="toast-body"><div class="toast-title">' + title + '</div>'
+ (msg ? '<div class="toast-msg">' + msg + '</div>' : '') + '</div>'
+ '<button class="toast-close" onclick="this.closest(\'.toast\').remove()"></button>';
c.appendChild(el);
setTimeout(function() { el.classList.add('removing'); setTimeout(function() { el.remove(); }, 300); }, duration);
};
// Convert Flask flash messages to toasts
var flashEl = document.getElementById('flashData');
if (flashEl) {
try {
var msgs = JSON.parse(flashEl.textContent);
msgs.forEach(function(m) {
var type = m[0] === 'danger' ? 'error' : (m[0] || 'info');
showToast(type, type.charAt(0).toUpperCase() + type.slice(1), m[1]);
});
} catch(e) {}
flashEl.remove();
}
// ── Copy to Clipboard ───────────────────────────────────────────────────
document.addEventListener('click', function(e) {
var el = e.target.closest('[data-copy]');
if (!el) return;
var text = el.getAttribute('data-copy') || el.textContent;
navigator.clipboard.writeText(text).then(function() {
var fb = document.createElement('div');
fb.className = 'copy-feedback';
fb.textContent = '✓ Copied';
var r = el.getBoundingClientRect();
fb.style.left = r.left + r.width / 2 - 24 + 'px';
fb.style.top = r.top - 8 + 'px';
document.body.appendChild(fb);
setTimeout(function() { fb.remove(); }, 600);
});
});
// ── Relative Time Tooltips ──────────────────────────────────────────────
window.renderRelativeTimes = function() {
document.querySelectorAll('[data-ts]').forEach(function(el) {
var ts = parseInt(el.getAttribute('data-ts'), 10);
if (!ts) return;
var d = new Date(ts * 1000);
el.setAttribute('title', d.toLocaleString());
// If text is a raw date, replace with relative
var now = Date.now() / 1000;
var diff = now - ts;
var txt;
if (diff < 60) txt = 'just now';
else if (diff < 3600) txt = Math.floor(diff / 60) + 'm ago';
else if (diff < 86400) txt = Math.floor(diff / 3600) + 'h ago';
else if (diff < 604800) txt = Math.floor(diff / 86400) + 'd ago';
else txt = d.toLocaleDateString();
if (el.hasAttribute('data-relative')) el.textContent = txt;
});
};
renderRelativeTimes();
// ── Command Palette ─────────────────────────────────────────────────────
var cmdOverlay = document.getElementById('cmdOverlay');
var cmdInput = document.getElementById('cmdInput');
var cmdList = document.getElementById('cmdList');
var cmdActive = 0;
var cmdItems = [];
var commands = [
{ icon: '🖥', label: 'Virtual Machines', kbd: '', action: function() { window.location.href = '/vms'; } },
{ icon: '📋', label: 'Backup Jobs', kbd: '', action: function() { window.location.href = '/jobs'; } },
{ icon: '', label: 'Create New Job', kbd: 'N', action: function() { window.location.href = '/jobs/create'; } },
{ icon: '💾', label: 'NFS Manager', kbd: '', action: function() { window.location.href = '/nfs'; } },
{ icon: '🔄', label: 'Refresh Page', kbd: 'R', action: function() { location.reload(); } },
{ icon: '🚪', label: 'Logout', kbd: '', action: function() { window.location.href = '/logout'; } },
];
function renderCommands(filter) {
filter = (filter || '').toLowerCase();
cmdItems = commands.filter(function(c) { return !filter || c.label.toLowerCase().indexOf(filter) >= 0; });
cmdActive = 0;
var html = '';
cmdItems.forEach(function(c, i) {
html += '<div class="cmd-item' + (i === 0 ? ' active' : '') + '" data-idx="' + i + '">'
+ '<span class="cmd-item-icon">' + c.icon + '</span>'
+ '<span class="cmd-item-label">' + c.label + '</span>'
+ (c.kbd ? '<span class="cmd-item-kbd">' + c.kbd + '</span>' : '')
+ '</div>';
});
cmdList.innerHTML = html || '<div style="padding:16px;color:var(--text-muted);text-align:center;">No matching commands</div>';
}
function openCmd() {
cmdOverlay.classList.add('open');
cmdInput.value = '';
renderCommands('');
setTimeout(function() { cmdInput.focus(); }, 50);
}
function closeCmd() { cmdOverlay.classList.remove('open'); }
cmdInput.addEventListener('input', function() { renderCommands(this.value); });
cmdOverlay.addEventListener('click', function(e) { if (e.target === cmdOverlay) closeCmd(); });
cmdInput.addEventListener('keydown', function(e) {
if (e.key === 'Escape') { closeCmd(); return; }
if (e.key === 'ArrowDown') { e.preventDefault(); cmdActive = Math.min(cmdActive + 1, cmdItems.length - 1); updateCmdActive(); }
if (e.key === 'ArrowUp') { e.preventDefault(); cmdActive = Math.max(cmdActive - 1, 0); updateCmdActive(); }
if (e.key === 'Enter' && cmdItems[cmdActive]) { closeCmd(); cmdItems[cmdActive].action(); }
});
cmdList.addEventListener('click', function(e) {
var item = e.target.closest('.cmd-item');
if (item) { closeCmd(); cmdItems[parseInt(item.dataset.idx)].action(); }
});
function updateCmdActive() {
cmdList.querySelectorAll('.cmd-item').forEach(function(el, i) { el.classList.toggle('active', i === cmdActive); });
var active = cmdList.querySelector('.cmd-item.active');
if (active) active.scrollIntoView({ block: 'nearest' });
}
// ── Global Keyboard Shortcuts ───────────────────────────────────────────
document.addEventListener('keydown', function(e) {
// Don't fire in inputs
var tag = (e.target.tagName || '').toLowerCase();
if (tag === 'input' || tag === 'textarea' || tag === 'select' || e.target.isContentEditable) return;
if ((e.ctrlKey || e.metaKey) && e.key === 'k') { e.preventDefault(); openCmd(); return; }
if (e.key === 'Escape' && cmdOverlay.classList.contains('open')) { closeCmd(); return; }
if (e.key === 'n' || e.key === 'N') { window.location.href = '/jobs/create'; }
if (e.key === 'r' || e.key === 'R') { location.reload(); }
if (e.key === '/') { e.preventDefault(); var s = document.querySelector('.search-bar input, #vmSearch'); if (s) s.focus(); }
});
})();
</script>
</body> </body>
</html> </html>

View File

@ -183,6 +183,59 @@
color: var(--text-secondary); color: var(--text-secondary);
} }
.empty-state .empty-icon { font-size: 52px; margin-bottom: 16px; opacity: 0.4; } .empty-state .empty-icon { font-size: 52px; margin-bottom: 16px; opacity: 0.4; }
/* ── VM Quick-Action Menu ── */
.vm-actions-btn {
position: absolute; top: 14px; right: 14px;
width: 30px; height: 30px;
display: flex; align-items: center; justify-content: center;
background: rgba(8,10,16,0.5);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text-muted);
cursor: pointer;
opacity: 0;
transition: all .15s ease;
z-index: 10;
font-size: 16px;
}
.vm-card:hover .vm-actions-btn { opacity: 1; }
.vm-actions-btn:hover {
background: rgba(99,102,241,0.15);
border-color: var(--accent);
color: var(--text-primary);
}
.vm-context-menu {
position: absolute; top: 50px; right: 14px;
background: rgba(18, 22, 35, 0.98);
backdrop-filter: blur(24px);
border: 1px solid var(--border-bright);
border-radius: var(--radius-sm);
box-shadow: 0 16px 48px rgba(0,0,0,0.5);
min-width: 200px;
z-index: 100;
display: none;
overflow: hidden;
animation: menu-in .15s ease;
}
@keyframes menu-in { from { opacity:0; transform:scale(0.95) translateY(-4px); } to { opacity:1; transform:scale(1) translateY(0); } }
.vm-context-menu.open { display: block; }
.ctx-item {
display: flex; align-items: center; gap: 10px;
padding: 10px 16px;
font-size: 13px; font-weight: 500;
color: var(--text-secondary);
cursor: pointer;
transition: all .1s ease;
text-decoration: none;
border: none; background: none; width: 100%;
text-align: left;
}
.ctx-item:hover { background: rgba(99,102,241,0.1); color: var(--text-primary); }
.ctx-item.danger:hover { background: rgba(239,68,68,0.1); color: #fca5a5; }
.ctx-item-icon { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }
.ctx-divider { height: 1px; background: var(--border); margin: 4px 0; }
.ctx-item .ctx-kbd { margin-left: auto; font-size: 10px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }
</style> </style>
{% endblock %} {% endblock %}
@ -276,6 +329,28 @@
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg> <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</div> </div>
<!-- Quick-action menu button -->
<button class="vm-actions-btn" onclick="event.stopPropagation(); toggleVmMenu(this)" title="Actions">
</button>
<div class="vm-context-menu" onclick="event.stopPropagation()">
<a class="ctx-item" href="/jobs/create?vm={{ vm.name|urlencode }}">
<span class="ctx-item-icon"></span> Backup Now
</a>
<a class="ctx-item" href="/jobs/create?vm={{ vm.name|urlencode }}&schedule=1">
<span class="ctx-item-icon">📅</span> Schedule Backup
</a>
<div class="ctx-divider"></div>
<button class="ctx-item" data-copy="{{ vm.name }}">
<span class="ctx-item-icon">📋</span> Copy VM Name
</button>
{% if vm.ip_address %}
<button class="ctx-item" data-copy="{{ vm.ip_address }}">
<span class="ctx-item-icon">🌐</span> Copy IP Address
</button>
{% endif %}
</div>
<div class="vm-card-header"> <div class="vm-card-header">
<div> <div>
<div class="vm-name">{{ vm.name }}</div> <div class="vm-name">{{ vm.name }}</div>
@ -451,5 +526,30 @@
selected.forEach(vm => params.append('vms', vm)); selected.forEach(vm => params.append('vms', vm));
window.location.href = '/jobs/batch?' + params.toString(); window.location.href = '/jobs/batch?' + params.toString();
} }
// ── VM Context Menu ───────────────────────────────────────────────────────
let openMenu = null;
function toggleVmMenu(btn) {
closeAllMenus();
const menu = btn.nextElementSibling;
menu.classList.add('open');
openMenu = menu;
}
function closeAllMenus() {
document.querySelectorAll('.vm-context-menu.open').forEach(m => m.classList.remove('open'));
openMenu = null;
}
document.addEventListener('click', function(e) {
if (openMenu && !openMenu.contains(e.target)) closeAllMenus();
});
// Hide action button when in select mode
const origToggle = toggleSelectMode;
toggleSelectMode = function() {
origToggle();
document.querySelectorAll('.vm-actions-btn').forEach(b => {
b.style.display = selectMode ? 'none' : '';
});
if (selectMode) closeAllMenus();
};
</script> </script>
{% endblock %} {% endblock %}