From 91db17b28e2c1f2160d4a46ee49c96f557b7b360 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Fri, 27 Sep 2024 15:59:35 +0200 Subject: [PATCH 1/3] [#57814] add detail page for hierarchy custom fields - https://community.openproject.org/work_packages/57814 - add switch to display primer detail page only for custom fields of type hierarchy - add all relevant form elements - remark: spacing is not correct yet and will be fixed for all primer forms later --- .../custom_fields/details_component.html.erb | 21 ++++++ .../custom_fields/details_component.rb | 36 ++++++++++ app/forms/custom_fields/details_form.rb | 72 +++++++++++++++++++ app/views/custom_fields/edit.html.erb | 14 ++-- config/locales/en.yml | 3 + 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 app/components/custom_fields/details_component.html.erb create mode 100644 app/components/custom_fields/details_component.rb create mode 100644 app/forms/custom_fields/details_form.rb diff --git a/app/components/custom_fields/details_component.html.erb b/app/components/custom_fields/details_component.html.erb new file mode 100644 index 000000000000..91e966f66f9f --- /dev/null +++ b/app/components/custom_fields/details_component.html.erb @@ -0,0 +1,21 @@ +<%= + component_wrapper do + flex_layout do |content| + content.with_row(mb: 3) do + render Primer::Alpha::Banner.new(scheme: :default, icon: :info, dismiss_scheme: :hide) do + I18n.t("custom_fields.admin.notice.remember_items_and_projects") + end + end + + content.with_row do + primer_form_with( + model:, + scope: :custom_field, + id: "custom_field_form", + url: custom_field_path(model), + method: :put + ) { |form| render CustomFields::DetailsForm.new(form) } + end + end + end +%> diff --git a/app/components/custom_fields/details_component.rb b/app/components/custom_fields/details_component.rb new file mode 100644 index 000000000000..ba38995317fe --- /dev/null +++ b/app/components/custom_fields/details_component.rb @@ -0,0 +1,36 @@ +# 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 CustomFields + class DetailsComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include OpTurbo::Streamable + end +end diff --git a/app/forms/custom_fields/details_form.rb b/app/forms/custom_fields/details_form.rb new file mode 100644 index 000000000000..b626e49dcfe7 --- /dev/null +++ b/app/forms/custom_fields/details_form.rb @@ -0,0 +1,72 @@ +# 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 CustomFields + class DetailsForm < ApplicationForm + form do |details_form| + details_form.text_field( + name: :name, + label: I18n.t(:label_name), + required: true + ) + + details_form.check_box( + name: :multi_value, + label: I18n.t("activerecord.attributes.custom_field.multi_value") + ) + + details_form.check_box( + name: :required, + label: I18n.t("activerecord.attributes.custom_field.is_required"), + caption: I18n.t("custom_fields.instructions.is_required") + ) + + 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: :is_filter, + label: I18n.t("activerecord.attributes.custom_field.is_filter"), + caption: I18n.t("custom_fields.instructions.is_filter") + ) + + details_form.check_box( + name: :searchable, + label: I18n.t("activerecord.attributes.custom_field.searchable"), + caption: I18n.t("custom_fields.instructions.searchable") + ) + + details_form.submit(name: :submit, label: I18n.t(:button_save), scheme: :default) + end + end +end diff --git a/app/views/custom_fields/edit.html.erb b/app/views/custom_fields/edit.html.erb index 3417c07bbfc6..dca852fc71df 100644 --- a/app/views/custom_fields/edit.html.erb +++ b/app/views/custom_fields/edit.html.erb @@ -33,9 +33,13 @@ See COPYRIGHT and LICENSE files for more details. <%= error_messages_for 'custom_field' %> -<%= labelled_tabular_form_for @custom_field, as: :custom_field, - url: custom_field_path(@custom_field), - html: {method: :put, id: 'custom_field_form'} do |f| %> - <%= render partial: 'form', locals: { f: f } %> - <%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %> +<% if @custom_field.field_format == "hierarchy" %> + <%= render CustomFields::DetailsComponent.new(@custom_field) %> +<% else %> + <%= labelled_tabular_form_for @custom_field, as: :custom_field, + url: custom_field_path(@custom_field), + html: { method: :put, id: 'custom_field_form' } do |f| %> + <%= render partial: 'form', locals: { f: f } %> + <%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %> + <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 9e02a20d6207..b4e348a4efc6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -234,6 +234,8 @@ en: is_for_all_blank_slate: heading: For all projects description: This custom field is enabled in all projects since the "For all projects" option is checked. It cannot be deactivated for individual projects. + notice: + remember_items_and_projects: "Remember to set items and projects in the respective tabs for this custom field." text_add_new_custom_field: > To add new custom fields to a project you first need to create them before @@ -702,6 +704,7 @@ en: editable: "Editable" field_format: "Format" is_filter: "Used as a filter" + is_for_all: "For all projects" is_required: "Required" max_length: "Maximum length" min_length: "Minimum length" From e0097af30ea398218127a02bc1840038eb5bbb47 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Fri, 27 Sep 2024 16:31:10 +0200 Subject: [PATCH 2/3] [#57814] exclude existing hierarchy fields from config lists - hide hierarchy custom fields when configuring work package types - hide hierarchy custom fields when enabling custom fields for projects --- app/controllers/projects/settings/custom_fields_controller.rb | 4 +++- app/models/type/attributes.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/settings/custom_fields_controller.rb b/app/controllers/projects/settings/custom_fields_controller.rb index ffd9d0b6244d..8c8009fc8983 100644 --- a/app/controllers/projects/settings/custom_fields_controller.rb +++ b/app/controllers/projects/settings/custom_fields_controller.rb @@ -30,7 +30,9 @@ class Projects::Settings::CustomFieldsController < Projects::SettingsController menu_item :settings_custom_fields def show - @wp_custom_fields = WorkPackageCustomField.order("lower(name)") + @wp_custom_fields = WorkPackageCustomField + .order("lower(name)") + .where.not(field_format: "hierarchy") # TODO: Remove after enabling hierarchy fields end def update diff --git a/app/models/type/attributes.rb b/app/models/type/attributes.rb index 61a0cc8f3c8c..e9e14b85d172 100644 --- a/app/models/type/attributes.rb +++ b/app/models/type/attributes.rb @@ -146,7 +146,9 @@ def merge_date_for_form_attributes(attributes) end def add_custom_fields_to_form_attributes(attributes) - WorkPackageCustomField.includes(:custom_options).all.find_each do |field| + WorkPackageCustomField.includes(:custom_options) + .where.not(field_format: "hierarchy") # TODO: Remove after enabling hierarchy fields + .find_each do |field| attributes[field.attribute_name] = { required: field.is_required, has_default: field.default_value.present?, From 6fdbc59911049f663e7b45a4dfb478b858290cbf Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Tue, 1 Oct 2024 14:02:02 +0200 Subject: [PATCH 3/3] [#57814] added predicate for field_format --- app/models/custom_field.rb | 4 ++++ app/services/custom_fields/create_service.rb | 2 +- app/views/custom_fields/edit.html.erb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 873b78ff3569..e8596a9e53e1 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -293,6 +293,10 @@ def multi_value_possible? version? || user? || list? end + def field_format_hierarchy? + field_format == "hierarchy" + end + def allow_non_open_versions_possible? version? end diff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rb index f405956717ca..5466f7cd28a0 100644 --- a/app/services/custom_fields/create_service.rb +++ b/app/services/custom_fields/create_service.rb @@ -56,7 +56,7 @@ def after_perform(call) if cf.is_a?(ProjectCustomField) add_cf_to_visible_columns(cf) - elsif cf.field_format == "hierarchy" + elsif cf.field_format_hierarchy? # TODO: Use persistence service CustomField::Hierarchy::Item.create(custom_field: cf, label: nil, diff --git a/app/views/custom_fields/edit.html.erb b/app/views/custom_fields/edit.html.erb index dca852fc71df..b6741374f91c 100644 --- a/app/views/custom_fields/edit.html.erb +++ b/app/views/custom_fields/edit.html.erb @@ -33,7 +33,7 @@ See COPYRIGHT and LICENSE files for more details. <%= error_messages_for 'custom_field' %> -<% if @custom_field.field_format == "hierarchy" %> +<% if @custom_field.field_format_hierarchy? %> <%= render CustomFields::DetailsComponent.new(@custom_field) %> <% else %> <%= labelled_tabular_form_for @custom_field, as: :custom_field,