Oil & Fuel: records load 50 at a time, the rest as you scroll (all records reachable; was capped at 200)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-11 20:27:48 -05:00
1 parent 455a26a346
commit 85326d494c
5 files changed
+77 -21

No files matched your search

@@ -3,10 +3,19 @@ class ConsumableRecordsController < ApplicationController
before_action :require_owner!, only: %i[edit update destroy]
before_action :set_record, only: %i[edit update destroy]
RECORDS_PER_PAGE = 50
# Records a page at a time; the rest load as you scroll (each page ends in
# a lazy frame that fetches the next). The charts cover everything.
def index
@page = [ params[:page].to_i, 1 ].max
rows = @aircraft.consumable_records.recent_first.offset((@page - 1) * RECORDS_PER_PAGE).limit(RECORDS_PER_PAGE + 1).to_a
@more = rows.size > RECORDS_PER_PAGE
@records = rows.first(RECORDS_PER_PAGE)
return render(partial: "consumable_records/records", locals: { records: @records, page: @page, more: @more }) if turbo_frame_request?
@oil = ConsumptionStats.new(@aircraft, "oil")
@fuel = ConsumptionStats.new(@aircraft, "fuel")
@records = @aircraft.consumable_records.recent_first.limit(200)
end
def new
@@ -0,0 +1,36 @@
<%# One page of records, in its own frame; a lazy frame after it loads the
next page when it scrolls into view. Each page is its own table, with the
same fixed column widths so the columns line up. Links open in the whole page. %>
<%= turbo_frame_tag "consumable-records-#{page}", target: "_top", class: "block" do %>
<div class="overflow-x-auto">
<table class="table w-full table-fixed">
<colgroup>
<col class="w-28"><col class="w-24"><col class="w-24"><col class="w-24"><col><col class="w-24"><col><col class="w-20">
</colgroup>
<% if page == 1 %>
<thead><tr><th>Date</th><th>Type</th><th class="text-right">Added</th><th class="text-right">Level after</th><th>Product</th><th class="text-right">Tach</th><th>Notes</th><th></th></tr></thead>
<% end %>
<tbody>
<% records.each do |r| %>
<tr class="consumable-record">
<td class="whitespace-nowrap"><%= r.date %></td>
<td><%= tag.span ConsumableRecord::TYPES[r.record_type], class: r.record_type == "oil" ? "badge-orange" : "badge-blue" %></td>
<td class="text-right tabular-nums" data-label="Added"><%= r.quantity_added %> <%= r.unit %></td>
<td class="text-right tabular-nums" data-label="Level after"><%= r.level_after ? "#{r.level_after} #{r.unit}" : "" %></td>
<td class="truncate" data-label="Product"><%= r.consumable_type %></td>
<td class="text-right tabular-nums" data-label="Tach"><%= hours(r.flight_hours) %></td>
<td class="text-xs text-slate-500 break-words"><%= r.notes %><%= " (excluded from average)" if r.excluded_from_averages? %></td>
<td class="text-right"><% if owner? %><%= link_to "Edit", edit_aircraft_consumable_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% if more %>
<%= turbo_frame_tag "consumable-records-#{page + 1}", src: aircraft_consumable_records_path(@aircraft, page: page + 1), loading: :lazy, target: "_top", class: "block" do %>
<p class="px-4 py-4 text-center text-sm text-slate-500">
Loading earlier records… <%= link_to "Load more", aircraft_consumable_records_path(@aircraft, page: page + 1), class: "link", data: { turbo_frame: "consumable-records-#{page + 1}" } %>
</p>
<% end %>
<% end %>
<% end %>
+1 -19
View File
@@ -27,25 +27,7 @@
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">Records</h2></div>
<% if @records.any? %>
<div class="overflow-x-auto">
<table class="table">
<thead><tr><th>Date</th><th>Type</th><th class="text-right">Added</th><th class="text-right">Level after</th><th>Product</th><th class="text-right">Tach</th><th>Notes</th><th></th></tr></thead>
<tbody>
<% @records.each do |r| %>
<tr>
<td class="whitespace-nowrap"><%= r.date %></td>
<td><%= tag.span ConsumableRecord::TYPES[r.record_type], class: r.record_type == "oil" ? "badge-orange" : "badge-blue" %></td>
<td class="text-right tabular-nums"><%= r.quantity_added %> <%= r.unit %></td>
<td class="text-right tabular-nums"><%= r.level_after ? "#{r.level_after} #{r.unit}" : "" %></td>
<td><%= r.consumable_type %></td>
<td class="text-right tabular-nums"><%= hours(r.flight_hours) %></td>
<td class="text-xs text-slate-500"><%= r.notes %><%= " (excluded from average)" if r.excluded_from_averages? %></td>
<td class="text-right"><% if owner? %><%= link_to "Edit", edit_aircraft_consumable_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= render "consumable_records/records", records: @records, page: @page, more: @more %>
<% else %>
<%= empty_state "No oil or fuel records yet." %>
<% end %>