Module: ArPollResultControl
- Defined in:
- app/controls/ar_poll_result_control.rb
Overview
AgileRails controls for ArPollResult model.
Instance Method Summary collapse
-
#default_filter ⇒ Object
Default data_set filter.
-
#do_export ⇒ Object
Export data to CSV file.
-
#set_filter ⇒ Object
Filter action called.
Instance Method Details
#default_filter ⇒ Object
Default data_set filter
32 33 34 |
# File 'app/controls/ar_poll_result_control.rb', line 32 def default_filter get_query end |
#do_export ⇒ Object
Export data to CSV file.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controls/ar_poll_result_control.rb', line 50 def do_export c, keys = '', [] get_query.to_a.each do |doc| # ensure, that fields are always in same order data = YAML.load(doc.data) if c.blank? data.each { |k, v| keys << k } c += "#{I18n.t('helpers.label.ar_poll_result.created_at')}\t" c += "#{keys.join("\t")}\n" end c += "#{doc.created_at.strftime(I18n.t('date.formats.default'))}\t" keys.each { |k| c += "#{data[k]}\t" } c += "\n" end File.write(Rails.root.join('public','export.csv'), c) render json: { window: 'export.csv' } # will download file end |
#set_filter ⇒ Object
Filter action called. Update url to reflect filter conditions and reload form.
39 40 41 42 43 44 45 |
# File 'app/controls/ar_poll_result_control.rb', line 39 def set_filter url = url_for(controller: :agile, action: :index, table: :ar_poll_result, 'record[poll_id]' => params[:record][:poll_id], 'record[start_date]' => params[:record][:start_date], 'record[end_date]' => params[:record][:end_date]) render json: { url: url } end |