Skip to content

Commit cc75107

Browse files
committed
Download as CSV
1 parent 25800a6 commit cc75107

File tree

4 files changed

+62
-32
lines changed

4 files changed

+62
-32
lines changed

index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ <h2>Visualize Your Backup</h2>
243243
</p>
244244

245245
<p>
246-
The files use the JSON format and can be opened in any text editor. You
247-
should store them somewhere encrypted for safety.
246+
The files use the JSON format and can be opened in any text editor.
247+
<strong>You should store them somewhere encrypted for safety.</strong>
248248
</p>
249249

250250
<p>
251251
By themselves, you may have trouble sifting through the large files. A
252-
visualizer is in the works.
252+
simple visualizer is available with more tools in the works.
253253
</p>
254254
<a href="visualizer.html">Continue to the Snapshot Visualizer</a>
255255

@@ -363,8 +363,13 @@ <h2>Disclaimers</h2>
363363

364364
<p>
365365
<strong>License & contact:</strong> This project is open source.
366-
<em>(Insert chosen license, e.g., MIT)</em>. For legal questions,
367-
takedown notices, or contact: <em>(insert contact email)</em>.
366+
<em
367+
>(<a
368+
href="https://github.com/wraybowling/baqup-tools/blob/main/LICENSE"
369+
>GPL 3.0</a
370+
>)</em
371+
>. For legal questions, takedown notices, or contact:
372+
<em>(insert contact email)</em>.
368373
</p>
369374

370375
<p>

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,7 @@ header img {
116116
flex-direction: column;
117117
}
118118
}
119+
120+
.hidden {
121+
display: none;
122+
}

visualizer.html

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,24 @@ <h2>Qubes</h2>
6565
<input type="file" id="fileInput" />
6666
<label for="fileInput"> Drag and drop your account file here. </label>
6767
</div>
68+
<button class="download hidden" onClick="downloadCSV()">
69+
Download as CSV
70+
</button>
6871

69-
<div class="sidescroll">
70-
<table id="qubes">
71-
<thead>
72-
<tr>
73-
<th>Name</th>
74-
<th>Type</th>
75-
<th>12 Month</th>
76-
<th>6 Month</th>
77-
<th>3 Month</th>
78-
<th>Budget</th>
79-
<th>Bill/Goal</th>
80-
</tr>
81-
</thead>
82-
<tbody></tbody>
83-
</table>
84-
</div>
72+
<table id="qubes">
73+
<thead>
74+
<tr>
75+
<th>Name</th>
76+
<th>Type</th>
77+
<th>12 Month</th>
78+
<th>6 Month</th>
79+
<th>3 Month</th>
80+
<th>Budget</th>
81+
<th>Bill/Goal</th>
82+
</tr>
83+
</thead>
84+
<tbody></tbody>
85+
</table>
8586

8687
<div class="bigbreak"></div>
8788

visualizer.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
document.querySelector('.dropzone').addEventListener('drop', (e) => {
2-
e.preventDefault();
3-
let file = e.dataTransfer.files[0];
1+
const downloadButton = document.querySelector('.download');
2+
3+
function downloadCSV() {
4+
const qubesTable = document.querySelector('#qubes');
5+
const rows = Array.from(qubesTable.querySelectorAll('tr')).map((row) =>
6+
Array.from(row.querySelectorAll('th,td')).map((cell) => cell.textContent)
7+
);
8+
const filename = 'baqup-qubes.csv';
9+
const csvContent = rows
10+
.map((row) => row.map((cell) => `"${cell}"`).join(','))
11+
.join('\n');
12+
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
13+
const url = URL.createObjectURL(blob);
14+
const a = document.createElement('a');
15+
a.href = url;
16+
a.setAttribute('download', filename);
17+
a.style.display = 'none';
18+
document.body.appendChild(a);
19+
a.click();
20+
document.body.removeChild(a);
21+
}
22+
function handleFile(file) {
423
let reader = new FileReader();
524
reader.onload = (event) => {
625
let jsonData = JSON.parse(event.target.result);
@@ -9,18 +28,19 @@ document.querySelector('.dropzone').addEventListener('drop', (e) => {
928
addQubesToTable(qubesTable, jsonData);
1029
};
1130
reader.readAsText(file);
31+
}
32+
33+
document.querySelector('.dropzone').addEventListener('drop', (e) => {
34+
e.preventDefault();
35+
let file = e.dataTransfer.files[0];
36+
handleFile(file);
37+
downloadButton.classList.remove('hidden');
1238
});
1339

1440
document.querySelector('input[type=file]').addEventListener('change', (e) => {
1541
let file = e.target.files[0];
16-
let reader = new FileReader();
17-
reader.onload = (event) => {
18-
let jsonData = JSON.parse(event.target.result);
19-
console.log(jsonData);
20-
const qubesTable = document.querySelector('#qubes > tbody');
21-
addQubesToTable(qubesTable, jsonData);
22-
};
23-
reader.readAsText(file);
42+
handleFile(file);
43+
downloadButton.classList.remove('hidden');
2444
});
2545

2646
function addQubesToTable(qubesTable, jsonData) {

0 commit comments

Comments
 (0)