Class: Jav::ActionsComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Jav::ActionsComponent
- Includes:
- ApplicationHelper
- Defined in:
- app/components/jav/actions_component.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#action_path(id) ⇒ Object
When running an action for one record we should do it on a special path.
- #actions ⇒ Object
-
#initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil) ⇒ ActionsComponent
constructor
A new instance of ActionsComponent.
-
#is_disabled?(action) ⇒ Boolean
How should the action be displayed by default.
- #render? ⇒ Boolean
Methods included from ApplicationHelper
#a_button, #a_link, #button_classes, #decode_filter_params, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg, #white_panel_classes
Constructor Details
#initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil) ⇒ ActionsComponent
Returns a new instance of ActionsComponent.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/components/jav/actions_component.rb', line 7 def initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil) super @actions = actions || [] @resource = resource @view = view @exclude = exclude @include = include @color = color @style = style @label = label || I18n.t("jav.actions") end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'app/components/jav/actions_component.rb', line 5 def label @label end |
Instance Method Details
#action_path(id) ⇒ Object
When running an action for one record we should do it on a special path.
We do that so we get the model param inside the action so we can prefill fields.
35 36 37 38 39 40 41 42 43 |
# File 'app/components/jav/actions_component.rb', line 35 def action_path(id) return many_records_path(id) unless @resource.has_model_id? if on_record_page? single_record_path id else many_records_path id end end |
#actions ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/components/jav/actions_component.rb', line 23 def actions if @exclude.present? @actions.reject { |action| action.class.in?(@exclude) } elsif @include.present? @actions.select { |action| action.class.in?(@include) } else @actions end end |
#is_disabled?(action) ⇒ Boolean
How should the action be displayed by default
46 47 48 49 50 |
# File 'app/components/jav/actions_component.rb', line 46 def is_disabled?(action) return false if action.standalone on_index_page? end |
#render? ⇒ Boolean
19 20 21 |
# File 'app/components/jav/actions_component.rb', line 19 def render? actions.present? end |