state_machine_buttons 0.2 → 2.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
- SHA1:
3
- metadata.gz: 2281ef49c3ce8b2c1716385e0d87972aa5ba44e8
4
- data.tar.gz: 9a317f931fbd0885a74731f9f36ebebbc0c1fb44
2
+ SHA256:
3
+ metadata.gz: f3dd4faca018028bd67f43b11c29cc9ff4ca7fd85c7259075cad6e9a2157771c
4
+ data.tar.gz: 652cf144d705d79f9c85db969cbb1b1968f7e095bc4cfc948ebe79c42ba50e56
5
5
  SHA512:
6
- metadata.gz: 8c7d5cec1df817b6ac7b00fd01ecf16e8e79e0b0331b6d61406c3bd51cf7cd44911df25879dbcd8d328f13ece75400cd8cc372ac6c898745e9065c683a9ae0e8
7
- data.tar.gz: a2df6c70d123ae8d302b2600face18bb963f26f0240ea2005c62c8009294e47710545f27d06ccc73b5535a8567a2a20928fc0c3c091382f0ec0cc58b81c05c7f
6
+ metadata.gz: 7bf8ce226badcb97849e3bf3ac9acf008e824164f7da69231011f8f5fd43cf7070365e541cadb745f374f4ff6975330468b1cdf10d3a938167211a6734da6c65
7
+ data.tar.gz: 6c69c3c9cd0225abafd76ec15086dc4975c789e0d68eabd2bcc947e3109283cecd03cf8ad249f170288ec8620db978f13ac301b23658efbd8efa74cdc84e354f
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
@@ -2,31 +2,47 @@
2
2
 
3
3
  module StateMachineButtons
4
4
  module Renderer
5
- def state_events_buttons(object, state_method: :state, url: nil, without: nil, namespace: nil)
5
+ def state_events_buttons(object, state_method: :state, controller:, action:, parameters: {}, without: nil, namespace: nil, model_param_name: nil, button_options: {})
6
6
  model_name = object.model.model_name.name.underscore
7
+ model_param_name ||= model_name
7
8
  excepted_actions = without.is_a?(Array) ? without.map(&:to_sym) : [without.to_sym] if without
8
- transitions = object.model.send("#{state_method}_transitions").reject do |t|
9
- excepted_actions.present? && excepted_actions.include?(t.event)
9
+ transitions = object.model.aasm(state_method).permitted_transitions.reject do |t|
10
+ excepted_actions.present? && excepted_actions.include?(t[:event])
10
11
  end
11
12
  content_tag(:div, class: 'btn-group-vertical') do
12
13
  transitions.each do |event|
13
- button event: event, model_name: model_name, object: object, state_method: state_method, url: url, namespace: namespace
14
+ button(
15
+ event: event[:event],
16
+ model_name: model_name,
17
+ object: object,
18
+ state_method: state_method,
19
+ controller: controller,
20
+ action: action,
21
+ namespace: namespace,
22
+ parameters: parameters,
23
+ model_param_name: model_param_name,
24
+ form_options: button_options
25
+ )
14
26
  end
15
27
  end
16
28
  end
17
29
 
18
30
  private
19
31
 
20
- def button(event:, model_name:, object:, state_method:, url:, namespace:)
21
- route_method_name = "#{namespace.present? ? "#{namespace}_": ""}#{model_name.gsub('/', '_')}_path"
22
- href = url || send(route_method_name, object.model, model_name => { state_method => event.to })
32
+ def button(event:, model_name:, object:, state_method:, controller:, action:, namespace:, parameters:, model_param_name:, form_options:)
33
+ attributes = { aasm_event: event }
23
34
  concat(
24
- link_to(
25
- href,
26
- class: "btn btn-sm btn-xs btn-#{object.send("#{state_method}_button_color", event.event)}",
27
- method: :patch
35
+ patch_button(
36
+ record: object.model,
37
+ controller: controller,
38
+ action: action,
39
+ parameters: parameters,
40
+ attributes: attributes,
41
+ model_name: model_param_name,
42
+ button_options: { class: "btn btn-sm btn-xs btn-#{object.send("#{state_method}_button_color", event)}" },
43
+ form_options: form_options
28
44
  ) do
29
- t("state_machines.#{model_name}.#{state_method}.events.#{event.event}")
45
+ I18n.t("state_machines.#{object.model.class.name.underscore}.#{state_method}.events.#{object.model.aasm(state_method).events.select { |ev| ev.name == event }.first.name}")
30
46
  end
31
47
  )
32
48
  end
@@ -1,3 +1,3 @@
1
1
  module StateMachineButtons
2
- VERSION = '0.2'
2
+ VERSION = '2.0'
3
3
  end
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.16"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
+
26
+ spec.add_dependency 'smart_buttons'
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machine_buttons
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-24 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: smart_buttons
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: State Machines events buttons renderer
56
70
  email:
57
71
  - kalashnikovisme@gmail.com
@@ -88,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.6.11
105
+ rubygems_version: 3.1.2
93
106
  signing_key:
94
107
  specification_version: 4
95
108
  summary: State Machines events buttons renderer