mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
AirTrail sync and export, GPS tracks, airport database with autocomplete
AirTrail (https://github.com/johanohly/AirTrail): - File export (Flights → Export for AirTrail) in AirTrail's import format, validated against its schema; same-day repeat legs get leg numbers so AirTrail's de-duplication doesn't merge them. - Automatic sync through AirTrail's REST API (Profile → AirTrail sync): per-user connection with an encrypted API key and scope check; flights are created/updated/deleted in background jobs; a full sync first links flights already in AirTrail (e.g. from a file import) instead of duplicating them; airports are resolved and cached, with manual mapping for unknown codes. - GPS tracks: GPX, KML and CSV track logs are converted to AirTrail's track format for both sync and export; the flight page shows a summary. - Aircraft ICAO type (e.g. C150) for AirTrail's aircraft type. Airport database (OurAirports, the source AirTrail uses): - Managed like AirTrail: downloaded in the background on first start, updated in place from Admin → Airports (adds, changes, removes; ids stable), with admin-managed custom airports that updates never touch. - Each airport carries AirTrail's code, so logged codes translate to AirTrail's exactly (1B9 → K1B9, 4MB → K5M3). - From/To autocomplete on new flights (airports this aircraft has used rank first); From is pre-filled with the last flight's destination; codes are normalized to uppercase. - Flights → Standardize airport codes: rewrite logged codes to the standard code, and fix codes not in the database (typos such as 0R8 → 08R are suggested). Also: admin pages grouped under an Admin dropdown menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c4803d717
commit
5bf682502b
68 files changed
+2667
-10
No files matched your search
@@ -0,0 +1,13 @@
|
||||
# Sync all of a user's flights: link ones already in AirTrail, push the rest.
|
||||
class AirTrailBackfillJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: ->(connection_id) { "air_trail_backfill_#{connection_id}" } if respond_to?(:limits_concurrency)
|
||||
retry_on AirTrailClient::NetworkError, wait: :polynomially_longer, attempts: 3
|
||||
discard_on AirTrailClient::AuthError
|
||||
|
||||
def perform(connection_id)
|
||||
connection = AirTrailConnection.find_by(id: connection_id) or return
|
||||
return unless connection.enabled?
|
||||
AirTrailSyncer.new(connection).backfill
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
# Remove a deleted flight from AirTrail.
|
||||
class AirTrailDeleteJob < ApplicationJob
|
||||
queue_as :default
|
||||
retry_on AirTrailClient::NetworkError, wait: :polynomially_longer, attempts: 6
|
||||
discard_on AirTrailClient::AuthError
|
||||
|
||||
def perform(connection_id, remote_id)
|
||||
connection = AirTrailConnection.find_by(id: connection_id) or return
|
||||
return unless connection.enabled?
|
||||
AirTrailSyncer.new(connection).delete_remote(remote_id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
# Create/update one flight in its pilot's AirTrail account.
|
||||
class AirTrailPushJob < ApplicationJob
|
||||
queue_as :default
|
||||
retry_on AirTrailClient::NetworkError, wait: :polynomially_longer, attempts: 6
|
||||
discard_on AirTrailClient::AuthError # recorded on the connection; user must fix the key
|
||||
|
||||
def perform(flight_log_id)
|
||||
flight = FlightLog.includes(:aircraft, user: :air_trail_connection).find_by(id: flight_log_id) or return
|
||||
connection = flight.user&.air_trail_connection
|
||||
return unless connection&.enabled?
|
||||
return unless AirTrailFlightData.exportable?(flight)
|
||||
AirTrailSyncer.new(connection).push(flight)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# Downloads OurAirports and syncs the airports table (AirportData.refresh!).
|
||||
class AirportUpdateJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: "airport_update", duration: 1.hour if respond_to?(:limits_concurrency)
|
||||
|
||||
def perform(update_id = nil)
|
||||
update = (update_id && AirportUpdate.find_by(id: update_id)) || AirportUpdate.create!(source_url: AirportData::SOURCE_URL)
|
||||
update.update!(status: "running", started_at: Time.current, error: nil)
|
||||
counts = AirportData.refresh!(update.source_url.presence || AirportData::SOURCE_URL)
|
||||
update.update!(status: "done", finished_at: Time.current, created_count: counts[:created],
|
||||
updated_count: counts[:updated], removed_count: counts[:removed])
|
||||
rescue StandardError => e
|
||||
update&.update!(status: "failed", finished_at: Time.current, error: "#{e.class}: #{e.message}".truncate(1000))
|
||||
Rails.logger.error("[airports] update failed: #{e.class}: #{e.message}")
|
||||
end
|
||||
|
||||
# Called at boot: populate the table on first start, like AirTrail does.
|
||||
def self.ensure_populated
|
||||
return if Airport.where(custom: false).exists? || AirportUpdate.in_progress.exists?
|
||||
update = AirportUpdate.create!(source_url: AirportData::SOURCE_URL)
|
||||
perform_later(update.id)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user