Skip to content

Commit

Permalink
Added option to compress JSON files
Browse files Browse the repository at this point in the history
on by default
  • Loading branch information
StrawberryMaster committed Jan 14, 2025
1 parent ef8257a commit f368f4a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ <h3>Stage</h3>
<ion-icon name="document-outline" aria-hidden="true"></ion-icon>
<span>Standard JSON</span>
</button>
<div class="compress-option">
<input type="checkbox" id="compress-json" checked>
<label for="compress-json">Compress JSON</label>
</div>
<button type="button" id="export-hurdat">
<ion-icon name="document-text-outline" aria-hidden="true"></ion-icon>
<span>HURDAT Format</span>
Expand Down
26 changes: 25 additions & 1 deletion static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,33 @@ ion-icon+span {

#export-options .formats-container {
display: flex;
flex-direction: column;
gap: .5rem;
}

.compress-option {
display: flex;
align-items: center;
gap: .25rem;
padding: .25rem;
background-color: rgba(255, 255, 255, 0.6);
border-radius: .2rem 0 0 .2rem;
font-size: .8em;
margin-left: .5rem;
}

.compress-option label {
font-size: .85em;
cursor: pointer;
}

.compress-option input[type="checkbox"] {
cursor: pointer;
width: auto;
margin: 0;
transform: scale(0.9);
}

#export-options button {
font-size: .9em;
flex: 1;
Expand Down Expand Up @@ -578,7 +602,7 @@ ion-icon+span {
grid-template-rows: 5fr 1fr;
}

#export-options .formats-container {
#export-options .formats-container {
flex-direction: column;
}

Expand Down
5 changes: 3 additions & 2 deletions static/js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SUCCESS_MESSAGES = {
function convertSpeed(speed, fromUnit, toUnit = 'knots') {
if (!speed) return speed;
if (fromUnit === toUnit) return speed;

if (toUnit === 'knots') {
return Math.round(speed / SPEED_CONVERSION[fromUnit]);
} else {
Expand Down Expand Up @@ -79,7 +79,8 @@ async function downloadTrackData(format = 'json') {
fileExtension = 'txt';
mimeType = 'text/plain';
} else {
content = JSON.stringify(data, null, 2);
const shouldCompress = document.querySelector("#compress-json")?.checked;
content = JSON.stringify(data, null, shouldCompress ? 0 : 2);
fileExtension = 'json';
mimeType = 'application/json';
}
Expand Down

0 comments on commit f368f4a

Please sign in to comment.