Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up css and url generation #8

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,18 @@ a {
a:hover {
text-decoration: underline;
}

#inner-box {
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 3px;
box-sizing: border-box;
}

#description {
text-align: center;
margin-bottom: 20px;
font-size: 1em;
color: #333;
}
32 changes: 24 additions & 8 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,33 @@ class MeetingDataProcessor {

// CSV export functionality
exportCSV(meetings) {
const csvContent = `data:text/csv;charset=utf-8,${encodeURIComponent(
this.constructor.convertToCSV(meetings)
)}`;
const convertedCSV = this.constructor.convertToCSV(meetings);
const csvContent = MeetingDataProcessor.createDownloadLink(
convertedCSV,
"text/csv"
);
const downloadLink = document.getElementById("downloadLink");
downloadLink.href = csvContent;
downloadLink.style.display = "block";
}

// KML export functionality
exportKML(meetings) {
const kmlContent = `data:text/xml;charset=utf-8,${encodeURIComponent(
this.constructor.convertToKML(meetings)
)}`;
const convertedKML = this.constructor.convertToKML(meetings);
const kmlContent = MeetingDataProcessor.createDownloadLink(
convertedKML,
"application/vnd.google-earth.kml+xml"
);
const kmlDownloadLink = document.getElementById("kmlDownloadLink");
kmlDownloadLink.href = kmlContent;
kmlDownloadLink.style.display = "block";
}

static createDownloadLink(data, type) {
const blob = new Blob([data], { type });
return URL.createObjectURL(blob);
}

static hideLinks() {
const downloadLink = document.getElementById("downloadLink");
downloadLink.style.display = "none";
Expand All @@ -107,16 +116,23 @@ class MeetingDataProcessor {

// Convert data to CSV
static convertToCSV(data) {
if (!Array.isArray(data) || data.length === 0) {
MeetingDataProcessor.displayError("No data found");
throw new Error("No data found");
}
const csvRows = [];
const keys = Object.keys(data[0]);
csvRows.push(keys.join(","));

data.forEach((row) => {
const values = keys.map((key) => {
let value = row[key];
let value = row[key] === null ? "" : row[key];
if (
typeof value === "string" &&
(value.includes(",") || value.includes('"'))
(value.includes(",") ||
value.includes('"') ||
value.includes("\n") ||
value.includes("\r"))
) {
value = `"${value.replace(/"/g, '""')}"`;
}
Expand Down
18 changes: 11 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
<body>
<h1>BMLT Data Converter</h1>
<div id="export-form">
<label for="query">BMLT URL Query:</label>
<input type="text" id="query" required>
<br>
<button onclick="exportData()">Generate Export Data</button>
<a id="downloadLink" style="display: none;" download="BMLT_data.csv">Download CSV</a>
<a id="kmlDownloadLink" style="display: none;" download="BMLT_data.kml">Download KML</a>
<div id="errorMessages" style="display: none;"></div>
<div id="description">Converts BMLT JSON meeting data to CSV or KML</div>
<div id="inner-box">
<label for="query">BMLT URL Query:</label>
<input type="text" id="query" required>
<br>
<button onclick="exportData()">Generate Export Data</button>
<a id="downloadLink" style="display: none;" download="BMLT_data.csv">Download CSV</a>
<a id="kmlDownloadLink" style="display: none;" download="BMLT_data.kml">Download KML</a>
<div id="errorMessages" style="display: none;"></div>
</div>
</div>

<script src="assets/js/main.js"></script>
</body>
</html>