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
[#64347] introduce formula field to custom field admin views
Tobias Dillmannfb60aabbe4f6
diff --git a/app/contracts/custom_fields/base_contract.rb b/app/contracts/custom_fields/base_contract.rbindex 6648bfc213b..ef77d39f10c 100644--- a/app/contracts/custom_fields/base_contract.rb+++ b/app/contracts/custom_fields/base_contract.rb@@ -41,6 +41,7 @@ module CustomFieldsattribute :nameattribute :possible_valuesattribute :regexp+ attribute :formulaattribute :searchableattribute :admin_onlyattribute :default_valuediff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rbindex a3e2330eb93..e537cf365c0 100644--- a/app/controllers/admin/settings/project_custom_fields_controller.rb+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb@@ -53,7 +53,7 @@ module Admin::Settingsdef show# quick fixing redirect issue from perform_update- # perform_update is always redirecting to the show action altough configured otherwise+ # perform_update is always redirecting to the show action although configured otherwiserender :editenddiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex e20d2d1735f..fb542d9033f 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -481,6 +481,7 @@ class PermittedParamscustom_field: [:editable,:field_format,+ :formula,:is_filter,:is_for_all,:is_required,diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erbindex 192fc485768..9ae12e18fdb 100644--- a/app/views/custom_fields/_form.html.erb+++ b/app/views/custom_fields/_form.html.erb@@ -76,6 +76,14 @@ See COPYRIGHT and LICENSE files for more details.</span></div>+ <div class="form--field" <%= format_dependent.attributes(:formula) %>>+ <%= f.text_field :formula,+ container_class: "-wide" %>+ <span class="form--field-instructions">+ <%= t("custom_fields.instructions.formula") %>+ </span>+ </div>+<% if @custom_field.new_record? || @custom_field.multi_value_possible? %><div class="form--field" <%= format_dependent.attributes(:multiSelect) %>><%= f.check_box :multi_value,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex ad8b83e97bf..b8fdfe6c783 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -303,6 +303,7 @@ en:is_filter: >Allow the custom field to be used in a filter in work package views.Note that only with 'For all projects' selected, the custom field will show up in global views.+ formula: "Add numeric values or type / to search for an attribute or a mathematical operator."tab:no_results_title_text: There are currently no custom fields.@@ -981,6 +982,7 @@ en:default_value: "Default value"editable: "Editable"field_format: "Format"+ formula: "Formula"is_filter: "Used as a filter"is_for_all: "For all projects"is_required: "Required"@@ -2857,6 +2859,7 @@ en:label_follows: "follows"label_force_user_language_to_default: "Set language of users having a non allowed language to default"label_form_configuration: "Form configuration"+ label_formula: "Formula"label_gantt_chart: "Gantt chart"label_gantt_chart_plural: "Gantt charts"label_general: "General"diff --git a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.tsindex 4ae929c6518..c7e5710789e 100644--- a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts@@ -47,6 +47,7 @@ export default class CustomFieldsController extends Controller {'multiSelect','possibleValues','regexp',+ 'formula','searchable','textOrientation',@@ -80,6 +81,7 @@ export default class CustomFieldsController extends Controller {declare readonly multiSelectTargets:HTMLElement[];declare readonly possibleValuesTargets:HTMLElement[];declare readonly regexpTargets:HTMLElement[];+ declare readonly formulaTargets:HTMLElement[];declare readonly searchableTargets:HTMLInputElement[];declare readonly textOrientationTargets:HTMLElement[];diff --git a/lib/open_project/custom_field_format_dependent.rb b/lib/open_project/custom_field_format_dependent.rbindex 0843c97f3f5..6a95d8a61f1 100644--- a/lib/open_project/custom_field_format_dependent.rb+++ b/lib/open_project/custom_field_format_dependent.rb@@ -36,8 +36,9 @@ module OpenProjectlength: [:except, %w[list bool date user version link hierarchy]],multiSelect: [:only, %w[list user version hierarchy]],possibleValues: [:only, %w[list]],- regexp: [:except, %w[list bool date user version hierarchy]],- searchable: [:except, %w[bool date float int user version hierarchy]],+ regexp: [:except, %w[list bool date user version hierarchy calculated_value]],+ formula: [:only, %w[calculated_value]],+ searchable: [:except, %w[bool date float int user version hierarchy calculated_value]],textOrientation: [:only, %w[text]],enterpriseBanner: [:only, %w[hierarchy]]}.freeze