Files
grecia/app/views/admin/milestones/_milestones.html.erb
Javi Martín 091abfc944 Use Active Storage to render attachments
This way we fix a bug we mentioned in commit 930bb753c which caused
links to documents to be broken when editing their title because the
title was used to generate the URL of the document.

Note we're still using Paperclip to render cached attachments because
this is the only case where we store files with just Paperclip and not
Active Storage.

With Active Storage, we render attachments just like any other resource,
using `polymorphic_path`. Paperclip included the `url` method in the
model; since the model doesn't have access to the request parameters
(like the host), this was inconvenient because it wasn't possible to
generate absolute URLs with Paperclip.

In order to simplify the code and make it similar to the way we used
Paperclip, we're adding a `variant` method accepting the name of a
variant and returning the variant.
2022-02-23 18:21:38 +01:00

70 lines
2.6 KiB
Plaintext

<h2 class="inline-block"><%= t("admin.milestones.index.milestone") %></h2>
<%= link_to t("admin.progress_bars.manage"),
admin_polymorphic_path(milestoneable.progress_bars.new),
class: "button hollow float-right" %>
<% if milestoneable.milestone_tag_list.any? %>
<div>
<strong>
<%= t("admin.milestones.index.milestone_tags") %>:
</strong> <%= milestoneable.milestone_tag_list.sort.join(", ") %>
</div>
<% end %>
<% if milestoneable.milestones.any? %>
<table>
<thead>
<tr>
<th><%= t("admin.milestones.index.table_id") %></th>
<th><%= t("admin.milestones.index.table_title") %></th>
<th><%= t("admin.milestones.index.table_description") %></th>
<th><%= t("admin.milestones.index.table_publication_date") %></th>
<th><%= t("admin.milestones.index.table_status") %></th>
<th><%= t("admin.milestones.index.image") %></th>
<th><%= t("admin.milestones.index.documents") %></th>
<th><%= t("admin.milestones.index.table_actions") %></th>
</tr>
</thead>
<tbody>
<% milestoneable.milestones.order_by_publication_date.each do |milestone| %>
<tr id="<%= dom_id(milestone) %>" class="milestone">
<td class="text-center"><%= milestone.id %></td>
<td><%= milestone.title %></td>
<td class="small small-5"><%= milestone.description %></td>
<td class="small">
<%= l(milestone.publication_date.to_date) if milestone.publication_date.present? %>
</td>
<td class="small">
<%= milestone.status.present? ? milestone.status.name : "" %>
</td>
<td class="small">
<%= link_to t("admin.milestones.index.show_image"),
milestone.image.variant(:large),
target: :_blank if milestone.image.present? %>
</td>
<td class="small">
<% if milestone.documents.present? %>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.storage_attachment,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
<% end %>
</td>
<td><%= render Admin::TableActionsComponent.new(milestone) %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p><%= t("admin.milestones.index.no_milestones") %></p>
<% end %>
<p>
<%= link_to t("admin.milestones.index.new_milestone"),
admin_polymorphic_path(milestoneable.milestones.new, action: :new),
class: "button hollow" %>
</p>