administrate_exportable 0.1.2 → 0.1.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
- SHA256:
3
- metadata.gz: 7290e0d143c8778841f5ab7a66582b2cb5c93d36bad718b2fe715b918f21f66c
4
- data.tar.gz: ff79db8b3840e3db6fc79863d94642d139bc3db9030137b24d24f4f947a9fefe
2
+ SHA1:
3
+ metadata.gz: 35b8f7ad01eec64832238b828b49732ffa7180ba
4
+ data.tar.gz: 26a780ff2ed1b139d23846d58df47f55dca525aa
5
5
  SHA512:
6
- metadata.gz: 7e5fb82aa7007d995fd098e9c7668ca9b3778cb36b9f04f1f88e158e0caf9a1f19173f46a4f79fb6dda8af93450c9195b2d1b89e1911eb4ea0a90009999cab45
7
- data.tar.gz: 41e667a0049aa408dcdfc73bf640881e9287e8554731ff93714804a4ae537085b43c3bd4a162b72d8ae2c44908d9cdd4bcfb28152a154b572b0d913dad4fb5d8
6
+ metadata.gz: 35ce161fee48f84948d18d23875e97f48f8a8d939bceb47397ba182bade08fb47d0f092effebb328ce9562a80808b816ed159cc706aec283f495881868e77d05
7
+ data.tar.gz: 749519e9a9f5517e7da047801e0b6f4b0380a78eb3617bce11f7ff1efdcaac528cf63b247739074d5d3f8b6e33697d704514a75071693496d902c725f0cedb4f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate_exportable (0.1.0)
4
+ administrate_exportable (0.1.3)
5
5
  actionview (>= 5.2.2.1)
6
6
  administrate (> 0.10.0)
7
7
  rails (>= 4.2)
@@ -51,23 +51,23 @@ GEM
51
51
  i18n (>= 0.7, < 2)
52
52
  minitest (~> 5.1)
53
53
  tzinfo (~> 1.1)
54
- administrate (0.11.0)
55
- actionpack (>= 4.2, < 6.0)
56
- actionview (>= 4.2, < 6.0)
57
- activerecord (>= 4.2, < 6.0)
54
+ administrate (0.12.0)
55
+ actionpack (>= 4.2)
56
+ actionview (>= 4.2)
57
+ activerecord (>= 4.2)
58
58
  autoprefixer-rails (>= 6.0)
59
59
  datetime_picker_rails (~> 0.0.7)
60
60
  jquery-rails (>= 4.0)
61
61
  kaminari (>= 1.0)
62
62
  momentjs-rails (~> 2.8)
63
- sass-rails (~> 5.0)
63
+ sassc-rails (~> 2.1)
64
64
  selectize-rails (~> 0.6)
65
65
  administrate-field-enumerate (0.0.1)
66
66
  administrate
67
67
  enumerate_it
68
68
  rails (>= 4.2, < 6.0)
69
69
  arel (9.0.0)
70
- autoprefixer-rails (9.6.1)
70
+ autoprefixer-rails (9.6.4)
71
71
  execjs
72
72
  builder (3.2.3)
73
73
  byebug (11.0.1)
@@ -79,12 +79,12 @@ GEM
79
79
  diff-lcs (1.3)
80
80
  enumerate_it (2.0.0)
81
81
  activesupport (>= 4.0.0)
82
- erubi (1.8.0)
82
+ erubi (1.9.0)
83
83
  execjs (2.7.0)
84
84
  ffi (1.11.1)
85
85
  globalid (0.4.2)
86
86
  activesupport (>= 4.2.0)
87
- i18n (1.6.0)
87
+ i18n (1.7.0)
88
88
  concurrent-ruby (~> 1.0)
89
89
  jquery-rails (4.3.5)
90
90
  rails-dom-testing (>= 1, < 3)
@@ -102,7 +102,7 @@ GEM
102
102
  activerecord
103
103
  kaminari-core (= 1.1.1)
104
104
  kaminari-core (1.1.1)
105
- loofah (2.2.3)
105
+ loofah (2.3.0)
106
106
  crass (~> 1.0.2)
107
107
  nokogiri (>= 1.5.9)
108
108
  mail (2.7.1)
@@ -113,11 +113,11 @@ GEM
113
113
  mimemagic (0.3.3)
114
114
  mini_mime (1.0.2)
115
115
  mini_portile2 (2.4.0)
116
- minitest (5.11.3)
116
+ minitest (5.12.2)
117
117
  momentjs-rails (2.20.1)
118
118
  railties (>= 3.1)
119
119
  nio4r (2.4.0)
120
- nokogiri (1.10.3)
120
+ nokogiri (1.10.4)
121
121
  mini_portile2 (~> 2.4.0)
122
122
  pry (0.12.2)
123
123
  coderay (~> 1.1.0)
@@ -144,18 +144,15 @@ GEM
144
144
  rails-dom-testing (2.0.3)
145
145
  activesupport (>= 4.2.0)
146
146
  nokogiri (>= 1.6)
147
- rails-html-sanitizer (1.1.0)
148
- loofah (~> 2.2, >= 2.2.2)
147
+ rails-html-sanitizer (1.3.0)
148
+ loofah (~> 2.3)
149
149
  railties (5.2.3)
150
150
  actionpack (= 5.2.3)
151
151
  activesupport (= 5.2.3)
152
152
  method_source
153
153
  rake (>= 0.8.7)
154
154
  thor (>= 0.19.0, < 2.0)
155
- rake (12.3.3)
156
- rb-fsevent (0.10.3)
157
- rb-inotify (0.10.0)
158
- ffi (~> 1.0)
155
+ rake (13.0.0)
159
156
  rb-readline (0.5.5)
160
157
  rspec-core (3.8.2)
161
158
  rspec-support (~> 3.8.0)
@@ -174,17 +171,14 @@ GEM
174
171
  rspec-mocks (~> 3.8.0)
175
172
  rspec-support (~> 3.8.0)
176
173
  rspec-support (3.8.2)
177
- sass (3.7.4)
178
- sass-listen (~> 4.0.0)
179
- sass-listen (4.0.0)
180
- rb-fsevent (~> 0.9, >= 0.9.4)
181
- rb-inotify (~> 0.9, >= 0.9.7)
182
- sass-rails (5.0.7)
183
- railties (>= 4.0.0, < 6)
184
- sass (~> 3.1)
185
- sprockets (>= 2.8, < 4.0)
186
- sprockets-rails (>= 2.0, < 4.0)
187
- tilt (>= 1.1, < 3)
174
+ sassc (2.2.1)
175
+ ffi (~> 1.9)
176
+ sassc-rails (2.1.2)
177
+ railties (>= 4.0.0)
178
+ sassc (>= 2.0)
179
+ sprockets (> 3.0)
180
+ sprockets-rails
181
+ tilt
188
182
  selectize-rails (0.12.6)
189
183
  sprockets (3.7.2)
190
184
  concurrent-ruby (~> 1.0)
@@ -196,7 +190,7 @@ GEM
196
190
  sqlite3 (1.4.1)
197
191
  thor (0.20.3)
198
192
  thread_safe (0.3.6)
199
- tilt (2.0.9)
193
+ tilt (2.0.10)
200
194
  tzinfo (1.2.5)
201
195
  thread_safe (~> 0.1)
202
196
  websocket-driver (0.7.1)
@@ -207,7 +201,7 @@ PLATFORMS
207
201
  ruby
208
202
 
209
203
  DEPENDENCIES
210
- administrate
204
+ administrate (~> 0.12.0)
211
205
  administrate-field-enumerate
212
206
  administrate_exportable!
213
207
  byebug
data/README.md CHANGED
@@ -56,7 +56,7 @@ ATTRIBUTE_TYPES = {
56
56
 
57
57
  By default the gem adds the Export button to the view `views/admin/application/index.html.erb`. But if you have your own Administrate `index` views, you can add the link manually:
58
58
  ```ruby
59
- link_to('Export', [:export, namespace, page.resource_name.to_s.pluralize, { format: :csv }], class: 'button') if valid_action?(:export)
59
+ link_to('Export', [:export, namespace, page.resource_name.to_s.pluralize, sanitized_order_params(page).to_h.merge(format: :csv)], class: 'button') if valid_action?(:export) %>
60
60
  ```
61
61
 
62
62
  Example:
@@ -72,7 +72,7 @@ Example:
72
72
  [:new, namespace, page.resource_path],
73
73
  class: "button",
74
74
  ) if valid_action?(:new) && show_action?(:new, new_resource) %>
75
- <%= link_to('Export', [:export, namespace, page.resource_name.to_s.pluralize, { format: :csv }], class: 'button') if valid_action?(:export) %>
75
+ <%= link_to('Export', [:export, namespace, page.resource_name.to_s.pluralize, sanitized_order_params(page).to_h.merge(format: :csv)], class: 'button') if valid_action?(:export) %>
76
76
  </div>
77
77
  ....
78
78
  ```
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "bundler", "~> 1.16"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "pry-byebug", "~> 3.0"
35
36
  spec.add_dependency 'administrate','> 0.10.0'
36
37
  spec.add_dependency 'rails', '>= 4.2'
37
38
  spec.add_dependency 'actionview', '>= 5.2.2.1'
@@ -45,11 +45,7 @@ It renders the `_table` partial to display details about the resources.
45
45
  [:new, namespace, page.resource_path],
46
46
  class: "button",
47
47
  ) if valid_action?(:new) && show_action?(:new, new_resource) %>
48
- <%= link_to(
49
- 'Export',
50
- [:export, namespace, page.resource_name.to_s.pluralize, { format: :csv }],
51
- class: 'button'
52
- ) if valid_action?(:export) %>
48
+ <%= link_to('Export', [:export, namespace, page.resource_name.to_s.pluralize, sanitized_order_params(page, :id).to_h.merge(format: :csv)], class: 'button') if valid_action?(:export) %>
53
49
  </div>
54
50
  </header>
55
51
 
@@ -9,7 +9,14 @@ module AdministrateExportable
9
9
  class_methods do
10
10
  def exportable
11
11
  define_method(:export) do
12
- csv_data = ExporterService.csv(dashboard, resource_class)
12
+ search_term = params[:search].to_s.strip
13
+ resources = Administrate::Search.new(scoped_resource,
14
+ dashboard_class,
15
+ search_term).run
16
+ resources = apply_collection_includes(resources)
17
+ resources = order.apply(resources)
18
+
19
+ csv_data = ExporterService.csv(dashboard, resource_class, resources)
13
20
 
14
21
  respond_to do |format|
15
22
  format.csv { send_data csv_data, filename: "#{resource_name.to_s.pluralize}-#{Date.today}.csv" }
@@ -2,13 +2,14 @@ require 'csv'
2
2
 
3
3
  module AdministrateExportable
4
4
  class ExporterService
5
- def self.csv(dashboard, resource_class)
6
- new(dashboard, resource_class).csv
5
+ def self.csv(dashboard, resource_class, resources)
6
+ new(dashboard, resource_class, resources).csv
7
7
  end
8
8
 
9
- def initialize(dashboard, resource_class)
9
+ def initialize(dashboard, resource_class, resources)
10
10
  @dashboard = dashboard
11
11
  @resource_class = resource_class
12
+ @resources = resources
12
13
  end
13
14
 
14
15
  def csv
@@ -26,7 +27,7 @@ module AdministrateExportable
26
27
 
27
28
  private
28
29
 
29
- attr_reader :dashboard, :resource_class, :sanitizer
30
+ attr_reader :dashboard, :resource_class, :resources, :sanitizer
30
31
 
31
32
  def record_attribute(record, attribute_key, attribute_type)
32
33
  field = attribute_type.new(attribute_key, record.send(attribute_key), 'index', resource: record)
@@ -80,12 +81,7 @@ module AdministrateExportable
80
81
  end
81
82
 
82
83
  def collection
83
- relation = resource_class.default_scoped
84
- resource_includes = dashboard.collection_includes
85
-
86
- return relation if resource_includes.empty?
87
-
88
- relation.includes(*resource_includes)
84
+ resources
89
85
  end
90
86
  end
91
87
  end
@@ -1,3 +1,3 @@
1
1
  module AdministrateExportable
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate_exportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Rancan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-09-14 00:00:00.000000000 Z
12
+ date: 2019-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry-byebug
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: administrate
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  requirements: []
154
- rubygems_version: 3.0.6
168
+ rubyforge_project:
169
+ rubygems_version: 2.6.13
155
170
  signing_key:
156
171
  specification_version: 4
157
172
  summary: Simple plugin to add CSV export feature to Administrate