<% content_for :title, t(".oil_analysis", tail_number: @aircraft.tail_number) %> <%= render "shared/aircraft_header", aircraft: @aircraft %> <%= render "shared/oil_subnav", aircraft: @aircraft %> <% recent = @analyses.first(OilAnalysesController::COMPARE_SAMPLES) %>
<% if can?(:record_oil_analyses) %>

<%= t(".import_a_lab_report") %>

<%= t(".avlab_or_blackstone_pdf_reports") %>

<%= render "import", aircraft: @aircraft %>
<% end %>

<%= t(".wear_metal_trends") %>

<% if can?(:record_oil_analyses) %><%= link_to t(".add_oil_analysis"), new_aircraft_oil_analysis_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
<% series = oil_trend_series(@analyses) %> <% if series.any? %> <%= line_chart series, ytitle: "ppm", height: "260px", curve: false, colors: OilAnalysesHelper::TREND_COLORS, legend: "bottom" %>

<%= t(".lead_is_left_out_of_html", excluded_from_averages: (t(".samples_marked_leave_out_of") if @analyses.any?(&:excluded_from_averages?))) %>

<% else %> <%= empty_state @analyses.any? ? t(".add_another_sample_to_see") : t(".no_oil_analyses_yet_add") %> <% end %>
<% if recent.any?(&:any_results?) %>

<%= t(".results_ppm") %>

<%= t(".lab_average_for_similar_engines") %> <%= t(".red") %> <%= t(".is_or_more_above_it_html", ratio: (OilAnalysis::FLAG_RATIO)) %>
<% recent.each do |a| %><% end %> <% recent.each do |a| %><% end %> <% OilAnalysis.elements_in(recent).each do |el| %> <% label, source = OilAnalysis::ELEMENTS.fetch(el), OilAnalysis::ELEMENT_SOURCES[el] %> <% recent.each do |a| %><% end %> <% end %> <% OilAnalysis::PROPERTIES.each_key do |key| %> <% next if recent.none? { _1.property(key) } %> <% recent.each do |a| %><% end %> <% end %>
<%= t(".element") %><%= link_to fmt_date(a.sample_date), aircraft_oil_analysis_path(@aircraft, a), class: "link" %>
<%= t(".engine_oil_hrs") %><%= a.engine_hours ? hours(a.engine_hours) : "—" %> / <%= a.oil_hours ? hours(a.oil_hours) : "—" %>
<%= label %><%= ppm_cell(a, el) %>
<%= OilAnalysis::PROPERTIES[key] %><%= oil_property(a, key) %>
<% end %>

<%= t(".samples") %>

<% if @analyses.any? %>
<% @analyses.each do |a| %> <% end %>
<%= t(".sampled") %><%= t(".result") %><%= t(".engine") %><%= t(".engine_hrs") %><%= t(".oil_hrs") %><%= t(".lab") %><%= t(".report") %>
<%= link_to fmt_date(a.sample_date), aircraft_oil_analysis_path(@aircraft, a), class: "link" %> <% if a.excluded_from_averages? %>
<%= t(".left_out_of_trends") %>
<% end %>
<%= oil_status_badge(a) %> <% if (flags = a.flagged_elements).any? %><%= t(".above_average_html", to_sentence: (flags.map { OilAnalysis.element_label(_1) }.to_sentence)) %><% end %> <%= a.component&.to_s || "—" %> <%= a.engine_hours ? hours(a.engine_hours) : "—" %> <%= a.oil_hours ? hours(a.oil_hours) : "—" %> <%= [ a.lab, a.sample_number ].compact.join(" · ").presence || "—" %> <%= a.report.attached? ? link_to(t(".pdf"), rails_blob_path(a.report, disposition: :inline), class: "link", target: "_blank", rel: "noopener") : "—" %>
<% else %> <%= empty_state t(".no_samples_recorded") %> <% end %>