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.



234
235
236
237
# File 'lib/active_scaffold/config/list.rb', line 234

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

Instance Attribute Details

#labelObject

This label has already been localized.



242
243
244
# File 'lib/active_scaffold/config/list.rb', line 242

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

#nested_default_sortingObject

Returns the value of attribute nested_default_sorting.



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

def nested_default_sorting
  @nested_default_sorting
end

#sortingObject



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/active_scaffold/config/list.rb', line 289

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



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

def count_includes
  @conf.count_includes
end

#default_sortingObject



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

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

#embedded_labelObject



246
247
248
# File 'lib/active_scaffold/config/list.rb', line 246

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

#pageObject



259
260
261
262
# File 'lib/active_scaffold/config/list.rb', line 259

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

#page=(value = nil) ⇒ Object



264
265
266
# File 'lib/active_scaffold/config/list.rb', line 264

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

#per_pageObject



250
251
252
253
# File 'lib/active_scaffold/config/list.rb', line 250

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



255
256
257
# File 'lib/active_scaffold/config/list.rb', line 255

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)


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

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