Skip to content

Commit

Permalink
Document the bulk add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Nov 23, 2015
1 parent 406bb8d commit 1010d72
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
7 changes: 5 additions & 2 deletions app/controllers/opportunities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def bulk_add
Opportunity.transaction do
CSV.parse(params[:csv].read, headers: true) do |row|
topic = Topic.find_by_name(row.delete('topic'))
resource_sub_type = ResourceSubType.find_by_name(row.delete('resource_sub_type'))
sub_type = ResourceSubType.find_by_name(row.delete('resource_sub_type'))

row['organizer_id'] = params[:organizer_id]
row['topic_id'] = unless topic.nil? then topic.id else nil end
row['resource_sub_type_id'] = unless resource_sub_type.nil? then resource_sub_type.id else nil end
row['resource_sub_type_id'] = unless sub_type.nil? then sub_type.id else nil end

opportunity = Opportunity.create(row.to_h)
@opportunities.push(opportunity)
Expand All @@ -62,6 +62,9 @@ def bulk_add
end
end
end

@topic_names = Topic.pluck(:name)
@sub_type_names = ResourceSubType.pluck(:name)
end

# GET /opportunities/1/edit
Expand Down
62 changes: 32 additions & 30 deletions app/views/opportunities/bulk_add.html.erb
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
<h1 class="page">Dashboard > Bulk Add Opportunities</h1>

<div class="opportunities bulk-add">
<%= form_tag({action: :bulk_add}, multipart: true) do %>

<h2>Step 1: Set the Organizer</h2>

<%= select_tag(:organizer_id, options_for_select(current_user.organizers.map {|o| [o.name, o.id]})) %>


<p>Upload a CSV with these columns:</p>
<h2>Step 2: Download the CSV Template</h2>

<p><a href="/opportunities.csv">Download the CSV template</a> to see what
fields are required and example values showing the expected format. Edit it
in Excel to enter your own data. Here are some notes on specific fields:</p>

<ul>
<li>name</li>
<li>description</li>
<li>registration_deadline</li>
<li>starts_at</li>
<li>ends_at</li>
<li>registration_url</li>
<li>program_type</li>
<li>logo_url</li>
<li>is_online</li>
<li>contact_name</li>
<li>contact_email</li>
<li>contact_phone</li>
<li>price_level</li>
<li>min_age</li>
<li>max_age</li>
<li>topic</li>
<li>resource_sub_type</li>
<li><b>program_type</b>&mdash;pick any value for this that makes sense for you</li>
<li><b>is_online</b>&mdash;"true" or "false"</li>
<li><b>topic</b>&mdash;must be: "<%= @topic_names.join('", "')%>"</li>
<li><b>resource_sub_type</b>&mdash;must be: "<%= @sub_type_names.join('", "')%>"</li>
</ul>

<%= form_tag({action: :bulk_add}, multipart: true) do %>
Organizer: <%= select_tag(:organizer_id, options_for_select(current_user.organizers.map {|o| [o.name, o.id]})) %>
<%= file_field_tag 'csv' %>
<%= submit_tag('Upload') %>
<% end %>

<br />
<br />
<h2>Step 3: Upload Your CSV</h2>

<%= file_field_tag 'csv' %>
<%= submit_tag('Upload') %>
<% end %>

<% if @nbad > 0 %>
<h1>We found <%= pluralize(@nerrors, "error") %> in <%= pluralize(@nbad, "record") %>.</h1>
<% end %>

<% if @opportunities.present? %>
<style>
td.good { background: #CCFFCC; }
td.bad { background: #FFCCCC; }
h2.disabled { color: #CCC; }
</style>

<% if not @opportunities.present? %>
<h2 class="disabled">Step 4: Review Results</h2>
<% else %>
<h2>Step 4: Review Results</h2>

<% if @nbad > 0 %>
<h3>We found <%= pluralize(@nerrors, "error") %> in <%= pluralize(@nbad, "record") %>.</h3>
<% end %>

<table class="pure-table pure-table-bordered">
<thead>
<tr>
Expand Down Expand Up @@ -83,5 +85,5 @@
<% end %>
</tbody>
</table>
<% end %>
<% end %>
</div>
2 changes: 2 additions & 0 deletions public/opportunities.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,description,registration_deadline,starts_at,ends_at,registration_url,program_type,logo_url,is_online,contact_name,contact_email,contact_phone,price_level,min_age,max_age,topic,resource_sub_type
Marbles,It's marble time!,2020-10-10,2020-10-10,2020-10-10,http://example.com/,Workshop,http://example.com/logo,true,Alice W. Underland,[email protected],+1-555-867-5309,10,0,1000,Making,Event

0 comments on commit 1010d72

Please sign in to comment.