Class: ActiveScaffold::Config::List::UserSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/active_scaffold/config/list.rb

Overview

don’t inherit, defined with columns_accessor, class_eval would complain about block too long

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf, storage, params) ⇒ UserSettings

Returns a new instance of UserSettings.



268
269
270
271
# File 'lib/active_scaffold/config/list.rb', line 268

def initialize(conf, storage, params)
  super(conf, storage, params, :list)
  @_sorting = nil
end

Instance Attribute Details

#labelObject

This label has already been localized.



276
277
278
# File 'lib/active_scaffold/config/list.rb', line 276

def label
  self['label'] || embedded_label || @label || @conf.label
end

#nested_default_sortingObject

Returns the value of attribute nested_default_sorting.



302
303
304
# File 'lib/active_scaffold/config/list.rb', line 302

def nested_default_sorting
  @nested_default_sorting
end

#sortingObject



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/active_scaffold/config/list.rb', line 323

def sorting
  if @_sorting.nil?
    # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data.
    self['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] && @params['sort_direction']
    self['sort'] = nil if @params['sort_direction'] == 'reset'

    if self['sort'] && @conf.core.columns[self['sort'][0]]
      sorting = sorting_dup
      sorting.set(*self['sort'])
      @_sorting = sorting
    else
      @_sorting = default_sorting
      @_sorting.set(*@sorting) if @sorting
      @_sorting.constraint_columns = @conf.columns.constraint_columns if @conf.columns.constraint_columns.present?
    end
  end
  @_sorting
end

Instance Method Details

#count_includesObject



342
343
344
# File 'lib/active_scaffold/config/list.rb', line 342

def count_includes
  @conf.count_includes
end

#default_sortingObject



309
310
311
# File 'lib/active_scaffold/config/list.rb', line 309

def default_sorting
  nested_default_sorting.nil? || @sorting.present? ? sorting_dup : nested_default_sorting
end

#embedded_labelObject



280
281
282
# File 'lib/active_scaffold/config/list.rb', line 280

def embedded_label
  @params.dig :embedded, :label
end

#pageObject



293
294
295
296
# File 'lib/active_scaffold/config/list.rb', line 293

def page
  self['page'] = @params['page'] || 1 if @params.key?('page') || @conf.auto_pagination
  self['page'] || 1
end

#page=(value = nil) ⇒ Object



298
299
300
# File 'lib/active_scaffold/config/list.rb', line 298

def page=(value = nil)
  self['page'] = value
end

#per_pageObject



284
285
286
287
# File 'lib/active_scaffold/config/list.rb', line 284

def per_page
  self['per_page'] = @params['limit'].to_i if @params.key? 'limit'
  self['per_page'] || @conf.per_page
end

#per_page=(value) ⇒ Object



289
290
291
# File 'lib/active_scaffold/config/list.rb', line 289

def per_page=(value)
  self['per_page'] = value
end

#user_sorting?Boolean

TODO: programatically set sorting, for per-request configuration, priority @params, then @sort

Returns:

  • (Boolean)


315
316
317
# File 'lib/active_scaffold/config/list.rb', line 315

def user_sorting?
  @params['sort'] && @params['sort_direction'] != 'reset'
end