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.
This commit is contained in:
@@ -1,21 +1,11 @@
|
|||||||
<li id="<%= dom_id(notification) %>" class="notification <%= "unread" if notification.unread? %>">
|
<li id="<%= dom_id(notification) %>" class="notification <%= 'unread' if notification&.unread? %>">
|
||||||
|
<% if notification.try(:notifiable_available?) %>
|
||||||
<% if notification.notifiable_available? %>
|
<% locals = { notification: notification,
|
||||||
<%= link_to notification do %>
|
timestamp: notification.timestamp,
|
||||||
<p>
|
title: notification.notifiable_title,
|
||||||
<em>
|
body: notification.notifiable.try(:body) } %>
|
||||||
<%= t("notifications.notification.action.#{notification.notifiable_action}",
|
<% link_text = render partial: '/notifications/notification_body', locals: locals %>
|
||||||
count: notification.counter) %>
|
<%= link_to_if notification.link.present?, link_text, notification.link %>
|
||||||
</em>
|
|
||||||
<strong id="<%= dom_id(notification) %>_title">
|
|
||||||
<%= notification.notifiable_title %>
|
|
||||||
</strong>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="time">
|
|
||||||
<%= l notification.timestamp, format: :datetime %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>
|
<p>
|
||||||
<strong>
|
<strong>
|
||||||
|
|||||||
17
app/views/notifications/_notification_body.html.erb
Normal file
17
app/views/notifications/_notification_body.html.erb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<p>
|
||||||
|
<% if notification && notification.notifiable_action %>
|
||||||
|
<em>
|
||||||
|
<%= t("notifications.notification.action.#{notification.notifiable_action}",
|
||||||
|
count: notification.counter) %>
|
||||||
|
</em>
|
||||||
|
<% end %>
|
||||||
|
<strong id="<%= dom_id(notification) if notification %>_title">
|
||||||
|
<%= title %>
|
||||||
|
</strong>
|
||||||
|
<% if body %>
|
||||||
|
<p><%= body %></p>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<p class="time">
|
||||||
|
<%= l(timestamp, format: :datetime) %>
|
||||||
|
</p>
|
||||||
@@ -24,7 +24,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<ul class="no-bullet clear notifications-list">
|
<ul class="no-bullet clear notifications-list">
|
||||||
<%= render @notifications %>
|
<% @notifications.each do |notification| %>
|
||||||
|
<%= render partial: '/notifications/notification', locals: {notification: notification} %>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user