From da1176fb952ac38f008be6bd1ef5d6b9f346b14d Mon Sep 17 00:00:00 2001 From: Jonas Jabari Date: Thu, 4 Apr 2024 12:40:40 +0200 Subject: [PATCH 1/5] [#53706] Reordering project attributes is popping back on render https://community.openproject.org/work_packages/53706 From 5e8969c2fcbfc0d9020632caba000ab8f0e40e10 Mon Sep 17 00:00:00 2001 From: Jonas Jabari Date: Thu, 4 Apr 2024 12:59:11 +0200 Subject: [PATCH 2/5] Added default ordering in order to resolve drag and drop error --- .../show_component.rb | 22 +++++++++---------- app/models/project_custom_field.rb | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/components/settings/project_custom_field_sections/show_component.rb b/app/components/settings/project_custom_field_sections/show_component.rb index 76fa3c16a738..dae8ff6f3abe 100644 --- a/app/components/settings/project_custom_field_sections/show_component.rb +++ b/app/components/settings/project_custom_field_sections/show_component.rb @@ -49,18 +49,18 @@ def wrapper_uniq_by def drag_and_drop_target_config { - 'is-drag-and-drop-target': true, - 'target-container-accessor': '.Box > ul', # the accessor of the container that contains the drag and drop items - 'target-id': @project_custom_field_section.id, # the id of the target - 'target-allowed-drag-type': 'custom-field' # the type of dragged items which are allowed to be dropped in this target + "is-drag-and-drop-target": true, + "target-container-accessor": ".Box > ul", # the accessor of the container that contains the drag and drop items + "target-id": @project_custom_field_section.id, # the id of the target + "target-allowed-drag-type": "custom-field" # the type of dragged items which are allowed to be dropped in this target } end def draggable_item_config(project_custom_field) { - 'draggable-id': project_custom_field.id, - 'draggable-type': 'custom-field', - 'drop-url': drop_admin_settings_project_custom_field_path(project_custom_field) + "draggable-id": project_custom_field.id, + "draggable-type": "custom-field", + "drop-url": drop_admin_settings_project_custom_field_path(project_custom_field) } end @@ -82,7 +82,7 @@ def move_action_item(menu, move_to, label_text, icon) menu.with_item(label: label_text, href: move_admin_settings_project_custom_field_section_path(@project_custom_field_section, move_to:), form_arguments: { - method: :put, data: { 'turbo-stream': true, qa_selector: "project-custom-field-section-move-#{move_to}" } + method: :put, data: { "turbo-stream": true, qa_selector: "project-custom-field-section-move-#{move_to}" } }) do |item| item.with_leading_visual_icon(icon:) end @@ -99,8 +99,8 @@ def edit_action_item(menu) menu.with_item(label: t("settings.project_attributes.label_edit_section"), tag: :button, content_arguments: { - 'data-show-dialog-id': "project-custom-field-section-dialog#{@project_custom_field_section.id}", - 'data-qa-selector': "project-custom-field-section-edit" + "data-show-dialog-id": "project-custom-field-section-dialog#{@project_custom_field_section.id}", + "data-qa-selector": "project-custom-field-section-edit" }, value: "") do |item| item.with_leading_visual_icon(icon: :pencil) @@ -112,7 +112,7 @@ def delete_action_item(menu) scheme: :danger, href: admin_settings_project_custom_field_section_path(@project_custom_field_section), form_arguments: { - method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true, + method: :delete, data: { confirm: t("text_are_you_sure"), "turbo-stream": true, qa_selector: "project-custom-field-section-delete" } }) do |item| item.with_leading_visual_icon(icon: :trash) diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb index d1aa6fe6077f..8afa3704111a 100644 --- a/app/models/project_custom_field.rb +++ b/app/models/project_custom_field.rb @@ -38,6 +38,8 @@ class ProjectCustomField < CustomField validates :custom_field_section_id, presence: true + default_scope { order(position_in_custom_field_section: :asc) } + def type_name :label_project_plural end From 1adf0804f6d59287e7c05a0d2a37702d717bd979 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:19:09 +0300 Subject: [PATCH 3/5] Define a custom ProjectCustomField class in the migrations --- ...231031133334_create_project_custom_field_project_mappings.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb b/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb index ff9580a45df2..8e258b85b737 100644 --- a/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb +++ b/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb @@ -18,6 +18,8 @@ def down private + class ProjectCustomField < CustomField; end + def create_default_mapping project_ids = Project.pluck(:id) custom_field_ids = ProjectCustomField.pluck(:id) From 111364711bd0acae6305d562de1f9e04ebf3150b Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:25:59 +0300 Subject: [PATCH 4/5] Add custom ProjectCustomField class for EnableCurrentProjectCustomFieldsColumns migration --- ...200903064009_enable_current_project_custom_fields_columns.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb index b568154c5d7c..90258d87c6b7 100644 --- a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb +++ b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb @@ -39,4 +39,6 @@ def up def down # Nothing to do as setting is not used end + + class ProjectCustomField < CustomField; end end From e7c546b89f999be602992ae5ea3865998f8b7532 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:56:42 +0300 Subject: [PATCH 5/5] Use a default sorting order on the custom_fields relation of the ProjectCustomFieldSection Instead of the default_scope on the ProjectCustomField. --- .../admin/settings/project_custom_fields_controller.rb | 1 - app/models/project_custom_field.rb | 2 -- app/models/project_custom_field_section.rb | 7 +++++-- ...3064009_enable_current_project_custom_fields_columns.rb | 2 -- ...1133334_create_project_custom_field_project_mappings.rb | 2 -- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb index f25cca6013da..9dcc5169df0d 100644 --- a/app/controllers/admin/settings/project_custom_fields_controller.rb +++ b/app/controllers/admin/settings/project_custom_fields_controller.rb @@ -111,7 +111,6 @@ def destroy def set_sections @project_custom_field_sections = ProjectCustomFieldSection .includes(custom_fields: :project_custom_field_project_mappings) - .order("custom_fields.position_in_custom_field_section ASC") .all end diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb index 8afa3704111a..d1aa6fe6077f 100644 --- a/app/models/project_custom_field.rb +++ b/app/models/project_custom_field.rb @@ -38,8 +38,6 @@ class ProjectCustomField < CustomField validates :custom_field_section_id, presence: true - default_scope { order(position_in_custom_field_section: :asc) } - def type_name :label_project_plural end diff --git a/app/models/project_custom_field_section.rb b/app/models/project_custom_field_section.rb index c88ef5f11b19..589de4ed3ba4 100644 --- a/app/models/project_custom_field_section.rb +++ b/app/models/project_custom_field_section.rb @@ -27,6 +27,9 @@ #++ class ProjectCustomFieldSection < CustomFieldSection - has_many :custom_fields, class_name: "ProjectCustomField", dependent: :destroy, foreign_key: :custom_field_section_id, - inverse_of: :project_custom_field_section + has_many :custom_fields, -> { order(position_in_custom_field_section: :asc) }, + class_name: "ProjectCustomField", + dependent: :destroy, + foreign_key: :custom_field_section_id, + inverse_of: :project_custom_field_section end diff --git a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb index 90258d87c6b7..b568154c5d7c 100644 --- a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb +++ b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb @@ -39,6 +39,4 @@ def up def down # Nothing to do as setting is not used end - - class ProjectCustomField < CustomField; end end diff --git a/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb b/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb index 8e258b85b737..ff9580a45df2 100644 --- a/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb +++ b/db/migrate/20231031133334_create_project_custom_field_project_mappings.rb @@ -18,8 +18,6 @@ def down private - class ProjectCustomField < CustomField; end - def create_default_mapping project_ids = Project.pluck(:id) custom_field_ids = ProjectCustomField.pluck(:id)