Permalink
Browse files

Import from CSV

* Re-fashion bulk add into an import for sake of prototype
* Use a textarea for pasting in a CSV
* Give guidance on the structure of the CSV
  * Header rows should be ignored, and not required
  * When a CSV doesn’t parse we should return with a validation error
* Hitting ‘continue’ will take you to a preview page, much like the
bulk add with a choice about overwriting, but each row must show all
mapping details
* This may be difficult when there are lots of mappings (see background
import problems)
  • Loading branch information...
Paul Hayes
Paul Hayes committed Apr 4, 2014
1 parent fda4684 commit 5c186832ffafa9ac600b2b6140816cec967bc21d
Showing with 10 additions and 54 deletions.
  1. +10 −54 app/views/mappings/new_multiple.html.erb
@@ -1,83 +1,39 @@
<% breadcrumb(:new_mappings, @site) %>
<%= content_for :page_title, 'New mappings' %>
<%= content_for :page_title, 'Import mappings' %>
<div class="page-title-with-border">
<h1>
<span class="small"><%= @site.default_host.hostname %></span>
Add mappings
Import mappings
</h1>
</div>
<%= form_tag new_multiple_confirmation_site_mappings_path(@site), role: 'form', 'data-module' => 'toggle-mapping-form-fields' do %>
<% if @errors %>
<%= render 'shared/error_messages', error_messages: @errors.values %>
<% end %>
<% if params[:return_path].present? %>
<%= hidden_field_tag 'return_path', params[:return_path] %>
<% end %>
<div class="row <% if @errors && @errors[:http_status] %>field_with_errors<% end %>">
<div class="col-md-2">
<%= label_tag(:http_status, 'Type') %>
<%= select_tag :http_status, options_for_select(options_for_supported_statuses, @bulk_add.http_status), { class: 'form-control remove-bottom-margin js-http-status' } %>
</div>
</div>
<div class="form-group <% if @errors && @errors[:paths] %>field_with_errors<% end %>">
<%= form_tag new_multiple_confirmation_site_mappings_path(@site), role: 'form' do %>
<div class="form-group">
<%#
Capture label HTML to avoid using a block, this circumvents a problem with
rails not wrapping the label with 'field_with_errors' on error
http://stackoverflow.com/questions/13862978/
%>
<% label_html = capture do %>
Old URLs
Import from CSV
<p class="text-muted normal add-label-margin">
Please add one path or URL per line, eg “/about” or “http://<%= @site.default_host.hostname %>/about”.
Please paste a CSV with the columns "old url,new url,type", where type is either redirect or archive.<br>
eg "http://www.ago.gov.uk/_layouts/feed.aspx,https://www.gov.uk/government/organisations/attorney-generals-office,redirect"
</p>
<% end %>
<%= label_tag :paths, label_html, class: 'add-top-margin' %>
<%= label_tag :paths, label_html %>
<div class="row">
<div class="old-urls col-md-8">
<%= text_area_tag :paths, @bulk_add.raw_paths.join("\n"), class: 'form-control', placeholder: '/path/to/page' %>
<%= text_area_tag :paths, @bulk_add.raw_paths.join("\n"), class: 'form-control', placeholder: 'old-url,new-url,status' %>
</div>
</div>
</div>
<%= field_set_tag nil, class: 'form-group js-for-redirect' do %>
<legend class="if-js-rm">
Redirect
</legend>
<div <% if @errors && @errors[:new_url] %>class="field_with_errors"<% end %>>
<%= label_tag :new_url, 'Redirect to' %>
<div class="row">
<div class="col-md-8">
<%= text_field_tag(:new_url, @bulk_add.new_url, class: 'form-control') %>
</div>
</div>
</div>
<% end %>
<%= field_set_tag nil, class: 'js-for-archive' do %>
<legend class="if-js-rm">
Archive
</legend>
<dl class="read-only-fields">
<dt>National Archive</dt>
<dd>
<p>The archive URLs will be automatically generated based on the old URLs provided above.</p>
</dd>
</dl>
<% end %>
<%= render partial: 'tag_list_field', locals: { bulk_tagger: @bulk_add } %>
<%= button_tag 'Continue', class: 'add-vertical-margins btn btn-success' %>
<div class="row">
<p class="col-md-8 text-muted">When you submit the form we’ll convert the URLs to lowercase and order the query parameters so they are consistent, and we’ll check whether they already exist. There will be a review step before your changes are saved.</p>
<p class="col-md-8 text-muted">When you submit the form we’ll convert the old URLs to lowercase and order the query parameters so they are consistent, and we’ll check whether they already exist. There will be a review step before your paths are imported.</p>
</div>
<% end %>

4 comments on commit 5c18683

@fofr

This comment has been minimized.

Contributor

fofr replied Apr 4, 2014

screen shot 2014-04-04 at 16 30 24

@jamiecobbett

This comment has been minimized.

Contributor

jamiecobbett replied Apr 4, 2014

👍

@jamiecobbett

This comment has been minimized.

Contributor

jamiecobbett replied Apr 4, 2014

One thing I've seen is TNA URLs supplied in the New URL column. This is sometimes because they are presenting the information slightly differently in their spreadsheet but partly because they may already be redirecting to the Archive. What I'm saying is: we should probably detect where a redirect is to TNA and make the mapping an archive.

@rjc123

This comment has been minimized.

Contributor

rjc123 replied Apr 4, 2014

+1 to this
They frequently 301 to archive, but we should translate that to a 410 with a custom archive link

Please sign in to comment.