activeadmin-exporter 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/Gemfile +4 -0
- data/README.md +3 -0
- data/Rakefile +8 -0
- data/activeadmin-exporter.gemspec +21 -0
- data/lib/active_admin/exporter.rb +20 -0
- data/lib/active_admin/exporter/build_download_format_links.rb +10 -0
- data/lib/active_admin/exporter/exporter_mailer.rb +46 -0
- data/lib/active_admin/exporter/railtie.rb +20 -0
- data/lib/active_admin/exporter/resource_controller_extension.rb +30 -0
- data/lib/active_admin/exporter/version.rb +5 -0
- data/lib/activeadmin-exporter.rb +2 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d41bab04aa0559e53eec7455e8faaa02ebfa5a38
|
4
|
+
data.tar.gz: c1a6ccc6419428f41e5b0baf9a5a5bc46dd4c7f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d1b11b2a104c5b43081e0715917ca93b643b0ea053513095ebefc6be5078fa7d71997449154edc8730fdc0f3b0380a16f259d3c6706f7f6fe6de725bd9706e3
|
7
|
+
data.tar.gz: 740e76c53b2da615dae32579b761a8064f70d28c63a0a73891d873a749fc5dacc9678c3ec19537b3d8b62dad2e8cf431af62201e0ae414a46603e0875a73b32b
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Created by .ignore support plugin (hsz.mobi)
|
2
|
+
### Ruby template
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/spec/examples.txt
|
11
|
+
/test/tmp/
|
12
|
+
/test/version_tmp/
|
13
|
+
/tmp/
|
14
|
+
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
## Specific to RubyMotion:
|
19
|
+
.dat*
|
20
|
+
.repl_history
|
21
|
+
build/
|
22
|
+
*.bridgesupport
|
23
|
+
build-iPhoneOS/
|
24
|
+
build-iPhoneSimulator/
|
25
|
+
|
26
|
+
## Specific to RubyMotion (use of CocoaPods):
|
27
|
+
#
|
28
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
29
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
30
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
31
|
+
#
|
32
|
+
# vendor/Pods/
|
33
|
+
|
34
|
+
## Documentation cache and generated files:
|
35
|
+
/.yardoc/
|
36
|
+
/_yardoc/
|
37
|
+
/doc/
|
38
|
+
/rdoc/
|
39
|
+
|
40
|
+
## Environment normalization:
|
41
|
+
/.bundle/
|
42
|
+
/vendor/bundle
|
43
|
+
/lib/bundler/man/
|
44
|
+
|
45
|
+
# for a library or gem, you might want to ignore these files since the code is
|
46
|
+
# intended to run in multiple environments; otherwise, check them in:
|
47
|
+
# Gemfile.lock
|
48
|
+
# .ruby-version
|
49
|
+
# .ruby-gemset
|
50
|
+
|
51
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
52
|
+
.rvmrc
|
53
|
+
|
54
|
+
/.idea/*
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/active_admin/exporter/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'activeadmin-exporter'
|
6
|
+
gem.version = ActiveAdmin::Exporter::VERSION
|
7
|
+
gem.authors = ['Nikita Anistratenko']
|
8
|
+
gem.email = ['steverovsky@gmail.com']
|
9
|
+
gem.description = %q{ActiveAdmin plugin for expanding export possibilities.}
|
10
|
+
gem.summary = %q{Allows to asynchronously pack export result in ZIP and send it to email.}
|
11
|
+
gem.homepage = "https://github.com/steverovsky/activeadmin-exporter"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'activeadmin'
|
19
|
+
gem.add_runtime_dependency 'sidekiq'
|
20
|
+
gem.add_runtime_dependency 'rubyzip'
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_admin'
|
2
|
+
require 'active_admin/exporter/build_download_format_links'
|
3
|
+
require 'active_admin/exporter/version'
|
4
|
+
require 'active_admin/exporter/resource_controller_extension'
|
5
|
+
require 'active_admin/exporter/exporter_mailer'
|
6
|
+
require 'active_admin/exporter/railtie'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'zip'
|
9
|
+
|
10
|
+
module ActiveAdmin
|
11
|
+
module Exporter
|
12
|
+
def self.from_email_address=(address)
|
13
|
+
@from_email_address = address
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_email_address
|
17
|
+
@from_email_address || 'admin@example.com'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Exporter
|
3
|
+
module BuildDownloadFormatLinks
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:alias_method, :build_download_format_links_without_email, :build_download_format_links)
|
6
|
+
base.send(:alias_method, :build_download_format_links, :build_download_format_links_with_email)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Exporter
|
3
|
+
class ExporterMailer < ActionMailer::Base
|
4
|
+
def csv_export(recipient_email, class_name, params_json)
|
5
|
+
params = JSON.parse(params_json)
|
6
|
+
controller = class_name.constantize.new
|
7
|
+
controller.send('params=', params)
|
8
|
+
|
9
|
+
config = controller.send(:active_admin_config)
|
10
|
+
csv_filename = controller.send(:csv_filename)
|
11
|
+
zip_filename = csv_filename.sub('.csv', '.zip')
|
12
|
+
|
13
|
+
def controller.find_collection(options = {})
|
14
|
+
options[:only] = [
|
15
|
+
:sorting,
|
16
|
+
:filtering,
|
17
|
+
:scoping,
|
18
|
+
:includes,
|
19
|
+
:pagination,
|
20
|
+
:collection_decorator
|
21
|
+
]
|
22
|
+
|
23
|
+
collection = scoped_collection
|
24
|
+
collection_applies(options).each do |applyer|
|
25
|
+
collection = send("apply_#{applyer}", collection)
|
26
|
+
end
|
27
|
+
collection
|
28
|
+
end
|
29
|
+
|
30
|
+
zip = Zip::OutputStream.write_buffer do |zio|
|
31
|
+
zio.put_next_entry(csv_filename)
|
32
|
+
config.csv_builder.build(controller, zio)
|
33
|
+
end
|
34
|
+
|
35
|
+
attachments[zip_filename] = zip.string
|
36
|
+
|
37
|
+
mail(
|
38
|
+
to: recipient_email,
|
39
|
+
subject: zip_filename,
|
40
|
+
body: 'See attached.',
|
41
|
+
from: ActiveAdmin::Exporter.from_email_address
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Exporter
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
config.after_initialize do
|
5
|
+
begin
|
6
|
+
if Mime::Type.lookup_by_extension(:email).nil?
|
7
|
+
Mime::Type.register 'application/email_export', :email, []
|
8
|
+
end
|
9
|
+
rescue NameError
|
10
|
+
# noop
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveAdmin::ResourceController.class_eval do
|
14
|
+
include ActiveAdmin::Exporter::ResourceControllerExtension
|
15
|
+
end
|
16
|
+
ActiveAdmin::Views::PaginatedCollection.add_format :email
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Exporter
|
3
|
+
module ResourceControllerExtension
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:alias_method, :index_without_email, :index)
|
6
|
+
base.send(:alias_method, :index, :index_with_email)
|
7
|
+
|
8
|
+
base.send(:respond_to, :email)
|
9
|
+
end
|
10
|
+
|
11
|
+
def index_with_email
|
12
|
+
index_without_email do |format|
|
13
|
+
format.email do
|
14
|
+
current_user_method = active_admin_config.namespace.application.current_user_method
|
15
|
+
recipient_email = send(current_user_method).email
|
16
|
+
class_name = self.class.to_s
|
17
|
+
|
18
|
+
ActiveAdmin::Exporter::ExporterMailer.csv_export(
|
19
|
+
recipient_email,
|
20
|
+
class_name,
|
21
|
+
params.to_json
|
22
|
+
).deliver_later
|
23
|
+
|
24
|
+
redirect_back(fallback_location: root_path, notice: "CSV export emailed to #{recipient_email}!")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin-exporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikita Anistratenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubyzip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ActiveAdmin plugin for expanding export possibilities.
|
56
|
+
email:
|
57
|
+
- steverovsky@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- activeadmin-exporter.gemspec
|
67
|
+
- lib/active_admin/exporter.rb
|
68
|
+
- lib/active_admin/exporter/build_download_format_links.rb
|
69
|
+
- lib/active_admin/exporter/exporter_mailer.rb
|
70
|
+
- lib/active_admin/exporter/railtie.rb
|
71
|
+
- lib/active_admin/exporter/resource_controller_extension.rb
|
72
|
+
- lib/active_admin/exporter/version.rb
|
73
|
+
- lib/activeadmin-exporter.rb
|
74
|
+
homepage: https://github.com/steverovsky/activeadmin-exporter
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Allows to asynchronously pack export result in ZIP and send it to email.
|
97
|
+
test_files: []
|