Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage Volumes #90

Merged
merged 19 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,106 @@ async function logout() {
buttonLoading(logoutButton, false, "Logout")
}
}

async function deleteVolume(block_name) {
const deleteButton = document.getElementById(`delete-block-button-${block_name}`);
const molly_csrf = document.getElementById("molly-csrf").value;
const formAlert = document.getElementById("form-alert");
try {
buttonLoading(deleteButton, true, "Deleting...")
const response = await fetch("/api/volume/delete", {
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
{
"block_name": block_name,
"molly_csrf": molly_csrf
})
})
const data = await response.json();
if (data.status === 200) {
formAlert.classList.remove("hidden", "text-secondary-500");
formAlert.classList.add("text-primary-500");
formAlert.textContent = "Successfully deleted";
postAlert("bg-primary-300", "Volume deleted succesfully");
setTimeout(() => window.location.reload(), 1000);
buttonLoading(deleteButton, false, "Delete")
} else {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = data.data
buttonLoading(deleteButton, false, "Delete")
}
} catch (error) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = error
buttonLoading(deleteButton, false, "Delete")
}
}

async function createVolume() {
const createButton = document.getElementById("create-block-button");
const block_name = document.getElementById("block_name").value;
const block_size = document.getElementById("block_size").innerText;
const data_toggle = document.getElementById("dataToggle").checked;
const molly_csrf = document.getElementById("molly-csrf").value;
const formAlert = document.getElementById("form-alert");
const block_compressed = document.getElementById("block_compressed").checked;
const block_data = document.getElementById("block_data").files[0];
try {
if (block_name === "") {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = "Please enter a name for this volume"
buttonLoading(createButton, false, "Create volume")
}
else if (Number(block_size) < 1) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = "Volume size must be 1MB or greater."
buttonLoading(createButton, false, "Create volume")
}
else {
buttonLoading(createButton, true, "Creating...")
let formData = new FormData();
formData.append("block_name", block_name);
formData.append("block_size", Number(block_size))
if (data_toggle && !block_data) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = "You must upload a file else switch 'Dumb data to this volume' off"
buttonLoading(createButton, false, "Create volume")
return;
}
formData.append("block_compressed", block_compressed)
formData.append("block_data", block_data)
formData.append("molly_csrf", molly_csrf)
const response = await fetch("/api/volume/create", {
method: 'POST',
body: formData
})
const data = await response.json();
if (data.status === 200) {
formAlert.classList.remove("hidden", "text-secondary-500");
formAlert.classList.add("text-primary-500");
formAlert.textContent = "Succesfully deleted";
postAlert("bg-primary-300", "Volume created succesfully");
setTimeout(() => window.location.reload(), 000);
buttonLoading(createButton, false, "Create volume")
} else {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = data.data
buttonLoading(createButton, false, "Create volume")
}
}
} catch (error) {
formAlert.classList.remove("hidden", "text-primary-500");
formAlert.classList.add("text-secondary-500");
formAlert.textContent = error
buttonLoading(createButton, false, "Create volume")
}
}
2 changes: 1 addition & 1 deletion assets/style.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions header_layout.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ let header ?(page_title = "Mollymawk") ~icon () =
"https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js";
]
(txt "");
(* chart.js is used for chart elements like pie charts. We use this to visualize usage data of policies*)
script ~a:[ a_src "https://cdn.jsdelivr.net/npm/chart.js" ] (txt "");
])
Loading