diff --git a/app/controllers/data_attributes_controller.rb b/app/controllers/data_attributes_controller.rb index 2aac5290a9..967ec0c3f6 100644 --- a/app/controllers/data_attributes_controller.rb +++ b/app/controllers/data_attributes_controller.rb @@ -13,7 +13,7 @@ def index } format.json { @data_attributes = Queries::DataAttribute::Filter.new(params).all - .where(project_id: sessions_current_project_id).page(params[:page] || 1).per(500) + .where(project_id: sessions_current_project_id).page(params[:page] || 1).per(params[:per] || 500) } end end diff --git a/lib/queries/data_attribute/filter.rb b/lib/queries/data_attribute/filter.rb index 1b15b03553..95eb7bac63 100644 --- a/lib/queries/data_attribute/filter.rb +++ b/lib/queries/data_attribute/filter.rb @@ -13,6 +13,8 @@ class Filter # Params specific to DataAttribute attr_accessor :value, :controlled_vocabulary_term_id, :import_predicate, :type, :object_global_id, :attribute_subject_type + attr_accessor :predicate_ids # alias for controlled_vocabulary_term_ids + # @params params [ActionController::Parameters] def initialize(params) @value = params[:value] @@ -22,6 +24,7 @@ def initialize(params) @attribute_subject_type = params[:attribute_subject_type] @object_global_id = params[:object_global_id] + @predicate_ids = params[:predicate_ids] || [] @options = params end @@ -34,6 +37,7 @@ def and_clauses matching_import_predicate, matching_attribute_subject_type, matching_controlled_vocabulary_term_id, + matching_predicate_ids, matching_subject ].compact @@ -70,6 +74,11 @@ def matching_import_predicate import_predicate.blank? ? nil : table[:import_predicate].eq(import_predicate) end + # @return [Arel::Node, nil] + def matching_predicate_ids + predicate_ids.empty? ? nil : table[:controlled_vocabulary_term_id].eq_any(predicate_ids) # meh, missmatched variable + end + # @return [Arel::Node, nil] def matching_type type.blank? ? nil : table[:type].eq(type) @@ -95,7 +104,7 @@ def all if _a = and_clauses ::DataAttribute.where(and_clauses) else - ::DataAttribute.none + ::DataAttribute.all end end