Move geozones index view to a component

This way we simplify the header and it will be easier to add more code
and tests.
This commit is contained in:
Javi Martín
2023-05-03 18:18:19 +02:00
parent ca013cf9f1
commit 882cc85532
3 changed files with 44 additions and 30 deletions

View File

@@ -0,0 +1,29 @@
<%= header do %>
<%= link_to t("admin.geozones.index.create"), new_admin_geozone_path %>
<% end %>
<table>
<thead>
<tr>
<th><%= t("admin.geozones.geozone.name") %></th>
<th><%= t("admin.geozones.geozone.external_code") %></th>
<th><%= t("admin.geozones.geozone.census_code") %></th>
<th><%= t("admin.geozones.geozone.coordinates") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% geozones.each do |geozone| %>
<tr id="<%= dom_id(geozone) %>">
<td><%= geozone.name %></td>
<td><%= geozone.external_code %></td>
<td><%= geozone.census_code %></td>
<td class="break"><%= geozone.html_map_coordinates %></td>
<td>
<%= render Admin::TableActionsComponent.new(geozone) %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,14 @@
class Admin::Geozones::IndexComponent < ApplicationComponent
include Header
attr_reader :geozones
def initialize(geozones)
@geozones = geozones
end
private
def title
t("admin.geozones.index.title")
end
end

View File

@@ -1,30 +1 @@
<%= link_to t("admin.geozones.index.create"),
new_admin_geozone_path, class: "button float-right" %>
<h2 class="inline-block"><%= t("admin.geozones.index.title") %></h2>
<table>
<thead>
<tr>
<th><%= t("admin.geozones.geozone.name") %></th>
<th><%= t("admin.geozones.geozone.external_code") %></th>
<th><%= t("admin.geozones.geozone.census_code") %></th>
<th><%= t("admin.geozones.geozone.coordinates") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @geozones.each do |geozone| %>
<tr id="<%= dom_id(geozone) %>">
<td><%= geozone.name %></td>
<td><%= geozone.external_code %></td>
<td><%= geozone.census_code %></td>
<td class="break"><%= geozone.html_map_coordinates %></td>
<td>
<%= render Admin::TableActionsComponent.new(geozone) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render Admin::Geozones::IndexComponent.new(@geozones) %>