Module: Discerner::Methods::Controllers::ExportParametersController

Included in:
ExportParametersController
Defined in:
lib/discerner/methods/controllers/export_parameters_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
# File 'lib/discerner/methods/controllers/export_parameters_controller.rb', line 5

def self.included(base)
  base.send :helper, :all
  base.send :before_filter, :load_search
  base.send :layout, 'layouts/discerner/searches'
end

Instance Method Details

#assignObject



22
23
24
25
26
27
28
29
# File 'lib/discerner/methods/controllers/export_parameters_controller.rb', line 22

def assign
  existing_export_parameters = @discerner_search.export_parameters || []
  export_parameter_ids = params[:parameter_ids] || []

  existing_export_parameters.map{ |export_parameter| export_parameter.delete unless export_parameter_ids.include?(export_parameter.parameter_id) }
  export_parameter_ids.map{ |parameter_id| @discerner_search.export_parameters.create(parameter_id: parameter_id) unless existing_export_parameters.where(parameter_id: parameter_id).any?}
  redirect_to search_path(@discerner_search, format: 'xls')
end

#indexObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/discerner/methods/controllers/export_parameters_controller.rb', line 11

def index
  if @discerner_search.disabled?
    error_message = "There is an issue with the this export that has to be corrected before it can be executed"
    if @discerner_search.warnings.any?
      error_message << ': '
      error_message << @discerner_search.warnings.full_messages.join(',')
    end
  end
  flash[:error] = error_message unless error_message.blank?
end