Class: AdminWidgets::ListWidget::Header

Inherits:
Object
  • Object
show all
Extended by:
Delegation
Defined in:
lib/admin_widgets/list_widget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegation

delegate

Constructor Details

#initialize(parent, field) ⇒ Header

Returns a new instance of Header.



160
161
162
# File 'lib/admin_widgets/list_widget.rb', line 160

def initialize(parent, field)
  @parent, @field = parent, field
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



158
159
160
# File 'lib/admin_widgets/list_widget.rb', line 158

def field
  @field
end

#parentObject

Returns the value of attribute parent.



158
159
160
# File 'lib/admin_widgets/list_widget.rb', line 158

def parent
  @parent
end

Instance Method Details

#css_classObject



204
205
206
# File 'lib/admin_widgets/list_widget.rb', line 204

def css_class
  sort_direction if current_sort_field?
end

#current_sort_field?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/admin_widgets/list_widget.rb', line 177

def current_sort_field?
  helper.params[:sort_field] == sort_field.to_s
end

#labelObject



196
197
198
# File 'lib/admin_widgets/list_widget.rb', line 196

def label
  resource_class.human_attribute_name(field.name)
end

#next_sort_directionObject



181
182
183
# File 'lib/admin_widgets/list_widget.rb', line 181

def next_sort_direction
  (current_sort_field? && sort_direction == 'asc') ? 'desc' : 'asc'
end

#sort_fieldObject



173
174
175
# File 'lib/admin_widgets/list_widget.rb', line 173

def sort_field
  field.name
end

#sort_paramsObject



185
186
187
188
189
190
191
192
193
194
# File 'lib/admin_widgets/list_widget.rb', line 185

def sort_params
  {
    :sort_field => sort_field,
    :sort_direction => next_sort_direction,
    :per_page => per_page,
    :page => page,
    :where => where,
    :scope => scope
  }
end

#urlObject



200
201
202
# File 'lib/admin_widgets/list_widget.rb', line 200

def url
  helper.collection_path(sort_params)
end