Skip to content

Commit

Permalink
Merge pull request #1791 from MushroomObserver/nimmo-name-map
Browse files Browse the repository at this point in the history
`MapSet` & `CollapsibleCollection` — Reject unknown locations
  • Loading branch information
nimmolo committed Jan 10, 2024
2 parents d3cefb8 + ea70aa6 commit 4ba12de
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 35 deletions.
10 changes: 8 additions & 2 deletions app/classes/mappable/collapsible_collection_of_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,24 @@ def round_number(num, prec)
(num.to_f * prec).round.to_f / prec
end

# Sets with unknown location are messing up the maps.
# Dismiss any set that has an unknown location.
# Similar to MapSet.init_objects_and_derive_extents
# These are MinimalMapLocations/Observations, so their properties
# are different.
def init_sets(objects)
objects = [objects] unless objects.is_a?(Array)
raise("Tried to create empty map!") if objects.empty?

@sets = {}
objects.each do |obj|
if obj.location?
if obj.location? && !Location.is_unknown?(obj.name)
add_box_set(obj, [obj], MAX_PRECISION)
elsif obj.observation?
if obj.lat && !obj.lat_long_dubious?
add_point_set(obj, [obj], MAX_PRECISION)
elsif (loc = obj.location)
elsif (loc = obj.location) &&
!Location.is_unknown?(loc.name)
add_box_set(loc, [obj], MAX_PRECISION)
end
else
Expand Down
5 changes: 3 additions & 2 deletions app/classes/mappable/map_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ def initialize(objects = [])

def init_objects_and_derive_extents
@objects.each do |obj|
if obj.location?
if obj.location? && !Location.is_unknown?(obj.name)
update_extents_with_box(obj)
elsif obj.observation?
if obj.lat && !obj.lat_long_dubious?
update_extents_with_point(obj)
elsif (loc = obj.location)
elsif (loc = obj.location) &&
!Location.is_unknown?(loc.name)
update_extents_with_box(loc)
end
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/locations/maps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Locations
class MapsController < ApplicationController
before_action :login_required

# Map results of a search or index.
# Map results of a search or index of Locations.
def show
@query = find_or_create_query(:Location)

Expand Down
5 changes: 4 additions & 1 deletion app/helpers/descriptions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def reader?(desc)
def show_embedded_description_title(desc, type)
title = description_title(desc)
links = description_mod_links(desc, type)
tag.p(tag.span(title, class: "text-lg") + links.safe_join(" | "))
tag.div do
[tag.span(title, class: "text-lg"),
links.safe_join(" | ")].safe_join(safe_nbsp)
end
end

def description_mod_links(desc, type)
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ module MapHelper
# returns an array of mapsets, each suitable for a marker or box
def make_map(objects: [], **args)
nothing_to_map = args[:nothing_to_map] || :runtime_map_nothing_to_map.t
return nothing_to_map unless objects.any?
# There's nothing to map if the location is unknown.
objects = objects.reject do |obj|
name = obj.respond_to?(:location) ? obj.location&.name : obj.name
Location.is_unknown?(name)
end
return tag.div(nothing_to_map, class: "w-100") unless objects.any?

default_args = {
map_div: "map_div",
Expand All @@ -16,7 +21,7 @@ def make_map(objects: [], **args)
controls: [:large_map, :map_type].to_json,
location_format: User.current_location_format # method has a default
}
map_args = default_args.merge(args.except(:objects, :nothing_to_map))
map_args = default_args.merge(args.except(:nothing_to_map))
map_args[:collection] = mappable_collection(objects, map_args).to_json
map_args[:localization] = {
nothing_to_map: nothing_to_map,
Expand All @@ -25,7 +30,6 @@ def make_map(objects: [], **args)
show_all: :show_all.t,
map_all: :map_all.t
}.to_json

map_html(map_args)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/locations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_tab_set(location_form_edit_tabs(location: @location))

@container = :full
action = { action: :update, id: @location.id,
approved_where: @display_name, q: get_query_param }
approved_where: @display_name, q: get_query_param }
%>
<%= render(partial: "locations/form",
Expand Down
44 changes: 20 additions & 24 deletions app/views/controllers/locations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,30 @@ add_tab_set(location_show_tabs(location: @location))
@container = :wide
%>
<%= render(partial: "locations/show/location", object: @location) %>

<div class="row">
<div class="col-sm-4 mb-3">
<div class="col-sm-8">
<%= render(partial: "comments/comments_for_object",
locals: { object: @location, controls: @user, limit: 2 }) %>
<% if @description&.notes? %>
<hr/>
<%= show_embedded_description_title(@description, :location) %>
<%= render(partial: "locations/descriptions/show/location_description",
object: @description) %>
<%= render(partial: "comments/comments_for_object",
locals: { object: @description, controls: @user, limit: 2 }) %>
<hr/>
<% end %>
<%= show_alt_descriptions(object: @location, projects: @projects) %>
</div>
<div class="col-sm-4">
<%= show_previous_version(@location, @versions) %>
<%= export_status_controls(@location) %>
</div>

<div class="col-sm-8 mb-3">
<%= show_alt_descriptions(object: @location, projects: @projects) %>
<%= show_object_footer(@location, @versions) %>
</div>
</div><!--.row-->

<%= render(partial: "locations/show/location", object: @location) %>
<%= render(partial: "comments/comments_for_object",
locals: { object: @location, controls: @user, limit: 2 }) %>
<div class="mt-3">
</div>

<div class="container-text">
<% if @description&.notes? %>
<hr/>
<%= show_embedded_description_title(@description, :location) %>
<%= render(partial: "locations/descriptions/show/location_description",
object: @description) %>
<%= render(partial: "comments/comments_for_object",
locals: { object: @description, controls: @user, limit: 2 }) %>
<hr/>
<% end %>

<div class="mt-3">
<%= show_object_footer(@location, @versions) %>
</div>
</div><!--.container-text-->
1 change: 0 additions & 1 deletion app/views/controllers/locations/show/_location.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<%= tag.div(class: "text-center") do
show_authors_and_editors(obj: location, versions: @versions, user: @user)
end %>
</div><!-- .text-center -->
</div><!--.col-sm-8-->

<div class="col-sm-4">
Expand Down

0 comments on commit 4ba12de

Please sign in to comment.