Class: EasyAdmin::Action
- Inherits:
-
Object
- Object
- EasyAdmin::Action
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/easy_admin/action.rb
Direct Known Subclasses
Constant Summary collapse
- INSTANT =
Execution modes
:instant- MODAL =
Execute immediately with optional confirmation
:modal- SINGLE =
Action types
:single- BATCH =
Single row action
:batch
Instance Attribute Summary collapse
-
#params ⇒ Object
Use attr_accessor instead of attribute for hash.
Class Method Summary collapse
-
.field_config(field_name) ⇒ Object
Helper method to get field configuration.
- .form_field(name, type, options = {}) ⇒ Object
- .instant(label:, icon: nil, style: :primary, confirm: nil, permissions: nil) ⇒ Object
-
.instant? ⇒ Boolean
Helper method to check if action is instant or modal.
- .modal(label:, icon: nil, style: :primary, title: nil, description: nil, permissions: nil) ⇒ Object
- .modal? ⇒ Boolean
Instance Method Summary collapse
-
#form_param(key) ⇒ Object
Helper method to access form parameters safely.
-
#initialize(attributes = {}) ⇒ Action
constructor
A new instance of Action.
-
#perform ⇒ Object
Main execution method - must be implemented by subclasses.
-
#permitted? ⇒ Boolean
Permission check.
-
#turbo_response_strategy ⇒ Object
Turbo response strategy for UI updates.
-
#visible? ⇒ Boolean
Visibility check.
Constructor Details
#initialize(attributes = {}) ⇒ Action
Returns a new instance of Action.
30 31 32 33 |
# File 'lib/easy_admin/action.rb', line 30 def initialize(attributes = {}) super @params ||= {} end |
Instance Attribute Details
#params ⇒ Object
Use attr_accessor instead of attribute for hash
28 29 30 |
# File 'lib/easy_admin/action.rb', line 28 def params @params end |
Class Method Details
.field_config(field_name) ⇒ Object
Helper method to get field configuration
140 141 142 |
# File 'lib/easy_admin/action.rb', line 140 def field_config(field_name) modal_form_fields&.find { |field| field[:name] == field_name } || {} end |
.form_field(name, type, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/easy_admin/action.rb', line 56 def form_field(name, type, = {}) self.modal_form_fields ||= [] self.modal_form_fields << { name: name, type: type, options: } # Add attribute and validation dynamically attribute name, get_attribute_type(type), **.slice(:default) # Add validations if specified if [:required] validates name, presence: true end if [:format] validates name, format: [:format] end end |
.instant(label:, icon: nil, style: :primary, confirm: nil, permissions: nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/easy_admin/action.rb', line 36 def instant(label:, icon: nil, style: :primary, confirm: nil, permissions: nil) self.execution_mode = INSTANT self.label = label self.icon = icon self.style = style self. = confirm self. = end |
.instant? ⇒ Boolean
Helper method to check if action is instant or modal
145 146 147 |
# File 'lib/easy_admin/action.rb', line 145 def instant? execution_mode == INSTANT end |
.modal(label:, icon: nil, style: :primary, title: nil, description: nil, permissions: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/easy_admin/action.rb', line 45 def modal(label:, icon: nil, style: :primary, title: nil, description: nil, permissions: nil) self.execution_mode = MODAL self.label = label self.icon = icon self.style = style self.modal_title = title || label self.modal_description = description self. = self.modal_form_fields = [] end |
.modal? ⇒ Boolean
149 150 151 |
# File 'lib/easy_admin/action.rb', line 149 def modal? execution_mode == MODAL end |
Instance Method Details
#form_param(key) ⇒ Object
Helper method to access form parameters safely
155 156 157 |
# File 'lib/easy_admin/action.rb', line 155 def form_param(key) params[key.to_s] || params[key.to_sym] end |
#perform ⇒ Object
Main execution method - must be implemented by subclasses
114 115 116 |
# File 'lib/easy_admin/action.rb', line 114 def perform raise NotImplementedError, "Subclasses must implement #perform method" end |
#permitted? ⇒ Boolean
Permission check
125 126 127 128 129 130 |
# File 'lib/easy_admin/action.rb', line 125 def permitted? return true unless self.class. # Integration with Permisi gem would go here # For now, always return true true end |
#turbo_response_strategy ⇒ Object
Turbo response strategy for UI updates
133 134 135 |
# File 'lib/easy_admin/action.rb', line 133 def turbo_response_strategy :replace # Default strategy, can be overridden end |
#visible? ⇒ Boolean
Visibility check
119 120 121 122 |
# File 'lib/easy_admin/action.rb', line 119 def visible? return true unless self.class.visibility_conditions instance_eval(&self.class.visibility_conditions) end |