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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.rbindex 2d064408901..18e4258956f 100644--- a/app/controllers/notifications/menus_controller.rb+++ b/app/controllers/notifications/menus_controller.rb@@ -32,9 +32,9 @@ module Notificationsno_authorization_required! :showdef 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_itemsrender layout: nilenddiff --git a/app/helpers/menus/notifications.rb b/app/menus/notifications/menu.rbsimilarity index 64%rename from app/helpers/menus/notifications.rbrename to app/menus/notifications/menu.rbindex 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 < SubmenuENTERPRISE_REASONS = %w[shared date_alert].freezeinclude 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 Menusprivate+ 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_reasonquery = Queries::Notifications::NotificationQuery.new(user: current_user)query.where(:read_ian, "=", "f")@@ -72,35 +87,25 @@ module Menusquery.group_valuesend- 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)enddef icon_mapdiff --git a/app/views/notifications/menus/_menu.html.erb b/app/views/notifications/menus/_menu.html.erbindex 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.rbindex 63bf00232ca..6e90bbb9517 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -699,14 +699,11 @@ Rails.application.routes.draw doroot to: "account#login"- scope :notifications do- get "(/*state)", to: "angular#notifications_layout", as: :notifications_center- end-- resources :notifications, only: :index do+ resource :notifications docollection doresource :menu, module: :notifications, only: %i[show], as: :notifications_menuend+ get "(/*state)", to: "angular#notifications_layout", as: :notifications_centerend# 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.tsindex 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> {