Skip to content

Commit

Permalink
Merge pull request #1748 from MushroomObserver/nimmo-naming-table-helper
Browse files Browse the repository at this point in the history
Move the naming table from partials to a helper
  • Loading branch information
nimmolo committed Dec 27, 2023
2 parents c6dda3e + 9c93577 commit 05902f2
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 245 deletions.
315 changes: 228 additions & 87 deletions app/helpers/namings_helper.rb

Large diffs are not rendered by default.

37 changes: 0 additions & 37 deletions app/views/observations/namings/_table.erb

This file was deleted.

32 changes: 0 additions & 32 deletions app/views/observations/namings/_table_footer.erb

This file was deleted.

26 changes: 0 additions & 26 deletions app/views/observations/namings/_table_header.erb

This file was deleted.

30 changes: 0 additions & 30 deletions app/views/observations/namings/_table_row.erb

This file was deleted.

12 changes: 6 additions & 6 deletions app/views/observations/namings/_update_observation.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ it updates the obs title and name_info.
# debugger
%>
<%= turbo_stream.replace("namings_table") do
render(
partial: "observations/namings/table",
locals: { obs: obs },
layout: false
)
<%= turbo_stream.replace("namings_table_rows") do
observation_namings_table_rows(obs)
end %>
<%= turbo_stream.replace("observation_name_info") do
Expand All @@ -26,3 +22,7 @@ end %>
<%= turbo_stream.update("title") do
show_obs_title(obs: obs)
end %>
<%= turbo_stream.update("page_flash") do
flash_notices_html
end %>
3 changes: 1 addition & 2 deletions app/views/observations/namings/index.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%=
tag.div(id: "observation_namings") do
render(partial: "observations/namings/table",
locals: { obs: @observation })
observation_namings_table(obs)
end %>
5 changes: 2 additions & 3 deletions app/views/observations/show/_namings.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%
@query ||= nil
@query ||= nil # tbd what this was ever used for in the table
%>

<!--OBSERVATION_NAMINGS / TABLE REFRESHED BY TURBO -->
<%= tag.div(id: "observation_namings") do
render(partial: "observations/namings/table",
locals: { obs: obs, query: @query })
observation_namings_table(obs)
end %>
<!--/OBSERVATION_NAMINGS -->
26 changes: 14 additions & 12 deletions app/views/observations/show/_section_update.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<%
<%=
# Update observation view with results of update or create
# Needs locals: identifier
# The namings table is in another folder
# The namings table is a helper
# N+1 - @observation.reload ?!
if identifier == "namings"
id = "namings_table"
partial = "observations/namings/table"
id = "namings_table_rows"
turbo_stream.replace(id) do
observation_namings_table_rows(@observation)
end
else
id = "observation_#{identifier}"
partial = "observations/show/#{identifier}"
turbo_stream.replace(id) do
render(
partial: partial,
locals: { obs: @observation },
layout: false
)
end
end
%>
<%= turbo_stream.replace(id) do
render(
partial: partial,
locals: { obs: @observation.reload },
layout: false
)
end %>
<%= turbo_stream.update("page_flash") do
flash_notices_html
end %>
18 changes: 9 additions & 9 deletions app/views/shared/_form_name_feedback.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ button_name - text: button to complete the action, e.g. Submit, Create
<%=
if valid_names
##### Warnings #####
flash_warning(:form_observations_there_is_a_problem_with_name.t)
concat(flash_warning(:form_observations_there_is_a_problem_with_name.t))

tag.div(class: "alert alert-warning", id: "name_messages") do
concat(tag.div(class: "alert alert-warning", id: "name_messages") do
concat(tag.div do
if suggest_corrections || names.blank?
:form_naming_not_recognized.t(name: what)
Expand Down Expand Up @@ -59,25 +59,25 @@ if valid_names
:div, :form_naming_not_recognized_help.t(button: button_name)
))
end
end
end)

##### Errors #####
elsif names&.length == 0

flash_error(:form_observations_there_is_a_problem_with_name.t)
concat(flash_error(:form_observations_there_is_a_problem_with_name.t))

tag.div(class: "alert alert-danger", id: "name_messages") do
concat(tag.div(class: "alert alert-danger", id: "name_messages") do
concat(tag.div(:form_naming_not_recognized.t(name: what)))
concat(help_note(
:div, :form_naming_not_recognized_help.t(button: button_name)
))
end
end)

elsif names&.length &.> 1

flash_error(:form_observations_there_is_a_problem_with_name.t)
concat(flash_error(:form_observations_there_is_a_problem_with_name.t))

tag.div(class: "alert alert-danger", id: "name_messages") do
concat(tag.div(class: "alert alert-danger", id: "name_messages") do
concat(tag.div([:form_naming_multiple_names.t(name: what), ":"].safe_join))
concat(fields_for(:chosen_name) do |f_c|
names.each do |n|
Expand All @@ -87,6 +87,6 @@ elsif names&.length &.> 1
end
end)
concat(help_note(:div, :form_naming_multiple_names_help.t))
end
end)

end %>
2 changes: 1 addition & 1 deletion test/controllers/observations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def assert_show_observation
assert_template("observations/show")
assert_template("observations/show/_name_info")
assert_template("observations/show/_observation_details")
assert_template("observations/show/_namings")
# assert_template("observations/show/_namings") now a helper
assert_template("comments/_comments_for_object")
assert_template("observations/show/_thumbnail_map")
end
Expand Down

0 comments on commit 05902f2

Please sign in to comment.