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

Change folder structure: Move submenu class from helper to its own folder as it is not really a helper in the rails sense

Henriette Darge3c946fca6213
diff --git a/app/helpers/menus/submenu.rb b/app/helpers/menus/submenu.rb
deleted file mode 100644
index f336fd2e2ee..00000000000
--- a/app/helpers/menus/submenu.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-# -- 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 Menus
- class Submenu
- include Rails.application.routes.url_helpers
- attr_reader :view_type, :project, :params
-
- def initialize(view_type:, project: nil, params: nil)
- # rubocop:disable Rails/HelperInstanceVariable
- @view_type = view_type
- @project = project
- @params = params
- # rubocop:enable Rails/HelperInstanceVariable
- end
-
- def 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: default_queries),
- 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_params(id), name) }
- end
-
- def default_queries
- raise NotImplementedError
- end
-
- def global_queries
- base_query
- .where("starred" => "f")
- .where("public" => "t")
- .pluck(:id, :name)
- .map { |id, name| menu_item(query_params(id), name) }
- end
-
- def custom_queries
- base_query
- .where("starred" => "f")
- .where("public" => "f")
- .pluck(:id, :name)
- .map { |id, name| menu_item(query_params(id), name) }
- end
-
- def base_query
- base_query ||= Query
- .visible(User.current)
- .includes(:project)
- .joins(:views)
- .where("views.type" => view_type)
-
- if project.present?
- base_query.where("queries.project_id" => project.id)
- else
- base_query.where("queries.project_id" => nil)
- end
- end
-
- def query_params(id)
- { query_id: id }
- end
-
- def menu_item(query_params, name)
- OpenProject::Menu::MenuItem.new(title: name,
- href: query_path(query_params),
- selected: selected?(query_params))
- end
-
- def selected?(query_params)
- query_params.each_key do |filter_key|
- if params[filter_key] != query_params[filter_key].to_s
- return false
- end
- end
-
- true
- end
-
- def query_path(query_params)
- raise NotImplementedError
- end
- end
-end
diff --git a/app/menus/submenu.rb b/app/menus/submenu.rb
new file mode 100644
index 00000000000..e2866c67922
--- /dev/null
+++ b/app/menus/submenu.rb
@@ -0,0 +1,111 @@
+# -- 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.
+# ++
+class Submenu
+ include Rails.application.routes.url_helpers
+ attr_reader :view_type, :project, :params
+
+ def initialize(view_type:, project: nil, params: nil)
+ @view_type = view_type
+ @project = project
+ @params = params
+ end
+
+ def 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: default_queries),
+ 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_params(id), name) }
+ end
+
+ def default_queries
+ raise NotImplementedError
+ end
+
+ def global_queries
+ base_query
+ .where("starred" => "f")
+ .where("public" => "t")
+ .pluck(:id, :name)
+ .map { |id, name| menu_item(query_params(id), name) }
+ end
+
+ def custom_queries
+ base_query
+ .where("starred" => "f")
+ .where("public" => "f")
+ .pluck(:id, :name)
+ .map { |id, name| menu_item(query_params(id), name) }
+ end
+
+ def base_query
+ base_query ||= Query
+ .visible(User.current)
+ .includes(:project)
+ .joins(:views)
+ .where("views.type" => view_type)
+
+ if project.present?
+ base_query.where("queries.project_id" => project.id)
+ else
+ base_query.where("queries.project_id" => nil)
+ end
+ end
+
+ def query_params(id)
+ { query_id: id }
+ end
+
+ def menu_item(query_params, name)
+ OpenProject::Menu::MenuItem.new(title: name,
+ href: query_path(query_params),
+ selected: selected?(query_params))
+ end
+
+ def selected?(query_params)
+ query_params.each_key do |filter_key|
+ if params[filter_key] != query_params[filter_key].to_s
+ return false
+ end
+ end
+
+ true
+ end
+
+ def query_path(query_params)
+ raise NotImplementedError
+ end
+end
diff --git a/modules/calendar/app/helpers/calendar/menu.rb b/modules/calendar/app/menus/calendar/menu.rb
similarity index 98%
rename from modules/calendar/app/helpers/calendar/menu.rb
rename to modules/calendar/app/menus/calendar/menu.rb
index 73d346aa521..148ce15fba0 100644
--- a/modules/calendar/app/helpers/calendar/menu.rb
+++ b/modules/calendar/app/menus/calendar/menu.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
# ++
module Calendar
- class Menu < Menus::Submenu
+ class Menu < Submenu
attr_reader :view_type, :project
def initialize(project: nil, params: nil)
diff --git a/modules/gantt/app/helpers/gantt/menu.rb b/modules/gantt/app/menus/gantt/menu.rb
similarity index 98%
rename from modules/gantt/app/helpers/gantt/menu.rb
rename to modules/gantt/app/menus/gantt/menu.rb
index dc1d7594017..f243ec98bd4 100644
--- a/modules/gantt/app/helpers/gantt/menu.rb
+++ b/modules/gantt/app/menus/gantt/menu.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
# ++
module Gantt
- class Menu < Menus::Submenu
+ class Menu < Submenu
attr_reader :view_type, :project
def initialize(project: nil, params: nil)