Skip to content

Commit

Permalink
Panel helper changes
Browse files Browse the repository at this point in the history
Images + Details collapsible
Fix carets display
refactor formatted content
  • Loading branch information
nimmolo committed Aug 17, 2024
1 parent dadf76b commit 7f52379
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
25 changes: 13 additions & 12 deletions app/helpers/panel_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def panel_block(**args, &block)
concat(heading)
if args[:panel_bodies].present?
concat(panel_bodies(args))
elsif args[:formatted_content].present?
concat(content)
elsif args[:collapse].present?
concat(panel_collapse_body(args, content))
else
Expand Down Expand Up @@ -59,10 +57,12 @@ def panel_heading_elements(args)
# The whole heading is a link that toggles the panel collapse.
# NOTE: args[:open] should be a boolean
def panel_heading_collapse_elements(args)
collapsed = args[:open] ? "" : "collapsed"

tag.h4(class: "panel-title") do
link_to(
"##{args[:collapse]}",
class: "panel-collapse-trigger",
class: class_names("panel-collapse-trigger", collapsed),
role: "button", data: { toggle: "collapse" },
aria: { expanded: args[:open], controls: args[:collapse] }
) do
Expand All @@ -78,15 +78,6 @@ def panel_collapse_icons
link_icon(:chevron_up, title: :CLOSE.l)].safe_join
end

def panel_body(args, content)
return "" if content.blank?

tag.div(class: class_names("panel-body", args[:inner_class]),
id: args[:inner_id]) do
concat(content)
end
end

# Some panels need multiple panel bodies.
def panel_bodies(args)
args[:panel_bodies].map do |body|
Expand All @@ -103,6 +94,16 @@ def panel_collapse_body(args, content)
end
end

def panel_body(args, content)
return "" if content.blank?
return content if args[:formatted_content]

tag.div(class: class_names("panel-body", args[:inner_class]),
id: args[:inner_id]) do
concat(content)
end
end

def panel_footer(args)
if args[:footer]
tag.div(class: "panel-footer") do
Expand Down
22 changes: 9 additions & 13 deletions app/views/controllers/observations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ naming_locals = {
unfocused: true,
name_help: :form_naming_name_help_leave_blank.t
}
show_notes = @observation.notes.present?
notes_fields = @observation.form_notes_parts(@user)
open_notes = notes_fields.length > 1 || !create # @observation.notes.present?
show_projects = @projects.any? || @error_checked_projects.any? ||
@suspect_checked_projects.any?
show_lists = @lists.any?
Expand Down Expand Up @@ -63,7 +63,8 @@ form_element_data = {

<%= panel_block(
heading: "#{:IMAGES.l} + #{:show_observation_details.l}",
id: "observation_images_details", formatted_content: true
id: "observation_images_details", formatted_content: true,
collapse: "observation_images_details_inner", open: true
) do
concat(render(partial: "observations/form/images", locals: { f: }))
concat(render(partial: "observations/form/details",
Expand All @@ -72,10 +73,9 @@ form_element_data = {
end %>

<%= panel_block(
id: "observation_identification",
heading: "#{:IDENTIFICATION.l} + #{:SPECIMEN.l}",
collapse: "observation_specimen_inner",
open: true # @given_name.present?
id: "observation_naming_specimen", # @given_name.present?
collapse: "observation_naming_specimen_inner", open: true
) do
tag.div(class: "row mt-3") do
concat(tag.div(class: "col-xs-12 col-md-6") do
Expand All @@ -91,19 +91,16 @@ form_element_data = {
<%= submit_button(form: f, button: button_name, center: true) %>

<%= panel_block(
heading: :NOTES.l,
id: "observation_notes",
collapse: "observation_notes_inner",
open: notes_fields.length > 1
heading: :NOTES.l, id: "observation_notes",
collapse: "observation_notes_inner", open: open_notes
) do
render(partial: "shared/notes_fields",
locals: { form: f, fields: notes_fields })
end %>

<% if show_projects %>
<%= panel_block(
heading: :PROJECTS.l,
id: "observation_projects",
heading: :PROJECTS.l, id: "observation_projects",
collapse: "observation_projects_inner",
open: @project_checks.any?
) do
Expand All @@ -113,8 +110,7 @@ form_element_data = {

<% if show_lists %>
<%= panel_block(
heading: :SPECIES_LISTS.l,
id: "observation_lists",
heading: :SPECIES_LISTS.l, id: "observation_lists",
collapse: "observation_lists_inner",
open: @list_checks.any?
) do
Expand Down

0 comments on commit 7f52379

Please sign in to comment.