diff --git a/app/controllers/flight_logs_controller.rb b/app/controllers/flight_logs_controller.rb
index a2f7000..9386dea 100644
--- a/app/controllers/flight_logs_controller.rb
+++ b/app/controllers/flight_logs_controller.rb
@@ -5,9 +5,20 @@ class FlightLogsController < ApplicationController
before_action :require_engine_data_access!, only: %i[attach_engine_data remove_engine_data]
helper_method :manage_engine_data?
+ DAYS_PER_PAGE = 30
+
+ # The flight log a page of days at a time; the rest load as you scroll
+ # (each page ends in a lazy frame that fetches the next).
def index
- @flight_logs = @aircraft.flight_logs.recent_first.includes(:user).with_attached_track_log.with_attached_engine_data
- @days = FlightDay.group(@flight_logs)
+ @page = [ params[:page].to_i, 1 ].max
+ dates = @aircraft.flight_logs.distinct.order(date: :desc)
+ .offset((@page - 1) * DAYS_PER_PAGE).limit(DAYS_PER_PAGE + 1).pluck(:date)
+ @more = dates.size > DAYS_PER_PAGE
+ logs = @aircraft.flight_logs.where(date: dates.first(DAYS_PER_PAGE))
+ .includes(:user).with_attached_track_log.with_attached_engine_data
+ @days = FlightDay.group(logs)
+ return render(partial: "flight_logs/days", locals: { days: @days, page: @page, more: @more }) if turbo_frame_request?
+
@stats = FlightStats.new(@aircraft)
end
diff --git a/app/views/flight_logs/_days.html.erb b/app/views/flight_logs/_days.html.erb
new file mode 100644
index 0000000..c7eb5bd
--- /dev/null
+++ b/app/views/flight_logs/_days.html.erb
@@ -0,0 +1,54 @@
+<%# One page of days. Rendered inside its own frame; the last day is followed
+ by a lazy frame that loads the next page when it scrolls into view.
+ Links in it open in the whole page (target _top). %>
+<% blank = tag.span("β", class: "text-slate-300") %>
+<% qty = ->(v) { v ? number_with_precision(v, precision: 2, strip_insignificant_zeros: true) : blank } %>
+<%= turbo_frame_tag "flight-days-#{page}", target: "_top", class: "block" do %>
+ <% days.each do |day| %>
+
+ <%= day.date.strftime("%a %b %-d, %Y") %><%= pluralize(day.flights.size, "flight") %>
+
+ <%= day.route.presence || blank %>
+ <% if day.track_log? %>π<% end %>
+ <% if day.engine_data? %>π<% end %>
+ <% if day.pilots.any? %><%= day.pilots.to_sentence %><% end %>
+
+ Tach <%= day.tach_time ? hours(day.tach_time) : blank %>
+ Hobbs <%= day.hobbs_time ? hours(day.hobbs_time) : blank %>
+ Fuel <%= qty.(day.fuel_added) %>
+ Oil <%= qty.(day.oil_added) %>
+
+
+
+
+
+
+ <% day.flights.each_with_index do |fl, i| %>
+ Leg Route Tach Hobbs Fuel (gal) Oil (qt) Pilot
+
+ <% end %>
+
+ <%= link_to "Leg #{i + 1}", aircraft_flight_log_path(@aircraft, fl), class: "link" %>
+
+ <%= fl.route_summary.presence || blank %>
+ <% if fl.track_log.attached? %>π<% end %>
+ <% if fl.engine_data.attached? %>π<% end %>
+
+ <%= fl.tach_time ? hours(fl.tach_time) : blank %>
+ <%= fl.hobbs_time ? hours(fl.hobbs_time) : blank %>
+ <%= qty.(fl.fuel_added) %>
+ <%= qty.(fl.oil_added) %>
+ <%= fl.user&.display_name || blank %>
+
+ Loading earlier flights⦠<%= link_to "Load more", aircraft_flight_logs_path(@aircraft, page: page + 1), class: "link", data: { turbo_frame: "flight-days-#{page + 1}" } %> +
+ <% end %> + <% end %> +<% end %> diff --git a/app/views/flight_logs/index.html.erb b/app/views/flight_logs/index.html.erb index ff2f444..bcbc9c2 100644 --- a/app/views/flight_logs/index.html.erb +++ b/app/views/flight_logs/index.html.erb @@ -3,53 +3,12 @@ <% if @stats.any? %><%= render "flight_logs/stats", stats: @stats %><% end %>| Leg | Route | Tach | Hobbs | Fuel (gal) | Oil (qt) | Pilot |
|---|---|---|---|---|---|---|
| <%= link_to "Leg #{i + 1}", aircraft_flight_log_path(@aircraft, fl), class: "link" %> | -- <%= fl.route_summary.presence || blank %> - <% if fl.track_log.attached? %>π<% end %> - <% if fl.engine_data.attached? %>π<% end %> - | -<%= fl.tach_time ? hours(fl.tach_time) : blank %> | -<%= fl.hobbs_time ? hours(fl.hobbs_time) : blank %> | -<%= qty.(fl.fuel_added) %> | -<%= qty.(fl.oil_added) %> | -<%= fl.user&.display_name || blank %> | -