active_admin-exportable 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 492217a8ab7a94caba14cd0673fefc1a75cdc0c152f46b4d378a2c1e07e2575c
4
- data.tar.gz: d9dbf70a7b7439ce8fdfe3f0acee705d96f2c2ba46dba52388526e379052d7d9
3
+ metadata.gz: 7437205e0fab408af85c631a7c6cdc8f9368520767d9d9e6f246ef47dec32af0
4
+ data.tar.gz: 405bc67713e460881442ba28f7f8a9441b7d628f7169792cde766ec783b3975b
5
5
  SHA512:
6
- metadata.gz: 0643aeb5f493af52e789fdf97ff0d14f5168b61a9946176423661e49e9ed9de08bb34ec62f437588d7ee53c904aa0d485980d650db5e227a7650f1eccbf8bd97
7
- data.tar.gz: 6edf3dbee65a1820eedcec682a7ffe76f2b2cca2591e82b4df925d59939b1e6e46a147a2c3dd323417a5fbcc8118bccedf53477b4165b93d2db2c6274b107ed5
6
+ metadata.gz: 89a625c0d39cb5a90d1352a7e1c1317a24fc0481e0dcf94bd7f24ee9939d857988141f97c961c50a0501903a968210a568fd4e828016a8e696a3c4bd54b8b7d5
7
+ data.tar.gz: ca78550ce9443fd4d59390b0c1f0b6f95c23c42ee50146c6da18ce12aee92906de8a00dcc78c1fb2cf3ab39185c34d942985df81706b225a66bc3c7e506f2e6b
@@ -5,7 +5,47 @@ module ActiveAdmin
5
5
  class Engine < Rails::Engine
6
6
  initializer 'active_admin' do |_app|
7
7
  ActiveAdmin.before_load do |app|
8
- app.load_paths << File.expand_path('../../../app/admin', __dir__)
8
+ ActiveAdmin.register_page 'Import' do
9
+ menu parent: 'Exportable'
10
+ controller do
11
+ private
12
+
13
+ def import_options
14
+ allow_update = ActiveModel::Type::Boolean.new.cast(params[:import][:allow_update])
15
+ file_path = params[:import][:file]&.path
16
+ format = params[:import][:format]
17
+ raise 'Format is required.' if format.blank?
18
+ raise 'File is required.' if file_path.blank?
19
+
20
+ { path: file_path, format: format, allow_update: allow_update }
21
+ end
22
+ end
23
+
24
+ content do
25
+ columns do
26
+ column do
27
+ div do
28
+ active_admin_form_for 'import', url: 'import/upload' do |f|
29
+ f.inputs name: 'Import', class: 'inputs' do
30
+ f.input :format, collection: %i[json yaml], input_html: { value: 'json' }
31
+ f.input :allow_update, as: :boolean
32
+ f.input :file, as: :file
33
+ f.action :submit
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ page_action :upload, method: :post do
42
+ imported = ActiveAdmin::Exportable::Importer.new(**import_options)
43
+ imported.import
44
+ redirect_to admin_import_path, notice: 'Imported'
45
+ rescue StandardError => e
46
+ redirect_to admin_import_path, flash: { error: e.message }
47
+ end
48
+ end
9
49
  end
10
50
  end
11
51
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module Exportable
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin-exportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wagner Caixeta
@@ -109,7 +109,6 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - active_admin-exportable.gemspec
112
- - app/admin/exportable/importer.rb
113
112
  - lib/active_admin/exportable.rb
114
113
  - lib/active_admin/exportable/engine.rb
115
114
  - lib/active_admin/exportable/exporter.rb
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveAdmin.register_page 'Import' do
4
- menu parent: 'Exportable'
5
- controller do
6
- private
7
-
8
- def import_options
9
- allow_update = ActiveModel::Type::Boolean.new.cast(params[:import][:allow_update])
10
- file_path = params[:import][:file]&.path
11
- format = params[:import][:format]
12
- raise 'Format is required.' if format.blank?
13
- raise 'File is required.' if file_path.blank?
14
-
15
- { path: file_path, format: format, allow_update: allow_update }
16
- end
17
- end
18
-
19
- content do
20
- columns do
21
- column do
22
- div do
23
- active_admin_form_for 'import', url: 'import/upload' do |f|
24
- f.inputs name: 'Import', class: 'inputs' do
25
- f.input :format, collection: %i[json yaml], input_html: { value: 'json' }
26
- f.input :allow_update, as: :boolean
27
- f.input :file, as: :file
28
- f.action :submit
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
-
36
- page_action :upload, method: :post do
37
- imported = ActiveAdmin::Exportable::Importer.new(**import_options)
38
- imported.import
39
- redirect_to admin_import_path, notice: 'Imported'
40
- rescue StandardError => e
41
- redirect_to admin_import_path, flash: { error: e.message }
42
- end
43
- end