mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Calendar feed: due items (inspections, ADs, component limits, documents) as a private iCalendar link, hour-based dates projected from the past year's flying
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
87e30946fe
commit
98e943cf0a
14 files changed
+266
-7
No files matched your search
@@ -0,0 +1,23 @@
|
||||
# The calendar feed: what's coming due on every aircraft the user can see,
|
||||
# as all-day events (dates for hour-based items are projected from the past
|
||||
# year's flying). Calendar apps fetch it with the secret link from Profile.
|
||||
class CalendarFeedsController < ApplicationController
|
||||
allow_unauthenticated_access
|
||||
skip_before_action :redirect_to_setup
|
||||
rate_limit to: 60, within: 1.hour, with: -> { head :too_many_requests }
|
||||
|
||||
def show
|
||||
user = User.active.find_by(calendar_token: params[:token].to_s) or return head(:not_found)
|
||||
cal = Ical.new("Aircraft maintenance")
|
||||
host = Sso.app_url
|
||||
user.accessible_aircraft.ordered.each do |aircraft|
|
||||
DueList.new(aircraft).items.each do |i|
|
||||
when_text = [ ("projected from recent flying" if i.projected), ("at #{i.due_hours} hrs" if i.due_hours) ].compact.join(", ")
|
||||
cal.add(uid: "#{aircraft.id}-#{i.key}@simple-aircraft-manager", date: i.date,
|
||||
summary: "#{aircraft.tail_number}: #{i.title}#{' (overdue)' if i.overdue?}",
|
||||
description: [ "#{aircraft.tail_number}: #{i.title}", when_text.presence ].compact.join("\n"), url: "#{host}#{i.path}")
|
||||
end
|
||||
end
|
||||
send_data cal.to_s, type: "text/calendar; charset=utf-8", disposition: "inline", filename: "aircraft-maintenance.ics"
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user