From e254c9c42944d236336210613178ca6dd83c3d37 Mon Sep 17 00:00:00 2001 From: KyerHarris <101298443+KyerHarris@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:56:12 -0600 Subject: [PATCH] can now attach and detach pod from pico --- samples/index.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/samples/index.js b/samples/index.js index 1054689..19463e0 100644 --- a/samples/index.js +++ b/samples/index.js @@ -1,10 +1,54 @@ -let ECI = ''; let pod = true; +document.addEventListener("DOMContentLoaded", function() { + // Set default photo + setCurrentFolder(''); + + // Modal attach button listener + const attachForm = document.getElementById('loginForm'); + attachForm.addEventListener('submit', function(event) { + event.preventDefault(); + + const storageURL = document.getElementById('podURL').value; + const clientID = document.getElementById('clientID').value; + const clientSecret = document.getElementById('clientSecret').value; + const tokenURL = document.getElementById('tokenURL').value; + + const data = { + storage_url: storageURL, + client_id: clientID, + client_secret: clientSecret, + token_url: tokenURL + }; + let pico = getPicoURL; + + fetch(`${pico}/temp/sample_app/attach_storage`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + console.log(response.json()); + const modal = document.getElementById('myModal'); + modal.style.display = 'none'; + }) + .catch(error => { + console.error('Error:', error); + }); + }); +}); + + async function attach(event) { event.preventDefault(); - ECI = document.getElementById('PicoECI').value; - console.log("Pico ECI: ", ECI); + let pico = document.getElementById('PicoECI').value; + setPicoURL(pico); + console.log("Pico URL: ", pico); window.location.href = 'pod.html'; } @@ -13,9 +57,17 @@ function toggleDetachAttachButtons() { const attachPodButton = document.getElementById('attachPod'); if (pod) { + let pico = getPicoURL; pod = false; detachPodButton.style.display = 'none'; attachPodButton.style.display = 'inline-block'; + fetch(`${pico}/temp/sample_app/detach_storage`) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + console.log(response.json()); + }) } else { pod = true; const modal = document.getElementById('myModal'); @@ -43,3 +95,19 @@ async function toggleFolder(folderHeader) { const folderContent = folderHeader.nextElementSibling; folderContent.classList.toggle('show'); } + +function setPicoURL(url) { + localStorage.setItem('PicoURL', url); +} + +function getPicoURL() { + return localStorage.getItem('PicoURL'); +} + +function setCurrentFolder(url) { + localStorage.setItem('currentFolder', url); +} + +function getCurrentFolder() { + return localStorage.getItem('currentFolder'); +}