From cc49bfa28176d1e01625c8a25d4764145a0b8ce3 Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Wed, 14 Aug 2024 18:41:02 -0700 Subject: [PATCH] Refactor obs form with panel helper --- .../controllers/observations/_form.html.erb | 87 +++++++++++++++++-- .../observations/form/_identify_step.erb | 4 +- .../observations/form/_projects.html.erb | 4 +- .../observations/form/_species_lists.html.erb | 4 +- 4 files changed, 87 insertions(+), 12 deletions(-) diff --git a/app/views/controllers/observations/_form.html.erb b/app/views/controllers/observations/_form.html.erb index 2c959fd666..6b2f79fc3b 100644 --- a/app/views/controllers/observations/_form.html.erb +++ b/app/views/controllers/observations/_form.html.erb @@ -32,7 +32,21 @@ data = { form_images_target: "form", exif_used: create ? false : true } -projects_lists = @projects.any? || @lists.any? +naming_locals = if include_naming + { + f: f, + action: action, + button_name: button_name, + show_reasons: false, + unfocused: true, + name_help: :form_naming_name_help_leave_blank.t + } + else + {} + end +show_projects = @projects.any? || @error_checked_projects.any? || + @suspect_checked_projects.any? +show_lists = @lists.any? %> <%= form_with( @@ -46,12 +60,12 @@ projects_lists = @projects.any? || @lists.any? data: ) do |f| %> - <%= if @field_code - tag.p("#{:form_observations_field_code.t} #{@field_code}") - end %> - <%= hidden_field_tag(:field_code, @field_code) %> + <% if @field_code %> + <%= tag.p("#{:form_observations_field_code.t} #{@field_code}") %> + <%= hidden_field_tag(:field_code, @field_code) %> + <% end %> - <%= tab_content do %> + <%# tab_content do %> <%= render(partial: "observations/form/record_step", locals: { f:, button_name:, location: @location, logging_optional: }) %> @@ -63,6 +77,67 @@ projects_lists = @projects.any? || @lists.any? <%= render(partial: "observations/form/add_to_step", locals: { f:, button_name: }) %> <% end %> + <%# end %> + + <%= panel_block( + heading: "#{:IMAGES.l} + #{:show_observation_details.l}", + id: "observation_images_details" + ) do %> + <%= render(partial: "observations/form/images", locals: { f: }) %> + + <%= render(partial: "observations/form/details", + locals: { f:, button_name:, location:, logging_optional: }) %> + <% end %> + + <%= panel_block( + heading: :IDENTIFICATION.l, + id: "observation_identification", + collapse: "observation_identification_inner", + open: false + ) do + render(partial: "observations/namings/fields", locals: naming_locals) + end %> + + <%= panel_block( + heading: :SPECIMEN.l, + id: "observation_specimen", + collapse: "observation_specimen_inner", + open: false + ) do + render(partial: "observations/form/specimen_section", + locals: { f:, action: }) + end %> + + <%= panel_block( + heading: :NOTES.l, + id: "observation_notes", + collapse: "observation_notes_inner", + open: false + ) do + render(partial: "shared/notes_fields", + locals: { form: f, fields: @observation.form_notes_parts(@user) }) + end %> + + <% if show_projects %> + <%= panel_block( + heading: :PROJECTS.l, + id: "observation_projects", + collapse: "observation_projects_inner", + open: false + ) do + render(partial: "observations/form/projects", locals: { button_name: }) + end %> + <% end %> + + <% if show_lists %> + <%= panel_block( + heading: :SPECIES_LISTS.l, + id: "observation_lists", + collapse: "observation_lists_inner", + open: false + ) do + render(partial: "observations/form/species_lists") + end %> <% end %> <% end %> diff --git a/app/views/controllers/observations/form/_identify_step.erb b/app/views/controllers/observations/form/_identify_step.erb index 0f8f794740..239d0c5dd6 100644 --- a/app/views/controllers/observations/form/_identify_step.erb +++ b/app/views/controllers/observations/form/_identify_step.erb @@ -22,8 +22,8 @@ <% end %> <%= tag.div(class: "col-xs-12 col-lg-6") do %> <%= render(partial: "shared/notes_fields", - locals: { form: f, - fields: @observation.form_notes_parts(@user) }) %> + locals: { form: f, + fields: @observation.form_notes_parts(@user) }) %> <% end %> <% end %> diff --git a/app/views/controllers/observations/form/_projects.html.erb b/app/views/controllers/observations/form/_projects.html.erb index 63a002ba13..3aa8931b18 100644 --- a/app/views/controllers/observations/form/_projects.html.erb +++ b/app/views/controllers/observations/form/_projects.html.erb @@ -20,7 +20,7 @@ if @suspect_checked_projects.any? end %> -<%= tag.div(id: "observation_projects") do %> +<%# tag.div(id: "observation_projects") do %> <%= fields_for(:project) do |f_p| %> <% if error_messages.present? || suspect_messages.present? %> @@ -71,5 +71,5 @@ end <% end %> <% end %> -<% end %> +<%# end %> diff --git a/app/views/controllers/observations/form/_species_lists.html.erb b/app/views/controllers/observations/form/_species_lists.html.erb index 1172d3fc85..16e147d639 100644 --- a/app/views/controllers/observations/form/_species_lists.html.erb +++ b/app/views/controllers/observations/form/_species_lists.html.erb @@ -1,6 +1,6 @@ <%# species_list section of create_observation form %> -<%= tag.div(id: "observation_projects") do %> +<%# tag.div(id: "observation_lists") do %> <%= fields_for(:list) do |f_l| %> <%= tag.div do @@ -23,4 +23,4 @@ <% end %> <% end %> -<% end %> +<%# end %>