activeadmin_async_export 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/activeadmin_async_export.gemspec +21 -0
- data/lib/active_admin/async_export/async_export_mailer.rb +31 -0
- data/lib/active_admin/async_export/build_download_format_links.rb +9 -0
- data/lib/active_admin/async_export/resource_controller_extension.rb +21 -0
- data/lib/active_admin/async_export/version.rb +5 -0
- data/lib/active_admin/async_export.rb +33 -0
- data/lib/activeadmin_async_export.rb +2 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrew Frankel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# ActiveadminAsyncExport
|
2
|
+
|
3
|
+
ActiveAdmin plugin for email delivery of CSV exports.
|
4
|
+
|
5
|
+
Uses resque_mailer to asynchronously run slow data exports and deliver the results via email.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'activeadmin_async_export'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install activeadmin_async_export
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Just add `gem 'activeadmin_async_export'` to your Gemfile. All of the active admin resource index pages will now include a link export data via email. This link will run the CSV report and email the results as an attachement to the current admin user.
|
24
|
+
|
25
|
+
### Set the from email address
|
26
|
+
|
27
|
+
In an initializer, include a line like the following:
|
28
|
+
|
29
|
+
ActiveAdmin::AsyncExport.from_email_address = 'admin@topshelfclothes.com'
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/active_admin/async_export/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "activeadmin_async_export"
|
6
|
+
gem.version = ActiveAdmin::AsyncExport::VERSION
|
7
|
+
gem.authors = ["Andrew Frankel"]
|
8
|
+
gem.email = ["andrew@leknarf.net"]
|
9
|
+
gem.description = %q{ActiveAdmin plugin for email delivery of CSV exports.}
|
10
|
+
gem.summary = %q{Uses resque_mailer to asynchronously run slow data exports and deliver the results via email.}
|
11
|
+
gem.homepage = "https://github.com/leknarf/activeadmin_async_export"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_path = 'lib'
|
17
|
+
gem.required_ruby_version = '>= 1.9.2'
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'activeadmin', '>= 0.5.1'
|
20
|
+
gem.add_runtime_dependency 'resque_mailer'
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module AsyncExport
|
3
|
+
class AsyncExportMailer < ActionMailer::Base
|
4
|
+
include Resque::Mailer
|
5
|
+
add_template_helper MethodOrProcHelper
|
6
|
+
|
7
|
+
def csv_export(admin_email, model_name)
|
8
|
+
controller = Kernel::qualified_const_get("Admins::#{model_name}sController").new
|
9
|
+
config = controller.send(:active_admin_config)
|
10
|
+
path = controller.send(:active_admin_template, 'index.csv')
|
11
|
+
csv_filename = controller.send(:csv_filename)
|
12
|
+
collection = Kernel::const_get(model_name).all
|
13
|
+
app = ActiveAdmin.application
|
14
|
+
|
15
|
+
csv = render_to_string(file: path,
|
16
|
+
layout: false,
|
17
|
+
locals: {
|
18
|
+
active_admin_application: app,
|
19
|
+
active_admin_config: config,
|
20
|
+
collection: collection,
|
21
|
+
})
|
22
|
+
|
23
|
+
attachments[csv_filename] = csv
|
24
|
+
mail(to: admin_email,
|
25
|
+
subject: csv_filename,
|
26
|
+
body: 'See attached',
|
27
|
+
from: ActiveAdmin::AsyncExport.from_email_address)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module AsyncExport
|
3
|
+
module ResourceControllerExtension
|
4
|
+
def self.included(base)
|
5
|
+
base.send :alias_method_chain, :index, :email
|
6
|
+
base.send :respond_to, :email
|
7
|
+
end
|
8
|
+
|
9
|
+
def index_with_email(options={}, &block)
|
10
|
+
index_without_email(options) do |format|
|
11
|
+
format.email do
|
12
|
+
current_user_method = active_admin_config.namespace.application.current_user_method
|
13
|
+
admin_email = send(current_user_method).email
|
14
|
+
ActiveAdmin::AsyncExport::AsyncExportMailer.csv_export(admin_email, collection.first.class.to_s).deliver
|
15
|
+
redirect_to :back, notice: "CSV export emailed to #{admin_email}!"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_admin'
|
2
|
+
require 'active_admin/async_export/build_download_format_links'
|
3
|
+
require 'active_admin/async_export/version'
|
4
|
+
require 'active_admin/async_export/resource_controller_extension'
|
5
|
+
require 'active_admin/async_export/async_export_mailer'
|
6
|
+
|
7
|
+
module ActiveAdmin
|
8
|
+
module AsyncExport
|
9
|
+
def self.from_email_address=(address)
|
10
|
+
@from_email_address = address
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_email_address
|
14
|
+
@from_email_address || 'admin@example.com'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Railtie < ::Rails::Railtie
|
20
|
+
initializer "active admin async export initalization" do
|
21
|
+
begin
|
22
|
+
if Mime::Type.lookup_by_extension(:email).nil?
|
23
|
+
# The mime type to be used in respond_to |format| style web-services in rails
|
24
|
+
Mime::Type.register 'application/email_export', :email, []
|
25
|
+
end
|
26
|
+
rescue NameError
|
27
|
+
# noop
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveAdmin::ResourceController.send :include, ActiveAdmin::AsyncExport::ResourceControllerExtension
|
31
|
+
ActiveAdmin::Views::PaginatedCollection.add_format :email
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin_async_export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Frankel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activeadmin
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: resque_mailer
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ActiveAdmin plugin for email delivery of CSV exports.
|
47
|
+
email:
|
48
|
+
- andrew@leknarf.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- activeadmin_async_export.gemspec
|
59
|
+
- lib/active_admin/async_export.rb
|
60
|
+
- lib/active_admin/async_export/async_export_mailer.rb
|
61
|
+
- lib/active_admin/async_export/build_download_format_links.rb
|
62
|
+
- lib/active_admin/async_export/resource_controller_extension.rb
|
63
|
+
- lib/active_admin/async_export/version.rb
|
64
|
+
- lib/activeadmin_async_export.rb
|
65
|
+
homepage: https://github.com/leknarf/activeadmin_async_export
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.9.2
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Uses resque_mailer to asynchronously run slow data exports and deliver the
|
89
|
+
results via email.
|
90
|
+
test_files: []
|
91
|
+
has_rdoc:
|