From 9f35370bb92c45aaba1d7d59a2af9f21c98044b1 Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Mon, 21 Sep 2020 14:41:40 +0200 Subject: [PATCH 1/3] Add page and show_all parameters, when reading... ... a notification. This will preserve the current pagination page and if all the results are shown, when a notification is marked as read. --- .../app/controllers/webui/users/notifications_controller.rb | 2 +- .../webui/users/notifications/_notifications_list.html.haml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/app/controllers/webui/users/notifications_controller.rb b/src/api/app/controllers/webui/users/notifications_controller.rb index 7cc711a3344..c3899f2fdbe 100644 --- a/src/api/app/controllers/webui/users/notifications_controller.rb +++ b/src/api/app/controllers/webui/users/notifications_controller.rb @@ -79,7 +79,7 @@ def fetch_notifications else NotificationsFinder.new(notifications_for_subscribed_user).for_notifiable_type(params[:type]) end - params['show_all'] ? show_all(notifications) : notifications.page(params[:page]) + params[:show_all] ? show_all(notifications) : notifications.page(params[:page]) end def notifications_filter diff --git a/src/api/app/views/webui/users/notifications/_notifications_list.html.haml b/src/api/app/views/webui/users/notifications/_notifications_list.html.haml index 1c104646c63..f2f2bad5693 100644 --- a/src/api/app/views/webui/users/notifications/_notifications_list.html.haml +++ b/src/api/app/views/webui/users/notifications/_notifications_list.html.haml @@ -12,7 +12,7 @@ - else .text-center %span.ml-3= page_entries_info notifications, entry_name: 'notification' - = link_to_all unless notifications.total_pages == 1 && params['show_all'].nil? + = link_to_all unless notifications.total_pages == 1 && params[:show_all].nil? .list-group.list-group-flush.mt-3 - notifications.each do |n| @@ -29,7 +29,8 @@ = link_to(notification.notifiable_link[:text], notification.notifiable_link[:path], class: 'mx-1 text-word-break-all') .actions.ml-auto.align-self-end.align-self-md-start - title, icon = notification.unread? ? ['Mark as "Read"', 'fa-check'] : ['Mark as "Unread"', 'fa-undo'] - - update_path = my_notification_path(id: notification, type: selected_filter[:type], project: selected_filter[:project]) + - update_path = my_notification_path(id: notification, type: selected_filter[:type], project: selected_filter[:project], + page: params[:page], show_all: params[:show_all]) = link_to(update_path, id: format('update-notification-%d', notification.id), method: :put, class: 'btn btn-sm btn-outline-success px-3', title: title, remote: true) do %i.fas{ class: "#{icon}" } From df316fe5302048c46edc24fe2d972e76d72c7cce Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Mon, 21 Sep 2020 14:44:37 +0200 Subject: [PATCH 2/3] Don't preserve the "page" parameter when changing... ... from "Show all" to "Show less", and viceversa. For example, keeping the second page of results when they change from being paginated from bunchs of 25 to bunchs of 300 results, brings no value. --- src/api/app/helpers/webui/notification_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/app/helpers/webui/notification_helper.rb b/src/api/app/helpers/webui/notification_helper.rb index 46028b6278e..70b64ae8656 100644 --- a/src/api/app/helpers/webui/notification_helper.rb +++ b/src/api/app/helpers/webui/notification_helper.rb @@ -1,6 +1,6 @@ module Webui::NotificationHelper def link_to_all - parameters = params.slice(:show_all, :type, :project, :page).permit! + parameters = params.slice(:show_all, :type, :project).permit! all_or_less = parameters[:show_all] ? 'less' : 'all' parameters[:show_all] = parameters[:show_all] ? nil : '1' link_to("Show #{all_or_less}", my_notifications_path(parameters), class: 'btn btn-sm btn-secondary ml-2') From e0adca52ee87fc2bcb6f19cf3b3644ea018a8ce4 Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Mon, 21 Sep 2020 15:18:02 +0200 Subject: [PATCH 3/3] Take the user to the last pagination page, when ... ... marking as read the only notification of the last page. This way, a page with no results will not be shown. --- src/api/app/controllers/webui/users/notifications_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/app/controllers/webui/users/notifications_controller.rb b/src/api/app/controllers/webui/users/notifications_controller.rb index c3899f2fdbe..82036e8fe34 100644 --- a/src/api/app/controllers/webui/users/notifications_controller.rb +++ b/src/api/app/controllers/webui/users/notifications_controller.rb @@ -79,6 +79,7 @@ def fetch_notifications else NotificationsFinder.new(notifications_for_subscribed_user).for_notifiable_type(params[:type]) end + params[:page] = notifications.page(params[:page]).total_pages if notifications.page(params[:page]).out_of_range? params[:show_all] ? show_all(notifications) : notifications.page(params[:page]) end