Module: Mensa::Scope
Instance Method Summary collapse
-
#filtered_scope ⇒ Object
Returns the scope, but filtered.
-
#ordered_scope ⇒ Object
Returns the filtered_columns, but ordered, we always reorder, scope shouldn’t include ordering.
- #paged_scope ⇒ Object
- #pagy_details ⇒ Object
-
#scope ⇒ Object
Returns the records we want to display, using the Active Record Query Interface By default it returns all records.
-
#selected_scope ⇒ Object
Return the ordered_scope, but with only the columns selected.
Instance Method Details
#filtered_scope ⇒ Object
Returns the scope, but filtered
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/tables/mensa/scope.rb', line 17 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 @filtered_scope = @filtered_scope.basic_search(params[:query]) if params[:query] # Use inject active_filters.each do |filter| @filtered_scope = filter.filter_scope(@filtered_scope) end @filtered_scope end |
#ordered_scope ⇒ Object
Returns the filtered_columns, but ordered, we always reorder, scope shouldn’t include ordering
34 35 36 37 38 39 40 41 |
# File 'app/tables/mensa/scope.rb', line 34 def ordered_scope return @ordered_scope if @ordered_scope @ordered_scope = filtered_scope @ordered_scope = @ordered_scope.reorder(order_hash) @ordered_scope end |
#paged_scope ⇒ Object
53 54 55 56 |
# File 'app/tables/mensa/scope.rb', line 53 def paged_scope pagy_object @records end |
#pagy_details ⇒ Object
58 59 60 61 |
# File 'app/tables/mensa/scope.rb', line 58 def pagy_details pagy_object @pagy_details end |
#scope ⇒ Object
Returns the records we want to display, using the Active Record Query Interface By default it returns all records
12 13 14 |
# File 'app/tables/mensa/scope.rb', line 12 def scope model.all end |
#selected_scope ⇒ Object
Return the ordered_scope, but with only the columns selected
44 45 46 47 48 49 50 51 |
# File 'app/tables/mensa/scope.rb', line 44 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 |