importr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 200e1ae712c85a1384e4457b03d2e03b27879d03
4
- data.tar.gz: bd1a84310f148253bfc741fd3912f7e060ccfa57
3
+ metadata.gz: 17a29355c196c8aac87b18a1d1aeb27d896897f2
4
+ data.tar.gz: aba05d865b2156224475e6a1aa94e13342ad7bf1
5
5
  SHA512:
6
- metadata.gz: 1661949302202ec3f98a1dd462228c0665cc8747b1bbbdf42dc5ee2e9011c4f513df2d30206570dedc943d64eee0dc1f9f3a953bc16ef4d0bb0073c14212e7cb
7
- data.tar.gz: 45be464372780cb563481e5f702d9f4b899ea628754c3952fd321792601e88936734d46d3893f55390bf3df709c877f30cc3350d1074defae57ae4599d5ca4c2
6
+ metadata.gz: 837ea81edf3b88a6ead963188b7d40b52e67f8614232118ea58745745de24efa7303cca5d00ede087253128e1e9039e7015605a184800e337e88330ff3328a66
7
+ data.tar.gz: 51f72029dfa4253f11f1ea7b32c847a9f4c87b88dce0272fb88f1d074758df8c77df42874ec5b88d23bc22bee33da1c26c4f781922ccbdbe48c7649c1f368913
@@ -5,5 +5,12 @@
5
5
  Row Number
6
6
  %th
7
7
  Error Messages
8
+
8
9
  %tbody
9
- %tr
10
+
11
+ - @data_import.error_messages.each do |err|
12
+ %tr
13
+ %td= err[:index]
14
+ %td= err[:error]
15
+
16
+
@@ -1,12 +1,17 @@
1
1
  :javascript
2
2
  (function() {
3
-
4
-
5
3
  var client = new Faye.Client("#{websocket_url_service}", { retry: 5 });
6
4
 
5
+ var max = {
6
+ processed_rows: 0,
7
+ success_count: 0,
8
+ error_count: 0,
9
+ };
10
+
7
11
  function update_row_count(message) {
8
12
  if (typeof(message.processed_rows) != 'undefined') {
9
- $('#rows-processed').html('' + message.processed_rows + ' / ' + message.total_rows)
13
+ max.processed_rows = Math.max(message.processed_rows, max.processed_rows)
14
+ $('#rows-processed').html('' + max.processed_rows + ' / ' + message.total_rows)
10
15
  }
11
16
  console.log(message)
12
17
  }
@@ -18,13 +23,15 @@
18
23
 
19
24
  client.subscribe("#{@data_import.websocket_channel(:error)}", function(message) {
20
25
  update_row_count(message)
21
- $('#rows-with-errors').html(message.error_count)
26
+ max.error_count = Math.max(message.error_count, max.error_count)
27
+ $('#rows-with-errors').html(max.error_count)
22
28
 
23
29
  $('#row-errors-panel tbody').append("<tr><td>" + message.index + "</td><td>" + message.error + "</td></tr>")
24
30
  $('#row-errors-panel').show();
25
31
  });
26
32
 
27
33
  client.subscribe("#{@data_import.websocket_channel(:success)}", function(message) {
34
+ max.success_count = Math.max(message.success_count, max.success_count)
28
35
  update_row_count(message)
29
36
  });
30
37
 
@@ -8,7 +8,7 @@ module Importr
8
8
  importer_type ||= "#{klass}Importer".constantize
9
9
 
10
10
  action_item :only => :index do
11
- link_to 'Import from Excel', :action => 'upload_excel'
11
+ link_to 'Import from Excel', :action => 'upload_excel' #if current_admin_user.is_admin?
12
12
  end
13
13
 
14
14
  collection_action :upload_excel do
@@ -27,8 +27,14 @@ module Importr
27
27
  end
28
28
 
29
29
  controller do
30
- def permitted_params
31
- params.permit data_import: [:document, :uuid, :importer_type]
30
+ before_filter :check_permisions, only: [:import_excel, :upload_excel]
31
+
32
+ def check_permisions
33
+ self.send(Importr::Config.restriction_method.to_sym) unless Importr::Config.restriction_method.blank?
34
+ end
35
+
36
+ def importer_params
37
+ {data_import: [:document, :uuid, :importer_type]}
32
38
  end
33
39
  end
34
40
  end
@@ -8,7 +8,8 @@ module Importr
8
8
  end
9
9
 
10
10
  mattr_accessor :web_socket_class, :web_socket_method,
11
- :websocket_url_service, :websocket_client_script
11
+ :websocket_url_service, :websocket_client_script,
12
+ :restriction_method
12
13
 
13
14
 
14
15
  end
@@ -14,24 +14,21 @@ module Importr
14
14
 
15
15
  alias_method :data_import, :context
16
16
 
17
- def row_success
18
- super
17
+ on :row_success do
19
18
  update_counters
20
19
  notify(:success, @counters)
21
20
  end
22
21
 
23
- def row_error(error_message)
24
- super
25
- update_counters
26
- notify(:error, @counters.merge(index: row_index, error: error_message))
22
+ on :row_error do |e|
23
+ update_counters({index: row_index, error: e.message})
24
+ notify(:error, @counters.merge(index: row_index, error: e.message))
27
25
  end
28
26
 
29
- def import_failed(error_message)
30
- super
31
- notify(:base, error: error_message)
27
+ on :import_failed do |e|
28
+ notify(:base, error: e.message)
32
29
  end
33
30
 
34
- def import_finished
31
+ on :import_finished do
35
32
  data_import.update_attribute(:finished, true) if data_import
36
33
  end
37
34
 
@@ -42,14 +39,21 @@ module Importr
42
39
  Importr::Notifier.notify(channel, message)
43
40
  end
44
41
 
45
- def update_counters
42
+ def update_counters(err= {})
46
43
  @counters = {
47
44
  success_count: row_success_count,
48
45
  error_count: row_error_count,
49
46
  processed_rows: row_processed_count,
50
47
  total_rows: row_count,
51
48
  }
52
- data_import.update_attributes(@counters) if data_import
49
+ if data_import
50
+ data_import.update_attributes(@counters)
51
+ add_error(err) unless err.blank?
52
+ end
53
+ end
54
+
55
+ def add_error(err)
56
+ data_import.update_attributes(error_messages: data_import.error_messages << err ) if data_import
53
57
  end
54
58
  end
55
59
  end
@@ -1,3 +1,3 @@
1
1
  module Importr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Garcia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-06 00:00:00.000000000 Z
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: active_importer
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 0.2.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 0.2.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: carrierwave
44
44
  requirement: !ruby/object:Gem::Requirement