active_admin-duplicatable 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/active_admin/duplicatable.rb +32 -0
- data/lib/active_admin/duplicatable/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb70dd281048047d1568dcb775b19aa46507ed41
|
4
|
+
data.tar.gz: baff5ba471c1409a7cd10d7954c45c54598e9759
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28623f63ac6b3877c16694ef73293f3837f3cd82c84a4618a305d8cbed9cef90f725ae04f04ad22115179e8aa4fdb3cce59527693b33ae92c42f47aad22d5c01
|
7
|
+
data.tar.gz: 1163c61a02ba1d7d667c4c69c99766f40daa584571cdc11e5b83c68a5052a130ccf99ff7bbe0cacf867fc0b95532b50ef6e034499fe78091b09f7082febf5c18
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [0.3.0] - 2017-10-03
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Allow custom duplication methods in the `:via` option. Rather than always
|
12
|
+
calling `#amoeba_dup`, it can be configured to call any method.
|
13
|
+
|
7
14
|
## [0.2.0] - 2015-07-23
|
8
15
|
|
9
16
|
- Avoid ActiveAdmin `1.0.0.pre1` deprecation warning when `#action_item` isn't
|
@@ -20,6 +27,7 @@ All notable changes to this project will be documented in this file.
|
|
20
27
|
|
21
28
|
- Initial release
|
22
29
|
|
23
|
-
[unreleased]: https://github.com/zorab47/active_admin-duplicatable/compare/v0.
|
30
|
+
[unreleased]: https://github.com/zorab47/active_admin-duplicatable/compare/v0.3.0...HEAD
|
24
31
|
[0.1.0]: https://github.com/zorab47/active_admin-duplicatable/compare/v0.0.1...v0.1.0
|
25
32
|
[0.2.0]: https://github.com/zorab47/active_admin-duplicatable/compare/v0.1.0...v0.2.0
|
33
|
+
[0.3.0]: https://github.com/zorab47/active_admin-duplicatable/compare/v0.2.0...v0.3.0
|
@@ -23,6 +23,8 @@ module ActiveAdmin
|
|
23
23
|
|
24
24
|
if via == :save
|
25
25
|
enable_resource_duplication_via_save
|
26
|
+
elsif via != :form
|
27
|
+
enable_resource_duplication_via_custom_method(via)
|
26
28
|
else
|
27
29
|
enable_resource_duplication_via_form
|
28
30
|
end
|
@@ -81,6 +83,36 @@ module ActiveAdmin
|
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
86
|
+
# Enables resource duplication via a custom method
|
87
|
+
#
|
88
|
+
# - Adds a duplicate action button.
|
89
|
+
# - Calls a custom duplication method on the model. The method should
|
90
|
+
# handle any copying of data and persistence of the new record.
|
91
|
+
# - Redirects the user to edit the newly duplicated resource.
|
92
|
+
#
|
93
|
+
# No return.
|
94
|
+
def enable_resource_duplication_via_custom_method(method)
|
95
|
+
action_item(*compatible_action_item_parameters) do
|
96
|
+
if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
|
97
|
+
link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :duplicate)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
member_action :duplicate do
|
102
|
+
resource = resource_class.find(params[:id])
|
103
|
+
|
104
|
+
authorize! ActiveAdmin::Auth::CREATE, resource
|
105
|
+
|
106
|
+
begin
|
107
|
+
duplicate = resource.send method
|
108
|
+
redirect_to({ action: :edit, id: duplicate.id }, flash: { notice: "#{active_admin_config.resource_label} was successfully duplicated." })
|
109
|
+
rescue => e
|
110
|
+
Rails.logger.warn(e)
|
111
|
+
redirect_to({ action: :show }, flash: { error: "#{active_admin_config.resource_label} could not be duplicated." })
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
84
116
|
# For ActiveAdmin `action_item` compatibility.
|
85
117
|
#
|
86
118
|
# - When ActiveAdmin is less than 1.0.0.pre1 exclude name parameter from
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin-duplicatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Maresh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|
@@ -149,11 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.2.
|
152
|
+
rubygems_version: 2.5.2.1
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: Simple duplication of ActiveAdmin resources
|
156
156
|
test_files:
|
157
157
|
- spec/duplicatable_spec.rb
|
158
158
|
- spec/spec_helper.rb
|
159
|
-
has_rdoc:
|