express_admin 1.7.21 → 1.7.22
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/app/components/express_admin/command_button.rb +3 -2
- data/app/components/express_admin/command_button_list.rb +11 -3
- data/lib/express_admin/commandable.rb +2 -2
- data/lib/express_admin/commands.rb +11 -3
- data/lib/express_admin/standard_actions.rb +1 -1
- data/lib/express_admin/version.rb +1 -1
- data/test/dummy/app/models/part.rb +5 -0
- data/test/dummy/test/components/command_button_test.rb +21 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cce00b8f840033a5025e39117a2bf09edf6e45a7
|
4
|
+
data.tar.gz: 48a72003e0762ed38cc9569be3d4554723439dfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9856a9fc7ba75f1411f3b5550d8d4563190ed7351b4ac93303140207e4046ec60b02337bc210cf24e9e8d975a6cdb74a9e416bacb3622ba684fbbf3fc608f2fe
|
7
|
+
data.tar.gz: f9a78b32974a2a635d4ed771be1da187213f8b59cb1a07cae829eb0725b3ada223717ba0a270e961fab60620dd09d6f2796a58e0148d09a311765d2b2a67d1ab
|
@@ -4,7 +4,6 @@ module ExpressAdmin
|
|
4
4
|
class CommandButton < ExpressTemplates::Components::Configurable
|
5
5
|
include ExpressTemplates::Components::Capabilities::Resourceful
|
6
6
|
|
7
|
-
|
8
7
|
has_argument :id, "The command name. Invoked as an action on the resource.", as: :command, type: :symbol
|
9
8
|
has_option :disabled, "Disables the button", type: :boolean
|
10
9
|
has_option :confirm, "Prompt with the question specified."
|
@@ -24,7 +23,9 @@ module ExpressAdmin
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def button_to_options
|
27
|
-
|
26
|
+
options = {}
|
27
|
+
options = { data: { confirm: config[:confirm] } } if config[:confirm]
|
28
|
+
options.merge({ disabled: config[:disabled] })
|
28
29
|
end
|
29
30
|
|
30
31
|
def action
|
@@ -13,7 +13,7 @@ module ExpressAdmin
|
|
13
13
|
contains -> {
|
14
14
|
commands.each do |command|
|
15
15
|
li {
|
16
|
-
command_button(command,
|
16
|
+
command_button(command[:name], command_button_options(command))
|
17
17
|
}
|
18
18
|
end
|
19
19
|
}
|
@@ -23,14 +23,22 @@ module ExpressAdmin
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def available?(command)
|
26
|
-
resource.available_commands.include?(command)
|
26
|
+
resource.available_commands.include?(command[:name])
|
27
27
|
end
|
28
28
|
|
29
29
|
def commands
|
30
30
|
resource.commands
|
31
31
|
end
|
32
32
|
|
33
|
+
private
|
34
|
+
|
35
|
+
def command_button_options(command)
|
36
|
+
options = {}
|
37
|
+
options = { confirm: command[:confirm] } if command[:confirm]
|
38
|
+
options.merge({ disabled: !available?(command) })
|
39
|
+
end
|
40
|
+
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
36
|
-
end
|
44
|
+
end
|
@@ -37,7 +37,7 @@ module ExpressAdmin
|
|
37
37
|
resource_class.commands.each do |action|
|
38
38
|
# post :foo, to: "module/controller#foo"
|
39
39
|
mapper.member do
|
40
|
-
mapper.post action.debang, to: "#{controller_name}##{action.debang}"
|
40
|
+
mapper.post action[:name].debang, to: "#{controller_name}##{action[:name].debang}"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -62,4 +62,4 @@ module ActionDispatch::Routing::Mapper::Resources
|
|
62
62
|
alias :resources_without_commandable :resources
|
63
63
|
alias :resources :resources_with_commandable
|
64
64
|
|
65
|
-
end
|
65
|
+
end
|
@@ -13,12 +13,15 @@ module ExpressAdmin
|
|
13
13
|
module ClassMethods
|
14
14
|
|
15
15
|
def exposes_command(command)
|
16
|
+
command = { name: command } if command.is_a?(Symbol)
|
17
|
+
|
16
18
|
exposes_commands command
|
17
19
|
end
|
18
20
|
|
19
21
|
def exposes_commands(*commands)
|
20
22
|
self.commands += commands
|
21
23
|
end
|
24
|
+
|
22
25
|
end
|
23
26
|
|
24
27
|
module InstanceMethods
|
@@ -29,9 +32,9 @@ module ExpressAdmin
|
|
29
32
|
|
30
33
|
def available_commands
|
31
34
|
if respond_to?(:aasm)
|
32
|
-
|
35
|
+
command_names & aasm_event_triggers
|
33
36
|
else
|
34
|
-
|
37
|
+
command_names - unavailable_commands
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
@@ -39,6 +42,11 @@ module ExpressAdmin
|
|
39
42
|
def aasm_event_triggers
|
40
43
|
aasm.events.map(&:name).map(&:to_s).map {|s| "#{s}!"}.map(&:to_sym)
|
41
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def command_names
|
48
|
+
commands.map { |command| command[:name] }
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
@@ -49,4 +57,4 @@ class Symbol
|
|
49
57
|
def debang
|
50
58
|
to_s.gsub(/\!\Z/, '').to_sym
|
51
59
|
end
|
52
|
-
end
|
60
|
+
end
|
@@ -13,6 +13,9 @@ module Components
|
|
13
13
|
def twiddle_widget_path(id)
|
14
14
|
"/widgets/#{id}/twiddle"
|
15
15
|
end
|
16
|
+
def trash_part_path(id)
|
17
|
+
"/parts/#{id}/trash"
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
@@ -25,19 +28,33 @@ module Components
|
|
25
28
|
test "command button creates a form with a submit button having the correct name" do
|
26
29
|
assert_match /form.*action="\/widgets\/\d+\/twiddle"/, command_button(:twiddle, resource_name: :widget)
|
27
30
|
assert_match /input type="submit" value="Twiddle"/, command_button(:twiddle, resource_name: :widget)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
test "command button accepts a confirm parameter to display a prompt" do
|
35
|
+
assert_match /input data-confirm="Are you sure\?" type="submit" value="Twiddle"/, command_button(:twiddle, resource_name: :widget, confirm: "Are you sure?")
|
28
36
|
end
|
29
37
|
|
30
|
-
def
|
38
|
+
def command_button_list_widget
|
31
39
|
arbre(widget: widgets(:one)) {
|
32
|
-
command_button_list(
|
40
|
+
command_button_list(:widget)
|
33
41
|
}
|
34
42
|
end
|
35
43
|
|
36
44
|
test "command_button_list creates a list of command buttons" do
|
37
|
-
assert_match /ul class="command-button-list"/,
|
38
|
-
assert_match /li.*<form.*\<\/li>/,
|
45
|
+
assert_match /ul class="command-button-list"/, command_button_list_widget
|
46
|
+
assert_match /li.*<form.*\<\/li>/, command_button_list_widget.split("\n").join
|
39
47
|
end
|
40
48
|
|
49
|
+
def command_button_list_parts
|
50
|
+
arbre(part: parts(:one)) {
|
51
|
+
command_button_list(:part)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
test "command_button_list accepts confirm parameters" do
|
56
|
+
assert_match /input data-confirm="Are you sure\?" type="submit" value="Trash"/, command_button_list_parts
|
57
|
+
end
|
41
58
|
end
|
42
59
|
|
43
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Talcott Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: express_templates
|