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
Replace angular sidemenu with rails based Submenu component for WorkPackages module
Henriette Dargee049cb03a48b
diff --git a/app/controllers/work_packages/menus_controller.rb b/app/controllers/work_packages/menus_controller.rbnew file mode 100644index 00000000000..7c5061c9513--- /dev/null+++ b/app/controllers/work_packages/menus_controller.rb@@ -0,0 +1,37 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++module WorkPackages+ class MenusController < ApplicationController+ before_action :load_and_authorize_in_optional_project++ def show+ @sidebar_menu_items = WorkPackages::Menu.new(project: @project, params:).menu_items+ render layout: nil+ end+ end+enddiff --git a/app/menus/submenu.rb b/app/menus/submenu.rbindex 0cdbcbbb861..e35b092cb48 100644--- a/app/menus/submenu.rb+++ b/app/menus/submenu.rb@@ -102,7 +102,7 @@ class Submenuendend- if query_params.empty? && params[:filters].present?+ if query_params.empty? && (%i[filters query_props query_id name].any? { |k| params.key? k })return falseenddiff --git a/app/menus/work_packages/menu.rb b/app/menus/work_packages/menu.rbnew file mode 100644index 00000000000..64ae6cbcc31--- /dev/null+++ b/app/menus/work_packages/menu.rb@@ -0,0 +1,79 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# +++module WorkPackages+ class Menu < Submenu+ attr_reader :view_type, :project, :params++ def initialize(project: nil, params: nil)+ @view_type = "work_packages_table"++ super(view_type:, project:, params:)+ end++ def default_queries+ query_generator = WorkPackages::DefaultQueryGeneratorService.new(with_project: project)+ WorkPackages::DefaultQueryGeneratorService::QUERY_OPTIONS.filter_map do |query_key|+ params = query_generator.call(query_key:)+ next if params.nil?++ menu_item(+ I18n.t("js.work_packages.default_queries.#{query_key}"),+ params+ )+ end+ end++ def query_path(query_params)+ if !EnterpriseToken.allows_to?(:work_package_sharing) &&+ %i[shared_with_users shared_with_me].any?(query_params[:name])+ return ee_upsale_path(query_params)+ end++ if project.present?+ return report_project_work_packages_path(project, { name: query_params[:name] }) if query_params[:name] == :summary++ project_work_packages_path(project, query_params)+ else+ work_packages_path(query_params)+ end+ end++ def selected?(query_params)+ # Special rules, as those are redirected to completely new pages where only the name parameter is preserved+ return true if query_params[:name] == :summary && params[:name] == "summary"+ return true if query_params[:name] == :shared_with_me && params[:name] == "shared_with_me"+ return true if query_params[:name] == :shared_with_users && params[:name] == "shared_with_users"++ super+ end++ def ee_upsale_path(query_params)+ share_upsale_work_packages_path({ name: query_params[:name] })+ end+ end+enddiff --git a/app/services/work_packages/default_query_generator_service.rb b/app/services/work_packages/default_query_generator_service.rbnew file mode 100644index 00000000000..0a86b78cc25--- /dev/null+++ b/app/services/work_packages/default_query_generator_service.rb@@ -0,0 +1,180 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module ::WorkPackages+ class DefaultQueryGeneratorService+ DEFAULT_QUERY = :all_open+ QUERY_OPTIONS = [+ DEFAULT_QUERY,+ :latest_activity,+ :recently_created,+ :overdue,+ :summary,+ :created_by_me,+ :assigned_to_me,+ :shared_with_users,+ :shared_with_me+ ].freeze++ DEFAULT_PARAMS =+ {+ g: "",+ hi: false,+ t: "updatedAt:desc,id:asc"+ }.freeze++ attr_reader :project++ def initialize(with_project:)+ @project = with_project+ end++ def call(query_key: DEFAULT_QUERY)+ return {} if query_key == DEFAULT_QUERY++ params = self.class.assign_params(query_key, project)++ return if params.nil?++ { query_props: params.to_json, name: query_key }+ end++ class << self+ def all_open_query+ {}+ end++ def latest_activity_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type status assignee updatedAt],+ t: "updatedAt:desc",+ f: [{ "n" => "status", "o" => "*", "v" => [] }]+ }+ )+ end++ def recently_created_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type status assignee createdAt],+ t: "createdAt:desc",+ f: [{ "n" => "status", "o" => "o", "v" => [] }]+ }+ )+ end++ def overdue_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id type subject status startDate dueDate duration],+ t: "createdAt:desc",+ f: [{ "n" => "dueDate", "o" => "<t-", "v" => ["1"] },+ { "n" => "status", "o" => "o", "v" => [] }]+ }+ )+ end++ def summary_query+ {}+ end++ def created_by_me_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type status assignee updatedAt],+ f: [{ "n" => "status", "o" => "o", "v" => [] },+ { "n" => "author", "o" => "=", "v" => ["me"] }]+ }+ )+ end++ def assigned_to_me_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type status author updatedAt],+ f: [{ "n" => "status", "o" => "o", "v" => [] },+ { "n" => "assigneeOrGroup", "o" => "=", "v" => ["me"] }]+ }+ )+ end++ def shared_with_users_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type project sharedWithUsers],+ f: [{ "n" => "sharedWithUser", "o" => "*", "v" => [] }]+ }+ )+ end++ def shared_with_me_query+ DEFAULT_PARAMS.merge(+ {+ c: %w[id subject type project],+ f: [{ "n" => "sharedWithMe", "o" => "=", "v" => "t" }]+ }+ )+ end++ def assign_params(query_key, project)+ case query_key+ when DEFAULT_QUERY+ all_open_query+ when :latest_activity+ latest_activity_query+ when :recently_created+ recently_created_query+ when :overdue+ overdue_query+ when :summary+ return if project.blank?++ summary_query+ else+ return unless User.current.logged?++ user_specific_queries(query_key)+ end+ end++ def user_specific_queries(query_key)+ case query_key+ when :created_by_me+ created_by_me_query+ when :assigned_to_me+ assigned_to_me_query+ when :shared_with_users+ shared_with_users_query+ when :shared_with_me+ shared_with_me_query+ end+ end+ end+ end+enddiff --git a/app/views/work_packages/_menu_query_select.html.erb b/app/views/work_packages/_menu_query_select.html.erbdeleted file mode 100644index 3713f99ad8a..00000000000--- a/app/views/work_packages/_menu_query_select.html.erb+++ /dev/null@@ -1,12 +0,0 @@-<div class="op-sidebar">- <%=- angular_component_tag 'op-view-select',- inputs: {- projectId: (@project ? @project.id.to_s : ''),- menuItems: [parent_name, name],- baseRoute: 'work-packages',- viewType: 'WorkPackagesTable',- },- class: 'op-sidebar--body'- %>-</div>diff --git a/app/views/work_packages/menus/_menu.html.erb b/app/views/work_packages/menus/_menu.html.erbnew file mode 100644index 00000000000..6391327f2b9--- /dev/null+++ b/app/views/work_packages/menus/_menu.html.erb@@ -0,0 +1,5 @@+<%= turbo_frame_tag "work_packages_sidemenu",+ src: @project ? menu_project_work_packages_path(@project, params.permit(:query_props, :query_id, :name)) : work_packages_menu_path(params.permit(:query_props, :query_id, :name)),+ target: "_top",+ data: { turbo: false },+ loading: :lazy %>diff --git a/app/views/work_packages/menus/show.html.erb b/app/views/work_packages/menus/show.html.erbnew file mode 100644index 00000000000..dffc0df9300--- /dev/null+++ b/app/views/work_packages/menus/show.html.erb@@ -0,0 +1,3 @@+<%= turbo_frame_tag "work_packages_sidemenu" do %>+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items, searchable: true) %>+<% end %>diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 86a096fffee..66fb0644075 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -168,7 +168,7 @@ Redmine::MenuManager.map :global_menu do |menu|menu.push :work_packages_query_select,{ controller: "/work_packages", action: "index" },parent: :work_packages,- partial: "work_packages/menu_query_select"+ partial: "work_packages/menus/menu"# Newsmenu.push :news,@@ -580,7 +580,7 @@ Redmine::MenuManager.map :project_menu do |menu|menu.push :work_packages_query_select,{ controller: "/work_packages", action: "index" },parent: :work_packages,- partial: "work_packages/menu_query_select",+ partial: "work_packages/menus/menu",last: true,caption: :label_all_open_wpsdiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 8b4ab0de971..710a479b7a7 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -204,7 +204,8 @@ Rails.application.reloader.to_prepare dojournals: %i[index],work_packages: %i[show index],work_packages_api: [:get],- "work_packages/reports": %i[report report_details]+ "work_packages/reports": %i[report report_details],+ "work_packages/menus": %i[show]},permissible_on: %i[work_package project],contract_actions: { work_packages: %i[read] }diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 3ab5a7eaa6d..64fc797b90c 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1110,6 +1110,7 @@ en:assigned_to_me: "Assigned to me"recently_created: "Recently created"all_open: "All open"+ overdue: "Overdue"summary: "Summary"shared_with_users: "Shared with users"shared_with_me: "Shared with me"diff --git a/config/routes.rb b/config/routes.rbindex 10d63e1decb..4b9e9627036 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -300,6 +300,7 @@ Rails.application.routes.draw docollection doget "/report/:detail" => "work_packages/reports#report_details"get "/report" => "work_packages/reports#report"+ get "menu" => "work_packages/menus#show"end# states managed by client-side routing on work_package#index@@ -530,6 +531,8 @@ Rails.application.routes.draw doendnamespace :work_packages do+ get "menu" => "menus#show"+match "auto_complete" => "auto_completes#index", via: %i[get post]resource :bulk, controller: "bulk", only: %i[edit update destroy]# FIXME: this is kind of evil!! We need to remove this soonest anddiff --git a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-routes.tsindex e6ca08b2dc7..0d5b7526bc3 100644--- a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts+++ b/frontend/src/app/features/work-packages/routing/work-packages-routes.ts@@ -40,12 +40,17 @@ import { KeepTabService } from 'core-app/features/work-packages/components/wp-siimport { ShareUpsaleComponent } from 'core-app/features/enterprise/share-upsale/share-upsale.component';export const menuItemClass = 'work-packages-menu-item';+export const sidemenuId = 'work_packages_sidemenu';+export const sideMenuOptions = {+ sidemenuId,+ hardReloadOnBaseRoute: true,+};export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [{name: 'work-packages',parent: 'optional_project',- url: '/work_packages?query_id&query_props&start_onboarding_tour',+ url: '/work_packages?query_id&query_props&name&start_onboarding_tour',redirectTo: 'work-packages.partitioned.list',views: {'!$default': { component: WorkPackagesBaseComponent },@@ -53,6 +58,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [data: {bodyClasses: 'router--work-packages-base',menuItem: menuItemClass,+ sideMenuOptions,},params: {query_id: { type: 'query', dynamic: true },@@ -60,6 +66,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [query_props: { type: 'opQueryString' },// Optional initial tour paramstart_onboarding_tour: { type: 'query', squash: true, value: undefined },+ name: { type: 'string', dynamic: true },},},{@@ -78,6 +85,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [bodyClasses: 'router--work-packages-full-create',menuItem: menuItemClass,successState: 'work-packages.show',+ sideMenuOptions,},},{@@ -90,6 +98,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [allowMovingInEditMode: true,bodyClasses: 'router--work-packages-full-create',menuItem: menuItemClass,+ sideMenuOptions,},},{@@ -111,6 +120,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [bodyClasses: ['router--work-packages-full-view', 'router--work-packages-base'],newRoute: 'work-packages.new',menuItem: menuItemClass,+ sideMenuOptions,},},{@@ -120,6 +130,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [data: {parent: 'work-packages.show',menuItem: menuItemClass,+ sideMenuOptions,},},{@@ -129,6 +140,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [data: {// This has to be empty to avoid inheriting the parent bodyClassesbodyClasses: '',+ sideMenuOptions,},},{@@ -142,6 +154,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [bodyClasses: ['router--work-packages-partitioned-split-view', 'router--work-packages-base'],menuItem: menuItemClass,partition: '-left-only',+ sideMenuOptions,},},...makeSplitViewRoutes(