From 3557050f8e27b84492423041c4908235d4b8f8be Mon Sep 17 00:00:00 2001 From: Arthur Wambst Date: Mon, 20 Oct 2025 17:11:19 +0200 Subject: [PATCH] remaking Immersion page for admins --- src/pages/Immersion.tsx | 270 +++++++++++++++++++++++++++++++++------- 1 file changed, 228 insertions(+), 42 deletions(-) diff --git a/src/pages/Immersion.tsx b/src/pages/Immersion.tsx index 6c4b248..d2830be 100644 --- a/src/pages/Immersion.tsx +++ b/src/pages/Immersion.tsx @@ -10,7 +10,10 @@ function Immersion() { const { id } = useParams(); const [ji, setJi] = useState(); const [instance, setInstance] = useState(); + const [allInstances, setAllInstances] = useState([]); + const [instancesStatus, setInstancesStatus] = useState>({}); const username = localStorage.getItem("username"); + const copyText = (copy: string) => { navigator.clipboard.writeText(copy); toast.success("Copied!", { @@ -31,6 +34,21 @@ function Immersion() { }); }, [id]); + useEffect(() => { + axios.get(`/api/ji/${id}/all-instances`).then((res) => { + setAllInstances(res.data); + // Récupérer le status de chaque instance + res.data.forEach((inst: Instance) => { + axios.get(`/api/ji/${id}/container`).then((statusRes) => { + setInstancesStatus(prev => ({ + ...prev, + [inst.id]: statusRes.data + })); + }); + }); + }); + }, [id]); + useEffect(() => { axios.get("/api/user/me").then((res) => { localStorage.setItem("username", res.data.username); @@ -45,13 +63,75 @@ function Immersion() { const container_status = localStorage.getItem("container_status"); + const handleCreateContainers = () => { + axios.post(`/api/ji/${id}/containers`).then((res) => { + if (res.status === 200) { + toast.success("Containers created successfully!", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + // Recharger les instances pour mettre à jour les status + axios.get(`/api/ji/${id}/all-instances`).then((res) => { + setAllInstances(res.data); + }); + } + }).catch((error) => { + toast.error("Failed to create containers", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + }); + }; + + const handleStartAllContainers = () => { + axios.post(`/api/ji/${id}/container/start`).then((res) => { + if (res.status === 200) { + toast.success("All containers started successfully!", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + // Recharger les instances pour mettre à jour les status + axios.get(`/api/ji/${id}/all-instances`).then((res) => { + setAllInstances(res.data); + }); + } + }).catch((error) => { + toast.error("Failed to start containers", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + }); + }; + + const handleStopAllContainers = () => { + axios.post(`/api/ji/${id}/container/stop`).then((res) => { + if (res.status === 200) { + toast.success("All containers stopped successfully!", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + // Recharger les instances pour mettre à jour les status + axios.get(`/api/ji/${id}/all-instances`).then((res) => { + setAllInstances(res.data); + }); + } + }).catch((error) => { + toast.error("Failed to stop containers", { + draggable: true, + theme: localStorage.getItem("theme") || "dark", + }); + }); + }; + return ( <> {ji && ( <>

{ji.name}

-
+ {/* Section supérieure : Info + iframe */} +
+ {/* Colonne gauche - Informations */}

@@ -69,49 +149,53 @@ function Immersion() {

- { instance &&
-

- Your credentials : -

-
    -
  • - SSH: -
    copyText(`ssh -p ${instance.port} ${username}@la-banquise.fr`)} - > - ssh -p {instance.port} {username}@la-banquise.fr -
    - + + {instance && ( +
    +

    + Your credentials : +

    +
      +
    • + SSH: +
      copyText(`ssh -p ${instance.port} ${username}@la-banquise.fr`)} + > + ssh -p {instance.port} {username}@la-banquise.fr +
      + +
      -
    -
  • -
  • - Instance name: -
    - {instance.name} -
    -
  • -
  • - Password: -
    copyText(instance.pwd)} - > - {instance.pwd} -
    - +
  • +
  • + Instance name: +
    + {instance.name}
    -
- -
  • - Status: -
    - {container_status} -
    -
  • - -
    } + +
  • + Password: +
    copyText(instance.pwd)} + > + {instance.pwd} +
    + +
    +
    +
  • +
  • + Status: +
    + {container_status} +
    +
  • + +
    + )} +
    + + {/* Colonne droite - iframe du sujet */} +
    +
    +

    + Subject +

    +