Files
simple-aircraft-manager-rails/app/views/loading_setups/edit.html.erb
T
rickyandClaude Opus 5.5 c822bda779 CG envelope can be entered as moment (lb-in/1000)
As POH moment-envelope charts and Garmin Pilot give it. Stored as CG
inches (moment x 1000 / weight), shown back as entered with the CG next
to each point; switching the units and saving re-reads the numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 14:42:44 -05:00

50 lines
4.2 KiB
ERB
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<% content_for :title, "#{@aircraft.tail_number} Loading setup" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<% stations = @setup.stations + Array.new([ 8 - @setup.stations.size, 2 ].max) { nil } %>
<% points = @setup.entered_envelope + Array.new([ 10 - @setup.envelope.size, 2 ].max) { nil } %>
<%= form_with url: aircraft_loading_setup_path(@aircraft), method: :patch, class: "card card-body max-w-3xl space-y-5" do %>
<div>
<h2 class="card-title">Loading setup</h2>
<p class="mt-1 text-sm text-slate-600">From the POH's weight and balance section. Arms are inches aft of the datum.</p>
</div>
<% if @setup.errors.any? %>
<div class="rounded-md bg-red-50 p-3 text-sm text-red-700 ring-1 ring-red-200" role="alert"><ul class="list-disc pl-5"><% @setup.errors.full_messages.each do |m| %><li><%= m %></li><% end %></ul></div>
<% end %>
<fieldset>
<legend class="label">Stations</legend>
<div class="grid grid-cols-[1fr_6rem_6rem_auto] gap-2 text-xs text-slate-500"><span>Name</span><span>Arm (in)</span><span>Max</span><span>Fuel (gal)</span></div>
<% stations.each_with_index do |st, i| %>
<div class="mt-1 grid grid-cols-[1fr_6rem_6rem_auto] items-center gap-2">
<%= text_field_tag "setup[stations][#{i}][name]", st&.name, class: "input", placeholder: ("Front seats" if i.zero?), "aria-label": "Station #{i + 1} name" %>
<%= text_field_tag "setup[stations][#{i}][arm]", st&.arm&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Station #{i + 1} arm" %>
<%= text_field_tag "setup[stations][#{i}][max]", st&.max&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Station #{i + 1} maximum" %>
<%= check_box_tag "setup[stations][#{i}][fuel]", "1", st&.fuel, class: "mx-auto h-4 w-4", "aria-label": "Station #{i + 1} is fuel" %>
</div>
<% end %>
<p class="hint">Tick "Fuel" for fuel tanks: their quantity is entered in gallons and the max is the usable capacity. Other maximums are in pounds.</p>
</fieldset>
<div class="max-w-xs">
<%= label_tag "setup[fuel_lb_per_gal]", "Fuel weight (lb per gallon)", class: "label" %>
<%= text_field_tag "setup[fuel_lb_per_gal]", @setup.fuel_lb_per_gal.to_s.sub(/\.0\z/, ""), class: "input", inputmode: "decimal" %>
<p class="hint">6 for avgas, 6.7 for Jet-A.</p>
</div>
<fieldset>
<legend class="label">CG envelope</legend>
<p class="hint !mt-0 mb-2">The corners of the normal-category envelope, in order around it (e.g. forward limit at low weight, forward limit at gross, aft limit at gross, aft limit at low weight).</p>
<div class="mb-3 max-w-xs">
<%= label_tag "setup[envelope_unit]", "Envelope values are", class: "label" %>
<%= select_tag "setup[envelope_unit]", options_for_select(LoadingSetup::ENVELOPE_UNITS.invert, @setup.envelope_unit), class: "input" %>
<p class="hint">Use the same units as your source: a POH “moment envelope” chart or Garmin Pilot give moment in lb-in/1000 (e.g. 2300 lb at 104.5). Moments are converted to CG (moment × 1000 ÷ weight) when saved. Changing this and saving reads the numbers below in the new units, so it also fixes moments typed in as CG.</p>
</div>
<div class="grid max-w-md grid-cols-3 gap-2 text-xs text-slate-500"><span>Weight (lb)</span><span><%= @setup.moment? ? "Moment (lb-in/1000)" : "CG (in)" %></span><span><%= "= CG (in)" if @setup.moment? %></span></div>
<% points.each_with_index do |pt, i| %>
<div class="mt-1 grid max-w-md grid-cols-3 items-center gap-2">
<%= text_field_tag "setup[envelope][#{i}][weight]", pt&.first&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Envelope point #{i + 1} weight" %>
<%= text_field_tag "setup[envelope][#{i}][cg]", pt&.last&.to_s&.sub(/\.0\z/, ""), class: "input", inputmode: "decimal", "aria-label": "Envelope point #{i + 1} #{@setup.moment? ? 'moment' : 'CG'}" %>
<span class="text-sm text-slate-600"><%= "#{@setup.envelope[i].last.round(2)} in" if @setup.moment? && @setup.envelope[i] %></span>
</div>
<% end %>
</fieldset>
<div class="flex gap-2"><%= submit_tag "Save", class: "btn-primary" %><%= link_to "Cancel", aircraft_weight_balance_records_path(@aircraft), class: "btn-secondary" %></div>
<% end %>