Module: Queries::Concerns::Users

Extended by:
ActiveSupport::Concern
Included in:
Queries::CollectionObject::Filter, Queries::Content::Filter, Image::Filter, Person::Filter, Source::Filter, TaxonName::Filter
Defined in:
lib/queries/concerns/users.rb

Overview

Helpers for queries that reference created/updated fields

!! You must have `#base_query` defined in the module to use this concern !! You must call set_user_dates in initialize() TODO: Isolate code to a gem

Concern specs are in

spec/lib/queries/person/filter_spec.rb

Instance Method Summary collapse

Instance Method Details

#created_updated_facetScope

Returns:

  • (Scope)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/queries/concerns/users.rb', line 49

def created_updated_facet
  return nil if user_id.empty? && user_target.nil? && user_date_start.nil? && user_date_end.nil?
  s, e = Utilities::Dates.normalize_and_order_dates(
    user_date_start,
    user_date_end)

  # TODO: this is ultimately going to require hourly scope
  s += ' 00:00:00' # adjust dates to beginning
  e += ' 23:59:59' # and end of date days

  q = nil

  # hand date range

  # What date?
  if !user_date_start.nil? || !user_date_end.nil?
    case user_target
    when 'updated'
      q = base_query.updated_in_date_range(s, e)
    when 'created'
      q = base_query.created_in_date_range(s, e)
    else
      q = base_query.updated_in_date_range(s, e).or(base_query.created_in_date_range(s,e))
    end
  end

  q = base_query if q.nil?

  # handle user_id
  if !user_id.empty?
    case user_target
    when 'updated'
      q = q.where(updated_by_id: user_id)
    when 'created'
      q = q.where(created_by_id: user_id)
    end
  end
  q
end

#set_user_dates(params) ⇒ Object



40
41
42
43
44
45
# File 'lib/queries/concerns/users.rb', line 40

def set_user_dates(params)
  @user_id = params[:user_id]
  @user_target = params[:user_target] # Add validation ?
  @user_date_start = params[:user_date_start]
  @user_date_end = params[:user_date_end]
end