-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
254 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import { processExportData } from '../utils/DataUtils'; | ||
import * as XLSX from 'xlsx'; | ||
export let data: any[]; | ||
let downloadUrl: string = ''; | ||
$: downloadUrl = exportCSV(data); | ||
function exportCSV(data: any[]): string { | ||
const processedData = processExportData(data); | ||
const wb = XLSX.utils.book_new(); | ||
const ws = XLSX.utils.json_to_sheet(processedData); | ||
XLSX.utils.book_append_sheet(wb, ws, 'Data'); | ||
const csvString = XLSX.write(wb, { bookType: 'csv', type: 'string' }); | ||
const blob = new Blob([csvString], { type: 'text/csv' }); | ||
return URL.createObjectURL(blob); | ||
} | ||
</script> | ||
|
||
<a href={downloadUrl} class="download-links" download="BMLT_data.csv">Download CSV</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<script lang="ts"> | ||
import type { Meeting } from '../utils/DataUtils'; | ||
export let data: Meeting[]; | ||
let downloadUrl: string = ''; | ||
$: downloadUrl = exportKML(data); | ||
function exportKML(data: Meeting[]): string { | ||
const placemarks = data.map(createPlacemark).filter(Boolean).join('\n'); | ||
const kmlContent = `<?xml version="1.0" encoding="UTF-8"?> | ||
<kml xmlns="http://www.opengis.net/kml/2.2"> | ||
<Document> | ||
${placemarks} | ||
</Document> | ||
</kml>`; | ||
const blob = new Blob([kmlContent], { type: 'application/vnd.google-earth.kml+xml' }); | ||
return URL.createObjectURL(blob); | ||
} | ||
function createPlacemark(meeting: Meeting): string { | ||
const name = meeting.meeting_name.trim() || 'NA Meeting'; | ||
const lng = parseFloat(meeting.longitude); | ||
const lat = parseFloat(meeting.latitude); | ||
if (!lng || !lat) return ''; | ||
const description = prepareSimpleLine(meeting); | ||
const address = prepareSimpleLine(meeting, false); | ||
return ` | ||
<Placemark> | ||
<name>${name}</name> | ||
${address ? `<address>${address}</address>` : ''} | ||
${description ? `<description>${description}</description>` : ''} | ||
<Point> | ||
<coordinates>${lng},${lat}</coordinates> | ||
</Point> | ||
</Placemark> | ||
`.trim(); | ||
} | ||
function prepareSimpleLine(meeting: Meeting, withDate: boolean = true): string { | ||
const getLocationInfo = () => { | ||
const locationInfo: string[] = []; | ||
const addInfo = (property: keyof Meeting) => { | ||
const value = meeting[property]?.trim() ?? ''; | ||
if (value) locationInfo.push(value); | ||
}; | ||
addInfo('location_text'); | ||
addInfo('location_street'); | ||
addInfo('location_city_subsection'); | ||
addInfo('location_municipality'); | ||
addInfo('location_neighborhood'); | ||
addInfo('location_province'); | ||
addInfo('location_postal_code_1'); | ||
addInfo('location_nation'); | ||
addInfo('location_info'); | ||
return locationInfo.join(', '); | ||
}; | ||
const getDateString = () => { | ||
const dayOfWeekInt = parseInt(meeting.weekday_tinyint?.trim() ?? '0'); | ||
const adjustedDay = dayOfWeekInt % 7; | ||
// January 1, 2023, was a Sunday. | ||
const baseDate = new Date('2023-01-01'); | ||
baseDate.setDate(baseDate.getDate() + adjustedDay); | ||
const lang = meeting.lang_enum ? (meeting.lang_enum === 'dk' ? 'da' : meeting.lang_enum) : window.navigator.language; | ||
const twelveHrLangs: string[] = ['en', 'es']; | ||
if (dayOfWeekInt && withDate) { | ||
let dateString = baseDate.toLocaleDateString(lang, { weekday: 'long' }); | ||
if (!isNaN(baseDate.getTime())) { | ||
dateString += `, ${baseDate.toLocaleTimeString(lang, { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
hour12: twelveHrLangs.includes(lang) | ||
})}`; | ||
} | ||
return dateString; | ||
} | ||
return ''; | ||
}; | ||
const locationInfo = getLocationInfo(); | ||
const dateString = getDateString(); | ||
if (withDate && dateString && locationInfo) { | ||
return `${dateString}, ${locationInfo}`; | ||
} else if (dateString) { | ||
return dateString; | ||
} else { | ||
return locationInfo; | ||
} | ||
} | ||
</script> | ||
|
||
<a href={downloadUrl} class="download-links" download="BMLT_data.kml">Download KML</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import { processExportData, s2ab } from '../utils/DataUtils'; | ||
import * as XLSX from 'xlsx'; | ||
export let data: any[]; | ||
let downloadUrl: string = ''; | ||
$: downloadUrl = exportXLSX(data); | ||
function exportXLSX(data: any[]): string { | ||
const processedData = processExportData(data); | ||
const wb = XLSX.utils.book_new(); | ||
const ws = XLSX.utils.json_to_sheet(processedData); | ||
XLSX.utils.book_append_sheet(wb, ws, 'Data'); | ||
const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'binary' }); | ||
const blob = new Blob([s2ab(wbout)], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); | ||
return URL.createObjectURL(blob); | ||
} | ||
</script> | ||
|
||
<a href={downloadUrl} class="download-links" download="BMLT_data.xlsx">Download XLSX</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
import { processExportData } from '../utils/DataUtils'; | ||
import * as js2xmlparser from 'js2xmlparser'; | ||
export let data: any[]; | ||
let downloadUrl: string = ''; | ||
$: downloadUrl = exportXML(data); | ||
function exportXML(data: any[]): string { | ||
const processedData = processExportData(data); | ||
const xmlResult = js2xmlparser.parse('root', processedData); | ||
const blob = new Blob([xmlResult], { type: 'text/xml' }); | ||
return URL.createObjectURL(blob); | ||
} | ||
</script> | ||
|
||
<a href={downloadUrl} class="download-links" download="BMLT_data.xml">Download XML</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
import { processExportData } from '../utils/DataUtils'; | ||
import * as yaml from 'js-yaml'; | ||
export let data: any[]; | ||
let downloadUrl: string = ''; | ||
$: downloadUrl = exportYAML(data); | ||
function exportYAML(data: any[]): string { | ||
const processedData = processExportData(data); | ||
const yamlString = yaml.dump(processedData); | ||
const blob = new Blob([yamlString], { type: 'application/x-yaml' }); | ||
return URL.createObjectURL(blob); | ||
} | ||
</script> | ||
|
||
<a href={downloadUrl} class="download-links" download="BMLT_data.yaml">Download YAML</a> |
Oops, something went wrong.