Skip to content

Commit

Permalink
Refactor obs form with panel helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 15, 2024
1 parent c567ed6 commit cc49bfa
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
87 changes: 81 additions & 6 deletions app/views/controllers/observations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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: }) %>
Expand All @@ -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 %><!--[/form:observation]-->
4 changes: 2 additions & 2 deletions app/views/controllers/observations/form/_identify_step.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/controllers/observations/form/_projects.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
Expand Down Expand Up @@ -71,5 +71,5 @@ end
<% end %>

<% end %>
<% end %>
<%# end %>

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,4 +23,4 @@
<% end %>

<% end %>
<% end %>
<%# end %>

0 comments on commit cc49bfa

Please sign in to comment.