<%= form_with model: [aircraft, analysis], class: "card card-body space-y-5 max-w-4xl" do |f| %> <%= f.errors_summary %>
<%= f.field :sample_date, as: :date, required: true %> <%= f.field :analysis_date, as: :date %> <%= f.field :status, as: :select, label: "Lab's verdict", collection: [ [ "Not rated", "" ] ] + OilAnalysis::STATUSES.invert.to_a %> <%= f.field :component_id, as: :select, label: "Engine", collection: component_options(aircraft) %> <%= f.field :lab, placeholder: "AvLab, Blackstone…" %> <%= f.field :sample_number, label: "Sample / lab #" %> <%= f.field :oil_type, label: "Oil", placeholder: "Aeroshell W100…", wrapper: { class: "sm:col-span-2" } %>
Hours <%= f.field :engine_hours, as: :number, step: 0.1, label: "Engine (TSN/TSO)" %> <%= f.field :oil_hours, as: :number, step: 0.1, label: "On oil" %> <%= f.field :filter_hours, as: :number, step: 0.1, label: "On filter" %> <%= f.field :oil_added, as: :number, step: 0.25, label: "Oil added (qt)" %>
Results (ppm)

Leave blank what the lab didn't test (N/A). Enter "< 0.1" as 0. The average is the lab's figure for similar engines, usually in (parentheses) under the result.

<%= render partial: "element_input", collection: OilAnalysis::COMMON_ELEMENTS, as: :element, locals: { analysis: analysis } %>
<% extra = OilAnalysis::ELEMENTS.keys - OilAnalysis::COMMON_ELEMENTS %>
> More elements (Blackstone and other labs)
<%= render partial: "element_input", collection: extra, as: :element, locals: { analysis: analysis } %>
> Oil properties
<% OilAnalysis::PROPERTIES.each do |key, (label, unit)| %>
<%= label_tag "oil_analysis_oil_properties_#{key}", [ label, (unit.presence && "(#{unit})") ].compact.join(" "), class: "label" %> <%= number_field_tag "oil_analysis[oil_properties][#{key}]", analysis.property(key), id: "oil_analysis_oil_properties_#{key}", step: "any", min: 0, class: "input" %>
<% end %>
<%= f.field :excluded_from_averages, as: :checkbox, label: "Leave out of trends", hint: "For a sample that isn't representative, e.g. right after an overhaul or a top end." %> <%= f.field :lab_comments, as: :textarea, rows: 2 %> <%= f.field :notes, as: :textarea, rows: 2 %> <%= f.field :report, as: :file, label: "Lab report (PDF)", accept: ".pdf,application/pdf,image/*" %> <% if analysis.report.attached? %>

Current: <%= analysis.report.filename %>. Choosing a file replaces it.

<% end %>
<%= f.submit "Save" %><%= link_to "Cancel", analysis.persisted? ? aircraft_oil_analysis_path(aircraft, analysis) : aircraft_oil_analyses_path(aircraft), class: "btn-secondary" %>
<% end %>