Class: Admin::Base::Resource::IndexConfig
- Inherits:
-
Object
- Object
- Admin::Base::Resource::IndexConfig
- Defined in:
- lib/admin/base/resource.rb
Overview
Index view configuration
Instance Attribute Summary collapse
-
#columns_list ⇒ Object
readonly
Returns the value of attribute columns_list.
-
#default_sort ⇒ Object
readonly
Returns the value of attribute default_sort.
-
#default_sort_direction ⇒ Object
readonly
Returns the value of attribute default_sort_direction.
-
#filters_list ⇒ Object
readonly
Returns the value of attribute filters_list.
-
#includes_list ⇒ Object
readonly
Returns the value of attribute includes_list.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#searchable_fields ⇒ Object
readonly
Returns the value of attribute searchable_fields.
-
#sortable_fields ⇒ Object
readonly
Returns the value of attribute sortable_fields.
-
#stats_list ⇒ Object
readonly
Returns the value of attribute stats_list.
Instance Method Summary collapse
- #columns(&block) ⇒ Object
- #filters(&block) ⇒ Object
-
#includes(*associations) ⇒ void
Kills the index's association N+1 (Task 3 made
belongs_tocolumns render as links, so each one now genuinely dereferences the association -- one query per row without this). -
#initialize ⇒ IndexConfig
constructor
A new instance of IndexConfig.
- #paginate(count) ⇒ Object
- #searchable(*fields) ⇒ Object
- #sortable(*fields, default: nil, direction: :desc) ⇒ Object
- #stats(&block) ⇒ Object
Constructor Details
#initialize ⇒ IndexConfig
Returns a new instance of IndexConfig.
279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/admin/base/resource.rb', line 279 def initialize @searchable_fields = [] @sortable_fields = [] @default_sort = nil @default_sort_direction = :desc @columns_list = [] @filters_list = [] @stats_list = [] @per_page = 25 @includes_list = [] end |
Instance Attribute Details
#columns_list ⇒ Object (readonly)
Returns the value of attribute columns_list.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def columns_list @columns_list end |
#default_sort ⇒ Object (readonly)
Returns the value of attribute default_sort.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def default_sort @default_sort end |
#default_sort_direction ⇒ Object (readonly)
Returns the value of attribute default_sort_direction.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def default_sort_direction @default_sort_direction end |
#filters_list ⇒ Object (readonly)
Returns the value of attribute filters_list.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def filters_list @filters_list end |
#includes_list ⇒ Object (readonly)
Returns the value of attribute includes_list.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def includes_list @includes_list end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def per_page @per_page end |
#searchable_fields ⇒ Object (readonly)
Returns the value of attribute searchable_fields.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def searchable_fields @searchable_fields end |
#sortable_fields ⇒ Object (readonly)
Returns the value of attribute sortable_fields.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def sortable_fields @sortable_fields end |
#stats_list ⇒ Object (readonly)
Returns the value of attribute stats_list.
276 277 278 |
# File 'lib/admin/base/resource.rb', line 276 def stats_list @stats_list end |
Instance Method Details
#columns(&block) ⇒ Object
322 323 324 325 326 |
# File 'lib/admin/base/resource.rb', line 322 def columns(&block) builder = ColumnsBuilder.new builder.instance_eval(&block) if block_given? @columns_list = builder.columns end |
#filters(&block) ⇒ Object
328 329 330 331 332 |
# File 'lib/admin/base/resource.rb', line 328 def filters(&block) builder = FiltersBuilder.new builder.instance_eval(&block) if block_given? @filters_list = builder.filters end |
#includes(*associations) ⇒ void
This method returns an undefined value.
Kills the index's association N+1 (Task 3 made belongs_to
columns render as links, so each one now genuinely dereferences
the association -- one query per row without this). The
controller applies this to the filtered scope only when the
scope actually responds to #includes -- PORO test doubles and
some host scopes don't -- and swallows a bad association name
(typo, renamed association) by logging and rendering
unoptimized rather than 500ing. nil entries (e.g. a stray
includes nil) are dropped rather than stored and handed to the
scope verbatim.
318 319 320 |
# File 'lib/admin/base/resource.rb', line 318 def includes(*associations) @includes_list = associations.flatten.compact end |
#paginate(count) ⇒ Object
301 302 303 |
# File 'lib/admin/base/resource.rb', line 301 def paginate(count) @per_page = count end |
#searchable(*fields) ⇒ Object
291 292 293 |
# File 'lib/admin/base/resource.rb', line 291 def searchable(*fields) @searchable_fields = fields end |
#sortable(*fields, default: nil, direction: :desc) ⇒ Object
295 296 297 298 299 |
# File 'lib/admin/base/resource.rb', line 295 def sortable(*fields, default: nil, direction: :desc) @sortable_fields = fields if fields.any? @default_sort = default || fields.first @default_sort_direction = direction end |
#stats(&block) ⇒ Object
334 335 336 337 338 |
# File 'lib/admin/base/resource.rb', line 334 def stats(&block) builder = StatsBuilder.new builder.instance_eval(&block) if block_given? @stats_list = builder.stats end |