From 6cf2e6ff39d7bbee17b8eefeb21b3b77c94b824f Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Tue, 10 Sep 2024 10:49:20 +0100 Subject: [PATCH] Move db queries to homepage presenter --- app/presenters/homepage_presenter.rb | 3 ++- app/views/home/index.html.erb | 2 +- app/views/notifications/_notification_home_section.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/presenters/homepage_presenter.rb b/app/presenters/homepage_presenter.rb index 1cb784e3a..3b3314667 100644 --- a/app/presenters/homepage_presenter.rb +++ b/app/presenters/homepage_presenter.rb @@ -2,7 +2,7 @@ class HomepagePresenter include Rails.application.routes.url_helpers include CollectionTimeHelper - attr_reader :current_year_in_progress_lettings_data, :current_year_completed_lettings_data, :current_year_in_progress_sales_data, :current_year_completed_sales_data, :last_year_in_progress_lettings_data, :last_year_completed_lettings_data, :last_year_in_progress_sales_data, :last_year_completed_sales_data, :incomplete_schemes_data + attr_reader :current_year_in_progress_lettings_data, :current_year_completed_lettings_data, :current_year_in_progress_sales_data, :current_year_completed_sales_data, :last_year_in_progress_lettings_data, :last_year_completed_lettings_data, :last_year_in_progress_sales_data, :last_year_completed_sales_data, :incomplete_schemes_data, :active_notifications def initialize(user) @user = user @@ -25,6 +25,7 @@ class HomepagePresenter path: schemes_path(status: [:incomplete], owning_organisation_select: "all"), } end + @active_notifications = Notification.active if @user.support? end def title_text_for_user diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 6ff6c2ccc..e55dc6c99 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -7,7 +7,7 @@ <% if @current_user.support? %> - <%= render partial: "notifications/notification_home_section" %> + <%= render partial: "notifications/notification_home_section", locals: { active_notifications: @homepage_presenter.active_notifications } %> <% end %>
diff --git a/app/views/notifications/_notification_home_section.html.erb b/app/views/notifications/_notification_home_section.html.erb index 723107b7f..1713ea0ea 100644 --- a/app/views/notifications/_notification_home_section.html.erb +++ b/app/views/notifications/_notification_home_section.html.erb @@ -1,6 +1,6 @@
-

<%== I18n.t("active_notifications", count: Notification.active.count) %>

- <% Notification.active.each do |notification| %> +

<%== I18n.t("active_notifications", count: active_notifications.count) %>

+ <% active_notifications.each do |notification| %>
<%== render_for_home(notification) %>