Module: AgileControl

Defined in:
app/controls/agile_control.rb

Overview

Common controls for Agile controller

Instance Method Summary collapse

Instance Method Details

#filter_offObject

Clear current form filter



32
33
34
35
36
37
38
39
# File 'app/controls/agile_control.rb', line 32

def filter_off
  table_name = AgileHelper.table_param(params).strip.split(';').first.underscore
  save_filter_value(nil, table_name, :filter)
  save_filter_value(1, table_name, :page)
  url = url_for(controller: :agile, t: table_name, f: AgileHelper.form_param(params))

  render json: { url: url }
end

#filter_onObject

Set current filter for table



44
45
46
47
48
49
50
51
52
53
54
# File 'app/controls/agile_control.rb', line 44

def filter_on
  table_name = AgileHelper.table_param(params).strip.split(';').first.underscore
  save_filter_value(1, table_name, :page)
  set_session_filter(table_name)
  url = url_for(controller: :agile, table: table_name, form_name: AgileHelper.form_param(params))
  respond_to do |format|
    format.json { render json: { url: url } }
    format.html { redirect_to url }
  end

end

#sortObject

Will check and set sorting options for current dataset. Subroutine of index method.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controls/agile_control.rb', line 59

def sort
  return if params['sort'].nil?

  table_name = AgileHelper.table_param(params).strip.split(';').first.underscore
  old_sort = session.dig(:filters, table_name, :sort).to_s
  sort, direction = old_sort.split(' ')
  # reverse sort if same selected
  direction = direction == 'asc' ? 'desc' : 'asc' if params['sort'] == sort
  direction ||= 'asc'
  save_filter_value("#{params[:sort]} #{direction}", table_name, :sort)
  save_filter_value(1, table_name, :page)

  params['sort'] = nil # otherwise there is problem with other links
  url = url_for(controller: :agile, t: table_name, f: AgileHelper.form_param(params))

  render json: { url: url }
end