Module: Mensa::Scope

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
app/tables/mensa/scope.rb

Overview

scope -> filtered_scope -> ordered_scope -> selected_scope ->

Instance Method Summary collapse

Instance Method Details

#filtered_scopeObject

Returns the scope, but filtered



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/tables/mensa/scope.rb', line 12

def filtered_scope
  return @filtered_scope if @filtered_scope

  @filtered_scope = scope
  # See https://github.com/textacular/textacular
  # This has problems - not all table fields are searched
  if params[:query].present?
    @filtered_scope = if Mensa.config.search == :fuzzy
      @filtered_scope.fuzzy_search(params[:query])
    else
      @filtered_scope.basic_search(params[:query])
    end
  end

  # Use inject
  active_filters.each do |filter|
    @filtered_scope = filter.filter_scope(@filtered_scope)
  end

  @filtered_scope
end

#ordered_scopeObject

Returns the filtered_columns, but ordered, we always reorder, scope shouldn’t include ordering



35
36
37
38
39
40
41
42
# File 'app/tables/mensa/scope.rb', line 35

def ordered_scope
  return @ordered_scope if @ordered_scope

  @ordered_scope = filtered_scope
  @ordered_scope = @ordered_scope.reorder(effective_order)

  @ordered_scope
end

#paged_scopeObject



54
55
56
57
# File 'app/tables/mensa/scope.rb', line 54

def paged_scope
  pagy_object
  @records
end

#pagy_detailsObject



59
60
61
62
# File 'app/tables/mensa/scope.rb', line 59

def pagy_details
  pagy_object
  @pagy_details
end

#selected_scopeObject

Return the ordered_scope, but with only the columns selected



45
46
47
48
49
50
51
52
# File 'app/tables/mensa/scope.rb', line 45

def selected_scope
  return @selected_scope if @selected_scope

  @selected_scope = ordered_scope
  @selected_scope = @selected_scope.select([:id] + columns.filter_map(&:attribute))

  @selected_scope
end