active_admin_csv_import 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c9d7a33e6c9e9fffec9f8419ea64d952ffbada9
4
+ data.tar.gz: 0e232f0c116103a0bf0a9b36003fa6415ca60e71
5
+ SHA512:
6
+ metadata.gz: 80657c5898a31b15f3ae616d85ef0d3e94be6fd11ef027490d7ce4f71d5cefcecc2fe2e60d215050519bf8681cf57e1e2c03f753878949f526e29215f05ba81d
7
+ data.tar.gz: 33c6d1e53db05fa0f0e14468128aa22589f8657b18a61f2589a2374ff8bab7d1af95799ff493687dafcba6702dd1addf844e6033d29f4725e4a6565aa8eb2e40
@@ -0,0 +1,68 @@
1
+ ActiveAdminCSVImport
2
+ =======================
3
+
4
+ [![Build Status](https://travis-ci.org/Papercloud/active_admin_csv_import.svg?branch=master)](https://travis-ci.org/Papercloud/active_admin_csv_import)
5
+
6
+ - Add CSV import with one line of code
7
+ - Parses the file client-side and imports line-by-line to avoid Heroku timeouts
8
+ - Validates the CSV has the correct column names before importing.
9
+
10
+ Inspired by https://github.com/krhorst/active_admin_importable and makes use of Recline.js. This is a relatively heavy solution with a lot of JS dependencies, but should be easier for large imports on Heroku than first uploading to a file server.
11
+
12
+ ## Compatibility
13
+
14
+ As of v2.0.0 Active Admin master with Rails 4.1 is supported. For older versions of Active Admin use v1 of active_admin_csv_import.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'active_admin_csv_import'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ ## Usage
27
+
28
+ Add 'csv_importable' into your active admin resource:
29
+
30
+ ```
31
+ ActiveAdmin.register Thing do
32
+ csv_importable :columns => [:code, :name, :state_name],
33
+ :import_unique_key => :code
34
+ end
35
+ ```
36
+
37
+ An import button should appear on the resource's index page. All columns are expected other than id, updated_at and created_at.
38
+
39
+ ## Demo
40
+
41
+ http://active-admin-csv-import.herokuapp.com/admin
42
+ ```
43
+ admin@example.com
44
+ password
45
+ ```
46
+ Source: https://github.com/Papercloud/active-admin-csv-import-example
47
+
48
+ ## Use other delimiter than semicolon
49
+
50
+ In `config/initializers/active_admin.rb`, search `csv_options` and set the csv separator as it's showed in the file.
51
+
52
+ ## Wishlist / TODOS
53
+
54
+ 1. Add Appraisal to test against multiple versions of Rails
55
+
56
+ ## Specs
57
+ ```
58
+ bundle exec rspec spec
59
+ ```
60
+ The test suite is limited, but it's a start.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
@@ -1,26 +1,27 @@
1
- module ActiveAdminCsvImport::Convenience
2
- extend ActiveSupport::Concern
1
+ module ActiveAdminCsvImport
2
+ module Convenience
3
+ extend ActiveSupport::Concern
3
4
 
4
- module ClassMethods
5
- # Look up a belongs_to association by name.
6
- # E.g.
7
- # lookup_belongs_to :state, by: :name
8
- # Adds state_name as an ivar.
9
- def lookup_belongs_to(name, options)
5
+ module ClassMethods
6
+ # Look up a belongs_to association by name.
7
+ # E.g.
8
+ # lookup_belongs_to :state, by: :name
9
+ # Adds state_name as an ivar.
10
+ def lookup_belongs_to(name, options)
11
+ lookup_by = options[:by]
10
12
 
11
- lookup_by = options[:by]
13
+ code = <<-eoruby
14
+ attr_accessor :#{name}_#{lookup_by}
12
15
 
13
- code = <<-eoruby
14
- attr_accessor :#{name}_#{lookup_by}
16
+ before_validation :lookup_#{name}_by_#{lookup_by}
15
17
 
16
- before_validation :lookup_#{name}_by_#{lookup_by}
17
-
18
- def lookup_#{name}_by_#{lookup_by}
19
- return if self.#{name}_#{lookup_by}.blank?
20
- self.#{name} = '#{name}'.camelize.constantize.where(#{lookup_by}: self.#{name}_#{lookup_by}).first
18
+ def lookup_#{name}_by_#{lookup_by}
19
+ return if self.#{name}_#{lookup_by}.blank?
20
+ self.#{name} = '#{name}'.camelize.constantize.where(#{lookup_by}: self.#{name}_#{lookup_by}).first
21
+ end
22
+ eoruby
23
+ class_eval(code)
21
24
  end
22
- eoruby
23
- class_eval(code)
24
25
  end
25
26
  end
26
27
  end
@@ -1,10 +1,10 @@
1
- require "active_admin_csv_import/engine"
2
- require "active_admin_csv_import/dsl"
3
- require "active_admin_csv_import/railtie"
4
- require "active_admin_csv_import/version"
1
+ require 'active_admin_csv_import/engine'
2
+ require 'active_admin_csv_import/dsl'
3
+ require 'active_admin_csv_import/railtie'
4
+ require 'active_admin_csv_import/version'
5
5
  require 'activeadmin'
6
6
 
7
7
  module ActiveAdminCsvImport
8
8
  end
9
9
 
10
- ::ActiveAdmin::DSL.send(:include, ActiveAdminCsvImport::DSL)
10
+ ::ActiveAdmin::DSL.send(:include, ActiveAdminCsvImport::DSL)
@@ -2,17 +2,17 @@ require 'csv'
2
2
 
3
3
  module ActiveAdminCsvImport
4
4
  module DSL
5
-
6
- def csv_importable(options={})
7
-
5
+ def csv_importable(options = {})
8
6
  # All columns
9
- columns = options[:columns] ||= active_admin_config.resource_class.columns.map(&:name) - ["id", "updated_at", "created_at"]
7
+ columns = options[:columns] ||= active_admin_config.resource_class.columns.map(&:name) - %(id updated_at created_at)
10
8
 
11
- # Required columns. A subset of all columns. A client-side validation error is raised if one of these is not found.
9
+ # Required columns. A subset of all columns.
10
+ # A client-side validation error is raised if one of these is not found.
12
11
  required_columns = options[:required_columns] ||= columns
13
12
 
14
- action_item :only => :index do
15
- link_to "Import #{active_admin_config.resource_name.to_s.pluralize}", :action => 'import_csv'
13
+ action_item :import_csv, :only => :index do
14
+ link_to "Import #{active_admin_config.resource_name.to_s.pluralize}",
15
+ :action => 'import_csv'
16
16
  end
17
17
 
18
18
  # Returns an example CSV based on the columns expected for import.
@@ -20,27 +20,31 @@ module ActiveAdminCsvImport
20
20
  csv_column_names = CSV.generate do |csv|
21
21
  csv << columns.map(&:to_s).map(&:humanize)
22
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")
23
+ send_data(csv_column_names,
24
+ type: 'text/csv; charset=utf-8; header=present',
25
+ filename: active_admin_config
26
+ .resource_class.name.to_s.pluralize + '.csv')
24
27
  end
25
28
 
26
- # Shows the form and JS which accepts a CSV file, parses it and posts each row to the server.
29
+ # Shows the form and JS which accepts a CSV file,
30
+ # parses it and posts each row to the server.
27
31
  collection_action :import_csv do
28
32
  @columns = columns
29
33
  @required_columns = required_columns
30
34
 
31
35
  @post_path = options[:path].try(:call)
32
- @post_path ||= collection_path + "/import_rows"
36
+ @post_path ||= collection_path + '/import_rows'
33
37
 
34
38
  @redirect_path = options[:redirect_path].try(:call)
35
39
  @redirect_path ||= collection_path
36
40
 
37
41
  @delimiter = options[:delimiter]
38
42
 
39
- render "admin/csv/import_csv"
43
+ render 'admin/csv/import_csv'
40
44
  end
41
45
 
42
46
  # Receives each row and saves it
43
- collection_action :import_rows, :method => :post do
47
+ collection_action :import_rows, method: :post do
44
48
 
45
49
  @failures = []
46
50
 
@@ -49,9 +53,9 @@ module ActiveAdminCsvImport
49
53
  row_number = row_params.delete('_row')
50
54
 
51
55
  resource = existing_row_resource(options[:import_unique_key], row_params)
52
- resource ||= active_admin_config.resource_class.new()
56
+ resource ||= active_admin_config.resource_class.new
53
57
 
54
- if not update_row_resource(resource, row_params)
58
+ unless update_row_resource(resource, row_params)
55
59
  @failures << {
56
60
  row_number: row_number,
57
61
  resource: resource
@@ -59,7 +63,7 @@ module ActiveAdminCsvImport
59
63
  end
60
64
  end
61
65
 
62
- render :partial => "admin/csv/import_csv_failed_row", :status => 200
66
+ render partial: 'admin/csv/import_csv_failed_row', status: 200
63
67
  end
64
68
 
65
69
  # Rails 4 Strong Parameters compatibility and backwards compatibility.
@@ -90,11 +94,9 @@ module ActiveAdminCsvImport
90
94
  value = params[lookup_column]
91
95
  return unless value.present?
92
96
 
93
- return active_admin_config.resource_class.send(finder_method, value)
97
+ active_admin_config.resource_class.send(finder_method, value)
94
98
  end
95
99
  end
96
-
97
100
  end
98
-
99
101
  end
100
102
  end
@@ -1,8 +1,8 @@
1
1
  class Railtie < ::Rails::Railtie
2
- initializer "active_admin_csv_import.setup_vendor", :after => "active_admin_csv_import.setup", :group => :all do |app|
3
- vendor_path = File.expand_path("../../vendor/assets", __FILE__)
2
+ initializer 'active_admin_csv_import.setup_vendor', after: 'active_admin_csv_import.setup', group: :all do |app|
3
+ vendor_path = File.expand_path('../../vendor/assets', __FILE__)
4
4
  app.config.assets.paths.push(vendor_path.to_s)
5
5
 
6
6
  app.config.assets.precompile += %w( active_admin_csv_import/import_csv.js )
7
7
  end
8
- end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminCsvImport
2
- VERSION = "1.3.1"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,38 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_csv_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tomas Spacek
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2015-01-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70177170926380 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: '3.1'
19
+ version: '4.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70177170926380
25
- - !ruby/object:Gem::Dependency
26
- name: railties
27
- requirement: &70177170940860 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: '3.1'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70177170940860
26
+ version: '4.0'
36
27
  description: CSV import for Active Admin capable of handling CSV files too large to
37
28
  import via direct file upload to Heroku
38
29
  email:
@@ -41,16 +32,19 @@ executables: []
41
32
  extensions: []
42
33
  extra_rdoc_files: []
43
34
  files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
44
38
  - app/assets/javascripts/active_admin_csv_import/import_csv.js
45
39
  - app/models/concerns/active_admin_csv_import/convenience.rb
46
40
  - app/views/admin/csv/_import_csv_failed_row.html.erb
47
41
  - app/views/admin/csv/_instructions.html.erb
48
42
  - app/views/admin/csv/import_csv.html.erb
43
+ - lib/active_admin_csv_import.rb
49
44
  - lib/active_admin_csv_import/dsl.rb
50
45
  - lib/active_admin_csv_import/engine.rb
51
46
  - lib/active_admin_csv_import/railtie.rb
52
47
  - lib/active_admin_csv_import/version.rb
53
- - lib/active_admin_csv_import.rb
54
48
  - vendor/assets/javascripts/backbone/backbone.js
55
49
  - vendor/assets/javascripts/backbone/json2.js
56
50
  - vendor/assets/javascripts/backbone/underscore.js
@@ -58,32 +52,28 @@ files:
58
52
  - vendor/assets/javascripts/recline/backend.memory.js
59
53
  - vendor/assets/javascripts/recline/model.js
60
54
  - vendor/assets/javascripts/underscore.string.min.js
61
- - MIT-LICENSE
62
- - Rakefile
63
- - README.rdoc
64
55
  homepage: http://www.papercloud.com.au
65
56
  licenses: []
57
+ metadata: {}
66
58
  post_install_message:
67
59
  rdoc_options: []
68
60
  require_paths:
69
61
  - lib
70
62
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
63
  requirements:
73
- - - ! '>='
64
+ - - ">="
74
65
  - !ruby/object:Gem::Version
75
66
  version: '0'
76
67
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
68
  requirements:
79
- - - ! '>='
69
+ - - ">="
80
70
  - !ruby/object:Gem::Version
81
71
  version: '0'
82
72
  requirements: []
83
73
  rubyforge_project:
84
- rubygems_version: 1.8.15
74
+ rubygems_version: 2.2.2
85
75
  signing_key:
86
- specification_version: 3
76
+ specification_version: 4
87
77
  summary: Add CSV import to Active Admin
88
78
  test_files: []
89
79
  has_rdoc:
@@ -1,3 +0,0 @@
1
- = ActiveAdminCsvImport
2
-
3
- This project rocks and uses MIT-LICENSE.