Skip to content

Commit

Permalink
add_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Dec 20, 2024
1 parent 4cc128c commit fb54b18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
14 changes: 11 additions & 3 deletions app/classes/query/initializers/observations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def observations_coercion_parameter_declarations
}
end

# This is just to allow the additional location conditions
def add_ids_condition(table = model.table_name, ids = :ids)
return if params[ids].nil? # [] is valid

super
add_is_collection_location_condition_for_locations
end

def initialize_herbaria_parameter
add_id_condition(
"herbarium_records.herbarium_id",
Expand Down Expand Up @@ -74,7 +82,7 @@ def add_for_project_condition
@title_tag = :query_title_for_project
@title_args[:project] = project.title
where << "project_observations.project_id = '#{params[:project]}'"
add_collection_location_condition_for_locations
add_is_collection_location_condition_for_locations
add_join(:observations, :project_observations)
end

Expand All @@ -101,11 +109,11 @@ def add_in_species_list_condition
@title_tag = :query_title_in_species_list
@title_args[:species_list] = spl.format_name
where << "species_list_observations.species_list_id = '#{spl.id}'"
add_collection_location_condition_for_locations
add_is_collection_location_condition_for_locations
add_join(:observations, :species_list_observations)
end

def add_collection_location_condition_for_locations
def add_is_collection_location_condition_for_locations
return unless model == Location

where << "observations.is_collection_location IS TRUE"
Expand Down
14 changes: 1 addition & 13 deletions app/classes/query/location_with_observations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parameter_declarations

def initialize_flavor
add_join(:observations)
add_ids_condition
add_ids_condition("observations", :obs_ids)
add_owner_and_time_stamp_conditions("observations")
add_by_user_condition("observations")
add_date_condition("observations.when", params[:date])
Expand All @@ -34,18 +34,6 @@ def initialize_flavor
super
end

def add_ids_condition
return unless params[:obs_ids]

set = clean_id_set(params[:obs_ids])
@where << "observations.id IN (#{set})"
self.order = "FIND_IN_SET(observations.id,'#{set}') ASC"

@title_args[:observations] = params[:old_title] ||
:query_title_in_set.t(type: :observation)
where << "observations.is_collection_location IS TRUE"
end

def add_where_conditions
add_where_condition(:observations, params[:locations])
add_at_location_parameter(:observations)
Expand Down

0 comments on commit fb54b18

Please sign in to comment.