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

Move settings for costs into its own controller

Klaus Zanders76418ac428b8
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index e52606a2769..7858a9a1015 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -547,13 +547,13 @@ Redmine::MenuManager.map :admin_menu do |menu|
if: proc { User.current.admin? && OpenProject::Configuration.ee_manager_visible? }
menu.push :admin_costs,
- { controller: "/admin/settings", action: "show_plugin", id: :costs },
+ { controller: "costs_settings", action: :show },
if: Proc.new { User.current.admin? },
caption: :project_module_costs,
icon: "op-cost-reports"
- menu.push :costs_setting,
- { controller: "/admin/settings", action: "show_plugin", id: :costs },
+ menu.push :costs_settings,
+ { controller: "costs_settings", action: :show },
if: Proc.new { User.current.admin? },
caption: :label_setting_plural,
parent: :admin_costs
diff --git a/modules/costs/app/controllers/costs_settings_controller.rb b/modules/costs/app/controllers/costs_settings_controller.rb
new file mode 100644
index 00000000000..737541a38b4
--- /dev/null
+++ b/modules/costs/app/controllers/costs_settings_controller.rb
@@ -0,0 +1,31 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 CostsSettingsController < Admin::SettingsController
+ menu_item :admin_costs
+end
diff --git a/modules/costs/app/views/costs_settings/show.html.erb b/modules/costs/app/views/costs_settings/show.html.erb
new file mode 100644
index 00000000000..fcaf0d1361b
--- /dev/null
+++ b/modules/costs/app/views/costs_settings/show.html.erb
@@ -0,0 +1,64 @@
+<%# -- copyright
+OpenProject is an open source project management software.
+Copyright (C) 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.
+
+++#%>
+
+<% html_title t(:label_administration), t(:label_costs) %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { t(:label_costs) }
+ header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
+ t(:label_costs)])
+ end
+%>
+
+<%= styled_form_tag(
+ admin_costs_settings_path,
+ method: :patch,
+ class: 'op-costs-admin-settings'
+ ) do %>
+
+ <section class="form--section">
+ <div class="form--field">
+ <%= setting_text_field :costs_currency, type: :string, container_class: "-middle" %>
+ </div>
+
+ <div class="form--field">
+ <%= setting_text_field :costs_currency_format, type: :string, container_class: "-middle" %>
+ </div>
+
+ <%- if OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? %>
+ <div class="form--field">
+ <%= setting_check_box :allow_tracking_start_and_end_times, container_class: "-middle" %>
+ </div>
+ <%- end %>
+ </section>
+
+
+ <%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %>
+<% end %>
diff --git a/modules/costs/app/views/settings/_costs.html.erb b/modules/costs/app/views/settings/_costs.html.erb
deleted file mode 100644
index 6e040565dcb..00000000000
--- a/modules/costs/app/views/settings/_costs.html.erb
+++ /dev/null
@@ -1,53 +0,0 @@
-<%#-- copyright
-OpenProject is an open source project management software.
-Copyright (C) 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.
-
-++#%>
-
-
-<div class="form--field">
- <%= styled_label_tag :label_currency, t(:label_currency) %>
- <div class="form--field-container">
- <%= styled_text_field_tag 'settings[costs_currency]', @settings['costs_currency'], container_class: '-xslim' %>
- </div>
-</div>
-
-<div class="form--field">
- <%= styled_label_tag :label_currency_format, t(:label_currency_format) %>
- <div class="form--field-container">
- <%= styled_text_field_tag 'settings[costs_currency_format]', @settings['costs_currency_format'], container_class: '-xslim' %>
- </div>
-</div>
-
-<%- if OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active? %>
- <div class="form--field">
- <%= styled_label_tag :label_track_start_and_end_times, t(:label_track_start_and_end_times) %>
- <div class="form--field-container">
- <%= hidden_field_tag "settings[track_start_and_end_times]", 'false' %>
- <%= styled_check_box_tag "settings[track_start_and_end_times]", 'true', ActiveRecord::Type::Boolean.new.cast(@settings['track_start_and_end_times']) %>
- </div>
- </div>
-<%- end %>
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index 49938da5df8..d07e35aee47 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -99,8 +99,6 @@ en:
label_cost_type_plural: "Cost types"
label_cost_type_specific: "Cost type #%{id}: %{name}"
label_costs_per_page: "Costs per page"
- label_currency: "Currency"
- label_currency_format: "Format of currency"
label_current_default_rate: "Current default rate"
label_date_on: "on"
label_deleted_cost_types: "Deleted cost types"
@@ -126,7 +124,6 @@ en:
label_rate_plural: "Rates"
label_status_finished: "Finished"
label_show: "Show"
- label_track_start_and_end_times: "Time records with start and end time"
label_units: "Cost units"
label_user: "User"
label_until: "until"
@@ -154,6 +151,10 @@ en:
project_module_costs: "Time and costs"
+ setting_allow_tracking_start_and_end_times: "Time records with start and end time"
+ setting_costs_currency: "Currency"
+ setting_costs_currency_format: "Format of currency"
+
text_assign_time_and_cost_entries_to_project: "Assign reported hours and costs to the project"
text_destroy_cost_entries_question: "%{cost_entries} were reported on the work packages you are about to delete. What do you want to do ?"
text_destroy_time_and_cost_entries: "Delete reported hours and costs"
diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rb
index 67904a56e56..1619251f6ea 100644
--- a/modules/costs/config/routes.rb
+++ b/modules/costs/config/routes.rb
@@ -61,4 +61,11 @@ Rails.application.routes.draw do
# TODO: this is a duplicate from a route defined under project/:project_id, check whether we really want to do that
resources :hourly_rates, only: %i[edit update]
+
+ scope :admin do
+ resource :costs,
+ only: %i[show update],
+ controller: :costs_settings,
+ as: "admin_costs_settings"
+ end
end
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb
index 4d3d18cb858..fa1bebf5a79 100644
--- a/modules/costs/lib/costs/engine.rb
+++ b/modules/costs/lib/costs/engine.rb
@@ -37,14 +37,7 @@ module Costs
register "costs",
author_url: "https://www.openproject.org",
bundled: true,
- settings: {
- partial: "settings/costs",
- page_title_key: :label_setting_plural,
- breadcrumb_elements: -> {
- [{ href: admin_settings_show_plugin_path(:costs), text: I18n.t(:project_module_costs) }]
- },
- menu_item: :costs_setting
- } do
+ settings: { menu_item: :costs_settings } do
project_module :costs do
permission :view_time_entries,
{},