Skip to content

Commit

Permalink
Added csv export of registrations as a backend action
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisek committed Mar 13, 2020
1 parent a49cc9e commit 01af962
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 22 additions & 0 deletions app/controllers/leads/event_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ def index
end
end

def export_csv
content = CSV.generate do |csv|
csv << ["#","Name","Email","Registered On","Id Type","Id #","State"]

@event.event_registrations.each do |registration|
csv << [
registration.id,
registration.user&.name,
registration.user&.email,
registration.created_at,
registration.gov_id_type,
registration.gov_id_number,
registration.state
]
end
end

send_data content,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=event_#{@event.id}_registrations.csv"
end

def mass_update
@event_registrations = @event.event_registrations

Expand Down
7 changes: 1 addition & 6 deletions app/views/leads/event_registrations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span class='pull-right'>
<%= link_to "Back to Event", leads_event_path(@event), :class => 'btn btn-sm btn-primary' %>
<%= link_to "Update Registration State", '#', :class => 'btn btn-sm btn-danger', :id => 'registration_update_btn' %>
<%= link_to "Export Report", '#', :class => 'btn btn-sm btn-primary', :id => 'export_report' %>
<%= link_to "Export Report", export_csv_leads_event_event_registrations_path(@event), :class => 'btn btn-sm btn-primary', :id => 'export_report' %>
</span>
</h4>
</div>
Expand Down Expand Up @@ -80,9 +80,4 @@
});
return false;
});


$('#export_report').click(function() {
$('.table2excel').TableCSVExport();
});
</script>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
resources :event_registrations do
collection do
put 'mass_update'
get 'export_csv'
end
end
resources :event_mailer_tasks do
Expand Down

0 comments on commit 01af962

Please sign in to comment.