From 957ead65219ef2f4a8b36ed4303e33fa8320c8c6 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 6 Dec 2024 18:57:28 +0100 Subject: [PATCH] Can see group VM screenshot --- remote_frontend/src/api/GroupApi.ts | 2 +- remote_frontend/src/widgets/GroupsWidget.tsx | 161 ++++++++++++------ .../src/widgets/VMLiveScreenshot.tsx | 11 +- 3 files changed, 121 insertions(+), 53 deletions(-) diff --git a/remote_frontend/src/api/GroupApi.ts b/remote_frontend/src/api/GroupApi.ts index 0fd84e9..a7703b9 100644 --- a/remote_frontend/src/api/GroupApi.ts +++ b/remote_frontend/src/api/GroupApi.ts @@ -96,7 +96,7 @@ export class GroupApi { /** * Request a screenshot of the VM of group */ - static async ScreenshotVM(g: VMGroup, vm?: VMInfo): Promise { + static async ScreenshotVM(g: VMGroup, vm?: VMInfo): Promise { return ( await APIClient.exec({ method: "GET", diff --git a/remote_frontend/src/widgets/GroupsWidget.tsx b/remote_frontend/src/widgets/GroupsWidget.tsx index d857a80..100f9a1 100644 --- a/remote_frontend/src/widgets/GroupsWidget.tsx +++ b/remote_frontend/src/widgets/GroupsWidget.tsx @@ -1,21 +1,33 @@ import { + Button, Card, + Dialog, + DialogActions, + DialogBody, + DialogContent, + DialogSurface, + DialogTitle, + DialogTrigger, Table, TableBody, TableCell, + TableCellActions, TableCellLayout, TableHeader, TableHeaderCell, TableRow, Title3, + Tooltip, } from "@fluentui/react-components"; -import { Desktop24Regular } from "@fluentui/react-icons"; +import { Desktop24Regular, ScreenshotRegular } from "@fluentui/react-icons"; import { filesize } from "filesize"; import React from "react"; import { GroupApi, GroupVMState } from "../api/GroupApi"; import { Rights, VMGroup } from "../api/ServerApi"; +import { VMInfo } from "../api/VMApi"; import { useToast } from "../hooks/providers/ToastProvider"; import { GroupVMAction } from "./GroupVMAction"; +import { VMLiveScreenshot } from "./VMLiveScreenshot"; export function GroupsWidget(p: { rights: Rights }): React.ReactElement { return ( @@ -31,12 +43,17 @@ function GroupInfo(p: { group: VMGroup }): React.ReactElement { const toast = useToast(); const [state, setState] = React.useState(); + const [screenshotVM, setScreenshotVM] = React.useState(); const load = async () => { const newState = await GroupApi.State(p.group); if (state !== newState) setState(newState); }; + const screenshot = (vm: VMInfo) => { + setScreenshotVM(vm); + }; + React.useEffect(() => { const interval = setInterval(async () => { try { @@ -54,55 +71,99 @@ function GroupInfo(p: { group: VMGroup }): React.ReactElement { }); return ( - -
- {p.group.id} - -
- - - - VM - Resources - State - Actions - - - - {p.group.vms.map((item) => ( - - - } - appearance="primary" - description={item.description} - > - {item.name} - - - - {item.architecture} • RAM :{" "} - {filesize(item.memory * 1000 * 1000)} • {item.number_vcpu}{" "} - vCPU - - {state?.[item.uuid] ?? ""} - - - + <> + +
+ {p.group.id} + +
+
+ + + VM + Resources + State + Actions - ))} - -
-
+ + + {p.group.vms.map((item) => ( + + + } + appearance="primary" + description={item.description} + > + {item.name} + + + {state?.[item.uuid] === "Running" && ( + + + + + + + + ); } diff --git a/remote_frontend/src/widgets/VMLiveScreenshot.tsx b/remote_frontend/src/widgets/VMLiveScreenshot.tsx index 115b958..74250d2 100644 --- a/remote_frontend/src/widgets/VMLiveScreenshot.tsx +++ b/remote_frontend/src/widgets/VMLiveScreenshot.tsx @@ -1,8 +1,13 @@ import React from "react"; +import { GroupApi } from "../api/GroupApi"; +import { VMGroup } from "../api/ServerApi"; import { VMApi, VMInfo } from "../api/VMApi"; import { useToast } from "../hooks/providers/ToastProvider"; -export function VMLiveScreenshot(p: { vm: VMInfo }): React.ReactElement { +export function VMLiveScreenshot(p: { + vm: VMInfo; + group?: VMGroup; +}): React.ReactElement { const toast = useToast(); const [screenshotURL, setScreenshotURL] = React.useState< @@ -14,7 +19,9 @@ export function VMLiveScreenshot(p: { vm: VMInfo }): React.ReactElement { React.useEffect(() => { const refresh = async () => { try { - const screenshot = await VMApi.Screenshot(p.vm); + const screenshot = p.group + ? await GroupApi.ScreenshotVM(p.group, p.vm) + : await VMApi.Screenshot(p.vm); const u = URL.createObjectURL(screenshot); setScreenshotURL(u); } catch (e) {