Skip to content

Commit 1e8feea

Browse files
committed
Remove set_counted_notifications method from NotificationController
1 parent 1c2e138 commit 1e8feea

File tree

6 files changed

+8
-32
lines changed

6 files changed

+8
-32
lines changed

src/api/app/components/notification_action_bar_component.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- if state != 'unread'
1212
= button_tag("Mark selected as 'Unread'", type: 'submit', class: 'btn btn-sm btn-outline-success px-3', id: 'unread-button',
1313
disabled: 'disabled', 'data-disable-with': disable_with_content, value: 'unread')
14-
- if counted_notifications['all'] > Notification.max_per_page
14+
- if total_count_notifications > Notification.max_per_page
1515
.ms-4
1616
= link_to(button_text(all: true), @update_path, method: :put, remote: true,
1717
class: 'btn btn-sm btn-outline-secondary px-3', 'data-disable-with': disable_with_content(all: true))

src/api/app/components/notification_action_bar_component.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# frozen_string_literal: true
22

33
class NotificationActionBarComponent < ApplicationComponent
4-
attr_accessor :state, :update_path, :counted_notifications
4+
attr_accessor :state, :update_path, :total_count_notifications
55

6-
def initialize(state:, update_path:, counted_notifications:)
6+
def initialize(state:, update_path:, total_count_notifications:)
77
super()
8-
98
@state = state
109
@update_path = toggle_update_path_states(update_path)
11-
@counted_notifications = counted_notifications
10+
@total_count_notifications = total_count_notifications
1211
end
1312

1413
def button_text(all: false)

src/api/app/controllers/webui/users/notifications_controller.rb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Webui::Users::NotificationsController < Webui::WebuiController
2626
:set_filter_project, :set_filter_group, :set_filter_request_state, :set_filter_label
2727
before_action :set_notifications
2828
before_action :set_notifications_to_be_updated, only: :update
29-
before_action :set_counted_notifications, only: :index
3029
before_action :filter_notifications, only: :index
3130
before_action :set_selected_filter
3231
before_action :set_preloaded_notifications, only: :index
@@ -46,7 +45,6 @@ def update
4645

4746
# manually update the count and the filtered subset after the update
4847
set_unread_notifications_count # before_action filter method defined in the Webui controller
49-
set_counted_notifications
5048
filter_notifications
5149
set_preloaded_notifications
5250
set_ordered_notifications
@@ -59,7 +57,7 @@ def update
5957
notifications: @notifications,
6058
unread_notifications_count: @unread_notifications_count,
6159
selected_filter: @selected_filter,
62-
counted_notifications: @counted_notifications,
60+
total_count_notifications: @notifications.count,
6361
user: User.session
6462
}
6563
end
@@ -158,26 +156,6 @@ def set_notifications
158156
@notifications = User.session.notifications.for_web
159157
end
160158

161-
def set_counted_notifications
162-
@counted_notifications = {}
163-
@counted_notifications['all'] = @notifications.count
164-
@counted_notifications['unread'] = @unread_notifications_count # Variable set in the Webui controller
165-
@counted_notifications['incoming_requests'] = @notifications.unread.for_incoming_requests(User.session).count
166-
@counted_notifications['outgoing_requests'] = @notifications.unread.for_outgoing_requests(User.session).count
167-
168-
# event_type: 'Event::RelationshipCreate', 'Event::RelationshipDelete', 'Event::BuildFail',
169-
counted_event_types = @notifications.unread.group(:event_type).count
170-
EVENT_TYPES_KEY_MAP.each do |notifications_key, event_types_key|
171-
@counted_notifications[notifications_key] = counted_event_types[event_types_key] || 0
172-
end
173-
174-
# notifiable_type: 'Report', 'WorkflowRun', 'Decision', 'Comment', 'BsRequest', 'Group'
175-
counted_notifiable_types = @notifications.unread.group(:notifiable_type).count
176-
NOTIFICATION_TYPES_KEY_MAP.each do |notifications_key, notification_types_key|
177-
@counted_notifications[notifications_key] = counted_notifiable_types[notification_types_key] || 0
178-
end
179-
end
180-
181159
def filter_notifications
182160
@notifications = filter_notifications_by_project(@notifications, @filter_project)
183161
@notifications = filter_notifications_by_group(@notifications, @filter_group)

src/api/app/views/webui/users/notifications/_notifications_list.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
.card
1414
.card-body.pt-1
1515
= render(NotificationActionBarComponent.new(state: selected_filter[:state],
16-
update_path: update_path,
17-
counted_notifications: counted_notifications))
16+
update_path: update_path,
17+
total_count_notifications: notifications.count))
1818
.text-center
1919
%span.ms-3= page_entries_info notifications, entry_name: ''
2020
- if notifications.total_count > Notification::THRESHOLD_TO_RECOMMEND_NOTIFICATION_MANAGEMENT
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
$('#content-selector-filters').html("<%= j(render partial: 'notification_filter', locals: { selected_filter: selected_filter, projects_for_filter: @projects_for_filter, groups_for_filter: @groups_for_filter }) %>");
2-
$('#notifications-list').html("<%= j(render partial: 'notifications_list', locals: { notifications: notifications, selected_filter: selected_filter, counted_notifications: @counted_notifications }) %>");
2+
$('#notifications-list').html("<%= j(render partial: 'notifications_list', locals: { notifications: notifications, selected_filter: selected_filter, total_count_notifications: total_count_notifications }) %>");
33
$('#flash').html("<%= escape_javascript(render(layout: false, partial: 'layouts/webui/flash', object: flash)) %>");
44
$('#top-notifications-counter, #bottom-notifications-counter').html("<%= escape_javascript(render partial: 'layouts/webui/unread_notifications_counter', locals: { unread_notifications_count: unread_notifications_count }) %>");

src/api/app/views/webui/users/notifications/index.html.haml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@
2020
= render partial: 'webui/shared/loading', locals: { text: 'Loading...', wrapper_css: ['loading'] }
2121
.col-md-8.col-lg-9.px-0.px-md-3.content-list#notifications-list
2222
= render partial: 'notifications_list', locals: { notifications: @notifications,
23-
counted_notifications: @counted_notifications,
2423
selected_filter: @selected_filter }

0 commit comments

Comments
 (0)