Skip to content

Commit

Permalink
predicate_ids[]= param to data attributes filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Jan 22, 2019
1 parent fc2733b commit 423e2b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/data_attributes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/queries/data_attribute/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -95,7 +104,7 @@ def all
if _a = and_clauses
::DataAttribute.where(and_clauses)
else
::DataAttribute.none
::DataAttribute.all
end
end

Expand Down

0 comments on commit 423e2b8

Please sign in to comment.