rails_admin_import 0.1.3 → 0.1.4

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.
@@ -76,8 +76,8 @@
76
76
  </table>
77
77
 
78
78
  <%= form_tag rails_admin.import_url(@abstract_model.to_param), :multipart => true do |f| -%>
79
+ <h5 style="color:red;">Please limit upload file to <%= RailsAdminImport.config.line_item_limit %> line items.</h5>
79
80
  <%= file_field_tag :file %>
80
-
81
81
  <p>
82
82
  <%= check_box_tag :update_if_exists %> Update if Exists<br />
83
83
  Update lookup field
@@ -10,6 +10,7 @@ module RailsAdminImport
10
10
  # @see RailsAdminImport::Config.model
11
11
  attr_reader :registry
12
12
  attr_accessor :logging
13
+ attr_accessor :line_item_limit
13
14
 
14
15
  # Loads a model configuration instance from the registry or registers
15
16
  # a new one if one is yet to be added.
@@ -37,6 +38,7 @@ module RailsAdminImport
37
38
  def reset
38
39
  @registry = {}
39
40
  @logging = false
41
+ @line_item_limit = 1000
40
42
  end
41
43
 
42
44
  # Reset a provided model's configuration.
@@ -60,7 +60,11 @@ module RailsAdminImport
60
60
 
61
61
  text = File.read(params[:file].tempfile)
62
62
  clean = text.gsub(/\n$/, '')
63
- file = CSV.new(clean)
63
+ file_check = CSV.new(clean)
64
+
65
+ if file_check.readlines.size > RailsAdminImport.config.line_item_limit
66
+ return results = { :success => [], :error => ["Please limit upload file to #{RailsAdminImport.config.line_item_limit} line items."] }
67
+ end
64
68
 
65
69
  if RailsAdminImport.config.logging
66
70
  FileUtils.copy(params[:file].tempfile, "#{Rails.root}/log/import/#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}-import.csv")
@@ -69,6 +73,7 @@ module RailsAdminImport
69
73
 
70
74
  map = {}
71
75
 
76
+ file = CSV.new(clean)
72
77
  file.readline.each_with_index do |key, i|
73
78
  if self.many_fields.include?(key.to_sym)
74
79
  map[key.to_sym] ||= []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: steph@endpoint.com