Class: AdminAssistant::IndexSettings

Inherits:
AbstractSettings show all
Defined in:
lib/admin_assistant/builder.rb

Defined Under Namespace

Classes: SearchSettings

Instance Attribute Summary collapse

Attributes inherited from AbstractSettings

#column_names

Instance Method Summary collapse

Methods inherited from AbstractSettings

#[], #columns

Constructor Details

#initialize(admin_assistant) ⇒ IndexSettings

Returns a new instance of IndexSettings.



214
215
216
217
218
219
220
221
222
# File 'lib/admin_assistant/builder.rb', line 214

def initialize(admin_assistant)
  super
  @actions = ActiveSupport::OrderedHash.new
  @right_column_links = []
  @search_fields = []
  @search_settings = SearchSettings.new @admin_assistant
  @sort_by = "#{admin_assistant.model_class.table_name}.id desc"
  @per_page = 25
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



212
213
214
# File 'lib/admin_assistant/builder.rb', line 212

def actions
  @actions
end

Returns the value of attribute right_column_links.



212
213
214
# File 'lib/admin_assistant/builder.rb', line 212

def right_column_links
  @right_column_links
end

#search_settingsObject (readonly)

Returns the value of attribute search_settings.



212
213
214
# File 'lib/admin_assistant/builder.rb', line 212

def search_settings
  @search_settings
end

#sort_by(*sb) ⇒ Object (readonly)

Returns the value of attribute sort_by.



212
213
214
# File 'lib/admin_assistant/builder.rb', line 212

def sort_by
  @sort_by
end

Instance Method Details

#cache_total_entries(time_span = nil) ⇒ Object



224
225
226
# File 'lib/admin_assistant/builder.rb', line 224

def cache_total_entries(time_span = nil)
  time_span ? (@cache_total_entries = time_span) : @cache_total_entries
end

#column_config_fieldsObject



228
229
230
231
# File 'lib/admin_assistant/builder.rb', line 228

def column_config_fields
  {:ajax_toggle => :accessor, :image_size => :accessor,
   :link_to_args => :block, :sort_by => :accessor}
end

#conditions(str = nil, &block) ⇒ Object



233
234
235
236
237
238
239
240
241
# File 'lib/admin_assistant/builder.rb', line 233

def conditions(str = nil, &block)
  if str.nil? && block.nil?
    @conditions
  elsif str
    @conditions = str
  elsif block
    @conditions = block
  end
end

#header(&block) ⇒ Object



243
244
245
# File 'lib/admin_assistant/builder.rb', line 243

def header(&block)
  block ? (@header = block) : @header
end

#include(*associations) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/admin_assistant/builder.rb', line 247

def include(*associations)
  if associations.empty?
    @include
  else
    @include = associations
  end
end

#per_page(*args) ⇒ Object



255
256
257
258
259
260
261
# File 'lib/admin_assistant/builder.rb', line 255

def per_page(*args)
  if args.empty?
    @per_page
  else
    @per_page = args.first
  end
end

#search(*columns) ⇒ Object



263
264
265
266
267
268
269
270
271
# File 'lib/admin_assistant/builder.rb', line 263

def search(*columns)
  if block_given?
    yield @search_settings
  elsif columns.empty?
    @search_settings
  else
    @search_settings.columns *columns
  end
end

#total_entries(&block) ⇒ Object



281
282
283
# File 'lib/admin_assistant/builder.rb', line 281

def total_entries(&block)
  block ? (@total_entries = block) : @total_entries
end