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.


229
230
231
232
# File 'lib/active_scaffold/config/list.rb', line 229

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

Instance Attribute Details

#labelObject

This label has already been localized.


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

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

#nested_default_sortingObject

Returns the value of attribute nested_default_sorting


262
263
264
# File 'lib/active_scaffold/config/list.rb', line 262

def nested_default_sorting
  @nested_default_sorting
end

#sortingObject


283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/active_scaffold/config/list.rb', line 283

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
      if @conf.columns.constraint_columns.present?
        @_sorting.constraint_columns = @conf.columns.constraint_columns
      end
    end
  end
  @_sorting
end

Instance Method Details

#count_includesObject


304
305
306
# File 'lib/active_scaffold/config/list.rb', line 304

def count_includes
  @conf.count_includes
end

#default_sortingObject


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

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

#embedded_labelObject


240
241
242
# File 'lib/active_scaffold/config/list.rb', line 240

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

#pageObject


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

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

#page=(value = nil) ⇒ Object


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

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

#per_pageObject


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

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


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

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)

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

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