Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Adapt structure of notifications sidemenu to the same we have in other modules

Henriette Darged7fe552ece76
diff --git a/app/controllers/notifications/menus_controller.rb b/app/controllers/notifications/menus_controller.rb
index 2d064408901..18e4258956f 100644
--- a/app/controllers/notifications/menus_controller.rb
+++ b/app/controllers/notifications/menus_controller.rb
@@ -32,9 +32,9 @@ module Notifications
no_authorization_required! :show
def show
- menu = Menus::Notifications.new(controller_path: params[:controller_path], params:, current_user:)
+ menu = Notifications::Menu.new(params:, current_user:)
- @sidebar_menu_items = menu.first_level_menu_items
+ @sidebar_menu_items = menu.menu_items
render layout: nil
end
diff --git a/app/helpers/menus/notifications.rb b/app/menus/notifications/menu.rb
similarity index 64%
rename from app/helpers/menus/notifications.rb
rename to app/menus/notifications/menu.rb
index 64a3618cac9..5fd9d1da677 100644
--- a/app/helpers/menus/notifications.rb
+++ b/app/menus/notifications/menu.rb
@@ -26,29 +26,27 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Menus
- class Notifications
+module Notifications
+ class Menu < Submenu
ENTERPRISE_REASONS = %w[shared date_alert].freeze
include Rails.application.routes.url_helpers
- attr_reader :controller_path, :params, :current_user,
+ attr_reader :params, :current_user,
:query, :unread_by_reason, :unread_by_project
- def initialize(controller_path:, params:, current_user:)
- # rubocop:disable Rails/HelperInstanceVariable
- @controller_path = controller_path
+ def initialize(params:, current_user:)
@params = params
@current_user = current_user
@unread_by_reason = filter_unread_by_reason
@unread_by_project = filter_unread_by_project
- # rubocop:enable Rails/HelperInstanceVariable
+
+ super(view_type: nil, project: nil, params:)
end
- def first_level_menu_items
+ def menu_items
[
- OpenProject::Menu::MenuGroup.new(header: nil,
- children: [inbox_menu]),
+ OpenProject::Menu::MenuGroup.new(header: nil, children: [inbox_menu]),
OpenProject::Menu::MenuGroup.new(header: I18n.t("notifications.menu.by_reason"),
children: reason_filters),
OpenProject::Menu::MenuGroup.new(header: I18n.t("notifications.menu.by_project"),
@@ -58,6 +56,23 @@ module Menus
private
+ def inbox_menu
+ menu_item(:inbox, I18n.t("notifications.menu.inbox"), nil, {})
+ end
+
+ def reason_filters
+ %w[mentioned assigned responsible watched date_alert shared].map do |reason|
+ count = unread_by_reason[reason]
+ menu_item(reason, I18n.t("mail.work_packages.reason.#{reason}"), count == 0 ? nil : count, query_params("reason", reason))
+ end
+ end
+
+ def project_filters
+ unread_by_project.map do |project, count|
+ menu_item(nil, project.name, count, query_params("project", project.id))
+ end
+ end
+
def filter_unread_by_reason
query = Queries::Notifications::NotificationQuery.new(user: current_user)
query.where(:read_ian, "=", "f")
@@ -72,35 +87,25 @@ module Menus
query.group_values
end
- def inbox_menu
- OpenProject::Menu::MenuItem.new(title: I18n.t("notifications.menu.inbox"),
- icon: :inbox,
- href: notifications_path,
- selected: !(params[:name] && params[:filter]))
+ def menu_item(key, title, count, query_params)
+ OpenProject::Menu::MenuItem.new(title:,
+ href: query_path(query_params),
+ icon: icon_map.fetch(key, key),
+ count:,
+ selected: selected?(query_params),
+ favored: favored?(query_params))
end
- def selected?(filter, name)
- params[:filter] == filter && params[:name] == name
+ def query_params(filter, name)
+ { filter:, name: }
end
- def reason_filters
- %w[mentioned assigned responsible watched date_alert shared].map do |reason|
- count = unread_by_reason[reason]
- OpenProject::Menu::MenuItem.new(title: I18n.t("mail.work_packages.reason.#{reason}"),
- icon: icon_map.fetch(reason, reason),
- href: notifications_path(filter: "reason", name: reason),
- count: count == 0 ? nil : count,
- selected: selected?("reason", reason))
- end
+ def selected?(query_params)
+ params[:filter] == query_params[:filter] && params[:name] == query_params[:name]
end
- def project_filters
- unread_by_project.map do |project, count|
- OpenProject::Menu::MenuItem.new(title: project.name,
- href: notifications_path(filter: "project", name: project.id),
- count: count,
- selected: selected?("project", project.id))
- end
+ def query_path(query_params)
+ notifications_path(query_params)
end
def icon_map
diff --git a/app/views/notifications/menus/_menu.html.erb b/app/views/notifications/menus/_menu.html.erb
index 25a13c75e09..a9df3947768 100644
--- a/app/views/notifications/menus/_menu.html.erb
+++ b/app/views/notifications/menus/_menu.html.erb
@@ -1,8 +1,5 @@
<%= turbo_frame_tag "notifications_sidemenu",
- src: notifications_menu_path(
- controller_path:,
- **params.permit(:filter, :name)
- ),
+ src: notifications_menu_path(**params.permit(:filter, :name)),
target: '_top',
data: { turbo: false },
loading: :lazy %>
diff --git a/config/routes.rb b/config/routes.rb
index 63bf00232ca..6e90bbb9517 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -699,14 +699,11 @@ Rails.application.routes.draw do
root to: "account#login"
- scope :notifications do
- get "(/*state)", to: "angular#notifications_layout", as: :notifications_center
- end
-
- resources :notifications, only: :index do
+ resource :notifications do
collection do
resource :menu, module: :notifications, only: %i[show], as: :notifications_menu
end
+ get "(/*state)", to: "angular#notifications_layout", as: :notifications_center
end
# OAuthClient needs a "callback" URL that Nextcloud calls with a "code" (see OAuth2 RFC)
diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
index daaa9fdaff1..ab8854ddc9f 100644
--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
@@ -370,7 +370,7 @@ export class IanCenterService extends UntilDestroyedMixin {
}
// Reload the sidemenu frame
- this.menuFrame.reload();
+ void this.menuFrame.reload();
}
private sideLoadInvolvedWorkPackages(elements:INotification[]):Promise<unknown> {