Skip to content

Commit

Permalink
Fix @matches and @Others
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Feb 19, 2024
1 parent b8a4da6 commit 32db456
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
22 changes: 14 additions & 8 deletions app/controllers/observations/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ class LocationsController < ApplicationController
# What the list shows is a list of defined Locations that match the given
# +where+ string, in order of closeness of match, in the following order:
# 1) matches = match the string
# 1) others that start with everything in "where" up to the comma
# 2) others that start with the first word in "where"
# 3) doesn't try other segments, because the second one could be a country
# 2) others that include everything in "where" up to the comma
# 3) others that include the first word in "where"
# 4) others that include the last word of the first segment in "where"
# (for example, "Estado de Guerrero, México": searches for "Guerrero")
# 5) doesn't try other segments, because the second one could be a country
#
# The form is not really a `form` and does not commit to a "create" action.
# It contains links to convert the observations sharing the +where+ string
# The form is not really a `form`, but the buttons do commit to "update".
# It contains links to assign the observations sharing the +where+ string
# to the given Location (AR record)

def edit
store_location
@where = Location.user_format(@user, params[:where].to_s)
# NOTE: Do not use or pass Location.user_format for @where.
# This is the string we're looking for in the db, in the `name` column,
# and we're also assuming "postal" order when splitting the string.
@where = params[:where].to_s
@matches = Location.name_includes(@where)
@others = []

Expand All @@ -46,7 +52,8 @@ def edit
return unless places.length > 1 || words.length > 1

@others = Location.name_includes(places.first).
or(Location.name_includes(words.first))
or(Location.name_includes(words.first)).
or(Location.name_includes(places.first.split.last))
end

# merges_controller_test
Expand Down Expand Up @@ -76,7 +83,6 @@ def update
# Move all the Observation's with a given +where+ into a given Location.
def update_observations_by_where(location, given_where)
success = true
# observations = Observation.find_all_by_where(given_where)
observations = Observation.where(where: given_where)
count = 3
observations.each do |o|
Expand Down
28 changes: 22 additions & 6 deletions app/views/controllers/observations/locations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%
@container = :full
add_page_title(:list_merge_options_title.t(where: @where))
# NOTE: the "forms" are patch buttons in the "row" partial
add_page_title(
:list_merge_options_title.t(where: Location.user_format(@user, @where))
)
# NOTE: the "forms" are patch buttons. Not using a partial for speed here.
%>

<div class="row">
Expand All @@ -12,8 +14,15 @@ add_page_title(:list_merge_options_title.t(where: @where))
<%= :list_merge_options_near_matches.t %>
</div>
<div class="list-group">
<%= render(partial: "observations/locations/row",
collection: @matches, as: :location) %>
<% @matches.map do |location| %>
<div class="list-group-item">
<%= patch_button(name: location.display_name.t,
path: assign_location_to_observations_path(
where: @where, location: location
), class: "text-left",
data: { confirm: :list_merge_are_you_sure.l }) %>
</div>
<% end %>
</div>
</div>
<% end %>
Expand All @@ -24,8 +33,15 @@ add_page_title(:list_merge_options_title.t(where: @where))
<%= :list_merge_options_others.t %>
</div>
<div class="list-group">
<%= render(partial: "observations/locations/row",
collection: @others, as: :location) %>
<% @others.map do |location| %>
<div class="list-group-item">
<%= patch_button(name: location.display_name.t,
path: assign_location_to_observations_path(
where: @where, location: location
), class: "text-left",
data: { confirm: :list_merge_are_you_sure.l }) %>
</div>
<% end %>
</div>
</div>
<% end %>
Expand Down

0 comments on commit 32db456

Please sign in to comment.