From df588f25bfcabd39f972bb95bd49c3fe57599e6c Mon Sep 17 00:00:00 2001 From: MacRimi Date: Tue, 3 Feb 2026 18:14:40 +0100 Subject: [PATCH] Update virtual-machines.tsx --- AppImage/components/virtual-machines.tsx | 435 +---------------------- 1 file changed, 11 insertions(+), 424 deletions(-) diff --git a/AppImage/components/virtual-machines.tsx b/AppImage/components/virtual-machines.tsx index dd255447..c7e64115 100644 --- a/AppImage/components/virtual-machines.tsx +++ b/AppImage/components/virtual-machines.tsx @@ -8,9 +8,7 @@ import { Badge } from "./ui/badge" import { Progress } from "./ui/progress" import { Button } from "./ui/button" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog" -import { Server, Play, Square, Cpu, MemoryStick, HardDrive, Network, Power, RotateCcw, StopCircle, Container, ChevronDown, ChevronUp, Terminal, Archive, Plus, Loader2, Clock, Database } from 'lucide-react' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select" -import { ScrollArea } from "./ui/scroll-area" +import { Server, Play, Square, Cpu, MemoryStick, HardDrive, Network, Power, RotateCcw, StopCircle, Container, ChevronDown, ChevronUp, Terminal } from 'lucide-react' import useSWR from "swr" import { MetricsView } from "./metrics-dialog" import { LxcTerminalModal } from "./lxc-terminal-modal" @@ -123,29 +121,6 @@ interface VMDetails extends VMData { } } -interface BackupStorage { - storage: string - type: string - content: string - total: number - used: number - avail: number - total_human?: string - used_human?: string - avail_human?: string -} - -interface VMBackup { - volid: string - storage: string - type: string - size: number - size_human: string - timestamp: number - date: string - notes?: string -} - const fetcher = async (url: string) => { return fetchApi(url) } @@ -296,14 +271,6 @@ export function VirtualMachines() { const [ipsLoaded, setIpsLoaded] = useState(false) const [loadingIPs, setLoadingIPs] = useState(false) const [networkUnit, setNetworkUnit] = useState<"Bytes" | "Bits">("Bytes") - - // Backup states - const [vmBackups, setVmBackups] = useState([]) - const [backupStorages, setBackupStorages] = useState([]) - const [selectedBackupStorage, setSelectedBackupStorage] = useState("") - const [loadingBackups, setLoadingBackups] = useState(false) - const [creatingBackup, setCreatingBackup] = useState(false) - const [modalPage, setModalPage] = useState(0) useEffect(() => { const fetchLXCIPs = async () => { @@ -380,13 +347,7 @@ export function VirtualMachines() { setShowNotes(false) setIsEditingNotes(false) setEditedNotes("") - setModalPage(0) setDetailsLoading(true) - - // Load backups and storages immediately (independent of config) - fetchBackupStorages() - fetchVmBackups(vm.vmid) - try { const details = await fetchApi(`/api/vms/${vm.vmid}`) setVMDetails(details) @@ -405,54 +366,6 @@ export function VirtualMachines() { setCurrentView("main") } - // Backup functions - const fetchBackupStorages = async () => { - try { - const response = await fetchApi("/api/backup-storages") - if (response.storages) { - setBackupStorages(response.storages) - if (response.storages.length > 0 && !selectedBackupStorage) { - setSelectedBackupStorage(response.storages[0].storage) - } - } - } catch (error) { - console.error("Error fetching backup storages:", error) - } - } - - const fetchVmBackups = async (vmid: number) => { - setLoadingBackups(true) - try { - const response = await fetchApi(`/api/vms/${vmid}/backups`) - if (response.backups) { - setVmBackups(response.backups) - } - } catch (error) { - console.error("Error fetching VM backups:", error) - setVmBackups([]) - } finally { - setLoadingBackups(false) - } - } - - const handleCreateBackup = async () => { - if (!selectedVM || !selectedBackupStorage) return - - setCreatingBackup(true) - try { - await fetchApi(`/api/vms/${selectedVM.vmid}/backup`, { - method: "POST", - body: JSON.stringify({ storage: selectedBackupStorage }), - }) - // Refresh backups list after creation - setTimeout(() => fetchVmBackups(selectedVM.vmid), 2000) - } catch (error) { - console.error("Error creating backup:", error) - } finally { - setCreatingBackup(false) - } - } - const handleVMControl = async (vmid: number, action: string) => { setControlLoading(true) try { @@ -613,7 +526,7 @@ const handleDownloadLogs = async (vmid: number, vmName: string) => { } const isHTML = (str: string): boolean => { - const htmlRegex = new RegExp('<\\/?[a-z][\\s\\S]*>', 'i') + const htmlRegex = /<\/?[a-z][\s\S]*>/i return htmlRegex.test(str) } @@ -1231,246 +1144,12 @@ const handleDownloadLogs = async (vmid: number, vmName: string) => { -
- {/* Mobile carousel */} -
-
- {/* Page 0: Main content */} -
-
- {selectedVM && ( - <> -
- - -
- {/* CPU */} -
-
CPU Usage
-
- {(selectedVM.cpu * 100).toFixed(1)}% -
- -
- {/* Memory */} -
-
Memory
-
- {(selectedVM.mem / 1024 ** 3).toFixed(1)} / {(selectedVM.maxmem / 1024 ** 3).toFixed(1)} GB -
- -
- {/* Disk */} -
-
Disk
-
- {(selectedVM.disk / 1024 ** 3).toFixed(1)} / {(selectedVM.maxdisk / 1024 ** 3).toFixed(1)} GB -
- -
- {/* Disk I/O */} -
-
Disk I/O
-
-
↓ {((selectedVM.diskread || 0) / 1024 ** 2).toFixed(2)} MB
-
↑ {((selectedVM.diskwrite || 0) / 1024 ** 2).toFixed(2)} MB
-
-
- {/* Network I/O */} -
-
Network I/O
-
-
↓ {formatNetworkTraffic(selectedVM.netin || 0, networkUnit)}
-
↑ {formatNetworkTraffic(selectedVM.netout || 0, networkUnit)}
-
-
- {/* OS Icon */} -
- {getOSIcon(vmDetails?.os_info, selectedVM.type)} -
-
-
-
-
- - {/* Resources Section Mobile */} - {vmDetails?.config && ( - - -
-
- -
-

Resources

-
-
- {vmDetails.config.cores && ( -
-
CPU Cores
-
{vmDetails.config.cores}
-
- )} - {vmDetails.config.memory && ( -
-
Memory
-
{vmDetails.config.memory} MB
-
- )} - {vmDetails.config.swap !== undefined && ( -
-
Swap
-
{vmDetails.config.swap} MB
-
- )} -
- {selectedVM?.type === "lxc" && vmDetails?.lxc_ip_info && vmDetails.lxc_ip_info.real_ips.length > 0 && ( -
-

IP Addresses

-
- {vmDetails.lxc_ip_info.real_ips.map((ip, index) => ( - - {ip} - - ))} -
-
- )} -
-
- )} - - )} -
-
- - {/* Page 1: Backups */} -
-
- - - {/* Header */} -
-
- -
-

Backups

-
- - {/* Create Backup */} -
- - -
- - {/* Divider */} -
- - {/* Backup List */} -
- Available backups - {vmBackups.length} -
- - {loadingBackups ? ( -
- - Loading... -
- ) : vmBackups.length === 0 ? ( -
- - No backups found -
- ) : ( -
- {vmBackups.map((backup, index) => ( -
-
-
- - {backup.date} -
- - {backup.size_human} - -
- ))} -
- )} - - -
-
-
- - {/* Pagination dots */} -
-
-
- - {/* Desktop layout */} -
-
- {selectedVM && ( - <> -
- +
+ {selectedVM && ( + <> +
+ @@ -1556,95 +1235,6 @@ const handleDownloadLogs = async (vmid: number, vmName: string) => {
- {/* Backups Section - Always visible, loads independently */} - - - {/* Header */} -
-
-
- -
-

Backups

-
-
- - {/* Create Backup Section */} -
- - -
- - {/* Divider */} -
- - {/* Backup List */} -
- Available backups - {vmBackups.length} -
- - {loadingBackups ? ( -
- - Loading backups... -
- ) : vmBackups.length === 0 ? ( -
- - No backups found -
- ) : ( -
- {vmBackups.map((backup, index) => ( -
-
-
- - {backup.date} -
- - {backup.size_human} - -
- ))} -
- )} - - - {detailsLoading ? (
Loading configuration...
) : vmDetails?.config ? ( @@ -1652,12 +1242,9 @@ const handleDownloadLogs = async (vmid: number, vmName: string) => {
-
-
- -
-

Resources

-
+

+ Resources +