Move admin pages index to a component

This way it'll be easier to write tests for it.
This commit is contained in:
Javi Martín
2023-01-22 16:32:34 +01:00
parent 854f20016e
commit f9d334fb36
3 changed files with 62 additions and 54 deletions

View File

@@ -0,0 +1,54 @@
<% provide :title do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.pages") %>
<% end %>
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button float-right" %>
<h2 class="inline-block"><%= t("admin.site_customization.pages.index.title") %></h2>
<% if pages.any? %>
<h3><%= page_entries_info pages %></h3>
<table class="cms-page-list">
<thead>
<tr>
<th><%= t("admin.site_customization.pages.page.title") %></th>
<th><%= t("admin.site_customization.pages.page.slug") %></th>
<th><%= t("admin.site_customization.pages.page.created_at") %></th>
<th><%= t("admin.site_customization.pages.page.updated_at") %></th>
<th><%= t("admin.site_customization.pages.page.status") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% pages.each do |page| %>
<tr id="<%= dom_id(page) %>">
<td><%= page.title %></td>
<td><%= page.slug %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
<td>
<%= render Admin::TableActionsComponent.new(page) do |actions| %>
<%= actions.action(:cards,
text: t("admin.site_customization.pages.page.see_cards"),
path: admin_site_customization_page_widget_cards_path(page)) %>
<% if page.status == "published" %>
<%= actions.action(:show,
text: t("admin.site_customization.pages.index.see_page"),
path: page.url,
options: { target: "_blank" }) %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate pages %>
<% else %>
<div class="callout primary">
<%= page_entries_info pages %>
</div>
<% end %>

View File

@@ -0,0 +1,7 @@
class Admin::SiteCustomization::Pages::IndexComponent < ApplicationComponent
attr_reader :pages
def initialize(pages)
@pages = pages
end
end

View File

@@ -1,54 +1 @@
<% provide :title do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.pages") %>
<% end %>
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button float-right" %>
<h2 class="inline-block"><%= t("admin.site_customization.pages.index.title") %></h2>
<% if @pages.any? %>
<h3><%= page_entries_info @pages %></h3>
<table class="cms-page-list">
<thead>
<tr>
<th><%= t("admin.site_customization.pages.page.title") %></th>
<th><%= t("admin.site_customization.pages.page.slug") %></th>
<th><%= t("admin.site_customization.pages.page.created_at") %></th>
<th><%= t("admin.site_customization.pages.page.updated_at") %></th>
<th><%= t("admin.site_customization.pages.page.status") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @pages.each do |page| %>
<tr id="<%= dom_id(page) %>">
<td><%= page.title %></td>
<td><%= page.slug %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
<td>
<%= render Admin::TableActionsComponent.new(page) do |actions| %>
<%= actions.action(:cards,
text: t("admin.site_customization.pages.page.see_cards"),
path: admin_site_customization_page_widget_cards_path(page)) %>
<% if page.status == "published" %>
<%= actions.action(:show,
text: t("admin.site_customization.pages.index.see_page"),
path: page.url,
options: { target: "_blank" }) %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @pages %>
<% else %>
<div class="callout primary">
<%= page_entries_info @pages %>
</div>
<% end %>
<%= render Admin::SiteCustomization::Pages::IndexComponent.new(@pages) %>