From 1010d725767399b6ad29e56d5515f6c19a34b194 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 23 Nov 2015 09:34:20 -0500 Subject: [PATCH] Document the bulk add workflow --- app/controllers/opportunities_controller.rb | 7 ++- app/views/opportunities/bulk_add.html.erb | 62 +++++++++++---------- public/opportunities.csv | 2 + 3 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 public/opportunities.csv diff --git a/app/controllers/opportunities_controller.rb b/app/controllers/opportunities_controller.rb index 2b778eb..449d05e 100644 --- a/app/controllers/opportunities_controller.rb +++ b/app/controllers/opportunities_controller.rb @@ -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) @@ -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 diff --git a/app/views/opportunities/bulk_add.html.erb b/app/views/opportunities/bulk_add.html.erb index 3dff971..c1fcaf9 100644 --- a/app/views/opportunities/bulk_add.html.erb +++ b/app/views/opportunities/bulk_add.html.erb @@ -1,47 +1,49 @@

Dashboard > Bulk Add Opportunities

+ <%= form_tag({action: :bulk_add}, multipart: true) do %> + +

Step 1: Set the Organizer

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

Upload a CSV with these columns:

+

Step 2: Download the CSV Template

+ +

Download the CSV template 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:

- <%= 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 %> -
-
+

Step 3: Upload Your CSV

+ + <%= file_field_tag 'csv' %> + <%= submit_tag('Upload') %> + <% end %> -<% if @nbad > 0 %> -

We found <%= pluralize(@nerrors, "error") %> in <%= pluralize(@nbad, "record") %>.

-<% end %> -<% if @opportunities.present? %> + + <% if not @opportunities.present? %> +

Step 4: Review Results

+ <% else %> +

Step 4: Review Results

+ + <% if @nbad > 0 %> +

We found <%= pluralize(@nerrors, "error") %> in <%= pluralize(@nbad, "record") %>.

+ <% end %> + @@ -83,5 +85,5 @@ <% end %>
-<% end %> + <% end %>
diff --git a/public/opportunities.csv b/public/opportunities.csv new file mode 100644 index 0000000..b53a5a8 --- /dev/null +++ b/public/opportunities.csv @@ -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,alice@example.com,+1-555-867-5309,10,0,1000,Making,Event