Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Jan 21, 2015
2 parents a2cbbd9 + 7e6f802 commit 7007dc5
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 91 deletions.
2 changes: 1 addition & 1 deletion app/controllers/serials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def destroy
format.json { head :no_content }
end
end

``
private
# Use callbacks to share common setup or constraints between actions.
def set_serial
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/serials_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def tasks_serials_serial_similar_link(serial)
# options = {}
# priority = [serial.container, serial.identifiers.first, serial ].compact.first
# link_to('Similar serials', verify_accessions_task_path(by: priority.metamorphosize.class.name.tableize.singularize.to_sym, id: priority.to_param))
link_to('Similar serials', tasks_serials_similar_serial_path(@serial))
link_to('Similar serials', find_serials_like_me_path(serial))
end

end
46 changes: 35 additions & 11 deletions app/models/geographic_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,46 @@ def self.find_for_autocomplete(params)
end

# @param geographic_item [GeographicItem]
# @return [Scope]
def self.find_others_contained_within(geographic_item)
pieces = GeographicItem.is_contained_by('any', geographic_item)
# @return [Scope] of geographic_items
def self.find_others_contained_by(geographic_area)
pieces = GeographicItem.is_contained_by('any_poly', geographic_area.geo_object)
pieces

# ce = []
# pieces.each { |o|
# ce.push(o.collecting_events_through_georeferences.to_a)
# ce.push(o.collecting_events_through_georeference_error_geographic_item.to_a)
# }
# pieces = CollectingEvent.where('id in (?)', ce.flatten.map(&:id).uniq)
#
pieces.excluding(geographic_item)
others = []
pieces.each { |o|
others.push(o.collecting_events_through_georeferences.to_a)
others.push(o.collecting_events_through_georeference_error_geographic_item.to_a)
}
pieces = CollectingEvent.where('id in (?)', others.flatten.map(&:id).uniq)

pieces.excluding(geographic_area)

end

# @param geographic_item [GeographicItem]
# @return [Scope] of geographic_items
def self.find_others_contained_in(geographic_area)
pieces = GeographicItem.is_contained_in('any', geographic_area.geo_object)
pieces

others = []
pieces.each { |o|
others.push(o.collecting_events_through_georeferences.to_a)
others.push(o.collecting_events_through_georeference_error_geographic_item.to_a)
}
pieces = CollectingEvent.where('id in (?)', others.flatten.map(&:id).uniq)

pieces.excluding(geographic_area)

end

# @param latitude [Double] Decimal degrees
# @param longitude [Double] Decimal degrees
# @return [Scope] of all area which contain the point specified
def self.find_by_lat_long(latitude = 0.0, longitude = 0.0)
point = GeographicItem.new(Georeference::FACTORY.point(longitude, latitude))
GeographicItem.is_contained_in('any_poly', point)
end

def children_at_level1
GeographicArea.descendants_of(self).where('level1_id IS NOT NULL AND level2_id IS NULL')
Expand Down
53 changes: 41 additions & 12 deletions app/models/geographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,47 @@ def self.disjoint_from(column_name, *geographic_items)
# it will return the 'or' of each of the objects against the table.
# SELECT COUNT(*) FROM "geographic_items" WHERE (ST_Contains(polygon::geometry, GeomFromEWKT('srid=4326;POINT (0.0 0.0 0.0)')) or ST_Contains(polygon::geometry, GeomFromEWKT('srid=4326;POINT (-9.8 5.0 0.0)')))
def self.is_contained_in(column_name, *geographic_items)
if column_name.downcase == 'any'
part = []
DATA_TYPES.each { |column|
unless column == :geometry_collection
part.push(GeographicItem.is_contained_in("#{column}", geographic_items).to_a)
end
}
# todo: change 'id in (?)' to some other sql construct
GeographicItem.where(id: part.flatten.map(&:id))
else
q = geographic_items.flatten.collect { |geographic_item| GeographicItem.containing_sql(column_name, geographic_item) }.join(' or ')
where(q)
# if column_name.downcase == 'any'
# part = []
# DATA_TYPES.each { |column|
# unless column == :geometry_collection
# part.push(GeographicItem.is_contained_in("#{column}", geographic_items).to_a)
# end
# }
# # todo: change 'id in (?)' to some other sql construct
# GeographicItem.where(id: part.flatten.map(&:id))
# else
# q = geographic_items.flatten.collect { |geographic_item| GeographicItem.containing_sql(column_name, geographic_item) }.join(' or ')
# where(q)
# end

column_name.downcase!
case column_name
when 'any'
part = []
DATA_TYPES.each { |column|
unless column == :geometry_collection
part.push(GeographicItem.is_contained_in("#{column}", geographic_items).to_a)
end
}
# todo: change 'id in (?)' to some other sql construct
GeographicItem.where(id: part.flatten.map(&:id))
when 'any_poly', 'any_line'
part = []
DATA_TYPES.each { |column|
unless column == :geometry_collection
if column.to_s.index(column_name.gsub('any_', ''))
part.push(GeographicItem.is_contained_in("#{column}", geographic_items).to_a)
end
end
}
# todo: change 'id in (?)' to some other sql construct
GeographicItem.where(id: part.flatten.map(&:id))
else
q = geographic_items.flatten.collect { |geographic_item|
GeographicItem.containing_sql(column_name, geographic_item)
}.join(' or ')
where(q) # .excluding(geographic_items)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/serial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @!attribute primary_language_id
# @return [Integer]
# The id of the Language langauge of this serial. According to the ISSN a new ISSN is minted for a journal that changes languages.
# The id of the Language - language of this serial. According to the ISSN a new ISSN is minted for any journal that changes languages.
#
class Serial < ActiveRecord::Base
# Include statements, and acts_as_type
Expand Down
10 changes: 0 additions & 10 deletions app/views/alternate_values/_object_pane.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/citations/_object_pane.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/data_attributes/_object_pane.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/identifiers/_object_pane.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/notes/_object_pane.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/shared/shared_data/user_defined/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<%= render(partial: '/shared/data/show/soft_validation', locals: {object: object}) if object.class.respond_to?(:soft_validates?) -%>
<%= render(partial: '/alternate_values/object_pane', locals: {object: object}) if object.has_alternate_values? %>
<%= render(partial: '/citations/object_pane', locals: {object: object}) if object.has_citations? %>
<%= render(partial: '/data_attributes/object_pane', locals: {object: object}) if object.has_data_attributes? %>
<%= render(partial: '/identifiers/object_pane', locals: {object: object}) if object.has_identifiers? %>
<%= render(partial: '/notes/object_pane', locals: {object: object}) if object.has_notes? %>
<%= render(partial: '/tags/object_pane', locals: {object: object}) if object.has_tags? %>
Expand Down
10 changes: 0 additions & 10 deletions app/views/tags/_object_pane.html.erb

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/tasks/serials/similar/like.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<ul>
<% @similar_serials.each do |serial| -%>
<li> <%= serial_tag(serial) -%>
<%= link_to('similar',tasks_serials_similar_serial_path(serial)) -%>
<%= link_to('similar',find_serials_like_me_path(serial)) -%>
<%= link_to('edit', edit_serial_path(serial)) -%>
</li>
<% end %>
</ul>

<%= form_tag(tasks_serials_similar_serial_path(@serial.to_param)) do |f| %>
<%= form_tag(find_serials_like_me_path(@serial.to_param)) do |f| %>
<div>
<div class="field">
<%= label_tag :enter_a_search_string %>
Expand Down
2 changes: 2 additions & 0 deletions config/interface/task_relations_for_navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
---
find_similar_serials_task:
- serials
find_serials_like_me:
- serials
build_biocuration_groups_task:
- quick_verbatim_material_task
quick_verbatim_material_task:
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
end

match 'find_similar_serials_task', to: 'tasks/serials/similar#find', via: [:get, :post]
match 'find_serials_like_me/:id', to: 'tasks/serials/similar#like', via: 'get', as: :find_serials_like_me

namespace :tasks do
namespace :gis do
Expand All @@ -202,8 +203,8 @@
end

namespace :serials do
get 'similar/like:id', to: 'similar#like', as: 'similar_serial'
post 'serial/update_find:id', to: 'similar#update_find', as: 'update_serial_find' # do I still need this? - eef
# get 'similar/like/:id', to: 'similar#like', as: 'find_serials_like_me'
post 'serial/update_find/:id', to: 'similar#update_find', as: 'update_serial_find' # do I still need this? - eef
# get 'serial/update'
# get 'serial/within'
end
Expand Down
32 changes: 32 additions & 0 deletions spec/models/geographic_area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,36 @@

end

context 'find_others... responses from geographic_areas' do

before(:all) do
clean_slate_geo
generate_political_areas_with_collecting_events
# generate_geo_test_objects
end

after(:all) do
clean_slate_geo
User.delete_all
Project.delete_all
ActiveRecord::Base.connection.reset_pk_sequence!('users')
ActiveRecord::Base.connection.reset_pk_sequence!('projects')
end

specify('find_others_contained_in')do
pending
expect(GeographicArea.find_others_contained_in(@area_land_mass)).to include(@item_n3)
end

specify('find_others_contained_by') do
pending
expect(GeographicArea.find_others_contained_by(@area_old_boxia)).to include(@area_r)
end

specify('find_by_lat_;ong') do
pending
expect(GeographicArea.find_by_lat_long(@area_old_boxia)).to include(@area_r)
end
end

end

0 comments on commit 7007dc5

Please sign in to comment.