diff --git a/app/classes/api2/comment_api.rb b/app/classes/api2/comment_api.rb index ee0f60b7f6..aa7821308a 100644 --- a/app/classes/api2/comment_api.rb +++ b/app/classes/api2/comment_api.rb @@ -59,7 +59,7 @@ def update_params end def query_flavor - @target ? :for_target : :all + :all end def validate_create_params!(params) diff --git a/app/classes/query.rb b/app/classes/query.rb index 0d2b9c0d33..3a874f7d92 100644 --- a/app/classes/query.rb +++ b/app/classes/query.rb @@ -17,8 +17,8 @@ # Each model has a default search flavor (:default), which is used by the prev # and next actions when the specified query no longer exists. For example, if # you click on an observation from the main index, prev and next travserse the -# results of an :Observation :by_rss_log query. If the user comes back a day -# later, this query will have been culled by the garbage collector (see +# results of an :Observation :all by: :rss_log query. If the user comes back +# a day later, this query will have been culled by the garbage collector (see # below), so prev and next need to be able to create a default query on the # fly. In this case it may be :Observation :all (see default_flavors array # below). diff --git a/app/classes/query/article_base.rb b/app/classes/query/article_base.rb index 285826d3b5..34b0e7e3e7 100644 --- a/app/classes/query/article_base.rb +++ b/app/classes/query/article_base.rb @@ -10,6 +10,7 @@ def parameter_declarations created_at?: [:time], updated_at?: [:time], users?: [User], + ids?: [Article], title_has?: :string, body_has?: :string ) @@ -17,6 +18,7 @@ def parameter_declarations def initialize_flavor add_owner_and_time_stamp_conditions("articles") + add_ids_condition add_search_condition("articles.title", params[:title_has]) add_search_condition("articles.body", params[:body_has]) super diff --git a/app/classes/query/article_by_rss_log.rb b/app/classes/query/article_by_rss_log.rb deleted file mode 100644 index 7a0cae53e1..0000000000 --- a/app/classes/query/article_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::ArticleByRssLog < Query::ArticleBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/article_in_set.rb b/app/classes/query/article_in_set.rb deleted file mode 100644 index 215cc50d2f..0000000000 --- a/app/classes/query/article_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::ArticleInSet < Query::ArticleBase - def parameter_declarations - super.merge( - ids: [Article] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/collection_number_base.rb b/app/classes/query/collection_number_base.rb index 16a31541e2..969a637dfd 100644 --- a/app/classes/query/collection_number_base.rb +++ b/app/classes/query/collection_number_base.rb @@ -10,7 +10,9 @@ def parameter_declarations created_at?: [:time], updated_at?: [:time], users?: [User], + observation?: Observation, observations?: [:string], + pattern?: :string, name?: [:string], number?: [:string], name_has?: :string, @@ -18,8 +20,11 @@ def parameter_declarations ) end + # rubocop:disable Metrics/AbcSize def initialize_flavor add_owner_and_time_stamp_conditions("collection_numbers") + add_for_observation_condition + add_pattern_condition add_id_condition("observation_collection_numbers.observation_id", params[:observations], :observation_collection_numbers) add_exact_match_condition("collection_numbers.name", params[:name]) @@ -28,6 +33,24 @@ def initialize_flavor add_search_condition("collection_numbers.number", params[:number_has]) super end + # rubocop:enable Metrics/AbcSize + + def add_for_observation_condition + return if params[:observation].blank? + + obs = find_cached_parameter_instance(Observation, :observation) + @title_tag = :query_title_for_observation + @title_args[:observation] = obs.unique_format_name + where << "observation_collection_numbers.observation_id = '#{obs.id}'" + add_join(:observation_collection_numbers) + end + + def search_fields + "CONCAT(" \ + "collection_numbers.name," \ + "collection_numbers.number" \ + ")" + end def self.default_order "name_and_number" diff --git a/app/classes/query/collection_number_for_observation.rb b/app/classes/query/collection_number_for_observation.rb deleted file mode 100644 index d616f28437..0000000000 --- a/app/classes/query/collection_number_for_observation.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class Query::CollectionNumberForObservation < Query::CollectionNumberBase - def parameter_declarations - super.merge( - observation: Observation - ) - end - - def initialize_flavor - obs = find_cached_parameter_instance(Observation, :observation) - title_args[:observation] = obs.unique_format_name - where << "observation_collection_numbers.observation_id = '#{obs.id}'" - add_join(:observation_collection_numbers) - super - end -end diff --git a/app/classes/query/collection_number_pattern_search.rb b/app/classes/query/collection_number_pattern_search.rb deleted file mode 100644 index ec5838e09e..0000000000 --- a/app/classes/query/collection_number_pattern_search.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class Query::CollectionNumberPatternSearch < Query::CollectionNumberBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "collection_numbers.name," \ - "collection_numbers.number" \ - ")" - end -end diff --git a/app/classes/query/comment_base.rb b/app/classes/query/comment_base.rb index aa27aaed39..8685523d82 100644 --- a/app/classes/query/comment_base.rb +++ b/app/classes/query/comment_base.rb @@ -11,15 +11,26 @@ def parameter_declarations super.merge( created_at?: [:time], updated_at?: [:time], + ids?: [Comment], + by_user?: User, + for_user?: User, users?: [User], types?: [{ string: Comment.all_type_tags }], summary_has?: :string, - content_has?: :string + content_has?: :string, + pattern?: :string, + target?: AbstractModel, + type?: :string ) end def initialize_flavor add_owner_and_time_stamp_conditions("comments") + add_by_user_condition("comments") + add_ids_condition + add_for_user_condition + add_for_target_condition + add_pattern_condition add_string_enum_condition("comments.target_type", params[:types], Comment.all_type_tags) add_search_condition("comments.summary", params[:summary_has]) @@ -27,6 +38,41 @@ def initialize_flavor super end + def add_for_user_condition + return if params[:for_user].blank? + + user = find_cached_parameter_instance(User, :for_user) + @title_tag = :query_title_for_user + @title_args[:user] = user.legal_name + add_join(:observations) + where << "observations.user_id = '#{params[:for_user]}'" + end + + def add_for_target_condition + return if params[:target].blank? || params[:type].blank? + + target = target_instance + @title_tag = :query_title_for_target + @title_args[:object] = target.unique_format_name + where << "comments.target_id = '#{target.id}'" + where << "comments.target_type = '#{target.class.name}'" + end + + def target_instance + unless (type = Comment.safe_model_from_name(params[:type])) + raise("The model #{params[:type].inspect} does not support comments!") + end + + find_cached_parameter_instance(type, :target) + end + + def search_fields + "CONCAT(" \ + "comments.summary," \ + "COALESCE(comments.comment,'')" \ + ")" + end + def self.default_order "created_at" end diff --git a/app/classes/query/comment_by_user.rb b/app/classes/query/comment_by_user.rb deleted file mode 100644 index 0441e2df7a..0000000000 --- a/app/classes/query/comment_by_user.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class Query::CommentByUser < Query::CommentBase - def parameter_declarations - super.merge( - user: User - ) - end - - def initialize_flavor - user = find_cached_parameter_instance(User, :user) - title_args[:user] = user.legal_name - where << "comments.user_id = '#{user.id}'" - super - end -end diff --git a/app/classes/query/comment_for_target.rb b/app/classes/query/comment_for_target.rb deleted file mode 100644 index 2175025906..0000000000 --- a/app/classes/query/comment_for_target.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class Query::CommentForTarget < Query::CommentBase - def parameter_declarations - super.merge( - target: AbstractModel, - type: :string - ) - end - - def initialize_flavor - target = target_instance - title_args[:object] = target.unique_format_name - where << "comments.target_id = '#{target.id}'" - where << "comments.target_type = '#{target.class.name}'" - super - end - - def target_instance - unless (type = Comment.safe_model_from_name(params[:type])) - raise("The model #{params[:type].inspect} does not support comments!") - end - - find_cached_parameter_instance(type, :target) - end -end diff --git a/app/classes/query/comment_for_user.rb b/app/classes/query/comment_for_user.rb deleted file mode 100644 index fde3c43c4d..0000000000 --- a/app/classes/query/comment_for_user.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class Query::CommentForUser < Query::CommentBase - def parameter_declarations - super.merge( - user: User - ) - end - - def initialize_flavor - user = find_cached_parameter_instance(User, :user) - title_args[:user] = user.legal_name - add_join(:observations) - where << "observations.user_id = '#{params[:user]}'" - super - end -end diff --git a/app/classes/query/comment_in_set.rb b/app/classes/query/comment_in_set.rb deleted file mode 100644 index 61ecf740dd..0000000000 --- a/app/classes/query/comment_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::CommentInSet < Query::CommentBase - def parameter_declarations - super.merge( - ids: [Comment] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/comment_pattern_search.rb b/app/classes/query/comment_pattern_search.rb deleted file mode 100644 index c507302d1a..0000000000 --- a/app/classes/query/comment_pattern_search.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class Query::CommentPatternSearch < Query::CommentBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "comments.summary," \ - "COALESCE(comments.comment,'')" \ - ")" - end -end diff --git a/app/classes/query/glossary_term_base.rb b/app/classes/query/glossary_term_base.rb index 082485a225..c50ee5d01a 100644 --- a/app/classes/query/glossary_term_base.rb +++ b/app/classes/query/glossary_term_base.rb @@ -12,18 +12,27 @@ def parameter_declarations updated_at?: [:time], users?: [User], name_has?: :string, - description_has?: :string + description_has?: :string, + pattern?: :string ) end def initialize_flavor add_owner_and_time_stamp_conditions("glossary_terms") + add_pattern_condition add_search_condition("glossary_terms.name", params[:name_has]) add_search_condition("glossary_terms.description", params[:description_has]) super end + def search_fields + "CONCAT(" \ + "glossary_terms.name," \ + "COALESCE(glossary_terms.description,'')" \ + ")" + end + def self.default_order "name" end diff --git a/app/classes/query/glossary_term_pattern_search.rb b/app/classes/query/glossary_term_pattern_search.rb deleted file mode 100644 index 05b084c49d..0000000000 --- a/app/classes/query/glossary_term_pattern_search.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module Query - class GlossaryTermPatternSearch < Query::GlossaryTermBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "glossary_terms.name," \ - "COALESCE(glossary_terms.description,'')" \ - ")" - end - end -end diff --git a/app/classes/query/herbarium_base.rb b/app/classes/query/herbarium_base.rb index 0a5df5aed4..10eb05629a 100644 --- a/app/classes/query/herbarium_base.rb +++ b/app/classes/query/herbarium_base.rb @@ -11,8 +11,11 @@ def parameter_declarations updated_at?: [:time], code?: :string, name?: :string, + ids?: [Herbarium], description?: :string, - address?: :string + address?: :string, + pattern?: :string, + nonpersonal?: :boolean ) end @@ -23,9 +26,28 @@ def initialize_flavor add_search_condition("herbaria.name", params[:name]) add_search_condition("herbaria.description", params[:description]) add_search_condition("herbaria.mailing_address", params[:address]) + add_ids_condition + add_pattern_condition + add_nonpersonal_condition super end + def add_nonpersonal_condition + return if params[:nonpersonal].blank? + + @title_tag = :query_title_nonpersonal + where << "herbaria.personal_user_id IS NULL" + end + + def search_fields + "CONCAT(" \ + "herbaria.code," \ + "herbaria.name," \ + "COALESCE(herbaria.description,'')," \ + "COALESCE(herbaria.mailing_address,'')" \ + ")" + end + def self.default_order "name" end diff --git a/app/classes/query/herbarium_in_set.rb b/app/classes/query/herbarium_in_set.rb deleted file mode 100644 index 86798875b4..0000000000 --- a/app/classes/query/herbarium_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumInSet < Query::HerbariumBase - def parameter_declarations - super.merge( - ids: [Herbarium] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/herbarium_nonpersonal.rb b/app/classes/query/herbarium_nonpersonal.rb deleted file mode 100644 index bd6d9f82be..0000000000 --- a/app/classes/query/herbarium_nonpersonal.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumNonpersonal < Query::HerbariumBase - def initialize_flavor - where << "herbaria.personal_user_id IS NULL" - super - end -end diff --git a/app/classes/query/herbarium_pattern_search.rb b/app/classes/query/herbarium_pattern_search.rb deleted file mode 100644 index b4b2217637..0000000000 --- a/app/classes/query/herbarium_pattern_search.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumPatternSearch < Query::HerbariumBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "herbaria.code," \ - "herbaria.name," \ - "COALESCE(herbaria.description,'')," \ - "COALESCE(herbaria.mailing_address,'')" \ - ")" - end -end diff --git a/app/classes/query/herbarium_record_base.rb b/app/classes/query/herbarium_record_base.rb index 699c726ba4..33c9311317 100644 --- a/app/classes/query/herbarium_record_base.rb +++ b/app/classes/query/herbarium_record_base.rb @@ -11,7 +11,10 @@ def parameter_declarations updated_at?: [:time], users?: [User], herbaria?: [:string], + herbarium?: Herbarium, + observation?: Observation, observations?: [:string], + pattern?: :string, with_notes?: :boolean, initial_det?: [:string], accession_number?: [:string], @@ -23,6 +26,9 @@ def parameter_declarations def initialize_flavor add_owner_and_time_stamp_conditions("herbarium_records") + add_for_observation_condition + add_in_herbarium_condition + add_pattern_condition initialize_association_parameters initialize_boolean_parameters initialize_exact_match_parameters @@ -30,6 +36,33 @@ def initialize_flavor super end + def add_for_observation_condition + return if params[:observation].blank? + + obs = find_cached_parameter_instance(Observation, :observation) + @title_tag = :query_title_for_observation + @title_args[:observation] = obs.unique_format_name + where << "observation_herbarium_records.observation_id = '#{obs.id}'" + add_join(:observation_herbarium_records) + end + + def add_in_herbarium_condition + return if params[:herbarium].blank? + + herbarium = find_cached_parameter_instance(Herbarium, :herbarium) + @title_tag = :query_title_in_herbarium + @title_args[:herbarium] = herbarium.name + where << "herbarium_records.herbarium_id = '#{herbarium.id}'" + end + + def search_fields + "CONCAT(" \ + "herbarium_records.initial_det," \ + "herbarium_records.accession_number," \ + "COALESCE(herbarium_records.notes,'')" \ + ")" + end + def initialize_association_parameters add_id_condition("herbarium_records.herbarium_id", lookup_herbaria_by_name(params[:herbaria])) diff --git a/app/classes/query/herbarium_record_for_observation.rb b/app/classes/query/herbarium_record_for_observation.rb deleted file mode 100644 index dab20fe730..0000000000 --- a/app/classes/query/herbarium_record_for_observation.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumRecordForObservation < Query::HerbariumRecordBase - def parameter_declarations - super.merge( - observation: Observation - ) - end - - def initialize_flavor - obs = find_cached_parameter_instance(Observation, :observation) - title_args[:observation] = obs.unique_format_name - where << "observation_herbarium_records.observation_id = '#{obs.id}'" - add_join(:observation_herbarium_records) - super - end -end diff --git a/app/classes/query/herbarium_record_in_herbarium.rb b/app/classes/query/herbarium_record_in_herbarium.rb deleted file mode 100644 index 8d3428e062..0000000000 --- a/app/classes/query/herbarium_record_in_herbarium.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumRecordInHerbarium < Query::HerbariumRecordBase - def parameter_declarations - super.merge( - herbarium: Herbarium - ) - end - - def initialize_flavor - herbarium = find_cached_parameter_instance(Herbarium, :herbarium) - title_args[:herbarium] = herbarium.name - where << "herbarium_records.herbarium_id = '#{herbarium.id}'" - super - end -end diff --git a/app/classes/query/herbarium_record_pattern_search.rb b/app/classes/query/herbarium_record_pattern_search.rb deleted file mode 100644 index e2204a021e..0000000000 --- a/app/classes/query/herbarium_record_pattern_search.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class Query::HerbariumRecordPatternSearch < Query::HerbariumRecordBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "herbarium_records.initial_det," \ - "herbarium_records.accession_number," \ - "COALESCE(herbarium_records.notes,'')" \ - ")" - end -end diff --git a/app/classes/query/image_base.rb b/app/classes/query/image_base.rb index ecfff764b1..f880d9ade6 100644 --- a/app/classes/query/image_base.rb +++ b/app/classes/query/image_base.rb @@ -14,7 +14,9 @@ def parameter_declarations created_at?: [:time], updated_at?: [:time], date?: [:date], + # by_user?: User, users?: [User], + # ids?: [Image], locations?: [:string], observations?: [Observation], projects?: [:string], @@ -29,7 +31,8 @@ def parameter_declarations with_votes?: :boolean, quality?: [:float], confidence?: [:float], - ok_for_export?: :boolean + ok_for_export?: :boolean, + pattern?: :string ).merge(names_parameter_declarations) end @@ -41,6 +44,9 @@ def initialize_flavor add_join(:observation_images) if params[:with_observation] initialize_notes_parameters end + # add_by_user_condition("images") + # add_ids_condition + add_pattern_condition initialize_association_parameters initialize_name_parameters(:observation_images, :observations) initialize_image_parameters @@ -91,6 +97,26 @@ def initialize_vote_parameters :observation_images, :observations) end + def add_pattern_condition + return if params[:pattern].blank? + + add_search_condition(search_fields, params[:pattern]) + add_join(:observation_images, :observations) + add_join(:observations, :locations!) + add_join(:observations, :names) + super + end + + def search_fields + "CONCAT(" \ + "names.search_name," \ + "COALESCE(images.original_name,'')," \ + "COALESCE(images.copyright_holder,'')," \ + "COALESCE(images.notes,'')," \ + "observations.where" \ + ")" + end + def self.default_order "created_at" end diff --git a/app/classes/query/image_pattern_search.rb b/app/classes/query/image_pattern_search.rb deleted file mode 100644 index 29eb3d0b27..0000000000 --- a/app/classes/query/image_pattern_search.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class Query::ImagePatternSearch < Query::ImageBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - add_join(:observation_images, :observations) - add_join(:observations, :locations!) - add_join(:observations, :names) - super - end - - def search_fields - "CONCAT(" \ - "names.search_name," \ - "COALESCE(images.original_name,'')," \ - "COALESCE(images.copyright_holder,'')," \ - "COALESCE(images.notes,'')," \ - "observations.where" \ - ")" - end -end diff --git a/app/classes/query/location_base.rb b/app/classes/query/location_base.rb index 34ce9dfd85..841484b9c5 100644 --- a/app/classes/query/location_base.rb +++ b/app/classes/query/location_base.rb @@ -16,6 +16,8 @@ def parameter_declarations south?: :float, east?: :float, west?: :float + # pattern?: :string, + # regexp?: :string ).merge(content_filter_parameter_declarations(Location)) end @@ -24,10 +26,36 @@ def initialize_flavor add_owner_and_time_stamp_conditions("locations") end add_bounding_box_conditions_for_locations + # add_pattern_condition + # add_regexp_condition initialize_content_filters(Location) super end + # def add_pattern_condition + # return if params[:pattern].blank? + + # add_join(:"location_descriptions.default!") + # super + # end + + # def add_regexp_condition + # return if params[:regexp].blank? + + # @title_tag = :query_title_regexp_search + # regexp = escape(params[:regexp].to_s.strip_squeeze) + # where << "locations.name REGEXP #{regexp}" + # end + + # def search_fields + # "CONCAT(" \ + # "locations.name," \ + # "#{LocationDescription.all_note_fields.map do |x| + # "COALESCE(location_descriptions.#{x},'')" + # end.join(",")}" \ + # ")" + # end + def self.default_order "name" end diff --git a/app/classes/query/location_by_rss_log.rb b/app/classes/query/location_by_rss_log.rb deleted file mode 100644 index c38b87a2a4..0000000000 --- a/app/classes/query/location_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::LocationByRssLog < Query::LocationBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/modules/conditions.rb b/app/classes/query/modules/conditions.rb index 1dce83d007..09c68ce218 100644 --- a/app/classes/query/modules/conditions.rb +++ b/app/classes/query/modules/conditions.rb @@ -12,6 +12,22 @@ def add_owner_and_time_stamp_conditions(table) lookup_users_by_name(params[:users])) end + def add_by_user_condition(table) + return if params[:by_user].blank? + + user = find_cached_parameter_instance(User, :by_user) + @title_tag = :query_title_by_user + @title_args[:user] = user.legal_name + where << "#{table}.user_id = '#{user.id}'" + end + + def add_pattern_condition + return if params[:pattern].blank? + + @title_tag = :query_title_pattern_search + add_search_condition(search_fields, params[:pattern]) + end + def add_boolean_condition(true_cond, false_cond, val, *) return if val.nil? @@ -70,6 +86,13 @@ def add_indexed_enum_condition(col, vals, allowed, *) add_joins(*) end + def add_ids_condition(table = model.table_name) + return if params[:ids].nil? # [] is valid + + initialize_in_set_flavor(table) + end + + # move this above when all in_set flavors converted def initialize_in_set_flavor(table = model.table_name) set = clean_id_set(params[:ids]) @where << "#{table}.id IN (#{set})" diff --git a/app/classes/query/name_by_rss_log.rb b/app/classes/query/name_by_rss_log.rb deleted file mode 100644 index c723efa28a..0000000000 --- a/app/classes/query/name_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::NameByRssLog < Query::NameBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/observation_base.rb b/app/classes/query/observation_base.rb index 6dcf5598cd..cd7c5d5a4a 100644 --- a/app/classes/query/observation_base.rb +++ b/app/classes/query/observation_base.rb @@ -28,6 +28,7 @@ def parameter_declarations species_lists?: [:string], users?: [User], field_slips?: [:string], + # pattern?: :string, # numeric confidence?: [:float], @@ -51,6 +52,7 @@ def parameter_declarations def initialize_flavor add_owner_and_time_stamp_conditions("observations") add_date_condition("observations.when", params[:date]) + # add_pattern_condition initialize_name_parameters initialize_association_parameters initialize_boolean_parameters diff --git a/app/classes/query/observation_by_rss_log.rb b/app/classes/query/observation_by_rss_log.rb deleted file mode 100644 index e78325368f..0000000000 --- a/app/classes/query/observation_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::ObservationByRssLog < Query::ObservationBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/project_base.rb b/app/classes/query/project_base.rb index 06a13e3e10..e56de08785 100644 --- a/app/classes/query/project_base.rb +++ b/app/classes/query/project_base.rb @@ -10,6 +10,7 @@ def parameter_declarations created_at?: [:time], updated_at?: [:time], users?: [User], + ids?: [Project], with_images?: { boolean: [true] }, with_observations?: { boolean: [true] }, with_species_lists?: { boolean: [true] }, @@ -19,7 +20,8 @@ def parameter_declarations summary_has?: :string, field_slip_prefix_has?: :string, comments_has?: :string, - member?: User + member?: User, + pattern?: :string ) end @@ -28,6 +30,8 @@ def initialize_flavor initialize_association_parameters initialize_boolean_parameters initialize_search_parameters + add_ids_condition + add_pattern_condition super end @@ -71,6 +75,14 @@ def initialize_search_parameters ) end + def search_fields + "CONCAT(" \ + "projects.title," \ + "COALESCE(projects.summary,'')," \ + "COALESCE(projects.field_slip_prefix,'')" \ + ")" + end + def self.default_order "updated_at" end diff --git a/app/classes/query/project_by_rss_log.rb b/app/classes/query/project_by_rss_log.rb deleted file mode 100644 index 158776f9e3..0000000000 --- a/app/classes/query/project_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::ProjectByRssLog < Query::ProjectBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/project_in_set.rb b/app/classes/query/project_in_set.rb deleted file mode 100644 index 7240422f2b..0000000000 --- a/app/classes/query/project_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::ProjectInSet < Query::ProjectBase - def parameter_declarations - super.merge( - ids: [Project] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/project_pattern_search.rb b/app/classes/query/project_pattern_search.rb deleted file mode 100644 index b951128798..0000000000 --- a/app/classes/query/project_pattern_search.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class Query::ProjectPatternSearch < Query::ProjectBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "projects.title," \ - "COALESCE(projects.summary,'')," \ - "COALESCE(projects.field_slip_prefix,'')" \ - ")" - end -end diff --git a/app/classes/query/rss_log_all.rb b/app/classes/query/rss_log_all.rb index 5a47e79775..9a67393b37 100644 --- a/app/classes/query/rss_log_all.rb +++ b/app/classes/query/rss_log_all.rb @@ -31,7 +31,7 @@ def coerce_into_species_list_query end def do_coerce(new_model) - Query.lookup(new_model, :by_rss_log, params_minus_type) + Query.lookup(new_model, :all, params_minus_type.merge(by: :rss_log)) end def params_minus_type diff --git a/app/classes/query/rss_log_base.rb b/app/classes/query/rss_log_base.rb index 38ffaec642..391598324f 100644 --- a/app/classes/query/rss_log_base.rb +++ b/app/classes/query/rss_log_base.rb @@ -10,7 +10,8 @@ def model def parameter_declarations super.merge( updated_at?: [:time], - type?: :string + type?: :string, + ids?: [RssLog] ).merge(content_filter_parameter_declarations(Observation)). merge(content_filter_parameter_declarations(Location)) end @@ -18,6 +19,7 @@ def parameter_declarations def initialize_flavor add_time_condition("rss_logs.updated_at", params[:updated_at]) initialize_type_parameter + add_ids_condition initialize_content_filters_for_rss_log(Observation) initialize_content_filters_for_rss_log(Location) super diff --git a/app/classes/query/rss_log_in_set.rb b/app/classes/query/rss_log_in_set.rb deleted file mode 100644 index 154d805852..0000000000 --- a/app/classes/query/rss_log_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::RssLogInSet < Query::RssLogBase - def parameter_declarations - super.merge( - ids: [RssLog] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/sequence_base.rb b/app/classes/query/sequence_base.rb index 9640d64981..0981afb093 100644 --- a/app/classes/query/sequence_base.rb +++ b/app/classes/query/sequence_base.rb @@ -26,7 +26,9 @@ def sequence_parameter_declarations accession?: [:string], locus_has?: :string, accession_has?: :string, - notes_has?: :string + notes_has?: :string, + pattern?: :string, + ids?: [Sequence] } end @@ -60,6 +62,8 @@ def initialize_flavor # for. Users would probably not understand why the search fails to find # some sequences because of this. add_owner_and_time_stamp_conditions("sequences") + add_pattern_condition + add_ids_condition initialize_association_parameters initialize_name_parameters(:observations) initialize_observation_parameters @@ -70,6 +74,18 @@ def initialize_flavor super end + def search_fields + # I'm leaving out bases because it would be misleading. Some formats + # allow spaces and other delimiting "garbage" which could break up + # the subsequence the user is searching for. + "CONCAT(" \ + "COALESCE(sequences.locus,'')," \ + "COALESCE(sequences.archive,'')," \ + "COALESCE(sequences.accession,'')," \ + "COALESCE(sequences.notes,'')" \ + ")" + end + def initialize_association_parameters add_id_condition("sequences.observation_id", params[:observations]) initialize_observers_parameter diff --git a/app/classes/query/sequence_for_observation.rb b/app/classes/query/sequence_for_observation.rb deleted file mode 100644 index bbed778f43..0000000000 --- a/app/classes/query/sequence_for_observation.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class Query::SequenceForObservation < Query::SequenceBase - def parameter_declarations - super.merge( - observation: Observation - ) - end - - def initialize_flavor - obs = find_cached_parameter_instance(Observation, :observation) - title_args[:observation] = obs.unique_format_name - where << "sequences.observation_id = '#{obs.id}'" - super - end -end diff --git a/app/classes/query/sequence_in_set.rb b/app/classes/query/sequence_in_set.rb deleted file mode 100644 index 15e004d347..0000000000 --- a/app/classes/query/sequence_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::SequenceInSet < Query::SequenceBase - def parameter_declarations - super.merge( - ids: [Sequence] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/sequence_pattern_search.rb b/app/classes/query/sequence_pattern_search.rb deleted file mode 100644 index 33fd27425d..0000000000 --- a/app/classes/query/sequence_pattern_search.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -class Query::SequencePatternSearch < Query::SequenceBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - # I'm leaving out bases because it would be misleading. Some formats - # allow spaces and other delimiting "garbage" which could break up - # the subsequence the user is searching for. - "CONCAT(" \ - "COALESCE(sequences.locus,'')," \ - "COALESCE(sequences.archive,'')," \ - "COALESCE(sequences.accession,'')," \ - "COALESCE(sequences.notes,'')" \ - ")" - end -end diff --git a/app/classes/query/species_list_base.rb b/app/classes/query/species_list_base.rb index 646151eb26..e0d5647da7 100644 --- a/app/classes/query/species_list_base.rb +++ b/app/classes/query/species_list_base.rb @@ -16,19 +16,27 @@ def parameter_declarations updated_at?: [:time], date?: [:date], users?: [User], + ids?: [SpeciesList], locations?: [:string], projects?: [:string], title_has?: :string, with_notes?: :boolean, notes_has?: :string, with_comments?: { boolean: [true] }, - comments_has?: :string + comments_has?: :string, + pattern?: :string, + project?: Project, + by_user?: User ).merge(names_parameter_declarations) end def initialize_flavor add_owner_and_time_stamp_conditions("species_lists") add_date_condition("species_lists.when", params[:date]) + add_pattern_condition + add_ids_condition + add_by_user_condition("species_lists") + add_for_project_condition initialize_name_parameters(:species_list_observations, :observations) initialize_association_parameters initialize_boolean_parameters @@ -36,6 +44,22 @@ def initialize_flavor super end + def add_pattern_condition + add_search_condition(search_fields, params[:pattern]) + add_join(:locations!) + super + end + + def add_for_project_condition + return if params[:project].blank? + + project = find_cached_parameter_instance(Project, :project) + @title_tag = :query_title_for_project + @title_args[:project] = project.title + where << "project_species_lists.project_id = '#{params[:project]}'" + add_join("project_species_lists") + end + def initialize_association_parameters add_where_condition("species_lists", params[:locations]) add_id_condition( @@ -70,6 +94,14 @@ def initialize_search_parameters ) end + def search_fields + "CONCAT(" \ + "species_lists.title," \ + "COALESCE(species_lists.notes,'')," \ + "IF(locations.id,locations.name,species_lists.where)" \ + ")" + end + def self.default_order "title" end diff --git a/app/classes/query/species_list_by_rss_log.rb b/app/classes/query/species_list_by_rss_log.rb deleted file mode 100644 index 8400e332e9..0000000000 --- a/app/classes/query/species_list_by_rss_log.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class Query::SpeciesListByRssLog < Query::SpeciesListBase - def initialize_flavor - add_join(:rss_logs) - super - end - - def default_order - "rss_log" - end -end diff --git a/app/classes/query/species_list_by_user.rb b/app/classes/query/species_list_by_user.rb deleted file mode 100644 index 40229c8c1d..0000000000 --- a/app/classes/query/species_list_by_user.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class Query::SpeciesListByUser < Query::SpeciesListBase - def parameter_declarations - super.merge( - user: User - ) - end - - def initialize_flavor - user = find_cached_parameter_instance(User, :user) - title_args[:user] = user.legal_name - where << "species_lists.user_id = '#{user.id}'" - super - end -end diff --git a/app/classes/query/species_list_for_project.rb b/app/classes/query/species_list_for_project.rb deleted file mode 100644 index 4c930585f2..0000000000 --- a/app/classes/query/species_list_for_project.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -class Query::SpeciesListForProject < Query::SpeciesListBase - def parameter_declarations - super.merge( - project: Project - ) - end - - def initialize_flavor - project = find_cached_parameter_instance(Project, :project) - title_args[:project] = project.title - where << "project_species_lists.project_id = '#{params[:project]}'" - add_join("project_species_lists") - super - end -end diff --git a/app/classes/query/species_list_in_set.rb b/app/classes/query/species_list_in_set.rb deleted file mode 100644 index 5423a692ef..0000000000 --- a/app/classes/query/species_list_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::SpeciesListInSet < Query::SpeciesListBase - def parameter_declarations - super.merge( - ids: [SpeciesList] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/species_list_pattern_search.rb b/app/classes/query/species_list_pattern_search.rb deleted file mode 100644 index 7342f5a752..0000000000 --- a/app/classes/query/species_list_pattern_search.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -class Query::SpeciesListPatternSearch < Query::SpeciesListBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - add_join(:locations!) - super - end - - def search_fields - "CONCAT(" \ - "species_lists.title," \ - "COALESCE(species_lists.notes,'')," \ - "IF(locations.id,locations.name,species_lists.where)" \ - ")" - end -end diff --git a/app/classes/query/user_base.rb b/app/classes/query/user_base.rb index d35991385f..34be8da9cd 100644 --- a/app/classes/query/user_base.rb +++ b/app/classes/query/user_base.rb @@ -8,16 +8,36 @@ def model def parameter_declarations super.merge( created_at?: [:time], - updated_at?: [:time] + updated_at?: [:time], + ids?: [User], + pattern?: :string, + with_contribution?: :boolean ) end def initialize_flavor add_time_condition("users.created_at", params[:created_at]) add_time_condition("users.updated_at", params[:updated_at]) + add_ids_condition + add_pattern_condition + add_contribution_condition super end + def add_contribution_condition + return unless params[:with_contribution].to_s == "true" + + @title_tag = :query_title_with_contribution + where << "users.contribution > 0" + end + + def search_fields + "CONCAT(" \ + "users.login," \ + "users.name" \ + ")" + end + def self.default_order "name" end diff --git a/app/classes/query/user_in_set.rb b/app/classes/query/user_in_set.rb deleted file mode 100644 index baf68f3748..0000000000 --- a/app/classes/query/user_in_set.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class Query::UserInSet < Query::UserBase - def parameter_declarations - super.merge( - ids: [User] - ) - end - - def initialize_flavor - initialize_in_set_flavor - super - end -end diff --git a/app/classes/query/user_pattern_search.rb b/app/classes/query/user_pattern_search.rb deleted file mode 100644 index 8a9358b5ca..0000000000 --- a/app/classes/query/user_pattern_search.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class Query::UserPatternSearch < Query::UserBase - def parameter_declarations - super.merge( - pattern: :string - ) - end - - def initialize_flavor - add_search_condition(search_fields, params[:pattern]) - super - end - - def search_fields - "CONCAT(" \ - "users.login," \ - "users.name" \ - ")" - end -end diff --git a/app/classes/query/user_with_contribution.rb b/app/classes/query/user_with_contribution.rb deleted file mode 100644 index bc7b1d8acd..0000000000 --- a/app/classes/query/user_with_contribution.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class Query::UserWithContribution < Query::UserBase - def initialize_flavor - where << "users.contribution > 0" - super - end -end diff --git a/app/controllers/collection_numbers_controller.rb b/app/controllers/collection_numbers_controller.rb index e1418e477b..1ea115420e 100644 --- a/app/controllers/collection_numbers_controller.rb +++ b/app/controllers/collection_numbers_controller.rb @@ -127,7 +127,7 @@ def pattern (collection_number = CollectionNumber.safe_find(pat)) redirect_to(action: :show, id: collection_number.id) else - query = create_query(:CollectionNumber, :pattern_search, pattern: pat) + query = create_query(:CollectionNumber, :all, pattern: pat) show_selected_collection_numbers(query) end end @@ -136,7 +136,7 @@ def pattern def observation_id @observation = Observation.find(params[:observation_id]) store_location - query = create_query(:CollectionNumber, :for_observation, + query = create_query(:CollectionNumber, :all, observation: params[:observation_id].to_s) show_selected_collection_numbers(query, always_index: true) end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 04049eb63b..43f1edad69 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -66,7 +66,7 @@ def by_user ) return unless user - query = create_query(:Comment, :by_user, user: user) + query = create_query(:Comment, :all, by_user: user) show_selected_comments(query) end @@ -79,7 +79,7 @@ def for_user ) return unless user - query = create_query(:Comment, :for_user, user: user) + query = create_query(:Comment, :all, for_user: user) show_selected_comments(query) end @@ -89,8 +89,8 @@ def target return no_model unless (model = Comment.safe_model_from_name(params[:type])) return unless (target = find_or_goto_index(model, params[:target].to_s)) - query = create_query(:Comment, :for_target, target: target.id, - type: target.class.name) + query = create_query(:Comment, :all, target: target.id, + type: target.class.name) show_selected_comments(query) end @@ -105,7 +105,7 @@ def pattern if pattern.match?(/^\d+$/) && (comment = Comment.safe_find(pattern)) redirect_to(action: :show, id: comment.id) else - query = create_query(:Comment, :pattern_search, pattern: pattern) + query = create_query(:Comment, :all, pattern: pattern) show_selected_comments(query) end end @@ -126,7 +126,7 @@ def show_selected_comments(query, args = {}) args[:letters] = "users.login" end - @full_detail = (query.flavor == :for_target) + @full_detail = query.params[:for_target].present? show_index_of_objects(query, args) end diff --git a/app/controllers/contributors_controller.rb b/app/controllers/contributors_controller.rb index 0a11a0ce2a..e22d2592df 100644 --- a/app/controllers/contributors_controller.rb +++ b/app/controllers/contributors_controller.rb @@ -6,7 +6,8 @@ class ContributorsController < ApplicationController # Contributors index def index - query = create_query(:User, :with_contribution, by: :contribution) + query = create_query(:User, :all, with_contribution: true, + by: :contribution) args = { action: :index, matrix: true, include: [:image] } show_index_of_objects(query, args) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 428a31c142..f8ac900dd5 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -93,7 +93,7 @@ def patterned_index location: glossary_term_path(glossary_term.id)) and return else show_selected_glossary_terms( - create_query(:GlossaryTerm, :pattern_search, pattern: pattern) + create_query(:GlossaryTerm, :all, pattern: pattern) ) end end diff --git a/app/controllers/herbaria_controller.rb b/app/controllers/herbaria_controller.rb index b45fee660b..399e7573a9 100644 --- a/app/controllers/herbaria_controller.rb +++ b/app/controllers/herbaria_controller.rb @@ -75,7 +75,7 @@ def index when "nonpersonal" # List institutional Herbaria store_location show_selected_herbaria( - create_query(:Herbarium, :nonpersonal, by: :code_then_name), + create_query(:Herbarium, :all, nonpersonal: true, by: :code_then_name), always_index: true ) else # default List herbaria resulting from query @@ -213,7 +213,7 @@ def patterned_index redirect_to(herbarium_path(herbarium.id)) else show_selected_herbaria( - create_query(:Herbarium, :pattern_search, pattern: pattern) + create_query(:Herbarium, :all, pattern: pattern) ) end end diff --git a/app/controllers/herbarium_records_controller.rb b/app/controllers/herbarium_records_controller.rb index b837a705bf..ef20e2bc14 100644 --- a/app/controllers/herbarium_records_controller.rb +++ b/app/controllers/herbarium_records_controller.rb @@ -152,14 +152,14 @@ def pattern (herbarium_record = HerbariumRecord.safe_find(pattern)) redirect_to(herbarium_record_path(herbarium_record.id)) else - query = create_query(:HerbariumRecord, :pattern_search, pattern: pattern) + query = create_query(:HerbariumRecord, :all, pattern: pattern) show_selected_herbarium_records(query) end end def herbarium_id store_location - query = create_query(:HerbariumRecord, :in_herbarium, + query = create_query(:HerbariumRecord, :all, herbarium: params[:herbarium_id].to_s, by: :herbarium_label) show_selected_herbarium_records(query, always_index: true) @@ -168,7 +168,7 @@ def herbarium_id def observation_id @observation = Observation.find(params[:observation_id]) store_location - query = create_query(:HerbariumRecord, :for_observation, + query = create_query(:HerbariumRecord, :all, observation: params[:observation_id].to_s, by: :herbarium_label) show_selected_herbarium_records(query, always_index: true) diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 3d9db51f94..91a4ff49a7 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -118,7 +118,7 @@ def pattern (image = Image.safe_find(pattern)) redirect_to(action: "show", id: image.id) else - query = create_query(:Image, :pattern_search, pattern: pattern) + query = create_query(:Image, :all, pattern: pattern) show_selected_images(query) end end diff --git a/app/controllers/lookups_controller.rb b/app/controllers/lookups_controller.rb index 2d036fe703..cb806df1a1 100644 --- a/app/controllers/lookups_controller.rb +++ b/app/controllers/lookups_controller.rb @@ -252,7 +252,10 @@ def handle_multiple_matches_or_suggestions( model:, id:, matches:, suggestions: ) obj = matches.first || suggestions.first - query = Query.lookup(model, :in_set, ids: matches + suggestions) + unconverted = [Image, Location, Name, Observation] + flavor = unconverted.include?(model) ? :in_set : :all + + query = Query.lookup(model, flavor, ids: matches + suggestions) if suggestions.any? flash_warning( :runtime_suggest_multiple_alternates.t(match: id, type: model.type_tag) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9cee799647..72d73e936b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -206,7 +206,7 @@ def pattern set_ivars_for_show render("show", location: project_path(@project.id)) else - query = create_query(:Project, :pattern_search, pattern: pattern) + query = create_query(:Project, :all, pattern: pattern) show_selected_projects(query) end end diff --git a/app/controllers/sequences_controller.rb b/app/controllers/sequences_controller.rb index 949165da97..8863eca9fe 100644 --- a/app/controllers/sequences_controller.rb +++ b/app/controllers/sequences_controller.rb @@ -43,6 +43,9 @@ class SequencesController < ApplicationController # https://mushroomobserver.org/sequences?flavor=all # => displays a list of all sequences in MO # + # NOTE: #index does not handle params[:pattern] or params[:ids] because + # we don't offer sequence pattern search. However, the Query::SequenceBase + # class can handle a pattern param. def index case params[:flavor] when "all" diff --git a/app/controllers/species_lists_controller.rb b/app/controllers/species_lists_controller.rb index 4cfc0cc089..a5d8e1a615 100644 --- a/app/controllers/species_lists_controller.rb +++ b/app/controllers/species_lists_controller.rb @@ -162,7 +162,7 @@ def by_user ) return unless user - query = create_query(:SpeciesList, :by_user, user: user) + query = create_query(:SpeciesList, :all, by_user: user) show_selected_species_lists(query) end @@ -171,7 +171,7 @@ def for_project project = find_or_goto_index(Project, params[:for_project].to_s) return unless project - query = create_query(:SpeciesList, :for_project, project: project) + query = create_query(:SpeciesList, :all, project: project) show_selected_species_lists(query, always_index: 1) end @@ -183,7 +183,7 @@ def pattern if spl redirect_to(action: :show, id: spl.id) else - query = create_query(:SpeciesList, :pattern_search, pattern: pattern) + query = create_query(:SpeciesList, :all, pattern: pattern) show_selected_species_lists(query) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3ffd011b17..eeb7c8a944 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -54,7 +54,7 @@ def user_search if (user = user_exact_match(pattern)) redirect_to(user_path(user.id)) else - query = create_query(:User, :pattern_search, pattern: pattern) + query = create_query(:User, :all, pattern: pattern) show_selected_users(query) end end diff --git a/app/helpers/tabs/locations_helper.rb b/app/helpers/tabs/locations_helper.rb index 76a8916419..9129396b5f 100644 --- a/app/helpers/tabs/locations_helper.rb +++ b/app/helpers/tabs/locations_helper.rb @@ -135,11 +135,12 @@ def location_countries_tabs # Add some alternate sorting criteria. def location_index_sorts(query:) + rss_log = query&.params&.dig(:by) == :rss_log || + query&.flavor == :rss_log [ ["name", :sort_by_name.t], ["created_at", :sort_by_created_at.t], - [(query&.flavor == :by_rss_log ? "rss_log" : "updated_at"), - :sort_by_updated_at.t], + [(rss_log ? "rss_log" : "updated_at"), :sort_by_updated_at.t], ["num_views", :sort_by_num_views.t], ["box_area", :sort_by_box_area.t] ] diff --git a/app/helpers/tabs/names_helper.rb b/app/helpers/tabs/names_helper.rb index 887787af9b..4a419a301c 100644 --- a/app/helpers/tabs/names_helper.rb +++ b/app/helpers/tabs/names_helper.rb @@ -274,11 +274,12 @@ def all_names_tab(query) end def names_index_sorts(query:) + rss_log = query&.params&.dig(:by) == :rss_log || + query&.flavor == :rss_log [ ["name", :sort_by_name.t], ["created_at", :sort_by_created_at.t], - [(query&.flavor == :by_rss_log ? "rss_log" : "updated_at"), - :sort_by_updated_at.t], + [(rss_log ? "rss_log" : "updated_at"), :sort_by_updated_at.t], ["num_views", :sort_by_num_views.t] ] end diff --git a/app/helpers/tabs/species_lists_helper.rb b/app/helpers/tabs/species_lists_helper.rb index 4f32f35190..874afb988a 100644 --- a/app/helpers/tabs/species_lists_helper.rb +++ b/app/helpers/tabs/species_lists_helper.rb @@ -136,7 +136,7 @@ def species_lists_index_sorts(query:) ["date", :sort_by_date.t], ["user", :sort_by_user.t], ["created_at", :sort_by_created_at.t], - [(query&.flavor == :by_rss_log ? "rss_log" : "updated_at"), + [(query.params[:by] == :rss_log ? "rss_log" : "updated_at"), :sort_by_updated_at.t] ] end diff --git a/app/models/rss_log.rb b/app/models/rss_log.rb index d58fbac3c4..3d4885ac23 100644 --- a/app/models/rss_log.rb +++ b/app/models/rss_log.rb @@ -59,13 +59,6 @@ # # <%= show_object_footer(@object) %> # -# 6) Add +by_rss_log+ flavor to Query for your model: -# -# self.allowed_model_flavors = { -# :Model => [ -# :by_rss_log, # Models with RSS logs, in RSS order. -# ] -# } # # == Usage # diff --git a/test/controllers/articles_controller_test.rb b/test/controllers/articles_controller_test.rb index d3fcf6b685..1469eb51b2 100644 --- a/test/controllers/articles_controller_test.rb +++ b/test/controllers/articles_controller_test.rb @@ -19,7 +19,7 @@ def test_index def test_index_filtered article = Article.first - query = Query.lookup(:Article, :in_set, ids: [article.id]) + query = Query.lookup(:Article, :all, ids: [article.id]) params = @controller.query_params(query) get(:index, params: params) diff --git a/test/controllers/herbaria_controller_test.rb b/test/controllers/herbaria_controller_test.rb index 32f0a2a304..1d50eae8ac 100644 --- a/test/controllers/herbaria_controller_test.rb +++ b/test/controllers/herbaria_controller_test.rb @@ -108,7 +108,7 @@ def test_show_prev def test_index set = [nybg, herbaria(:rolf_herbarium)] - query = Query.lookup_and_save(:Herbarium, :in_set, by: :name, ids: set) + query = Query.lookup_and_save(:Herbarium, :all, by: :name, ids: set) login("zero") # Does not own any herbarium in set get(:index, params: { q: query.record.id.alphabetize }) diff --git a/test/controllers/observations/identify_controller_test.rb b/test/controllers/observations/identify_controller_test.rb index f5b3f7d72e..89ef84021a 100644 --- a/test/controllers/observations/identify_controller_test.rb +++ b/test/controllers/observations/identify_controller_test.rb @@ -16,6 +16,7 @@ def test_identify_observations_index query = Query.lookup_and_save(:Observation, :needs_naming) assert_equal(query.num_results, obs_count) + get(:index) assert_no_flash assert_select(".matrix-box", obs_count) diff --git a/test/controllers/sequences_controller_test.rb b/test/controllers/sequences_controller_test.rb index df5deff435..1001bece61 100644 --- a/test/controllers/sequences_controller_test.rb +++ b/test/controllers/sequences_controller_test.rb @@ -23,7 +23,7 @@ def obs_creator(sequence) def test_index login obs = observations(:genbanked_obs) - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) results = query.results assert_operator(results.count, :>, 3) q = query.id.alphabetize @@ -360,7 +360,7 @@ def test_edit_redirect obs = observations(:genbanked_obs) sequence = obs.sequences[2] assert_operator(obs.sequences.count, :>, 3) - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) q = query.id.alphabetize params = { id: sequence.id, sequence: { locus: sequence.locus, @@ -574,7 +574,7 @@ def test_update_redirect_to_observation_keeps_params obs = observations(:genbanked_obs) assert_operator(obs.sequences.count, :>, 3) sequence = obs.sequences[2] - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) q = query.id.alphabetize params = { id: sequence.id, sequence: { locus: sequence.locus, @@ -591,7 +591,7 @@ def test_update_redirect_to_sequence_keeps_params obs = observations(:genbanked_obs) assert_operator(obs.sequences.count, :>, 3) sequence = obs.sequences[2] - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) q = query.id.alphabetize params = { id: sequence.id, sequence: { locus: sequence.locus, @@ -672,7 +672,7 @@ def test_destroy_redirect def test_destroy_redirect_to_observation_with_query obs = observations(:genbanked_obs) seqs = obs.sequences - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) q = query.id.alphabetize # Prove that it keeps query param intact when returning to observation. @@ -684,7 +684,7 @@ def test_destroy_redirect_to_observation_with_query def test_destroy_redirect_to_index_with_query obs = observations(:genbanked_obs) seqs = obs.sequences - query = Query.lookup_and_save(:Sequence, :for_observation, observation: obs) + query = Query.lookup_and_save(:Sequence, :all, observations: obs) q = query.id.alphabetize # Prove that it can return to index, too, with query intact. diff --git a/test/fixtures/observations.yml b/test/fixtures/observations.yml index 3028419924..a3f5ad84c9 100644 --- a/test/fixtures/observations.yml +++ b/test/fixtures/observations.yml @@ -729,6 +729,7 @@ wolf_fart: images: lone_wolf_image # images: lone_wolf_image, lone_wolf_image2 +# did not have rss_log reused_observation: <<: *DEFAULTS user: rolf @@ -739,6 +740,7 @@ reused_observation: where: MO Inc., 68 Bay Rd., North Falmouth, Massachusetts, USA species_lists: reused_list +# did not have rss_log deprecated_name_obs: <<: *DEFAULTS created_at: 2014-04-04 04:05:03 diff --git a/test/models/query_test.rb b/test/models/query_test.rb index a3b46f7f11..f1eae6f76c 100644 --- a/test/models/query_test.rb +++ b/test/models/query_test.rb @@ -86,32 +86,32 @@ def test_validate_params Query.lookup(:Image, :by_user, user: rolf.id.to_s). params[:user]) - assert_raises(RuntimeError) { Query.lookup(:User, :in_set) } # Oops, :in_set query is generic, # doesn't know to require Name instances here. # assert_raises(RuntimeError) { Query.lookup(:Name, :in_set, ids: rolf) } assert_raises(RuntimeError) { Query.lookup(:Name, :in_set, ids: "one") } assert_raises(RuntimeError) { Query.lookup(:Name, :in_set, ids: "1,2,3") } - assert_equal([], Query.lookup(:User, :in_set, ids: []).params[:ids]) - assert_equal([rolf.id], Query.lookup(:User, :in_set, - ids: rolf.id).params[:ids]) assert_equal([names(:fungi).id], Query.lookup(:Name, :in_set, ids: names(:fungi).id.to_s).params[:ids]) + + # assert_raises(RuntimeError) { Query.lookup(:User, :all) } + assert_equal([], Query.lookup(:User, :all, ids: []).params[:ids]) + assert_equal([rolf.id], Query.lookup(:User, :all, + ids: rolf.id).params[:ids]) assert_equal([rolf.id, mary.id], - Query.lookup(:User, :in_set, + Query.lookup(:User, :all, ids: [rolf.id, mary.id]).params[:ids]) assert_equal([1, 2], - Query.lookup(:User, :in_set, ids: %w[1 2]).params[:ids]) + Query.lookup(:User, :all, ids: %w[1 2]).params[:ids]) assert_equal([rolf.id, mary.id], - Query.lookup(:User, :in_set, + Query.lookup(:User, :all, ids: [rolf.id.to_s, mary.id.to_s]).params[:ids]) - assert_equal([rolf.id], Query.lookup(:User, :in_set, - ids: rolf).params[:ids]) + assert_equal([rolf.id], Query.lookup(:User, :all, ids: rolf).params[:ids]) assert_equal([rolf.id, mary.id], - Query.lookup(:User, :in_set, ids: [rolf, mary]).params[:ids]) + Query.lookup(:User, :all, ids: [rolf, mary]).params[:ids]) assert_equal([rolf.id, mary.id, junk.id], - Query.lookup(:User, :in_set, + Query.lookup(:User, :all, ids: [rolf, mary.id, junk.id.to_s]).params[:ids]) assert_raises(RuntimeError) { Query.lookup(:Name, :pattern_search) } @@ -1316,15 +1316,10 @@ def test_rss_log_coercion assert_equal("Observation", q4.model.to_s) assert_equal("SpeciesList", q5.model.to_s) - assert_equal(:by_rss_log, q2.flavor) - assert_equal(:by_rss_log, q3.flavor) - assert_equal(:by_rss_log, q4.flavor) - assert_equal(:by_rss_log, q5.flavor) - - assert_equal({}, q2.params) - assert_equal({}, q3.params) - assert_equal({}, q4.params) - assert_equal({}, q5.params) + assert_equal(:rss_log, q2.params[:by].to_sym) + assert_equal(:rss_log, q3.params[:by].to_sym) + assert_equal(:rss_log, q4.params[:by].to_sym) + assert_equal(:rss_log, q5.params[:by].to_sym) end def test_coercable @@ -1344,13 +1339,13 @@ def test_article_all def test_article_by_rss_log assert_query(Article.joins(:rss_log).distinct, - :Article, :by_rss_log) + :Article, :all, by: :rss_log) end def test_article_in_set assert_query([articles(:premier_article).id], :Article, - :in_set, ids: [articles(:premier_article).id]) - assert_query([], :Article, :in_set, ids: []) + :all, ids: [articles(:premier_article).id]) + assert_query([], :Article, :all, ids: []) end def test_collection_number_all @@ -1361,8 +1356,7 @@ def test_collection_number_all def test_collection_number_for_observation obs = observations(:detailed_unknown_obs) expect = obs.collection_numbers.sort_by(&:format_name) - assert_query(expect, :CollectionNumber, :for_observation, - observation: obs.id) + assert_query(expect, :CollectionNumber, :all, observation: obs.id) end def test_collection_number_pattern_search @@ -1370,13 +1364,13 @@ def test_collection_number_pattern_search where(CollectionNumber[:name].matches("%Singer%"). or(CollectionNumber[:number].matches("%Singer%"))). sort_by(&:format_name) - assert_query(expect, :CollectionNumber, :pattern_search, pattern: "Singer") + assert_query(expect, :CollectionNumber, :all, pattern: "Singer") expect = CollectionNumber. where(CollectionNumber[:name].matches("%123a%"). or(CollectionNumber[:number].matches("%123a%"))). sort_by(&:format_name) - assert_query(expect, :CollectionNumber, :pattern_search, pattern: "123a") + assert_query(expect, :CollectionNumber, :all, pattern: "123a") end def test_comment_all @@ -1386,26 +1380,25 @@ def test_comment_all def test_comment_by_user expect = Comment.where(user_id: mary.id).reverse - assert_query(expect, :Comment, :by_user, user: mary) + assert_query(expect, :Comment, :all, by_user: mary) end def test_comment_for_target obs = observations(:minimal_unknown_obs) expect = Comment.where(target_id: obs.id) - assert_query(expect, :Comment, :for_target, target: obs, - type: "Observation") + assert_query(expect, :Comment, :all, target: obs, type: "Observation") end def test_comment_for_user expect = Comment.all.select { |c| c.target.user == mary } - assert_query(expect, :Comment, :for_user, user: mary) - assert_query([], :Comment, :for_user, user: rolf) + assert_query(expect, :Comment, :all, for_user: mary) + assert_query([], :Comment, :all, for_user: rolf) end def test_comment_in_set assert_query([comments(:detailed_unknown_obs_comment).id, comments(:minimal_unknown_obs_comment_1).id], - :Comment, :in_set, + :Comment, :all, ids: [comments(:detailed_unknown_obs_comment).id, comments(:minimal_unknown_obs_comment_1).id]) end @@ -1415,7 +1408,7 @@ def test_comment_pattern_search comments(:minimal_unknown_obs_comment_1), comments(:detailed_unknown_obs_comment) ] - assert_query(expect, :Comment, :pattern_search, pattern: "unknown") + assert_query(expect, :Comment, :all, pattern: "unknown") end def test_external_link_all @@ -1444,14 +1437,13 @@ def test_glossary_term_all end def test_glossary_term_pattern_search - assert_query([], :GlossaryTerm, :pattern_search, - pattern: "no glossary term has this") + assert_query([], :GlossaryTerm, :all, pattern: "no glossary term has this") # name assert_query( GlossaryTerm. where(GlossaryTerm[:name].matches("%conic_glossary_term%"). or(GlossaryTerm[:description].matches("%conic_glossary_term%"))), - :GlossaryTerm, :pattern_search, pattern: "conic_glossary_term" + :GlossaryTerm, :all, pattern: "conic_glossary_term" ) # description expect = @@ -1463,10 +1455,8 @@ def test_glossary_term_pattern_search where(GlossaryTerm[:description].matches("%of%")). where(GlossaryTerm[:description].matches("%Term%")) ) - assert_query(expect, - :GlossaryTerm, :pattern_search, pattern: "Description of Term") - assert_query(GlossaryTerm.all, - :GlossaryTerm, :pattern_search, pattern: "") + assert_query(expect, :GlossaryTerm, :all, pattern: "Description of Term") + assert_query(GlossaryTerm.all, :GlossaryTerm, :all, pattern: "") end def test_herbarium_all @@ -1489,12 +1479,50 @@ def test_herbarium_in_set herbaria(:dick_herbarium), herbaria(:nybg_herbarium) ] - assert_query(expect, :Herbarium, :in_set, ids: expect) + assert_query(expect, :Herbarium, :all, ids: expect) end def test_herbarium_pattern_search expect = [herbaria(:nybg_herbarium)] - assert_query(expect, :Herbarium, :pattern_search, pattern: "awesome") + assert_query(expect, :Herbarium, :all, pattern: "awesome") + end + + def test_herbarium_record_all + expect = HerbariumRecord.all.sort_by(&:herbarium_label) + assert_query(expect, :HerbariumRecord, :all) + end + + def test_herbarium_record_for_observation + obs = observations(:coprinus_comatus_obs) + expect = obs.herbarium_records.sort_by(&:herbarium_label) + assert_query(expect, :HerbariumRecord, :all, observation: obs.id) + end + + def test_herbarium_record_in_herbarium + nybg = herbaria(:nybg_herbarium) + expect = nybg.herbarium_records.sort_by(&:herbarium_label) + assert_query(expect, :HerbariumRecord, :all, herbarium: nybg.id) + end + + def test_herbarium_record_pattern_search + expect = [herbarium_records(:interesting_unknown)] + assert_query(expect, :HerbariumRecord, :all, pattern: "dried") + + assert_query([], :HerbariumRecord, :all, + pattern: "no herbarium record has this") + assert_query( + HerbariumRecord.where( + HerbariumRecord[:initial_det].matches("%Agaricus%") + ), + :HerbariumRecord, :all, pattern: "Agaricus" + ) + assert_query( + HerbariumRecord.where(HerbariumRecord[:notes].matches("%rare%")), + :HerbariumRecord, :all, pattern: "rare" + ) + assert_query( + HerbariumRecord.all, :HerbariumRecord, :all, pattern: "" + ) end def test_image_advanced_search @@ -1523,24 +1551,6 @@ def test_image_advanced_search content: "little", location: "burbank") end - def test_herbarium_record_all - expect = HerbariumRecord.all.sort_by(&:herbarium_label) - assert_query(expect, :HerbariumRecord, :all) - end - - def test_herbarium_record_for_observation - obs = observations(:coprinus_comatus_obs) - expect = obs.herbarium_records.sort_by(&:herbarium_label) - assert_query(expect, :HerbariumRecord, :for_observation, - observation: obs.id) - end - - def test_herbarium_record_in_herbarium - nybg = herbaria(:nybg_herbarium) - expect = nybg.herbarium_records.sort_by(&:herbarium_label) - assert_query(expect, :HerbariumRecord, :in_herbarium, herbarium: nybg.id) - end - def test_image_all expect = Image.all.reverse assert_query(expect, :Image, :all) @@ -1595,24 +1605,24 @@ def test_image_for_project def test_image_pattern_search assert_query([images(:agaricus_campestris_image).id], - :Image, :pattern_search, pattern: "agaricus") # name + :Image, :all, pattern: "agaricus") # name assert_query([images(:agaricus_campestris_image).id, images(:connected_coprinus_comatus_image).id, images(:turned_over_image).id, images(:in_situ_image).id], - :Image, :pattern_search, pattern: "bob dob") # copyright holder + :Image, :all, pattern: "bob dob") # copyright holder assert_query( [images(:in_situ_image).id], - :Image, :pattern_search, pattern: "looked gorilla OR original" # notes + :Image, :all, pattern: "looked gorilla OR original" # notes ) assert_query([images(:agaricus_campestris_image).id, images(:connected_coprinus_comatus_image).id], - :Image, :pattern_search, pattern: "notes some") # notes + :Image, :all, pattern: "notes some") # notes assert_query( [images(:turned_over_image).id, images(:in_situ_image).id], - :Image, :pattern_search, pattern: "dobbs -notes" # (c), not notes + :Image, :all, pattern: "dobbs -notes" # (c), not notes ) - assert_query([images(:in_situ_image).id], :Image, :pattern_search, + assert_query([images(:in_situ_image).id], :Image, :all, pattern: "DSCN8835") # original filename end @@ -1795,12 +1805,10 @@ def test_image_with_observations_in_set assert_query([images(:agaricus_campestris_image).id, images(:turned_over_image).id, images(:in_situ_image).id], - :Image, - :with_observations_in_set, + :Image, :with_observations_in_set, ids: [observations(:detailed_unknown_obs).id, observations(:agaricus_campestris_obs).id]) - assert_query([], :Image, - :with_observations_in_set, + assert_query([], :Image, :with_observations_in_set, ids: [observations(:minimal_unknown_obs).id]) end @@ -1843,8 +1851,8 @@ def test_image_with_observations_of_name assert_query([images(:connected_coprinus_comatus_image).id], :Image, :with_observations, names: [names(:coprinus_comatus).id]) - assert_query([images(:agaricus_campestris_image).id], :Image, - :with_observations, + assert_query([images(:agaricus_campestris_image).id], + :Image, :with_observations, names: [names(:agaricus_campestris).id]) assert_query([], :Image, :with_observations, names: [names(:conocybe_filaris).id]) @@ -1918,7 +1926,7 @@ def test_location_by_editor def test_location_by_rss_log assert_query(Location.joins(:rss_log).distinct, - :Location, :by_rss_log) + :Location, :all, by: :rss_log) end def test_location_in_set @@ -2199,14 +2207,13 @@ def test_location_with_observations_in_set assert_query([locations(:burbank).id], :Location, :with_observations_in_set, ids: [observations(:minimal_unknown_obs).id]) - assert_query([], :Location, - :with_observations_in_set, + assert_query([], :Location, :with_observations_in_set, ids: [observations(:coprinus_comatus_obs).id]) end def test_location_with_observations_in_species_list - assert_query([locations(:burbank).id], :Location, - :with_observations_in_species_list, + assert_query([locations(:burbank).id], + :Location, :with_observations_in_species_list, species_list: species_lists(:unknown_species_list).id) assert_query([], :Location, :with_observations_in_species_list, species_list: species_lists(:first_species_list).id) @@ -2360,7 +2367,7 @@ def test_name_by_editor def test_name_by_rss_log assert_query(Name.joins(:rss_log).order("rss_logs.updated_at"), - :Name, :by_rss_log) + :Name, :all, by: :rss_log) end def test_name_in_set @@ -2422,27 +2429,22 @@ def test_name_with_descriptions def test_name_with_descriptions_by_user assert_query([names(:agaricus_campestris).id, names(:peltigera).id], - :Name, - :with_descriptions_by_user, user: mary, by: :id) + :Name, :with_descriptions_by_user, user: mary, by: :id) assert_query([names(:boletus_edulis).id, names(:peltigera).id, names(:suillus).id], - :Name, - :with_descriptions_by_user, user: dick, by: :id) + :Name, :with_descriptions_by_user, user: dick, by: :id) end def test_name_with_descriptions_by_author assert_query([names(:coprinus_comatus).id, names(:peltigera).id], - :Name, - :with_descriptions_by_author, user: rolf, by: :id) + :Name, :with_descriptions_by_author, user: rolf, by: :id) assert_query([names(:agaricus_campestris).id, names(:peltigera).id], - :Name, - :with_descriptions_by_author, user: mary, by: :id) + :Name, :with_descriptions_by_author, user: mary, by: :id) assert_query([names(:boletus_edulis).id], - :Name, - :with_descriptions_by_author, user: dick, by: :id) + :Name, :with_descriptions_by_author, user: dick, by: :id) end def test_name_with_descriptions_by_editor @@ -2603,8 +2605,8 @@ def test_name_with_observations_at_location end def test_name_with_observations_at_where - assert_query([names(:coprinus_comatus).id], :Name, - :with_observations_at_where, + assert_query([names(:coprinus_comatus).id], + :Name, :with_observations_at_where, user_where: "glendale", location: "glendale") end @@ -2632,8 +2634,7 @@ def test_name_with_observations_in_set assert_query([names(:agaricus_campestras).id, names(:agaricus_campestris).id, names(:fungi).id], - :Name, - :with_observations_in_set, + :Name, :with_observations_in_set, ids: [observations(:detailed_unknown_obs).id, observations(:agaricus_campestris_obs).id, observations(:agaricus_campestras_obs).id]) @@ -2643,8 +2644,7 @@ def test_name_with_observations_in_species_list assert_query([names(:fungi).id], :Name, :with_observations_in_species_list, species_list: species_lists(:unknown_species_list).id) - assert_query([], :Name, - :with_observations_in_species_list, + assert_query([], :Name, :with_observations_in_species_list, species_list: species_lists(:first_species_list).id) end @@ -2705,19 +2705,19 @@ def test_name_description_in_set end def test_observation_advanced_search - assert_query([observations(:strobilurus_diminutivus_obs).id], :Observation, - :advanced_search, name: "diminutivus") - assert_query([observations(:coprinus_comatus_obs).id], :Observation, - :advanced_search, location: "glendale") # where + assert_query([observations(:strobilurus_diminutivus_obs).id], + :Observation, :advanced_search, name: "diminutivus") + assert_query([observations(:coprinus_comatus_obs).id], + :Observation, :advanced_search, location: "glendale") # where expect = Observation.where(location_id: locations(:burbank)).to_a - assert_query(expect, :Observation, - :advanced_search, location: "burbank", by: :id) # location + assert_query(expect, :Observation, :advanced_search, + location: "burbank", by: :id) # location expect = Observation.where(user_id: rolf.id).to_a assert_query(expect, :Observation, :advanced_search, user: "rolf", by: :id) - assert_query([observations(:coprinus_comatus_obs).id], :Observation, - :advanced_search, content: "second fruiting") # notes - assert_query([observations(:minimal_unknown_obs).id], :Observation, - :advanced_search, content: "agaricus") # comment + assert_query([observations(:coprinus_comatus_obs).id], # notes + :Observation, :advanced_search, content: "second fruiting") + assert_query([observations(:minimal_unknown_obs).id], + :Observation, :advanced_search, content: "agaricus") # comment end def test_observation_all @@ -2745,7 +2745,7 @@ def test_observation_at_where def test_observation_by_rss_log expect = Observation.where.not(rss_log: nil) - assert_query(expect, :Observation, :by_rss_log) + assert_query(expect, :Observation, :all, by: :rss_log) end def test_observation_by_user @@ -2945,28 +2945,28 @@ def test_project_all def test_project_by_rss_log assert_query(Project.joins(:rss_log).distinct, - :Project, :by_rss_log) + :Project, :all, by: :rss_log) end def test_project_in_set - assert_query([projects(:eol_project).id], :Project, - :in_set, ids: [projects(:eol_project).id]) - assert_query([], :Project, :in_set, ids: []) + assert_query([projects(:eol_project).id], :Project, :all, + ids: [projects(:eol_project).id]) + assert_query([], :Project, :all, ids: []) end def test_project_pattern_search assert_query([], - :Project, :pattern_search, pattern: "no project has this") + :Project, :all, pattern: "no project has this") # title assert_query(Project.where(Project[:summary].matches("%bolete%"). or(Project[:title].matches("%bolete%"))), - :Project, :pattern_search, pattern: "bolete") + :Project, :all, pattern: "bolete") # summary assert_query(Project.where(Project[:summary].matches("%two lists%"). or(Project[:title].matches("%two lists%"))), - :Project, :pattern_search, pattern: "two lists") + :Project, :all, pattern: "two lists") assert_query(Project.all, - :Project, :pattern_search, pattern: "") + :Project, :all, pattern: "") end def test_rss_log_all @@ -2982,7 +2982,7 @@ def test_rss_log_type def test_rss_log_in_set rsslog_set_ids = [rss_logs(:species_list_rss_log).id, rss_logs(:name_rss_log).id] - assert_query(rsslog_set_ids, :RssLog, :in_set, ids: rsslog_set_ids) + assert_query(rsslog_set_ids, :RssLog, :all, ids: rsslog_set_ids) end def test_sequence_all @@ -3038,17 +3038,17 @@ def test_uses_join_hash def test_sequence_in_set list_set_ids = [sequences(:fasta_formatted_sequence).id, sequences(:bare_formatted_sequence).id] - assert_query(list_set_ids, :Sequence, :in_set, ids: list_set_ids) + assert_query(list_set_ids, :Sequence, :all, ids: list_set_ids) end def test_sequence_pattern_search - assert_query([], :Sequence, :pattern_search, pattern: "nonexistent") + assert_query([], :Sequence, :all, pattern: "nonexistent") assert_query(Sequence.where(Sequence[:locus].matches("ITS%")), - :Sequence, :pattern_search, pattern: "ITS") + :Sequence, :all, pattern: "ITS") assert_query([sequences(:alternate_archive)], - :Sequence, :pattern_search, pattern: "UNITE") + :Sequence, :all, pattern: "UNITE") assert_query([sequences(:deposited_sequence)], - :Sequence, :pattern_search, pattern: "deposited_sequence") + :Sequence, :all, pattern: "deposited_sequence") end def test_species_list_all @@ -3076,75 +3076,57 @@ def test_species_list_at_where def test_species_list_by_rss_log assert_query([species_lists(:first_species_list).id], - :SpeciesList, :by_rss_log) + :SpeciesList, :all, by: :rss_log) end def test_species_list_by_user assert_query([species_lists(:first_species_list).id, species_lists(:another_species_list).id], - :SpeciesList, :by_user, user: rolf, by: :id) + :SpeciesList, :all, by_user: rolf, by: :id) assert_query(SpeciesList.where(user: mary), - :SpeciesList, :by_user, user: mary) - assert_query([], :SpeciesList, :by_user, user: dick) + :SpeciesList, :all, by_user: mary) + assert_query([], :SpeciesList, :all, by_user: dick) end def test_species_list_for_project assert_query([], - :SpeciesList, :for_project, project: projects(:empty_project)) + :SpeciesList, :all, project: projects(:empty_project)) assert_query(projects(:bolete_project).species_lists, - :SpeciesList, :for_project, project: projects(:bolete_project)) + :SpeciesList, :all, project: projects(:bolete_project)) assert_query( projects(:two_list_project).species_lists, - :SpeciesList, :for_project, project: projects(:two_list_project) + :SpeciesList, :all, project: projects(:two_list_project) ) end def test_species_list_in_set list_set_ids = [species_lists(:first_species_list).id, species_lists(:unknown_species_list).id] - assert_query(list_set_ids, :SpeciesList, :in_set, ids: list_set_ids) + assert_query(list_set_ids, :SpeciesList, :all, ids: list_set_ids) end def test_species_list_pattern_search assert_query([], - :SpeciesList, :pattern_search, pattern: "nonexistent pattern") + :SpeciesList, :all, pattern: "nonexistent pattern") # in title assert_query(SpeciesList.where(title: "query_first_list"), - :SpeciesList, :pattern_search, pattern: "query_first_list") + :SpeciesList, :all, pattern: "query_first_list") # in notes pattern = species_lists(:query_notes_list).notes assert_query(SpeciesList.where(notes: pattern), - :SpeciesList, :pattern_search, pattern: pattern) + :SpeciesList, :all, pattern: pattern) # in location assert_query( SpeciesList.where(location: locations(:burbank)), - :SpeciesList, :pattern_search, pattern: locations(:burbank).name + :SpeciesList, :all, pattern: locations(:burbank).name ) # in where pattern = species_lists(:where_list).where assert_query(SpeciesList.where(where: pattern), - :SpeciesList, :pattern_search, pattern: pattern) + :SpeciesList, :all, pattern: pattern) assert_query(SpeciesList.all, - :SpeciesList, :pattern_search, pattern: "") - end - - def test_herbarium_record_pattern_search - assert_query([], :HerbariumRecord, :pattern_search, - pattern: "no herbarium record has this") - assert_query( - HerbariumRecord.where( - HerbariumRecord[:initial_det].matches("%Agaricus%") - ), - :HerbariumRecord, :pattern_search, pattern: "Agaricus" - ) - assert_query( - HerbariumRecord.where(HerbariumRecord[:notes].matches("%rare%")), - :HerbariumRecord, :pattern_search, pattern: "rare" - ) - assert_query( - HerbariumRecord.all, :HerbariumRecord, :pattern_search, pattern: "" - ) + :SpeciesList, :all, pattern: "") end def test_user_all @@ -3155,27 +3137,25 @@ def test_user_all end def test_user_in_set - assert_query([rolf.id, mary.id, junk.id], - :User, :in_set, - ids: [junk.id, mary.id, rolf.id], - by: :reverse_name) + assert_query([rolf.id, mary.id, junk.id], :User, :all, + ids: [junk.id, mary.id, rolf.id], by: :reverse_name) end def test_user_pattern_search assert_query([], - :User, :pattern_search, pattern: "nonexistent pattern") + :User, :all, pattern: "nonexistent pattern") # in login assert_query(User.where(login: users(:spammer).login), - :User, :pattern_search, pattern: users(:spammer).login) + :User, :all, pattern: users(:spammer).login) # in name assert_query(User.where(name: users(:mary).name), - :User, :pattern_search, pattern: users(:mary).name) + :User, :all, pattern: users(:mary).name) assert_query(User.all, - :User, :pattern_search, pattern: "") + :User, :all, pattern: "") # sorted by location should include Users without location # (Differs from searches on other Classes or by other sort orders) assert_query(User.all, - :User, :pattern_search, pattern: "", by: "location") + :User, :all, pattern: "", by: "location") end ############################################################################## @@ -3248,8 +3228,7 @@ def test_filtering_content ############################################################################## def test_whiny_nil_in_map_locations - query = Query.lookup(:User, :in_set, - ids: [rolf.id, 1000, mary.id]) + query = Query.lookup(:User, :all, ids: [rolf.id, 1000, mary.id]) query.query assert_equal(2, query.results.length) end