Skip to content

Commit

Permalink
Bugfix: projects without places showing counts from place were broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Apr 16, 2014
1 parent 7b41ab0 commit db39fe8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions app/controllers/shared/lists_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def show
@search_taxon_ids = set_search_taxon_ids(@q)

if place_based_list?(@list)
@place = set_place(@observable_list)
@other_check_lists = set_other_check_lists(@observable_list, @place)
if @place = set_place(@observable_list)
@other_check_lists = set_other_check_lists(@observable_list, @place)
end
end


Expand Down Expand Up @@ -393,7 +394,10 @@ def taxa

private
def set_place(list)
list.try(:place)
unless p = list.place
p = list.project.place if list.is_a?(ProjectList)
end
p
end

def set_other_check_lists(list, place)
Expand Down Expand Up @@ -702,15 +706,19 @@ def allow_batch_adding(list, current_user)
def place_based_list?(list)
list.type == "CheckList" || place_based_project_list?(list)
end

def place_based_project_list?(list)
list.type == "ProjectList" && list.project.show_from_place
end

def default_checklist?(list)
list.type=="CheckList" && list.is_default?
end

def already_in_list_and_observed_and_not_place_based(results, listed_taxon)
results.find{|lt| (listed_taxon['taxon_id'] == lt['taxon_id'] && lt['last_observation_id'] && lt['place_id'].nil? )}
end

def not_yet_in_list_and_unobserved(aggregator, listed_taxon)
aggregator["#{listed_taxon['taxon_id']}"].nil? && (listed_taxon['last_observation_id'].nil?)
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Project < ActiveRecord::Base
has_many :assessments, :dependent => :destroy

before_save :strip_title
before_save :unset_show_from_place_if_no_place
after_create :create_the_project_list
after_save :add_owner_as_project_user

Expand All @@ -34,7 +35,6 @@ class Project < ActiveRecord::Base

preference :count_from_list, :boolean, :default => false
preference :place_boundary_visible, :boolean, :default => false

preference :count_by, :string, :default => 'species'

# For some reason these don't work here
Expand Down Expand Up @@ -137,6 +137,11 @@ def strip_title
true
end

def unset_show_from_place_if_no_place
self.show_from_place = false if place.blank?
true
end

def cover_dimensions
return true unless cover.queued_for_write[:original]
dimensions = Paperclip::Geometry.from_file(cover.queued_for_write[:original].path)
Expand Down

0 comments on commit db39fe8

Please sign in to comment.