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
Refactor gantt sidebar menu to the rails SubmenuComponent
Henriette Darge3ef79e816693
diff --git a/modules/gantt/app/controllers/gantt/menus_controller.rb b/modules/gantt/app/controllers/gantt/menus_controller.rbnew file mode 100644index 00000000000..3ea9ea412cb--- /dev/null+++ b/modules/gantt/app/controllers/gantt/menus_controller.rb@@ -0,0 +1,108 @@+# -- 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 ::Gantt+ class MenusController < ApplicationController+ before_action :find_optional_project++ def show+ @sidebar_menu_items = first_level_menu_items + nested_menu_items+ render layout: nil+ end++ private++ def first_level_menu_items+ []+ end++ def nested_menu_items+ [+ OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_starred_queries'), children: starred_queries),+ OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_default_queries'), children: []),+ OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_global_queries'), children: global_queries),+ OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_custom_queries'), children: custom_queries)+ ]+ end++ def starred_queries+ base_query+ .where('starred' => 't')+ .pluck(:id, :name)+ .map { |id, name| menu_item(:query_id, id, name) }+ end++ def global_queries+ base_query+ .where('starred' => 'f')+ .where('public' => 't')+ .pluck(:id, :name)+ .map { |id, name| menu_item(:query_id, id, name) }+ end++ def custom_queries+ base_query+ .where('starred' => 'f')+ .where('public' => 'f')+ .pluck(:id, :name)+ .map { |id, name| menu_item(:query_id, id, name) }+ end++ def base_query+ base_query ||= Query+ .visible(current_user)+ .joins(:views, :project)+ .where('views.type' => 'gantt')++ if @project.present?+ base_query = base_query.where('queries.project_id' => @project.id)+ end++ base_query+ end++ def menu_item(filter_key, id, name)+ OpenProject::Menu::MenuItem.new(title: name,+ href: gantt_path(filter_key, id),+ selected: selected?(filter_key, id))+ end++ def selected?(filter_key, value)+ return false if active_filter_count > 1++ params[filter_key] == value.to_s+ end++ def active_filter_count+ @active_filter_count ||= params[:filters].present? ? params[:filters].count : 0+ end++ def gantt_path(filter_key, id)+ @project.present? ? project_gantt_index_path(@project, filter_key => id) : gantt_index_path(filter_key => id)+ end+ end+enddiff --git a/modules/gantt/app/views/gantt/gantt/_menu.html.erb b/modules/gantt/app/views/gantt/gantt/_menu.html.erbdeleted file mode 100644index 7346511d268..00000000000--- a/modules/gantt/app/views/gantt/gantt/_menu.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: 'gantt',- viewType: 'Gantt',- },- class: 'op-sidebar--body'- %>-</div>diff --git a/modules/gantt/app/views/gantt/menus/_menu.html.erb b/modules/gantt/app/views/gantt/menus/_menu.html.erbnew file mode 100644index 00000000000..2a2c60d350b--- /dev/null+++ b/modules/gantt/app/views/gantt/menus/_menu.html.erb@@ -0,0 +1,5 @@+<%= turbo_frame_tag "gantt_menu",+ src: @project ? menu_project_gantt_index_path(@project, params.permit(:filters, :query_id)) : gantt_menu_path(params.permit(:filters, :query_id)),+ target: '_top',+ data: { turbo: false },+ loading: :lazy %>diff --git a/modules/gantt/app/views/gantt/menus/show.html.erb b/modules/gantt/app/views/gantt/menus/show.html.erbnew file mode 100644index 00000000000..00db47455e5--- /dev/null+++ b/modules/gantt/app/views/gantt/menus/show.html.erb@@ -0,0 +1,3 @@+<%= turbo_frame_tag "gantt_menu" do %>+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items) %>+<% end %>diff --git a/modules/gantt/config/routes.rb b/modules/gantt/config/routes.rbindex f6ec732fac9..68eb3b11c25 100644--- a/modules/gantt/config/routes.rb+++ b/modules/gantt/config/routes.rb@@ -2,6 +2,9 @@ OpenProject::Application.routes.draw doscope 'projects/:project_id', as: 'project' doresources :gantt, controller: 'gantt/gantt', only: [:index] docollection do+ # The menu route has to be above the state routes! Otherwise, the menu will be interpreted as another state+ get 'menu' => 'gantt/menus#show'+# states managed by client-side routing on work_package#indexget '(/*state)' => 'gantt/gantt#index', as: ''get '/create_new' => 'gantt/gantt#index', as: 'new_split'@@ -18,4 +21,8 @@ OpenProject::Application.routes.draw doget '/' => 'gantt/gantt#index', as: 'index'endend++ namespace :gantt do+ resource :menu, only: %[show]+ endenddiff --git a/modules/gantt/lib/open_project/gantt/engine.rb b/modules/gantt/lib/open_project/gantt/engine.rbindex 67a9f292a01..db6a3a9175e 100644--- a/modules/gantt/lib/open_project/gantt/engine.rb+++ b/modules/gantt/lib/open_project/gantt/engine.rb@@ -49,6 +49,8 @@ module OpenProject::GanttOpenProject::AccessControl.permission(:view_work_packages).tap do |add|add.controller_actions << 'gantt/gantt/index'+ add.controller_actions << 'gantt/gantt/menu'+ add.controller_actions << 'gantt/menus/show'endend@@ -71,6 +73,15 @@ module OpenProject::Gantticon: 'view-timeline',if: should_render_global_menu_item+ menu :global_menu,+ :global_gantt_query_select,+ { controller: '/gantt/gantt', action: 'index' },+ parent: :gantt,+ partial: 'gantt/menus/menu',+ last: true,+ caption: :label_gantt_chart,+ if: should_render_global_menu_item+menu :project_menu,:gantt,{ controller: '/gantt/gantt', action: 'index' },@@ -86,7 +97,7 @@ module OpenProject::Gantt:gantt_query_select,{ controller: '/gantt/gantt', action: 'index' },parent: :gantt,- partial: 'gantt/gantt/menu',+ partial: 'gantt/menus/menu',last: true,caption: :label_gantt_chart,if: ->(project) { should_render_project_menu.call(project) }