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:
Bertocq
2018-02-28 20:57:39 +01:00
committed by decabeza
parent a10169bac0
commit a683fcff98
3 changed files with 28 additions and 19 deletions

View File

@@ -1,21 +1,11 @@
<li id="<%= dom_id(notification) %>" class="notification <%= "unread" if notification.unread? %>">
<% if notification.notifiable_available? %>
<%= link_to notification do %>
<p>
<em>
<%= t("notifications.notification.action.#{notification.notifiable_action}",
count: notification.counter) %>
</em>
<strong id="<%= dom_id(notification) %>_title">
<%= notification.notifiable_title %>
</strong>
</p>
<p class="time">
<%= l notification.timestamp, format: :datetime %>
</p>
<% end %>
<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>

View 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>

View File

@@ -24,7 +24,9 @@
</div>
<% else %>
<ul class="no-bullet clear notifications-list">
<%= render @notifications %>
<% @notifications.each do |notification| %>
<%= render partial: '/notifications/notification', locals: {notification: notification} %>
<% end %>
</ul>
<% end %>
</div>