Extract components to render custom image table actions

This way it'll be easier to refactor them. We're also giving a proper
title to the images index page.
This commit is contained in:
Javi Martín
2024-03-31 19:31:36 +02:00
parent e884bc28e1
commit b33eec101e
5 changed files with 56 additions and 31 deletions

View File

@@ -0,0 +1,22 @@
<%= header %>
<table>
<thead>
<tr>
<th><%= t("admin.site_customization.images.index.image") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% images.each do |image| %>
<tr id="image_<%= image.name %>">
<td class="small-12 medium-4">
<strong><%= image.name %></strong> (<%= image.required_width %>x<%= image.required_height %>)
</td>
<td class="small-12 medium-8">
<%= render Admin::SiteCustomization::Images::TableActionsComponent.new(image) %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

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

View File

@@ -0,0 +1,12 @@
<div class="site-customization-images-table-actions">
<%= form_for([:admin, image], html: { id: "edit_#{dom_id(image)}" }) do |f| %>
<div class="small-12 medium-6 large-6 column">
<%= image_tag image.image if image.persisted_attachment? %>
<%= f.file_field :image, label: false %>
</div>
<div class="small-12 medium-6 large-6 column">
<%= f.submit(t("admin.site_customization.images.index.update"), class: "button hollow") %>
<%= link_to t("admin.site_customization.images.index.delete"), admin_site_customization_image_path(image), method: :delete, class: "button hollow alert" if image.persisted_attachment? %>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,7 @@
class Admin::SiteCustomization::Images::TableActionsComponent < ApplicationComponent
attr_reader :image
def initialize(image)
@image = image
end
end

View File

@@ -1,31 +1 @@
<h2><%= t("admin.site_customization.images.index.title") %></h2>
<table>
<thead>
<tr>
<th><%= t("admin.site_customization.images.index.image") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @images.each do |image| %>
<tr id="image_<%= image.name %>">
<td class="small-12 medium-4">
<strong><%= image.name %></strong> (<%= image.required_width %>x<%= image.required_height %>)
</td>
<td class="small-12 medium-8">
<%= form_for([:admin, image], html: { id: "edit_#{dom_id(image)}" }) do |f| %>
<div class="small-12 medium-6 large-6 column">
<%= image_tag image.image if image.persisted_attachment? %>
<%= f.file_field :image, label: false %>
</div>
<div class="small-12 medium-6 large-6 column">
<%= f.submit(t("admin.site_customization.images.index.update"), class: "button hollow") %>
<%= link_to t("admin.site_customization.images.index.delete"), admin_site_customization_image_path(image), method: :delete, class: "button hollow alert" if image.persisted_attachment? %>
</div>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render Admin::SiteCustomization::Images::IndexComponent.new(@images) %>