Browse Source

feat: use newest active unread/unauthenticated notification and update start page

pull/2131/head
natdeanlewissoftwire 2 years ago
parent
commit
b49133a2d1
  1. 12
      app/controllers/notifications_controller.rb
  2. 6
      app/helpers/application_helper.rb
  3. 5
      app/models/notification.rb
  4. 4
      app/models/user.rb
  5. 8
      app/views/layouts/application.html.erb
  6. 18
      app/views/notifications/_notification_banner.html.erb
  7. 2
      app/views/notifications/show.html.erb
  8. 2
      app/views/start/index.html.erb

12
app/controllers/notifications_controller.rb

@ -1,13 +1,15 @@
class NotificationsController < ApplicationController
def dismiss
current_user.oldest_active_unread_notification.mark_as_read! for: current_user
redirect_back(fallback_location: root_path)
if current_user.blank?
redirect_to root_path
else
current_user.newest_active_unread_notification.mark_as_read! for: current_user
redirect_back(fallback_location: root_path)
end
end
def show
@notification = current_user.oldest_active_unread_notification
@notification = current_user&.newest_active_unread_notification || Notification.newest_active_unauthenticated_notification
if @notification&.page_content
render "show"
else

6
app/helpers/application_helper.rb

@ -10,9 +10,9 @@ module ApplicationHelper
end
def govuk_header_classes(current_user)
if current_user && current_user.support?
if current_user&.support?
"app-header app-header--orange"
elsif current_user && Notification.unread_by(current_user).present? && !current_page?(notifications_path)
elsif (current_user.blank? || current_user.active_unread_notifications.present?) && !current_page?(notifications_path)
"app-header app-header__no-border-bottom"
else
"app-header"
@ -20,7 +20,7 @@ module ApplicationHelper
end
def govuk_phase_banner_tag(current_user)
if current_user && current_user.support?
if current_user&.support?
{ colour: "orange", text: "Support beta" }
else
{ text: "Beta" }

5
app/models/notification.rb

@ -2,4 +2,9 @@ class Notification < ApplicationRecord
acts_as_readable
scope :active, -> { where("start_date <= ?", Time.zone.now).where("end_date >= ?", Time.zone.now) }
scope :unauthenticated, -> { where(show_on_unauthenticated_pages: true) }
def self.newest_active_unauthenticated_notification
active.unauthenticated.last
end
end

4
app/models/user.rb

@ -233,8 +233,8 @@ class User < ApplicationRecord
Notification.active.unread_by(self)
end
def oldest_active_unread_notification
active_unread_notifications.first
def newest_active_unread_notification
active_unread_notifications.last
end
protected

8
app/views/layouts/application.html.erb

@ -101,8 +101,12 @@
end
end %>
<% if current_user.present? && Notification.unread_by(current_user).present? && !current_page?(notifications_path)%>
<%= render "notifications/notification_banner" %>
<% unless current_page?(notifications_path) %>
<% if current_user&.active_unread_notifications.present? %>
<%= render "notifications/notification_banner", notification_count: current_user.active_unread_notifications.count, notification: current_user.newest_active_unread_notification %>
<% elsif !current_user.present? && Notification.unauthenticated.present? %>
<%= render "notifications/notification_banner", notification_count: Notification.unauthenticated.count, notification: Notification.newest_active_unauthenticated_notification %>
<% end %>
<% end %>

18
app/views/notifications/_notification_banner.html.erb

@ -3,19 +3,21 @@
<br>
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<% if current_user.active_unread_notifications.count > 1 %>
<p>Notification 1 of <%= current_user.active_unread_notifications.count %></p>
<% if notification_count > 1 && current_user.present?%>
<p>Notification 1 of <%= notification_count %></p>
<% end %>
<p class="govuk-!-font-weight-bold"><%= current_user.oldest_active_unread_notification.title %></p>
<% if current_user.oldest_active_unread_notification.page_content.present? %>
<p class="govuk-!-font-weight-bold"><%= notification.title %></p>
<% if notification.page_content.present? %>
<div class ="govuk-body">
<%= govuk_link_to current_user.oldest_active_unread_notification.link_text, notifications_path, class: "govuk-link--inverse govuk-!-font-weight-bold"%>
<%= govuk_link_to notification.link_text, notifications_path, class: "govuk-link--inverse govuk-!-font-weight-bold"%>
</div>
<% end %>
</div>
<p class="govuk-grid-column-one-quarter govuk-!-text-align-right ">
<%= govuk_link_to "Dismiss", dismiss_notifications_path, class: "govuk-link--inverse"%>
</p>
<% if current_user.present? %>
<p class="govuk-grid-column-one-quarter govuk-!-text-align-right ">
<%= govuk_link_to "Dismiss", dismiss_notifications_path, class: "govuk-link--inverse"%>
</p>
<% end %>
</div>
</div>
</div>

2
app/views/notifications/show.html.erb

@ -13,5 +13,5 @@
</div>
<br>
<div>
<%= govuk_button_link_to "Back to Home", root_path %>
<%= govuk_button_link_to "Back to #{current_user.present? ? "Home": "Start"}", root_path %>
</div>

2
app/views/start/index.html.erb

@ -23,10 +23,10 @@
<p class="govuk-body">If you need to set up a new account, speak to your organisation’s CORE data coordinator. If you don’t know who that is, <%= govuk_link_to("contact the helpdesk", GlobalConstants::HELPDESK_URL) %>.</p>
<p class="govuk-body">You can <%= govuk_mail_to("dluhc.digital-services@levellingup.gov.uk", "request an account", subject: "CORE: Request a new account") %> if your organisation doesn’t have one.</p>
<p class="govuk-body"><strong><%= govuk_link_to guidance_path do %>Guidance for submitting social housing lettings and sales data (CORE)<% end %></strong><p>
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m">
</div>
</div>
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render partial: "layouts/collection_resources" %>

Loading…
Cancel
Save