Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Mar 25, 2021
1 parent 43e5637 commit 0601192
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
## [unreleased]

### Added
- Collection object filter params for preparation and buffered fields [#2118]
- Added soft_validations and fixes for coordinate name citations and roles.
- `/collection_objects/123/navigation.json` route/view
- Determination, OTU and repository smart selectors on New image task [#2101]
- Georeferences coordinates in label generate on New collecting event [#2107]
- Lock buttons on New image [#2101]
- Open PDF slider in all tabs [#2106]
- TaxonName autocomplete by internal id
- Preparation type and with/out facets [#2118]
- bind `alt/ctrl + f` to focus the search autocomplete [#2132]
- Annotations on Browse nomenclature
- Collectors facet on Filter collection objects task
Expand All @@ -30,6 +30,8 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
- Determiner facet on Filter collection objects task

### Fixed
- Collection object filter, collecting event related params were not being passed [#1807]
- Collection object filter with/out facets, in part [#1455]
- CoLDP missing values for names without original combinations [#2146]
- Multiple parent OTUs via parent_otu_id raised in CoLDp export [#2011]
- Not being able to get pinboard items on some circumstances
Expand All @@ -40,6 +42,10 @@ This project <em>does not yet</em> adheres to [Semantic Versioning](https://semv
- Missing Determiner param [#2119]
- Refresh status and relationship list on rank change [#2010]


[#1455]: https://github.com/SpeciesFileGroup/taxonworks/issues/1455
[#1807]: https://github.com/SpeciesFileGroup/taxonworks/issues/1807
[#2114]: https://github.com/SpeciesFileGroup/taxonworks/issues/2114
[#2146]: https://github.com/SpeciesFileGroup/taxonworks/issues/2146
[#2010]: https://github.com/SpeciesFileGroup/taxonworks/issues/2010
[#2011]: https://github.com/SpeciesFileGroup/taxonworks/issues/2011
Expand Down
22 changes: 13 additions & 9 deletions app/controllers/collection_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,13 @@ def filter_params
:never_loaned,
:on_loan,
:partial_overlap_dates,
:radius,
:preparation_type_id,
:radius, # CE filter
:repository,
:repository_id,
:sled_image_id,
:spatial_geographic_areas,
:start_date,
:start_date, # CE filter
:taxon_determinations,
:type_material,
:type_specimen_taxon_name_id,
Expand All @@ -467,7 +468,8 @@ def filter_params
keyword_id_and: [],
keyword_id_or: [],
otu_ids: [],
collector_ids: [] #
collector_ids: [], #
preparation_type_id: []
# user_id: []
# collecting_event: {
# :recent,
Expand Down Expand Up @@ -496,7 +498,7 @@ def api_params
:depictions,
:determiner_id_or,
:dwc_indexed,
:end_date,
:end_date, # CE filter
:exact_buffered_collecting_event,
:exact_buffered_determinations,
:exact_buffered_other_labels,
Expand All @@ -511,13 +513,14 @@ def api_params
:in_labels,
:in_verbatim_locality,
:loaned,
:md5_verbatim_label,
:md5_verbatim_label, # CE filter
:namespace_id,
:never_loaned,
:on_loan,
:partial_overlap_dates,
:partial_overlap_dates, # CE filter
:radius,
:repository,
:preparation_type_id,
:repository_id,
:sled_image_id,
:spatial_geographic_areas,
Expand All @@ -530,17 +533,18 @@ def api_params
:user_id,
:user_target,
:validity,
:wkt,
:wkt, # CE filter
biocuration_class_ids: [],
biological_relationship_ids: [],
collecting_event_ids: [],
collector_ids: [],
determiner_id: [],
geographic_area_ids: [],
geographic_area_ids: [], # CE filter
is_type: [],
keyword_id_and: [],
keyword_id_or: [],
otu_ids: [],
collector_ids: []
preparation_type_id: [],

# collecting_event: {
# :recent,
Expand Down
17 changes: 16 additions & 1 deletion lib/queries/collecting_event/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ class Filter
class_eval { attr_accessor a.to_sym }
end

PARAMS = %w{collector_ids
collector_ids_or
spatial_geographic_areas
wkt
geographic_area_ids
start_date
end_date
radius
partial_overlap_dates
md5_verbatim_label
in_verbatim_locality
in_labels
geo_json
}

# Wildcard wrapped matching any label
attr_accessor :in_labels

Expand Down Expand Up @@ -84,7 +99,7 @@ def initialize(params)
@recent = params[:recent].blank? ? nil : params[:recent].to_i
@spatial_geographic_areas = (params[:spatial_geographic_areas]&.downcase == 'true' ? true : false) if !params[:spatial_geographic_areas].nil?
@wkt = params[:wkt]

set_tags_params(params)
set_attributes(params)
set_dates(params)
Expand Down
45 changes: 28 additions & 17 deletions lib/queries/collection_object/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,16 @@ class Filter < Queries::Query
# nil - not applied
attr_accessor :type_material


# @param [Hash] args are permitted params
def initialize(params)
params.reject!{ |_k, v| v.blank? } # dump all entries with empty values

# Only CollectingEvent fields are permitted now.
# (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.
collecting_event_params = Queries::CollectingEvent::Filter::ATTRIBUTES + Queries::CollectingEvent::Filter::PARAMS

@collecting_event_query = Queries::CollectingEvent::Filter.new(
params.select{|a,b| Queries::CollectingEvent::Filter::ATTRIBUTES.include?(a.to_s) }.merge(
collector_ids: params[:collector_ids],
collector_ids_or: params[:collector_ids_or]
)
params.select{|a,b| collecting_event_params.include?(a.to_s) }
)

@ancestor_id = params[:ancestor_id].blank? ? nil : params[:ancestor_id]
Expand Down Expand Up @@ -206,6 +204,7 @@ def initialize(params)
@on_loan = boolean_param(params, :on_loan)
@otu_descendants = boolean_param(params, :otu_descendants)
@otu_ids = params[:otu_ids] || []
@preparation_type_id = params[:preparation_type_id]
@recent = params[:recent].blank? ? false : true
@repository = boolean_param(params, :repository)
@repository_id = params[:repository_id].blank? ? nil : params[:repository_id]
Expand Down Expand Up @@ -258,6 +257,10 @@ def determiner_id
[@determiner_id].flatten.compact
end

def preparation_type_id
[@preparation_type_id].flatten.compact
end

def taxon_determinations_facet
return nil if taxon_determinations.nil?

Expand Down Expand Up @@ -402,6 +405,11 @@ def collecting_event_ids_facet
table[:collecting_event_id].eq_any(collecting_event_ids)
end

def preparation_type_id_facet
return nil if preparation_type_id.empty?
table[:preparation_type_id].eq_any(preparation_type_id)
end

def repository_id_facet
return nil if repository_id.blank?
table[:repository_id].eq(repository_id)
Expand Down Expand Up @@ -449,6 +457,7 @@ def base_and_clauses
attribute_exact_facet(:buffered_collecting_event),
attribute_exact_facet(:buffered_other_labels),
collecting_event_ids_facet,
preparation_type_id_facet,
type_facet,
repository_id_facet
]
Expand Down Expand Up @@ -476,7 +485,7 @@ def base_merge_clauses
created_updated_facet, # See Queries::Concerns::Users
identifiers_facet, # See Queries::Concerns::Identifiers
identifier_between_facet,
identifier_facet,
identifier_facet, # See Queries::Concerns::Identifiers
identifier_namespace_facet,
loaned_facet,
on_loan_facet,
Expand Down Expand Up @@ -607,18 +616,20 @@ def ancestors_facet
::CollectionObject.joins(q.join_sources).where(z)
end


# TODO: is this used?
# @return [Scope]
def geographic_area_scope
# This could be simplified if the AJAX selector returned a geographic_item_id rather than a GeographicAreaId
target_geographic_item_ids = []
geographic_area_ids.each do |ga_id|
target_geographic_item_ids.push(::GeographicArea.joins(:geographic_items)
.find(ga_id)
.default_geographic_item.id)
end
::CollectionObject.joins(:geographic_items)
.where(::GeographicItem.contained_by_where_sql(target_geographic_item_ids))
end
# def geographic_area_scope
# # This could be simplified if the AJAX selector returned a geographic_item_id rather than a GeographicAreaId
# target_geographic_item_ids = []
# geographic_area_ids.each do |ga_id|
# target_geographic_item_ids.push(::GeographicArea.joins(:geographic_items)
# .find(ga_id)
# .default_geographic_item.id)
# end
# ::CollectionObject.joins(:geographic_items)
# .where(::GeographicItem.contained_by_where_sql(target_geographic_item_ids))
# end


end
Expand Down
20 changes: 12 additions & 8 deletions lib/queries/concerns/identifiers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
# For filter queries:
# !! requires a `query_base` method
# !! requires `set_identifiers` be called in initialize()
#
#
# See spec/lib/queries/collection_object/filter_spec.rb for existing spec tests
#
module Queries::Concerns::Identifiers


include Queries::Helpers

extend ActiveSupport::Concern

included do
# Limit to this namespace
# Limit to this namespace
attr_accessor :namespace_id

# @return [String]
Expand All @@ -25,7 +28,7 @@ module Queries::Concerns::Identifiers
# Match on cached
attr_accessor :identifier

# Match like or exact on cached
# Match like or exact on cached
attr_accessor :identifier_exact

# param identifier_type [Array]
Expand Down Expand Up @@ -53,9 +56,10 @@ def set_identifier(params)
@identifier_start = params[:identifier_start]
@identifier_end = params[:identifier_end]
@identifier = params[:identifier]
@identifiers = boolean_param(params, :identifiers)

@identifier_exact = (params[:identifier_exact]&.downcase == 'true' ? true : false) if !params[:identifier_exact].nil?
@identifier_type = params[:identifier_type] || []
@identifier_exact = boolean_param(params, :identifier_exact)
@identifier_type = params[:identifier_type] || []
end

# @return [Arel::Table]
Expand Down Expand Up @@ -101,14 +105,14 @@ def identifier_facet
identifier_table[:cached].matches('%' + identifier + '%')

w = w.and(identifier_table[:namespace_id].eq(namespace_id)) if namespace_id
q.where(w)
q.where(w)
end

def identifier_type_facet
return nil if identifier_type.empty?
q = query_base.joins(:identifiers)
w = identifier_table[:type].eq_any(identifier_type)
q.where(w)
q.where(w)
end

def identifier_namespace_facet
Expand Down Expand Up @@ -166,7 +170,7 @@ def with_identifier_cached_like_fragments
# See lib/queries/identifiers/autocomplete for autocomplete for identifiers
#
# May need to alter base query here
#
#
def autocomplete_identifier_cached_exact
query_base.joins(:identifiers).where(with_identifier_cached.to_sql)
end
Expand Down

0 comments on commit 0601192

Please sign in to comment.