Class: Koi::IndexActionsBuilder
- Inherits:
-
Object
- Object
- Koi::IndexActionsBuilder
- Defined in:
- app/helpers/koi/index_actions_helper.rb
Instance Method Summary collapse
- #actions ⇒ Object
- #create? ⇒ Boolean
- #create_button(_form) ⇒ Object
-
#initialize(context, search:, create:) ⇒ IndexActionsBuilder
constructor
A new instance of IndexActionsBuilder.
- #links(form) ⇒ Object
- #render ⇒ Object
- #search(form) ⇒ Object
- #search? ⇒ Boolean
-
#search_button(form) ⇒ Object
Hidden button to trigger search, avoids triggering create instead.
- #search_input(form) ⇒ Object
- #search_options ⇒ Object
- #sort_input(form) ⇒ Object
Constructor Details
#initialize(context, search:, create:) ⇒ IndexActionsBuilder
Returns a new instance of IndexActionsBuilder.
13 14 15 16 17 |
# File 'app/helpers/koi/index_actions_helper.rb', line 13 def initialize(context, search:, create:) @context = context @search = search @create = create end |
Instance Method Details
#actions ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/koi/index_actions_helper.rb', line 83 def actions [ ("shortcut:cancel@document->index-actions#clear" if search?), ("shortcut:create@document->index-actions#create" if create?), ("shortcut:search@document->index-actions#search" if search?), "shortcut:page-prev@document->index-actions#prevPage", "shortcut:page-next@document->index-actions#nextPage", ].compact.join(" ") end |
#create? ⇒ Boolean
23 24 25 |
# File 'app/helpers/koi/index_actions_helper.rb', line 23 def create? !!@create end |
#create_button(_form) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/helpers/koi/index_actions_helper.rb', line 62 def (_form) tag.(t("koi.labels.new", default: "New"), type: :submit, formaction: @create == true ? url_for(action: :new) : new_polymorphic_path(@create), class: "button--primary", data: { index_actions_target: "create" }) end |
#links(form) ⇒ Object
77 78 79 80 81 |
# File 'app/helpers/koi/index_actions_helper.rb', line 77 def links(form, &) tag.div(class: "actions-group") do yield(form) if block_given? end end |
#render ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/koi/index_actions_helper.rb', line 27 def render(&) tag.nav class: "index-actions", data: { controller: "index-actions", action: actions } do form_with(**, data: { controller: "search", turbo_action: "replace", action: <<~ACTIONS, input->index-actions#update change->index-actions#update submit->index-actions#submit ACTIONS }) do |form| concat(links(form, &)) concat(sort_input(form)) concat(search(form)) if create? || search? end end end |
#search(form) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/helpers/koi/index_actions_helper.rb', line 45 def search(form) tag.div class: "actions-group" do concat((form)) if search? concat((form)) if create? concat(search_input(form)) if search? end end |
#search? ⇒ Boolean
19 20 21 |
# File 'app/helpers/koi/index_actions_helper.rb', line 19 def search? !!@search end |
#search_button(form) ⇒ Object
Hidden button to trigger search, avoids triggering create instead.
58 59 60 |
# File 'app/helpers/koi/index_actions_helper.rb', line 58 def (form) form.submit("Search", hidden: "") end |
#search_input(form) ⇒ Object
70 71 72 73 74 75 |
# File 'app/helpers/koi/index_actions_helper.rb', line 70 def search_input(form) form.search_field(:search, placeholder: t("koi.labels.search", default: "Search"), value: params[:search], data: { index_actions_target: "search" }) end |
#search_options ⇒ Object
93 94 95 96 97 |
# File 'app/helpers/koi/index_actions_helper.rb', line 93 def = { url: request.path, method: :get, scope: "" } .merge!(@search) if @search.is_a?(Hash) end |
#sort_input(form) ⇒ Object
53 54 55 |
# File 'app/helpers/koi/index_actions_helper.rb', line 53 def sort_input(form) form.hidden_field(:sort, value: params[:sort], data: { index_actions_target: "sort" }) end |