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 Time&Costs module
Henriette Darge4961d3845b97
diff --git a/modules/reporting/app/controllers/cost_reports/menus_controller.rb b/modules/reporting/app/controllers/cost_reports/menus_controller.rbnew file mode 100644index 00000000000..a886c94f05e--- /dev/null+++ b/modules/reporting/app/controllers/cost_reports/menus_controller.rb@@ -0,0 +1,38 @@+# -- 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 ::CostReports+ class MenusController < ApplicationController+ before_action :load_and_authorize_in_optional_project++ def show+ @submenu_menu_items = ::CostReports::Menu.new(project: @project, params:).menu_items++ render layout: nil+ end+ end+enddiff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rbindex 81880f56d24..4d074fc19d3 100644--- a/modules/reporting/app/controllers/cost_reports_controller.rb+++ b/modules/reporting/app/controllers/cost_reports_controller.rb@@ -109,7 +109,7 @@ class CostReportsController < ApplicationControllerenddef menu_item_to_highlight_on_index- @project ? :costs : :cost_reports_global_report_menu+ @project ? :costs : :cost_reports_globalend##diff --git a/modules/reporting/app/menus/cost_reports/menu.rb b/modules/reporting/app/menus/cost_reports/menu.rbnew file mode 100644index 00000000000..8677d824ebb--- /dev/null+++ b/modules/reporting/app/menus/cost_reports/menu.rb@@ -0,0 +1,74 @@+# -- 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 CostReports+ class Menu < Submenu+ attr_reader :view_type, :project++ def initialize(project: nil, params: nil)+ @project = project+ @params = params++ super(view_type:, project:, params:)+ end++ def menu_items+ [+ OpenProject::Menu::MenuGroup.new(header: I18n.t("label_public_report_plural"), children: global_queries),+ OpenProject::Menu::MenuGroup.new(header: I18n.t("label_private_report_plural"), children: custom_queries)+ ]+ end++ def global_queries+ CostQuery.public(project)+ .pluck(:id, :name)+ .map { |id, name| menu_item(query_params(id), name) }+ end++ def custom_queries+ CostQuery.private(project, User.current)+ .pluck(:id, :name)+ .map { |id, name| menu_item(query_params(id), name) }+ end++ def selected?(query_params)+ query_params[:id].to_s == params[:id]+ end++ def query_params(id)+ { id: }+ end++ def query_path(query_params)+ if project.present?+ project_cost_report_path(project, query_params)+ else+ global_cost_report_path(query_params)+ end+ end+ end+enddiff --git a/modules/reporting/app/views/cost_reports/_report_menu.html.erb b/modules/reporting/app/views/cost_reports/_report_menu.html.erbdeleted file mode 100644index 51924ade931..00000000000--- a/modules/reporting/app/views/cost_reports/_report_menu.html.erb+++ /dev/null@@ -1,60 +0,0 @@-<%#-- 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.--++#%>--<% items = [] %>-<% [:public, :private].each do |report_type| %>- <% queries = report_type == :public ? CostQuery.public(@project) : CostQuery.private(@project, current_user) %>- <% if queries.length > 0 %>- <% item = {- title: t(:"label_#{report_type}_report_plural"),- collapsible: true,- children: []- } %>-- <% queries.each do |query| -%>- <% item[:children].push({- title: query.name,- href: url_for(:controller => '/cost_reports', :action => 'show', :id => query.id)- }) %>- <% end -%>- <% items.push(item) %>- <% end %>-<% end %>--<div class="op-sidebar">- <div class="op-sidebar--body">- <%=- angular_component_tag 'op-sidemenu',- inputs: {- title: '',- items: items- }- %>- </div>-</div>diff --git a/modules/reporting/app/views/cost_reports/menus/_menu.html.erb b/modules/reporting/app/views/cost_reports/menus/_menu.html.erbnew file mode 100644index 00000000000..82625223b24--- /dev/null+++ b/modules/reporting/app/views/cost_reports/menus/_menu.html.erb@@ -0,0 +1,5 @@+<%= turbo_frame_tag "cost_reports_sidemenu",+ src: @project ? menu_project_cost_reports_path(@project, **params.permit(:id)) : cost_reports_menu_path(**params.permit(:id)),+ target: "_top",+ data: { turbo: false },+ loading: :lazy %>diff --git a/modules/reporting/app/views/cost_reports/menus/show.html.erb b/modules/reporting/app/views/cost_reports/menus/show.html.erbnew file mode 100644index 00000000000..d3f4ad6bc7a--- /dev/null+++ b/modules/reporting/app/views/cost_reports/menus/show.html.erb@@ -0,0 +1,3 @@+<%= turbo_frame_tag "cost_reports_sidemenu" do %>+ <%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @submenu_menu_items) %>+<% end %>diff --git a/modules/reporting/config/routes.rb b/modules/reporting/config/routes.rbindex 1cc8ea7b225..fdab1c5d5fd 100644--- a/modules/reporting/config/routes.rb+++ b/modules/reporting/config/routes.rb@@ -31,15 +31,21 @@ Rails.application.routes.draw doresources :cost_reports, except: :create docollection domatch :index, via: %i[get post]+ get "menu" => "cost_reports/menus#show", as: :menu_projectendmember do+ get :index, as: :projectpost :updatepost :renameendendend+ namespace :cost_reports do+ resource :menu, only: %[show]+ end+resources :cost_reports, except: :create docollection domatch :index, via: %i[get post]@@ -49,6 +55,7 @@ Rails.application.routes.draw doendmember do+ get :index, as: :globalpost :updatepost :renameenddiff --git a/modules/reporting/lib/open_project/reporting/engine.rb b/modules/reporting/lib/open_project/reporting/engine.rbindex fca3ae6f8ba..c8d62b9f1eb 100644--- a/modules/reporting/lib/open_project/reporting/engine.rb+++ b/modules/reporting/lib/open_project/reporting/engine.rb@@ -57,6 +57,11 @@ module OpenProject::ReportingOpenProject::AccessControl.permission(:view_cost_entries).controller_actions << "cost_reports/#{action}"OpenProject::AccessControl.permission(:view_own_cost_entries).controller_actions << "cost_reports/#{action}"end++ OpenProject::AccessControl.permission(:view_time_entries).controller_actions << "cost_reports/menus/show"+ OpenProject::AccessControl.permission(:view_own_time_entries).controller_actions << "cost_reports/menus/show"+ OpenProject::AccessControl.permission(:view_cost_entries).controller_actions << "cost_reports/menus/show"+ OpenProject::AccessControl.permission(:view_own_cost_entries).controller_actions << "cost_reports/menus/show"endend@@ -90,7 +95,7 @@ module OpenProject::Reporting:cost_reports_global_report_menu,{ controller: "/cost_reports", action: "index", project_id: nil },parent: :cost_reports_global,- partial: "cost_reports/report_menu",+ partial: "cost_reports/menus/menu",if: should_rendermenu :project_menu,@@ -105,7 +110,7 @@ module OpenProject::Reporting:costs_menu,{ controller: "/cost_reports", action: "index" },if: Proc.new { |project| project.module_enabled?(:costs) },- partial: "/cost_reports/report_menu",+ partial: "cost_reports/menus/menu",parent: :costsend