From c1e279a18d8418f2c5fbc8134ecbf7cdab89011d Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sat, 10 May 2025 23:43:21 +0200 Subject: [PATCH] added the behaviour for the download results btn --- public/js/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index f5e83e8..5eca1c7 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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}%`;