From 9e14963bad67ab2c640e98bb2148635b551727ae Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Wed, 16 Jul 2025 19:18:50 -0400 Subject: add csv download --- pnit-form.mjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pnit-form.mjs') diff --git a/pnit-form.mjs b/pnit-form.mjs index c1fa16c..f85457b 100644 --- a/pnit-form.mjs +++ b/pnit-form.mjs @@ -1,3 +1,5 @@ +import CSVDump from './csv-dump.mjs'; + const worker = new Worker('worker.js', { type: 'module' }); export default class extends HTMLElement { @@ -24,6 +26,10 @@ export default class extends HTMLElement { return inputs.flatMap(inp => Array.from(inp.files)); } + get downloadButton() { + return this.querySelector('#csv-download'); + } + get resultTable() { return document.getElementById('pnit-results'); } @@ -37,6 +43,11 @@ export default class extends HTMLElement { this.form.onchange = this.process.bind(this); this.form.onchange(); + + this.downloadButton.onclick = _ => { + const dumper = new CSVDump(this.results); + dumper.download(); + } } handleWorkerMessage(e) { @@ -46,6 +57,7 @@ export default class extends HTMLElement { col.innerText = v; row.appendChild(col); }); + this.results.push(e.data); this.resultTable.appendChild(row); } @@ -60,6 +72,7 @@ export default class extends HTMLElement { process() { console.debug('PNITForm#process', this); + this.results = []; this.resultTable.innerHTML = ''; if (isNaN(this.threshold)) { -- cgit v1.3