-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: export flights * fix: export to csv and json * fix: import from AirTrail export * docs: add guide to importing from AirTrail export
- Loading branch information
Showing
11 changed files
with
387 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Export | ||
|
||
The export feature allows you to export your flight data from AirTrail. | ||
|
||
## Export flights | ||
|
||
To export your flights, follow these steps: | ||
|
||
1. Go to the AirTrail application. | ||
2. Go to the settings page. | ||
3. Click on the "Export" tab. | ||
4. Choose your desired export format (CSV or JSON). | ||
|
||
## Export formats | ||
|
||
### CSV | ||
|
||
The CSV export option allows you to export your flights as a CSV file, which can be opened in any spreadsheet | ||
application like Microsoft Excel or Google Sheets. It is a simple and easy-to-use format that can be used to | ||
analyze your flight data. | ||
|
||
#### Format | ||
|
||
The CSV file contains the following columns: | ||
|
||
- `date`: The date of the flight (YYYY-MM-DD format). | ||
- `from`: The IATA code of the departure airport. | ||
- `to`: The IATA code of the arrival airport. | ||
- `departure`: The departure time in ISO 8601 format (if available). | ||
- `arrival`: The arrival time in ISO 8601 format (if available). | ||
- `duration`: The duration of the flight in seconds. | ||
- `flightNumber`: The flight number (if available). | ||
- `flightReason`: The reason for the flight (if provided). | ||
- `airline`: The airline operating the flight (if available). | ||
- `aircraft`: The type of aircraft used (if available). | ||
- `aircraftReg`: The registration number of the aircraft (if available). | ||
- `note`: Any additional notes about the flight. | ||
- `seat`: The type of seat (e.g., window, aisle, etc.). | ||
- `seatNumber`: The seat number (if available). | ||
- `seatClass`: The class of the seat (e.g., economy, business). | ||
|
||
### JSON | ||
|
||
:::tip | ||
The JSON format can be reimported into AirTrail using the import feature. | ||
::: | ||
|
||
The JSON export option provides a more structured format that is ideal for developers or when integrating the data into | ||
other systems. It contains nested objects for each flight and detailed data for each user and their seat information. | ||
|
||
#### Format | ||
|
||
The JSON file follows this structure: | ||
|
||
```json | ||
{ | ||
"users": [ | ||
{ | ||
"id": "user_id", | ||
"displayName": "User Name", | ||
"username": "username" | ||
} | ||
], | ||
"flights": [ | ||
{ | ||
"date": "YYYY-MM-DD", | ||
"from": "ICAO_CODE", | ||
"to": "ICAO_CODE", | ||
"departure": "ISO_8601_DATETIME", | ||
"arrival": "ISO_8601_DATETIME", | ||
"duration": flight_duration_in_seconds, | ||
"flightNumber": "FLIGHT_NUMBER", | ||
"flightReason": "FLIGHT_REASON", | ||
"airline": "ICAO_AIRLINE_CODE", | ||
"aircraft": "ICAO_AIRCRAFT_TYPE", | ||
"aircraftReg": "AIRCRAFT_REGISTRATION", | ||
"note": "FLIGHT_NOTE", | ||
"seats": [ | ||
{ | ||
"userId": "USER_ID", | ||
"guestName": "GUEST_NAME", | ||
"seat": "SEAT_TYPE", | ||
"seatNumber": "SEAT_NUMBER", | ||
"seatClass": "SEAT_CLASS" | ||
} | ||
] | ||
} | ||
] | ||
} |
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
64 changes: 64 additions & 0 deletions
64
src/lib/components/modals/settings/pages/ExportPage.svelte
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,64 @@ | ||
<script lang="ts"> | ||
import { PageHeader } from '.'; | ||
import { api } from '$lib/trpc'; | ||
import { cn } from '$lib/utils'; | ||
import { FileSpreadsheet, FileJson } from '@o7/icon/lucide'; | ||
import { Card } from '$lib/components/ui/card'; | ||
import { toast } from 'svelte-sonner'; | ||
const downloadBlob = (blob: Blob, filename: string) => { | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = filename; | ||
a.click(); | ||
toast.info('Your download should start shortly'); | ||
URL.revokeObjectURL(url); | ||
}; | ||
const downloadCsv = async () => { | ||
const csv = await api.flight.exportCsv.query(); | ||
const blob = new Blob([csv], { type: 'text/csv' }); | ||
downloadBlob(blob, 'airtrail.csv'); | ||
}; | ||
const downloadJson = async () => { | ||
const json = await api.flight.exportJson.query(); | ||
const blob = new Blob([json], { type: 'application/json' }); | ||
downloadBlob(blob, 'airtrail.json'); | ||
}; | ||
</script> | ||
|
||
<PageHeader title="Export"> | ||
{#snippet subtitleHtml()} | ||
<p class="text-muted-foreground text-sm"> | ||
Export your data. Learn more about the data formats <a | ||
href="https://johanohly.github.io/AirTrail/docs/features/export#export-formats" | ||
target="_blank" | ||
class="text-blue-500 underline">in the documentation</a | ||
>. | ||
</p> | ||
{/snippet} | ||
<div class="flex"> | ||
<button onclick={downloadCsv} class="w-full"> | ||
<Card | ||
class={cn( | ||
'cursor-pointer py-12 border-2 border-dashed border-r-0 rounded-r-none flex flex-col items-center hover:bg-card-hover dark:hover:bg-dark-2', | ||
)} | ||
> | ||
<FileSpreadsheet size={64} /> | ||
<span class="text-muted-foreground">.csv</span> | ||
</Card> | ||
</button> | ||
<button onclick={downloadJson} class="w-full"> | ||
<Card | ||
class={cn( | ||
'cursor-pointer py-12 border-2 border-dashed rounded-l-none flex flex-col items-center hover:bg-card-hover dark:hover:bg-dark-2', | ||
)} | ||
> | ||
<FileJson size={64} /> | ||
<span class="text-muted-foreground">.json</span> | ||
</Card> | ||
</button> | ||
</div> | ||
</PageHeader> |
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
19 changes: 13 additions & 6 deletions
19
src/lib/components/modals/settings/pages/PageHeader.svelte
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
Oops, something went wrong.