Module: RubyCms::Admin::BulkActionTableHelper

Defined in:
app/helpers/ruby_cms/admin/bulk_action_table_helper.rb

Instance Method Summary collapse

Instance Method Details

#bulk_action_button(name:, label:, url:, confirm: nil, action_type: nil, class: nil) ⇒ Hash

Build bulk action button configuration hash

Examples:

bulk_action_button(
  name: "publish",
  label: "Publish Selected",
  url: bulk_publish_path,
  confirm: "Are you sure?"
)

Parameters:

  • Action name (used internally)

  • Button label text

  • Action URL

  • (defaults to: nil)

    Confirmation message

  • (defaults to: nil)

    “redirect” for redirect actions, nil for dialog actions

  • (defaults to: nil)

    Additional CSS classes

Returns:

  • Button configuration hash



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/helpers/ruby_cms/admin/bulk_action_table_helper.rb', line 140

def bulk_action_button(
  name:,
  label:,
  url:,
  confirm: nil,
  action_type: nil,
  class: nil
)
  {
    name: name,
    label: label,
    url: url,
    confirm: confirm,
    action_type: action_type,
    class: binding.local_variable_get(:class)
  }.compact
end

#render_admin_page(title:, subtitle: nil, actions: nil, breadcrumbs: nil, padding: true, overflow: true, turbo_frame: nil, turbo_frame_options: nil) ⇒ String

Render an admin page with consistent layout

Examples:

<%= render_admin_page(
  title: "Content Blocks",
  actions: [
    { label: "New Block", url: new_content_block_path, primary: true }
  ],
  turbo_frame: "admin_table_content"
) do %>
  <div class="ruby_cms-card">
    <!-- Content here -->
  </div>
<% end %>

Parameters:

  • Page title

  • (defaults to: nil)

    Optional subtitle

  • (defaults to: nil)

    Array of action button configs

  • (defaults to: nil)

    Array of breadcrumb items

  • (defaults to: true)

    Add padding classes (default: true)

  • (defaults to: true)

    Allow overflow (default: true)

  • (defaults to: nil)

    Turbo Frame ID for wrapping

  • (defaults to: nil)

    Custom Turbo Frame options

  • Block that renders page content

Returns:

  • Rendered HTML



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/helpers/ruby_cms/admin/bulk_action_table_helper.rb', line 99

def render_admin_page(
  title:,
  subtitle: nil,
  actions: nil,
  breadcrumbs: nil,
  padding: true,
  overflow: true,
  turbo_frame: nil,
  turbo_frame_options: nil
)
  render RubyCms::Admin::AdminPage.new(
    title:,
    subtitle:,
    actions:,
    breadcrumbs:,
    padding:,
    overflow:,
    turbo_frame:,
    turbo_frame_options:
  ) do
    yield if block_given?
  end
end

#render_bulk_action_table(headers:, turbo_frame: "admin_table_content", pagination: nil, pagination_path: nil, bulk_actions_url: nil, bulk_action_buttons: [], item_name: "item", controller_name: "ruby-cms--bulk-action-table", &block) ⇒ String

Render a complete bulk action table using Phlex components

Examples:

Basic usage

<%= render_bulk_action_table(
  collection: @items,
  headers: ["Name", "Status", { text: "Actions", class: "text-right" }],
  bulk_actions_url: bulk_delete_items_path,
  item_name: "item"
) do %>
  <% @items.each do |item| %>
    <%= render RubyCms::Admin::BulkActionTable::BulkActionTableRow.new(
      data: { item_id: item.id }
    ) do %>
      <td><%= item.name %></td>
      <td><%= item.status %></td>
      <td class="text-right">
        <%= render RubyCms::Admin::BulkActionTable::BulkActionTableActions.new(
          edit_path: edit_item_path(item),
          delete_path: item_path(item),
          item_id: item.id
        ) %>
      </td>
    <% end %>
  <% end %>
<% end %>

Parameters:

  • The collection to display

  • Array of header labels or hashes with :text and :class

  • (defaults to: "admin_table_content")

    Turbo Frame ID for seamless updates

  • (defaults to: nil)

    Pagination hash from AdminPagination concern

  • (defaults to: nil)

    Lambda for generating pagination URLs

  • (defaults to: nil)

    URL for bulk delete action

  • (defaults to: [])

    Array of custom bulk action button configs

  • (defaults to: "item")

    Singular name for items (default: “item”)

  • (defaults to: "ruby-cms--bulk-action-table")

    Stimulus controller identifier

  • Block that renders table rows

Returns:

  • Rendered HTML



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/ruby_cms/admin/bulk_action_table_helper.rb', line 43

def render_bulk_action_table(
  headers:,
  turbo_frame: "admin_table_content",
  pagination: nil,
  pagination_path: nil,
  bulk_actions_url: nil,
  bulk_action_buttons: [],
  item_name: "item",
  controller_name: "ruby-cms--bulk-action-table",
  &block
)
  render RubyCms::Admin::BulkActionTable::BulkActionTable.new(
    turbo_frame: turbo_frame,
    pagination: pagination,
    pagination_path: pagination_path,
    bulk_actions_url: bulk_actions_url,
    bulk_actions_buttons: bulk_action_buttons,
    item_name: item_name,
    controller_name: controller_name,
    csrf_token: form_authenticity_token
  ) do
    render RubyCms::Admin::BulkActionTable::BulkActionTableHeader.new(
      headers: headers,
      bulk_actions_enabled: bulk_actions_url.present? || bulk_action_buttons.any?,
      controller_name: controller_name
    )

    render RubyCms::Admin::BulkActionTable::BulkActionTableBody.new(&block)
  end
end