activeadmin_jobs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +280 -0
- data/MIT-LICENSE +20 -0
- data/README.md +272 -0
- data/Rakefile +21 -0
- data/activeadmin_jobs.gemspec +35 -0
- data/app/admin/jobs.rb +30 -0
- data/app/assets/images/activeadmin_jobs/.keep +0 -0
- data/app/assets/javascripts/activeadmin_jobs/application.js +13 -0
- data/app/assets/javascripts/activeadmin_jobs/base.js +3 -0
- data/app/assets/javascripts/activeadmin_jobs/growl_setup.js.erb +115 -0
- data/app/assets/stylesheets/activeadmin_jobs/application.css +15 -0
- data/app/assets/stylesheets/activeadmin_jobs/base.scss +19 -0
- data/app/controllers/activeadmin_jobs/application_controller.rb +4 -0
- data/app/helpers/activeadmin_jobs/application_helper.rb +4 -0
- data/app/views/layouts/activeadmin_jobs/application.html.erb +14 -0
- data/bin/rails +12 -0
- data/config/locales/activeadmin_jobs.en.yml +24 -0
- data/config/locales/activeadmin_jobs.es.yml +24 -0
- data/config/routes.rb +2 -0
- data/docs/images/error-notification.png +0 -0
- data/docs/images/error-view.png +0 -0
- data/docs/images/import-form.png +0 -0
- data/docs/images/jobs-example.gif +0 -0
- data/docs/images/jobs-list.png +0 -0
- data/docs/images/success-notification.png +0 -0
- data/docs/images/success-view.png +0 -0
- data/lib/activeadmin_jobs.rb +8 -0
- data/lib/activeadmin_jobs/activeadmin_config.rb +31 -0
- data/lib/activeadmin_jobs/engine.rb +16 -0
- data/lib/activeadmin_jobs/i18n_dictionary.rb +7 -0
- data/lib/activeadmin_jobs/job_extensions.rb +11 -0
- data/lib/activeadmin_jobs/job_result_renderer.rb +27 -0
- data/lib/activeadmin_jobs/version.rb +3 -0
- data/lib/generators/activeadmin_jobs/install/USAGE +5 -0
- data/lib/generators/activeadmin_jobs/install/install_generator.rb +18 -0
- data/lib/tasks/activeadmin_jobs_tasks.rake +4 -0
- metadata +331 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 247bf751fb99e82fa5102afb73e50bd748c427ed
|
4
|
+
data.tar.gz: 5da929cd88a48ed17bedf8b290a78a16ed378578
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec4dd211b6c1de9e73b07931088c9b95ae28a66832d14ddda515265ecbeaf280487c4161c22fcc75389a0a93bacdff1fc5d81ee580ac13046e88ee6c615754b9
|
7
|
+
data.tar.gz: e0737dccf487852412e95177695d6a78eaa660681fefda1059b63c78f966597bae20fbb450cf0a1a827527c344f0d998a183d80bc6a78fa55457ae7bdf2f1e61
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
source 'https://rails-assets.org' do
|
4
|
+
gem 'rails-assets-growl'
|
5
|
+
end
|
6
|
+
|
7
|
+
# Declare your gem's dependencies in activeadmin_jobs.gemspec.
|
8
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
9
|
+
# development dependencies will be added by default to the :development group.
|
10
|
+
gemspec
|
11
|
+
|
12
|
+
# Declare any dependencies that are still in development here instead of in
|
13
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
14
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
15
|
+
# your gem to rubygems.org.
|
16
|
+
|
17
|
+
# To use a debugger
|
18
|
+
# gem 'byebug', group: [:development, :test]
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activeadmin_jobs (0.1.0)
|
5
|
+
activeadmin (~> 1.0.0.pre2)
|
6
|
+
activeadmin_addons (~> 0.9, >= 0.9.2)
|
7
|
+
devise (~> 3.5, >= 3.5.0)
|
8
|
+
job_notifier (~> 1.1, >= 1.1.1)
|
9
|
+
rails (~> 4.2, >= 4.2.0)
|
10
|
+
rails-assets-growl (~> 1.3, >= 1.3.1)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
remote: https://rails-assets.org/
|
15
|
+
specs:
|
16
|
+
actionmailer (4.2.6)
|
17
|
+
actionpack (= 4.2.6)
|
18
|
+
actionview (= 4.2.6)
|
19
|
+
activejob (= 4.2.6)
|
20
|
+
mail (~> 2.5, >= 2.5.4)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
actionpack (4.2.6)
|
23
|
+
actionview (= 4.2.6)
|
24
|
+
activesupport (= 4.2.6)
|
25
|
+
rack (~> 1.6)
|
26
|
+
rack-test (~> 0.6.2)
|
27
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
+
actionview (4.2.6)
|
30
|
+
activesupport (= 4.2.6)
|
31
|
+
builder (~> 3.1)
|
32
|
+
erubis (~> 2.7.0)
|
33
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
35
|
+
activeadmin (1.0.0.pre4)
|
36
|
+
arbre (~> 1.0, >= 1.0.2)
|
37
|
+
bourbon
|
38
|
+
coffee-rails
|
39
|
+
formtastic (~> 3.1)
|
40
|
+
formtastic_i18n
|
41
|
+
inherited_resources (~> 1.6)
|
42
|
+
jquery-rails
|
43
|
+
jquery-ui-rails
|
44
|
+
kaminari (~> 0.15)
|
45
|
+
rails (>= 3.2, < 5.1)
|
46
|
+
ransack (~> 1.3)
|
47
|
+
sass-rails
|
48
|
+
sprockets (< 4)
|
49
|
+
activeadmin_addons (0.9.3)
|
50
|
+
railties
|
51
|
+
select2-rails (~> 3.5.9)
|
52
|
+
xdan-datetimepicker-rails (~> 2.5.1)
|
53
|
+
activejob (4.2.6)
|
54
|
+
activesupport (= 4.2.6)
|
55
|
+
globalid (>= 0.3.0)
|
56
|
+
activemodel (4.2.6)
|
57
|
+
activesupport (= 4.2.6)
|
58
|
+
builder (~> 3.1)
|
59
|
+
activerecord (4.2.6)
|
60
|
+
activemodel (= 4.2.6)
|
61
|
+
activesupport (= 4.2.6)
|
62
|
+
arel (~> 6.0)
|
63
|
+
activesupport (4.2.6)
|
64
|
+
i18n (~> 0.7)
|
65
|
+
json (~> 1.7, >= 1.7.7)
|
66
|
+
minitest (~> 5.1)
|
67
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
68
|
+
tzinfo (~> 1.1)
|
69
|
+
addressable (2.4.0)
|
70
|
+
arbre (1.1.1)
|
71
|
+
activesupport (>= 3.0.0)
|
72
|
+
arel (6.0.3)
|
73
|
+
bcrypt (3.1.11)
|
74
|
+
bourbon (4.2.7)
|
75
|
+
sass (~> 3.4)
|
76
|
+
thor (~> 0.19)
|
77
|
+
builder (3.2.2)
|
78
|
+
capybara (2.7.0)
|
79
|
+
addressable
|
80
|
+
mime-types (>= 1.16)
|
81
|
+
nokogiri (>= 1.3.3)
|
82
|
+
rack (>= 1.0.0)
|
83
|
+
rack-test (>= 0.5.4)
|
84
|
+
xpath (~> 2.0)
|
85
|
+
childprocess (0.5.9)
|
86
|
+
ffi (~> 1.0, >= 1.0.11)
|
87
|
+
coderay (1.1.1)
|
88
|
+
coffee-rails (4.2.1)
|
89
|
+
coffee-script (>= 2.2.0)
|
90
|
+
railties (>= 4.0.0, < 5.2.x)
|
91
|
+
coffee-script (2.4.1)
|
92
|
+
coffee-script-source
|
93
|
+
execjs
|
94
|
+
coffee-script-source (1.10.0)
|
95
|
+
colorize (0.8.1)
|
96
|
+
concurrent-ruby (1.0.2)
|
97
|
+
daemons (1.2.3)
|
98
|
+
database_cleaner (1.5.3)
|
99
|
+
delayed_job (4.1.2)
|
100
|
+
activesupport (>= 3.0, < 5.1)
|
101
|
+
delayed_job_active_record (4.1.1)
|
102
|
+
activerecord (>= 3.0, < 5.1)
|
103
|
+
delayed_job (>= 3.0, < 5)
|
104
|
+
devise (3.5.10)
|
105
|
+
bcrypt (~> 3.0)
|
106
|
+
orm_adapter (~> 0.1)
|
107
|
+
railties (>= 3.2.6, < 5)
|
108
|
+
responders
|
109
|
+
thread_safe (~> 0.1)
|
110
|
+
warden (~> 1.2.3)
|
111
|
+
diff-lcs (1.2.5)
|
112
|
+
enumerize (1.0.0)
|
113
|
+
activesupport (>= 3.2)
|
114
|
+
erubis (2.7.0)
|
115
|
+
execjs (2.7.0)
|
116
|
+
ffi (1.9.10)
|
117
|
+
formtastic (3.1.4)
|
118
|
+
actionpack (>= 3.2.13)
|
119
|
+
formtastic_i18n (0.6.0)
|
120
|
+
globalid (0.3.6)
|
121
|
+
activesupport (>= 4.1.0)
|
122
|
+
has_scope (0.6.0)
|
123
|
+
actionpack (>= 3.2, < 5)
|
124
|
+
activesupport (>= 3.2, < 5)
|
125
|
+
i18n (0.7.0)
|
126
|
+
inherited_resources (1.6.0)
|
127
|
+
actionpack (>= 3.2, < 5)
|
128
|
+
has_scope (~> 0.6.0.rc)
|
129
|
+
railties (>= 3.2, < 5)
|
130
|
+
responders
|
131
|
+
job_notifier (1.1.1)
|
132
|
+
colorize (~> 0.7, >= 0.7.7)
|
133
|
+
enumerize (~> 1.0.0, ~> 1.0)
|
134
|
+
rails (~> 4.2, >= 4.2.0)
|
135
|
+
silencer (= 1.0.0.rc3)
|
136
|
+
jquery-rails (4.1.1)
|
137
|
+
rails-dom-testing (>= 1, < 3)
|
138
|
+
railties (>= 4.2.0)
|
139
|
+
thor (>= 0.14, < 2.0)
|
140
|
+
jquery-ui-rails (5.0.5)
|
141
|
+
railties (>= 3.2.16)
|
142
|
+
json (1.8.3)
|
143
|
+
kaminari (0.17.0)
|
144
|
+
actionpack (>= 3.0.0)
|
145
|
+
activesupport (>= 3.0.0)
|
146
|
+
loofah (2.0.3)
|
147
|
+
nokogiri (>= 1.5.9)
|
148
|
+
mail (2.6.4)
|
149
|
+
mime-types (>= 1.16, < 4)
|
150
|
+
method_source (0.8.2)
|
151
|
+
mime-types (3.0)
|
152
|
+
mime-types-data (~> 3.2015)
|
153
|
+
mime-types-data (3.2016.0221)
|
154
|
+
mini_portile2 (2.0.0)
|
155
|
+
minitest (5.9.0)
|
156
|
+
nokogiri (1.6.7.2)
|
157
|
+
mini_portile2 (~> 2.0.0.rc2)
|
158
|
+
orm_adapter (0.5.0)
|
159
|
+
polyamorous (1.3.1)
|
160
|
+
activerecord (>= 3.0)
|
161
|
+
pry (0.10.3)
|
162
|
+
coderay (~> 1.1.0)
|
163
|
+
method_source (~> 0.8.1)
|
164
|
+
slop (~> 3.4)
|
165
|
+
pry-rails (0.3.4)
|
166
|
+
pry (>= 0.9.10)
|
167
|
+
quiet_assets (1.1.0)
|
168
|
+
railties (>= 3.1, < 5.0)
|
169
|
+
rack (1.6.4)
|
170
|
+
rack-test (0.6.3)
|
171
|
+
rack (>= 1.0)
|
172
|
+
rails (4.2.6)
|
173
|
+
actionmailer (= 4.2.6)
|
174
|
+
actionpack (= 4.2.6)
|
175
|
+
actionview (= 4.2.6)
|
176
|
+
activejob (= 4.2.6)
|
177
|
+
activemodel (= 4.2.6)
|
178
|
+
activerecord (= 4.2.6)
|
179
|
+
activesupport (= 4.2.6)
|
180
|
+
bundler (>= 1.3.0, < 2.0)
|
181
|
+
railties (= 4.2.6)
|
182
|
+
sprockets-rails
|
183
|
+
rails-assets-growl (1.3.1)
|
184
|
+
rails-assets-jquery
|
185
|
+
rails-assets-jquery (2.2.4)
|
186
|
+
rails-deprecated_sanitizer (1.0.3)
|
187
|
+
activesupport (>= 4.2.0.alpha)
|
188
|
+
rails-dom-testing (1.0.7)
|
189
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
190
|
+
nokogiri (~> 1.6.0)
|
191
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
192
|
+
rails-html-sanitizer (1.0.3)
|
193
|
+
loofah (~> 2.0)
|
194
|
+
railties (4.2.6)
|
195
|
+
actionpack (= 4.2.6)
|
196
|
+
activesupport (= 4.2.6)
|
197
|
+
rake (>= 0.8.7)
|
198
|
+
thor (>= 0.18.1, < 2.0)
|
199
|
+
rake (11.1.2)
|
200
|
+
ransack (1.8.0)
|
201
|
+
actionpack (>= 3.0)
|
202
|
+
activerecord (>= 3.0)
|
203
|
+
activesupport (>= 3.0)
|
204
|
+
i18n
|
205
|
+
polyamorous (~> 1.3)
|
206
|
+
responders (2.2.0)
|
207
|
+
railties (>= 4.2.0, < 5.1)
|
208
|
+
rspec-core (3.4.4)
|
209
|
+
rspec-support (~> 3.4.0)
|
210
|
+
rspec-expectations (3.4.0)
|
211
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
212
|
+
rspec-support (~> 3.4.0)
|
213
|
+
rspec-mocks (3.4.1)
|
214
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
215
|
+
rspec-support (~> 3.4.0)
|
216
|
+
rspec-rails (3.4.2)
|
217
|
+
actionpack (>= 3.0, < 4.3)
|
218
|
+
activesupport (>= 3.0, < 4.3)
|
219
|
+
railties (>= 3.0, < 4.3)
|
220
|
+
rspec-core (~> 3.4.0)
|
221
|
+
rspec-expectations (~> 3.4.0)
|
222
|
+
rspec-mocks (~> 3.4.0)
|
223
|
+
rspec-support (~> 3.4.0)
|
224
|
+
rspec-support (3.4.1)
|
225
|
+
rubyzip (1.2.0)
|
226
|
+
sass (3.4.22)
|
227
|
+
sass-rails (5.0.5)
|
228
|
+
railties (>= 4.0.0, < 6)
|
229
|
+
sass (~> 3.1)
|
230
|
+
sprockets (>= 2.8, < 4.0)
|
231
|
+
sprockets-rails (>= 2.0, < 4.0)
|
232
|
+
tilt (>= 1.1, < 3)
|
233
|
+
select2-rails (3.5.10)
|
234
|
+
thor (~> 0.14)
|
235
|
+
selenium-webdriver (2.53.0)
|
236
|
+
childprocess (~> 0.5)
|
237
|
+
rubyzip (~> 1.0)
|
238
|
+
websocket (~> 1.0)
|
239
|
+
silencer (1.0.0.rc3)
|
240
|
+
slop (3.6.0)
|
241
|
+
sprockets (3.6.3)
|
242
|
+
concurrent-ruby (~> 1.0)
|
243
|
+
rack (> 1, < 3)
|
244
|
+
sprockets-rails (3.1.1)
|
245
|
+
actionpack (>= 4.0)
|
246
|
+
activesupport (>= 4.0)
|
247
|
+
sprockets (>= 3.0.0)
|
248
|
+
sqlite3 (1.3.11)
|
249
|
+
thor (0.19.1)
|
250
|
+
thread_safe (0.3.5)
|
251
|
+
tilt (2.0.5)
|
252
|
+
tzinfo (1.2.2)
|
253
|
+
thread_safe (~> 0.1)
|
254
|
+
warden (1.2.6)
|
255
|
+
rack (>= 1.0)
|
256
|
+
websocket (1.2.3)
|
257
|
+
xdan-datetimepicker-rails (2.5.4)
|
258
|
+
jquery-rails
|
259
|
+
rails (>= 3.2.16)
|
260
|
+
xpath (2.0.0)
|
261
|
+
nokogiri (~> 1.3)
|
262
|
+
|
263
|
+
PLATFORMS
|
264
|
+
ruby
|
265
|
+
|
266
|
+
DEPENDENCIES
|
267
|
+
activeadmin_jobs!
|
268
|
+
capybara
|
269
|
+
daemons
|
270
|
+
database_cleaner
|
271
|
+
delayed_job_active_record
|
272
|
+
pry-rails
|
273
|
+
quiet_assets
|
274
|
+
rails-assets-growl!
|
275
|
+
rspec-rails (~> 3.4.0)
|
276
|
+
selenium-webdriver
|
277
|
+
sqlite3
|
278
|
+
|
279
|
+
BUNDLED WITH
|
280
|
+
1.12.4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Platanus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,272 @@
|
|
1
|
+
# Active Admin Jobs
|
2
|
+
|
3
|
+
It's a Rails engine that allows you to play nice with [Active Job](https://github.com/rails/activejob) in [Active Admin](https://github.com/activeadmin/activeadmin) providing user feedback.
|
4
|
+
|
5
|
+
- An Active Admin's index view to list jobs.
|
6
|
+
- An Active Admin's show view to see job details with a special panel to show success/error feedback. To achieve this we are going to use the [Job Notifier](https://github.com/platanus/job_notifier) gem.
|
7
|
+
- A way to customize the success and error partials.
|
8
|
+
- A mechanism to listen job status changes and notify them using [jQuery Growl](http://ksylvest.github.io/jquery-growl/)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add to your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "activeadmin_jobs"
|
16
|
+
```
|
17
|
+
|
18
|
+
```bash
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
```bash
|
23
|
+
rails generate job_notifier:install
|
24
|
+
```
|
25
|
+
|
26
|
+
If you use `AdminUser` class in `ActiveAdmin` you will need to add the following code:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class AdminUser < ActiveRecord::Base
|
30
|
+
include JobNotifier::Identifier
|
31
|
+
identify_job_through(:id, :email)
|
32
|
+
|
33
|
+
# more code...
|
34
|
+
end
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
To make it easy I'm going to explain how to use this gem with an example.
|
41
|
+
|
42
|
+
Example:
|
43
|
+
|
44
|
+
As an **admin user**:
|
45
|
+
|
46
|
+
1. From a form, I want to pick a big .xls file containing users information.
|
47
|
+
2. In the endpoint pointed by the form, I want to create a job to parse that heavy file in background to create users in the system.
|
48
|
+
3. I need a way to know when the process is completed.
|
49
|
+
4. Also, I want to see success and error feedback.
|
50
|
+
|
51
|
+
<img src="./docs/images/jobs-example.gif" height="500" />
|
52
|
+
|
53
|
+
Next, I will explain how to solve each step:
|
54
|
+
|
55
|
+
#### Step 1: pick the file.
|
56
|
+
|
57
|
+
Suppose you want to go to the import form from the `AdminUser`'s index page. To do that, you can add an `action_item` with a `collection_action`:
|
58
|
+
|
59
|
+
*/your_app/app/admin/admin_users.rb*
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
ActiveAdmin.register AdminUser do
|
63
|
+
# more code...
|
64
|
+
action_item :import_users, only: :index do
|
65
|
+
link_to "Import Users", import_form_admin_admin_users_path
|
66
|
+
end
|
67
|
+
|
68
|
+
collection_action :import_form, title: "Import Users" do
|
69
|
+
# Nothing here. We just want to render the form.
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
With the related wiew:
|
75
|
+
|
76
|
+
*your_app/app/views/admin/admin_users/import_form.html.erb*
|
77
|
+
|
78
|
+
```erb
|
79
|
+
<%= semantic_form_for :data, url: { action: :import }, method: :post do |f| %>
|
80
|
+
<%= f.inputs "Form" do %>
|
81
|
+
<%= f.input :source, as: :file, label: "File", :hint => "Excel file with thousands rows that need to be processed in background..." %>
|
82
|
+
<% end %>
|
83
|
+
<%= f.actions do %>
|
84
|
+
<%= f.action :submit, as: :button, label: "Import" %>
|
85
|
+
<% end %>
|
86
|
+
<% end %>
|
87
|
+
```
|
88
|
+
|
89
|
+
<img src="./docs/images/import-form.png" height="300" />
|
90
|
+
|
91
|
+
You need to add the endpoint pointed in the form action too.
|
92
|
+
|
93
|
+
*/your_app/app/admin/admin_users.rb*
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
ActiveAdmin.register AdminUser do
|
97
|
+
# more code...
|
98
|
+
collection_action :import, title: "Import Users", method: :post do
|
99
|
+
# We fill this in the next step.
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Step 2: create a job.
|
105
|
+
|
106
|
+
Inside the import action definition, you need to call the job in charge of parsing the .xls file. To do this:
|
107
|
+
|
108
|
+
First, we need to create the job. We need to do it using `perform_with_feedback` method provided by [Job Notifier](https://github.com/platanus/job_notifier) gem. You can see how it works reading the **Third and Fourth Steps** of the [usage section](https://github.com/platanus/job_notifier#usage).
|
109
|
+
|
110
|
+
*/your_app/app/jobs/user_upload_job.rb*
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
class UserUploadJob < ActiveJob::Base
|
114
|
+
def perform_with_feedback(xls_path)
|
115
|
+
# Here you need to process the file an return a success or error result.
|
116
|
+
#
|
117
|
+
# Lets say I'm going to return this message:
|
118
|
+
#
|
119
|
+
# "Users successfully loaded"
|
120
|
+
#
|
121
|
+
# with a successful result and something like this:
|
122
|
+
#
|
123
|
+
# errors = [
|
124
|
+
# { row: 4, errors: ["Invalid First Name", "Invalid Category"] },
|
125
|
+
# { row: 6, errors: ["Invalid Last Name"] },
|
126
|
+
# { row: 84, errors: ["Invalid ID"] }
|
127
|
+
# ]
|
128
|
+
#
|
129
|
+
# raise JobNotifier::Error::Validation.new(errors)
|
130
|
+
#
|
131
|
+
# with unsuccessful result.
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
Then, we call the job in the import action:
|
138
|
+
|
139
|
+
*/your_app/app/admin/admin_users.rb*
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
ActiveAdmin.register AdminUser do
|
143
|
+
# more code...
|
144
|
+
collection_action :import, title: "Import Users", method: :post do
|
145
|
+
file_path = get_file_path(params[:data][:source]) # I'm not going to implement this. It's just an example.
|
146
|
+
UserUploadJob.perform_later(current_admin_user.job_identifier, file_path)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
#### Step 3: notify process completion.
|
152
|
+
|
153
|
+
You don't need to do nothing here, the gem will do it for you using [jQuery Growl](http://ksylvest.github.io/jquery-growl/).
|
154
|
+
|
155
|
+
On success...
|
156
|
+
|
157
|
+
<img src="./docs/images/success-notification.png" height="300" />
|
158
|
+
|
159
|
+
On error...
|
160
|
+
|
161
|
+
<img src="./docs/images/error-notification.png" height="300" />
|
162
|
+
|
163
|
+
#### Step 4: show success and error feedback.
|
164
|
+
|
165
|
+
The gem includes an index view for jobs. There, you can see a jobs list with the current state of each job.
|
166
|
+
|
167
|
+
<img src="./docs/images/jobs-list.png" height="400" />
|
168
|
+
|
169
|
+
To show feedback, you need to add one partial by possible job state prefixed by the job's class name in snake_case. For example:
|
170
|
+
If you have the `UserUploadJob` job, following the convention: `_[job_class_name].[job_state].html.erb`, you will need two partials:
|
171
|
+
|
172
|
+
One for success...
|
173
|
+
|
174
|
+
*/your_app/app/views/admin/jobs/_user_upload_job.finished.html.erb*
|
175
|
+
|
176
|
+
```erb
|
177
|
+
<%= result %>
|
178
|
+
```
|
179
|
+
|
180
|
+
> Remember: we get this: "Users successfully loaded" as `result` on success.
|
181
|
+
|
182
|
+
<img src="./docs/images/success-view.png" height="400" />
|
183
|
+
|
184
|
+
One for error...
|
185
|
+
|
186
|
+
*/your_app/app/views/admin/jobs/_user_upload_job.failed.html.erb*
|
187
|
+
|
188
|
+
```erb
|
189
|
+
<h2>Errors :(</h2>
|
190
|
+
|
191
|
+
<% result.each do |record| %>
|
192
|
+
<h3>Row #<%= record[:row] %>:</h3>
|
193
|
+
<ul>
|
194
|
+
<% record[:errors].each do |error| %>
|
195
|
+
<li><%= error %></li>
|
196
|
+
<% end %>
|
197
|
+
</ul>
|
198
|
+
<% end %>
|
199
|
+
```
|
200
|
+
|
201
|
+
> Remember: we get something like this:
|
202
|
+
```ruby
|
203
|
+
[
|
204
|
+
{ row: 4, errors: ["Invalid First Name", "Invalid Category"] },
|
205
|
+
{ row: 6, errors: ["Invalid Last Name"] },
|
206
|
+
{ row: 84, errors: ["Invalid ID"] }
|
207
|
+
]
|
208
|
+
```
|
209
|
+
as `result` on error.
|
210
|
+
|
211
|
+
<img src="./docs/images/error-view.png" height="600" />
|
212
|
+
|
213
|
+
Those partials will be rendered in the job's show view depending on its state.
|
214
|
+
|
215
|
+
## I18n
|
216
|
+
|
217
|
+
If you want to translate your notifications, you can do it following this convention:
|
218
|
+
|
219
|
+
**/your_app/config/locales/en.yml**
|
220
|
+
|
221
|
+
```yml
|
222
|
+
en:
|
223
|
+
activeadmin_jobs:
|
224
|
+
[job_class_name]:
|
225
|
+
description: "XXX"
|
226
|
+
finished:
|
227
|
+
title: "XXX"
|
228
|
+
one: "XXX"
|
229
|
+
other: "XXX"
|
230
|
+
failed:
|
231
|
+
title: "XXX"
|
232
|
+
one: "XXX"
|
233
|
+
other: "XXX"
|
234
|
+
```
|
235
|
+
|
236
|
+
For example:
|
237
|
+
|
238
|
+
```yml
|
239
|
+
en:
|
240
|
+
activeadmin_jobs:
|
241
|
+
user_upload_job:
|
242
|
+
description: "Users upload through .xls file"
|
243
|
+
finished:
|
244
|
+
title: "Users have been uploaded! :)"
|
245
|
+
one: "One .xls file was completed with no errors. Click here to see the result"
|
246
|
+
other: ".xls files were completed with no errors. Click here to see the result"
|
247
|
+
failed:
|
248
|
+
title: "Error trying to upload users :("
|
249
|
+
one: "One .xls file could not be uploaded. Click here to see errors"
|
250
|
+
other: ".xls files could not be uploaded. Click here to see errors"
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
## Contributing
|
255
|
+
|
256
|
+
1. Fork it
|
257
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
258
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
259
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
260
|
+
5. Create new Pull Request
|
261
|
+
|
262
|
+
## Credits
|
263
|
+
|
264
|
+
Thank you [contributors](https://github.com/platanus/activeadmin_jobs/graphs/contributors)!
|
265
|
+
|
266
|
+
<img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
|
267
|
+
|
268
|
+
Active Admin Jobs is maintained by [platanus](http://platan.us).
|
269
|
+
|
270
|
+
## License
|
271
|
+
|
272
|
+
Active Admin Jobs is © 2016 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
|