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

[#64347] primerize view for calculated value

Tobias Dillmanna5f30703e83a
diff --git a/app/components/admin/custom_fields/calculated_values/details_component.html.erb b/app/components/admin/custom_fields/calculated_values/details_component.html.erb
new file mode 100644
index 00000000000..848b0f996e4
--- /dev/null
+++ b/app/components/admin/custom_fields/calculated_values/details_component.html.erb
@@ -0,0 +1,15 @@
+<%=
+ component_wrapper do
+ flex_layout do |content|
+ content.with_row do
+ settings_primer_form_with(
+ model:,
+ scope: :custom_field,
+ id: "custom_field_form",
+ url: form_url,
+ method: form_method
+ ) { |form| render Admin::CustomFields::CalculatedValues::DetailsForm.new(form) }
+ end
+ end
+ end
+%>
diff --git a/app/components/admin/custom_fields/calculated_values/details_component.rb b/app/components/admin/custom_fields/calculated_values/details_component.rb
new file mode 100644
index 00000000000..74d88666d0f
--- /dev/null
+++ b/app/components/admin/custom_fields/calculated_values/details_component.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+#
+module Admin::CustomFields::CalculatedValues
+ class DetailsComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ alias_method :custom_field, :model
+
+ private
+
+ def form_url
+ if custom_field.new_record?
+ admin_settings_project_custom_fields_path
+ else
+ admin_settings_project_custom_field_path(custom_field)
+ end
+ end
+
+ def form_method
+ custom_field.new_record? ? :post : :put
+ end
+ end
+end
diff --git a/app/components/admin/custom_fields/calculated_values/details_form.rb b/app/components/admin/custom_fields/calculated_values/details_form.rb
new file mode 100644
index 00000000000..d051e60cf89
--- /dev/null
+++ b/app/components/admin/custom_fields/calculated_values/details_form.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+
+module Admin::CustomFields::CalculatedValues
+ class DetailsForm < ApplicationForm
+ form do |details_form|
+ details_form.text_field(
+ name: :name,
+ label: I18n.t(:label_name),
+ required: true
+ )
+
+ details_form.select_list(
+ name: :custom_field_section_id,
+ label: I18n.t("activerecord.attributes.project_custom_field.custom_field_section"),
+ required: true
+ ) do |li|
+ ProjectCustomFieldSection.all.collect.each do |cs|
+ li.option(value: cs.id, label: cs.name)
+ end
+ end
+
+ details_form.text_field(
+ name: :formula,
+ label: I18n.t(:label_formula),
+ required: true,
+ caption: I18n.t("custom_fields.instructions.formula")
+ )
+
+ details_form.check_box(
+ name: :is_for_all,
+ label: I18n.t("activerecord.attributes.custom_field.is_for_all"),
+ caption: I18n.t("custom_fields.instructions.is_for_all")
+ )
+
+ details_form.check_box(
+ name: :admin_only,
+ label: I18n.t("activerecord.attributes.custom_field.admin_only"),
+ caption: I18n.t("custom_fields.instructions.admin_only")
+ )
+
+ details_form.hidden(name: :field_format)
+ details_form.hidden(name: :type, scope_name_to_model: false)
+
+ details_form.submit(name: :submit, label: I18n.t(:button_save), scheme: :default)
+ end
+ end
+end
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
index 37916605dc1..4a8b84596a1 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
@@ -8,7 +8,7 @@
content_container.with_column(mr: 2) do
render(
Primer::Beta::Link.new(
- href: edit_admin_settings_project_custom_field_path(@project_custom_field),
+ href: edit_path,
underline: false,
font_weight: :bold,
data: { turbo: "false" }
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
index 74cade38187..a181c078dbc 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -42,9 +42,17 @@ module Settings
private
+ def edit_path
+ if @project_custom_field.field_format_calculated_value?
+ edit_admin_settings_project_custom_field_calculated_value_path(@project_custom_field)
+ else
+ edit_admin_settings_project_custom_field_path(@project_custom_field)
+ end
+ end
+
def edit_action_item(menu)
menu.with_item(label: t("label_edit"),
- href: edit_admin_settings_project_custom_field_path(@project_custom_field),
+ href: edit_path,
data: { turbo: "false", test_selector: "project-custom-field-edit" }) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
diff --git a/app/controllers/admin/settings/project_custom_field_calculated_values_controller.rb b/app/controllers/admin/settings/project_custom_field_calculated_values_controller.rb
new file mode 100644
index 00000000000..a7d331eb14b
--- /dev/null
+++ b/app/controllers/admin/settings/project_custom_field_calculated_values_controller.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+
+module Admin::Settings
+ class ProjectCustomFieldCalculatedValuesController < ::Admin::SettingsController
+ include CustomFields::SharedActions
+ include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
+ include FlashMessagesOutputSafetyHelper
+ include Admin::Settings::ProjectCustomFields::ComponentStreams
+
+ def show
+ # quick fixing redirect issue from perform_update
+ # perform_update is always redirecting to the show action although configured otherwise
+ render :edit
+ end
+
+ def new
+ @custom_field = ProjectCustomField.new(custom_field_section_id: params[:custom_field_section_id],
+ field_format: "calculated_value")
+
+ respond_to :html
+ end
+
+ def edit
+ @custom_field = ProjectCustomField.find(params[:id])
+ end
+ end
+end
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index e537cf365c0..cf801f9ad2c 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
diff --git a/app/controllers/concerns/custom_fields/shared_actions.rb b/app/controllers/concerns/custom_fields/shared_actions.rb
index d02ad148891..0b35ca37a63 100644
--- a/app/controllers/concerns/custom_fields/shared_actions.rb
+++ b/app/controllers/concerns/custom_fields/shared_actions.rb
@@ -41,7 +41,11 @@ module CustomFields
def edit_path(custom_field, params = {})
if custom_field.type == "ProjectCustomField"
- admin_settings_project_custom_field_path(**params)
+ if custom_field.field_format_calculated_value?
+ admin_settings_project_custom_field_calculated_values_path(**params)
+ else
+ admin_settings_project_custom_fields_path(**params)
+ end
else
edit_custom_field_path(**params)
end
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 3fcab7a3a61..8b2f42fd876 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -299,6 +299,10 @@ class CustomField < ApplicationRecord
field_format == "hierarchy"
end
+ def field_format_calculated_value?
+ field_format == "calculated_value"
+ end
+
def multi_value_possible?
OpenProject::CustomFieldFormat.find_by(name: field_format)&.multi_value_possible?
end
diff --git a/app/views/admin/settings/project_custom_field_calculated_values/edit.html.erb b/app/views/admin/settings/project_custom_field_calculated_values/edit.html.erb
new file mode 100644
index 00000000000..909df98646f
--- /dev/null
+++ b/app/views/admin/settings/project_custom_field_calculated_values/edit.html.erb
@@ -0,0 +1,43 @@
+<%#-- 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("settings.project_attributes.heading"), @custom_field.name %>
+
+<%=
+ render(
+ Settings::ProjectCustomFields::EditFormHeaderComponent.new(
+ custom_field: @custom_field,
+ selected: :project_custom_field_edit
+ )
+ )
+%>
+
+<%= error_messages_for "custom_field" %>
+
+<%= render Admin::CustomFields::CalculatedValues::DetailsComponent.new(@custom_field) %>
diff --git a/app/views/admin/settings/project_custom_field_calculated_values/new.html.erb b/app/views/admin/settings/project_custom_field_calculated_values/new.html.erb
new file mode 100644
index 00000000000..67d84e9a517
--- /dev/null
+++ b/app/views/admin/settings/project_custom_field_calculated_values/new.html.erb
@@ -0,0 +1,36 @@
+<%#-- 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("settings.project_attributes.heading"), t("settings.project_attributes.new.heading") %>
+
+<%= render(Settings::ProjectCustomFields::NewFormHeaderComponent.new) %>
+
+<%= error_messages_for "custom_field" %>
+
+<%= render Admin::CustomFields::CalculatedValues::DetailsComponent.new(@custom_field) %>
diff --git a/config/routes.rb b/config/routes.rb
index 363e9a1fe5a..fe2743311e1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -601,6 +601,10 @@ Rails.application.routes.draw do
delete :unlink
end
end
+
+ resources :project_custom_field_calculated_values,
+ controller: "/admin/settings/project_custom_field_calculated_values"
+
resources :project_custom_field_sections, controller: "/admin/settings/project_custom_field_sections",
only: %i[create update destroy] do
member do
diff --git a/lib/open_project/custom_field_format_dependent.rb b/lib/open_project/custom_field_format_dependent.rb
index 6a95d8a61f1..a07c6d0828d 100644
--- a/lib/open_project/custom_field_format_dependent.rb
+++ b/lib/open_project/custom_field_format_dependent.rb
@@ -32,8 +32,8 @@ module OpenProject
allowNonOpenVersions: [:only, %w[version]],
defaultBool: [:only, %w[bool]],
defaultLongText: [:only, %w[text]],
- defaultText: [:except, %w[list bool date text user version hierarchy]],
- length: [:except, %w[list bool date user version link hierarchy]],
+ defaultText: [:except, %w[list bool date text user version hierarchy calculated_value]],
+ length: [:except, %w[list bool date user version link hierarchy calculated_value]],
multiSelect: [:only, %w[list user version hierarchy]],
possibleValues: [:only, %w[list]],
regexp: [:except, %w[list bool date user version hierarchy calculated_value]],