Skip to content

Commit

Permalink
can now attach and detach pod from pico
Browse files Browse the repository at this point in the history
  • Loading branch information
KyerHarris authored Mar 22, 2024
1 parent 8057371 commit e254c9c
Showing 1 changed file with 71 additions and 3 deletions.
74 changes: 71 additions & 3 deletions samples/index.js
Original file line number Diff line number Diff line change
@@ -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';
}

Expand All @@ -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');
Expand Down Expand Up @@ -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');
}

0 comments on commit e254c9c

Please sign in to comment.