<%# Engine / propeller (or other component) the entry is for, and its times at the entry. %> <% comps = aircraft.components.where.not(status: "DISPOSED").includes(:component_type).order(:install_location) %>
<%= f.label :component_id, t(".component"), class: "label" %> <%= f.select :component_id, options_for_select([ [ t(".none"), "" ] ] + comps.map { |c| [ "#{c} · #{c.manufacturer} #{c.model}#{" · #{t('.serial_short', serial: c.serial_number)}" if c.serial_number.present?}", c.id, { "data-total" => c.hours_in_service.to_f, "data-since" => c.hours_since_overhaul.to_f, "data-kind" => (c.engine? ? "ENG" : c.propeller? ? "PROP" : ""), "data-abbr" => c.since_overhaul_abbreviation } ] }, f.object.component_id), {}, class: "input", data: { component_times_target: "component", action: "component-times#componentChanged" } %>

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

<%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: t(".component_total_time"), data: { component_times_target: "total", action: "input->component-times#markManual" } %> <%= f.field :component_since_overhaul_at_entry, as: :number, step: 0.1, label: t(".since_overhaul"), data: { component_times_target: "since", action: "input->component-times#markManual" }, hint: t(".worked_out_from_the_component") %>
<%# Sub-components of the chosen component (oil filter, magnetos…): tick to include them with their times. %> <% children = comps.select(&:parent_component_id) %> <% if children.any? %> <% parts = f.object.parts.index_by(&:component_id) %> <% selected = f.object.component %>
> <%= t(".sub_components") %> <% children.each do |c| %> <% part = parts[c.id] %> <% ancestors = c.ancestor_ids %> <% field = "#{f.object_name}[parts][#{c.id}]" %>
>
<%= number_field_tag "#{field}[hours]", part&.hours_at_entry, id: "part_#{c.id}_hours", step: 0.1, class: "input", data: { role: "hours", action: "input->component-times#partEdited" } %>
<%= number_field_tag "#{field}[since]", part&.since_overhaul_at_entry, id: "part_#{c.id}_since", step: 0.1, class: "input", data: { role: "since", action: "input->component-times#partEdited" } %>
<% if f.object.new_record? %>
<%= select_tag "#{field}[service]", options_for_select([ [ t(".not_changed"), "" ], [ t(".serviced"), "serviced" ], [ t(".replaced"), "replaced" ] ], params.dig(:logbook_entry, :parts, c.id.to_s, :service)), id: "part_#{c.id}_service", class: "input" %>
<% end %>
<% end %>

<%= t(f.object.new_record? ? ".their_times_new_html" : ".their_times_are_worked_out_html") %>

<% end %>