Files
grecia/app/views/notifications/_notification.html.erb
Bertocq a683fcff98 Refactor notification partials and index view
The notification body has been extracted to a new partial to allow
notifications without link to be rendered without needing an if-else
duplicating view code.

Note the `link_to_if` at _notification partial, as well as the optional
body attribute.
2018-07-25 18:31:41 +02:00

29 lines
1.1 KiB
Plaintext

<li id="<%= dom_id(notification) %>" class="notification <%= 'unread' if notification&.unread? %>">
<% if notification.try(:notifiable_available?) %>
<% locals = { notification: notification,
timestamp: notification.timestamp,
title: notification.notifiable_title,
body: notification.notifiable.try(:body) } %>
<% link_text = render partial: '/notifications/notification_body', locals: locals %>
<%= link_to_if notification.link.present?, link_text, notification.link %>
<% else %>
<p>
<strong>
<%= t("notifications.notification.notifiable_hidden") %>
</strong>
</p>
<% end %>
<% if notification.unread? %>
<%= link_to t("notifications.notification.mark_as_read"),
mark_as_read_notification_path(notification),
method: :put, remote: true,
class: "mark-notification small" %>
<% else %>
<%= link_to t("notifications.notification.mark_as_unread"),
mark_as_unread_notification_path(notification),
method: :put, remote: true,
class: "mark-notification small" %>
<% end %>
</li>