active_admin_csv_import 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@
|
|
4
4
|
default: 'Import %{resource_name} from a CSV File' ) %>
|
5
5
|
</h3>
|
6
6
|
<ul>
|
7
|
-
<li><%= t('.file_type', default: "Save a CSV as 'Windows Comma Separated' from Excel.") %></li>
|
8
|
-
<li><%= t('.must_have_headings', columns: @required_columns.to_sentence, default: "Your CSV should have the following column headings: %{columns}. The order doesn't matter.") %></li>
|
7
|
+
<li><%= t('.file_type', default: "Save a CSV as 'Windows Comma Separated' from Excel if you're on Mac, or 'CSV' otherwise.") %></li>
|
8
|
+
<li><%= t('.must_have_headings', columns: @required_columns.map(&:to_s).map(&:humanize).to_sentence, default: "Your CSV should have the following column headings: %{columns}. The order doesn't matter.") %></li>
|
9
|
+
<li><%= link_to(t('.example_link', default: "Download an example"), url_for(:controller => controller_name, :action => 'example_csv')) %></li>
|
9
10
|
</ul>
|
@@ -1,16 +1,32 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module ActiveAdminCsvImport
|
2
4
|
module DSL
|
3
5
|
|
4
6
|
def csv_importable(options={})
|
5
7
|
|
8
|
+
# All columns
|
9
|
+
columns = options[:columns] ||= active_admin_config.resource_class.columns.map(&:name) - ["id", "updated_at", "created_at"]
|
10
|
+
|
11
|
+
# Required columns. A subset of all columns. A client-side validation error is raised if one of these is not found.
|
12
|
+
required_columns = options[:required_columns] ||= columns
|
13
|
+
|
6
14
|
action_item :only => :index do
|
7
15
|
link_to "Import #{active_admin_config.resource_name.to_s.pluralize}", :action => 'import_csv'
|
8
16
|
end
|
9
17
|
|
18
|
+
# Returns an example CSV based on the columns expected for import.
|
19
|
+
collection_action :example_csv do
|
20
|
+
csv_column_names = CSV.generate do |csv|
|
21
|
+
csv << columns.map(&:to_s).map(&:humanize)
|
22
|
+
end
|
23
|
+
send_data(csv_column_names, :type => 'text/csv; charset=utf-8; header=present', :filename => active_admin_config.resource_class.name.to_s.pluralize + ".csv")
|
24
|
+
end
|
25
|
+
|
10
26
|
# Shows the form and JS which accepts a CSV file, parses it and posts each row to the server.
|
11
27
|
collection_action :import_csv do
|
12
|
-
@columns =
|
13
|
-
@required_columns =
|
28
|
+
@columns = columns
|
29
|
+
@required_columns = required_columns
|
14
30
|
|
15
31
|
@post_path = options[:path].try(:call)
|
16
32
|
@post_path ||= collection_path + "/import_rows"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin_csv_import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70339062483560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70339062483560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: railties
|
27
|
-
requirement: &
|
27
|
+
requirement: &70339062497880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '3.1'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70339062497880
|
36
36
|
description: CSV import for Active Admin capable of handling CSV files too large to
|
37
37
|
import via direct file upload to Heroku
|
38
38
|
email:
|