mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 06:08:13 +02:00
added the behaviour for the download results btn
This commit is contained in:
@ -7,6 +7,8 @@ const statusEl = document.getElementById("status");
|
||||
|
||||
const resultsContainer = document.getElementById("results-container");
|
||||
|
||||
let results = {};
|
||||
|
||||
// Download logic
|
||||
document.getElementById("download-dataset").onclick = () => {
|
||||
const ds = document.getElementById("dataset-select").value;
|
||||
@ -43,13 +45,14 @@ document.getElementById("upload-btn").onclick = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
results = json;
|
||||
progressContainer.style.display = "none";
|
||||
resultsContainer.style.display = "block";
|
||||
|
||||
const tbody = resultsContainer.querySelector("table tbody");
|
||||
tbody.innerHTML = "";
|
||||
|
||||
Object.entries(json).forEach(([id, info]) => {
|
||||
Object.entries(results).forEach(([id, info]) => {
|
||||
const row = tbody.insertRow(); // create a new row
|
||||
const idCell = row.insertCell(); // cell 1: id
|
||||
const commentCell = row.insertCell(); // cell 2: proposed comment
|
||||
@ -61,6 +64,18 @@ document.getElementById("upload-btn").onclick = async () => {
|
||||
});
|
||||
};
|
||||
|
||||
document.getElementById("download-results").onclick = () => {
|
||||
const dataStr =
|
||||
"data:text/json;charset=utf-8," +
|
||||
encodeURIComponent(JSON.stringify(results));
|
||||
const dlAnchorElem = document.createElement("a");
|
||||
dlAnchorElem.setAttribute("href", dataStr);
|
||||
dlAnchorElem.setAttribute("download", "results.json");
|
||||
document.body.appendChild(dlAnchorElem);
|
||||
dlAnchorElem.click();
|
||||
document.body.removeChild(dlAnchorElem);
|
||||
};
|
||||
|
||||
function setProgress(percent) {
|
||||
progressBar.value = percent;
|
||||
progressText.textContent = `${percent}%`;
|
||||
|
Reference in New Issue
Block a user