Class: GeoLabels::DashboardController

Inherits:
ApplicationController show all
Defined in:
app/controllers/geo_labels/dashboard_controller.rb

Instance Method Summary collapse

Instance Method Details

#aboutObject



16
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 16

def about; end

#exportObject

SHOW action for the view to call the export_file action



19
20
21
22
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 19

def export
  authorize! :read, GeoLabels::Contact
  authorize! :read, GeoLabels::Label
end

#export_fileObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 24

def export_file
  authorize! :read, GeoLabels::Contact
  authorize! :read, GeoLabels::Label

  timestamp = Time.now.utc.iso8601.first(19).gsub(/-|:/, '')
  respond_to do |format|
    format.yaml do
      send_data GeoLabels::Exporter.export_str,
                filename: "GeoLabels-export-#{timestamp}.yml",
                type: :text,
                disposition: :attachment
    end
    format.csv do
      send_data GeoLabels::Contact.to_csv,
                filename: "GeoLabels-export-#{timestamp}.csv",
                type: :text,
                disposition: :attachment
    end
  end
end

#importObject



45
46
47
48
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 45

def import
  authorize! :update, GeoLabels::Contact
  authorize! :update, GeoLabels::Label
end

#import_fileObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 50

def import_file
  authorize! :update, GeoLabels::Contact
  authorize! :update, GeoLabels::Label

  GeoLabels::Importer.import params[:file]
  redirect_to root_path, notice: 'File imported'
rescue => e
  redirect_to import_path, alert: e.message
end

#mainObject



6
7
8
9
10
11
12
13
14
# File 'app/controllers/geo_labels/dashboard_controller.rb', line 6

def main
  return unless params[:label_ids].present?

  label_ids = params[:label_ids]
  # fomantic-ui uses comma separated id values
  label_ids = label_ids.to_s.split(',') unless label_ids.is_a?(Array)
  states_array = (params[:states].presence || 'approved').split(',')
  @contacts = Contact.geocoded.includes(:labels).for_label_ids(label_ids, predication: params[:predication], states: states_array)
end