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
introducing project attributes management with generic drag and drop approach
Jonas Jabari7d83ab051785
diff --git a/app/components/settings/project_attributes/header_component.html.erb b/app/components/settings/project_attributes/header_component.html.erbnew file mode 100644index 00000000000..0e244cdfd0a--- /dev/null+++ b/app/components/settings/project_attributes/header_component.html.erb@@ -0,0 +1,51 @@+<%=+ component_wrapper do+ flex_layout do |header_container|+ header_container.with_row do+ flex_layout(justify_content: :space_between, align_items: :center) do |title_container|++ title_container.with_column(flex: 1) do+ render(Primer::Beta::Heading.new(tag: :h1)) { t('settings.project_attributes.heading') }+ end++ title_container.with_column do+ flex_layout(justify_content: :space_between, align_items: :center) do |action_buttons_container|++ action_buttons_container.with_column(mr: 2) do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: new_custom_field_path(type: "ProjectCustomField"),+ scheme: :primary,+ data: { 'turbo-frame': 'true' }+ )) do |button|+ button.with_leading_visual_icon(icon: :plus)+ t('settings.project_attributes.label_new_attribute')+ end+ end++ action_buttons_container.with_column do+ render(Primer::Alpha::Dialog.new(+ id: "project-custom-field-section-dialog", title: t('settings.project_attributes.label_new_section'),+ size: :medium_portrait+ )) do |dialog|+ dialog.with_show_button('aria-label': t('settings.project_attributes.label_new_section'), scheme: :default) do |button|+ button.with_leading_visual_icon(icon: :plus)+ t('settings.project_attributes.label_new_section')+ end+ render(Settings::ProjectAttributes::Section::DialogBodyFormComponent.new())+ end+ end++ end+ end++ end+ end++ header_container.with_row(mt: 1, pb: 3, mb: 2, border: :bottom) do+ render(Primer::Beta::Text.new(color: :muted)) { t('settings.project_attributes.heading_description') }+ end++ end+ end+%>diff --git a/app/components/settings/project_attributes/header_component.rb b/app/components/settings/project_attributes/header_component.rbnew file mode 100644index 00000000000..5efac759681--- /dev/null+++ b/app/components/settings/project_attributes/header_component.rb@@ -0,0 +1,41 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Settings+ module ProjectAttributes+ class HeaderComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize+ super+ end+ end+ end+enddiff --git a/app/components/settings/project_attributes/section/dialog_body_form_component.html.erb b/app/components/settings/project_attributes/section/dialog_body_form_component.html.erbnew file mode 100644index 00000000000..49626ea97d5--- /dev/null+++ b/app/components/settings/project_attributes/section/dialog_body_form_component.html.erb@@ -0,0 +1,27 @@+<%=+ component_wrapper do+ primer_form_with(**form_config) do |f|+ component_collection do |collection|+ collection.with_component(Primer::Alpha::Dialog::Body.new) do+ flex_layout(my: 3) do |modal_body|+ modal_body.with_row do+ render(ProjectCustomFieldSections::NameForm.new(f))+ end+ end+ end++ collection.with_component(Primer::Alpha::Dialog::Footer.new) do+ component_collection do |modal_footer|+ modal_footer.with_component(Primer::ButtonComponent.new(data: { 'close-dialog-id': "project-custom-field-section-dialog#{@project_custom_field_section.id}" })) do+ t("button_cancel")+ end++ modal_footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) do+ t("button_save")+ end+ end+ end+ end+ end+ end+%>diff --git a/app/components/settings/project_attributes/section/dialog_body_form_component.rb b/app/components/settings/project_attributes/section/dialog_body_form_component.rbnew file mode 100644index 00000000000..32fdb04726f--- /dev/null+++ b/app/components/settings/project_attributes/section/dialog_body_form_component.rb@@ -0,0 +1,59 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Settings+ module ProjectAttributes+ module Section+ class DialogBodyFormComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(section: ProjectCustomFieldSection.new)+ super++ @project_custom_field_section = section+ end++ private++ def wrapper_uniq_by+ @project_custom_field_section.id+ end++ def form_config+ {+ model: @project_custom_field_section,+ method: @project_custom_field_section.persisted? ? :put : :post,+ url: @project_custom_field_section.persisted? ? admin_settings_project_custom_field_section_path(@project_custom_field_section) : admin_settings_project_custom_field_sections_path+ }+ end+ end+ end+ end+enddiff --git a/app/components/settings/project_attributes/section/index_component.html.erb b/app/components/settings/project_attributes/section/index_component.html.erbnew file mode 100644index 00000000000..f932849eb99--- /dev/null+++ b/app/components/settings/project_attributes/section/index_component.html.erb@@ -0,0 +1,13 @@+<%=+ component_wrapper(data: wrapper_data_attributes) do+ flex_layout(classes: 'dragula-container', data: { 'allowed-drop-type': 'section' }.merge(drop_target_config) ) do |flex|+ @sections.each do |section|+ flex.with_row(+ data: draggable_item_config(section)+ ) do+ render(Settings::ProjectAttributes::SectionComponent.new(section:))+ end+ end+ end+ end+%>diff --git a/app/components/settings/project_attributes/section/index_component.rb b/app/components/settings/project_attributes/section/index_component.rbnew file mode 100644index 00000000000..d72ad581994--- /dev/null+++ b/app/components/settings/project_attributes/section/index_component.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Settings+ module ProjectAttributes+ module Section+ class IndexComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(sections:)+ super++ @sections = sections+ end++ private++ def wrapper_data_attributes+ {+ controller: 'generic-drag-and-drop',+ 'application-target': 'dynamic'+ }+ end++ def drop_target_config+ {+ 'is-drag-and-drop-target': true,+ 'target-allowed-drag-type': 'section' # the type of dragged items which are allowed to be dropped in this target+ }+ end++ def draggable_item_config(section)+ {+ 'draggable-id': section.id,+ 'draggable-type': 'section',+ 'drop-url': drop_admin_settings_project_custom_field_section_path(section)+ }+ end+ end+ end+ end+enddiff --git a/app/components/settings/project_attributes/section/project_custom_field_component.html.erb b/app/components/settings/project_attributes/section/project_custom_field_component.html.erbnew file mode 100644index 00000000000..7b5a3bb3bce--- /dev/null+++ b/app/components/settings/project_attributes/section/project_custom_field_component.html.erb@@ -0,0 +1,24 @@+<%=+ component_wrapper do+ flex_layout(justify_content: :space_between, align_items: :center) do |main_container|+ main_container.with_column(flex_layout: true, align_items: :center) do |content_container|+ content_container.with_column(mr: 2) do+ render(Primer::OpenProject::DragHandle.new(classes: 'handle'))+ end+ content_container.with_column do+ render(Primer::Beta::Text.new(font_weight: :bold)) do+ "#{@project_custom_field.project_custom_field_section_mapping.position} #{@project_custom_field.name}"+ end+ end+ end+ main_container.with_column do+ render(Primer::Alpha::ActionMenu.new) do |menu|+ menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_project_custom_field_actions"), scheme: :invisible)+ edit_action_item(menu)+ move_actions(menu)+ # delete_action_item(menu)+ end+ end+ end+ end+%>diff --git a/app/components/settings/project_attributes/section/project_custom_field_component.rb b/app/components/settings/project_attributes/section/project_custom_field_component.rbnew file mode 100644index 00000000000..78bb056482d--- /dev/null+++ b/app/components/settings/project_attributes/section/project_custom_field_component.rb@@ -0,0 +1,85 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Settings+ module ProjectAttributes+ module Section+ class ProjectCustomFieldComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(project_custom_field:)+ super++ @project_custom_field = project_custom_field+ end++ private++ def edit_action_item(menu)+ menu.with_item(label: t("label_edit"),+ href: edit_custom_field_path(@project_custom_field)) do |item|+ item.with_leading_visual_icon(icon: :pencil)+ end+ end++ def move_actions(menu)+ move_action_item(menu, :highest, t("label_agenda_item_move_to_top"), "move-to-top") unless @project_custom_field.first?+ move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up") unless @project_custom_field.first?+ move_action_item(menu, :lower, t("label_agenda_item_move_down"), "chevron-down") unless @project_custom_field.last?+ unless @project_custom_field.last?+ move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"),+ "move-to-bottom")+ end+ end++ def move_action_item(menu, move_to, label_text, icon)+ menu.with_item(label: label_text,+ href: move_admin_settings_project_custom_field_path(@project_custom_field, move_to:),+ form_arguments: {+ method: :put, data: { 'turbo-stream': true }+ }) do |item|+ item.with_leading_visual_icon(icon:)+ end+ end++ # def delete_action_item(menu)+ # menu.with_item(label: t("text_destroy"),+ # scheme: :danger,+ # href: meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item),+ # form_arguments: {+ # method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true }+ # }) do |item|+ # item.with_leading_visual_icon(icon: :trash)+ # end+ # end+ end+ end+ end+enddiff --git a/app/components/settings/project_attributes/section_component.html.erb b/app/components/settings/project_attributes/section_component.html.erbnew file mode 100644index 00000000000..6813016a9d3--- /dev/null+++ b/app/components/settings/project_attributes/section_component.html.erb@@ -0,0 +1,57 @@+<%=+ component_wrapper do+ render(Primer::Beta::BorderBox.new(mt: 3, data: {+ id: @section.id, 'allowed-drop-type': 'custom-field'+ }.merge(drag_and_drop_target_config))) do |component|+ component.with_header(font_weight: :bold) do+ flex_layout(justify_content: :space_between, align_items: :center) do |section_header_container|+ section_header_container.with_column(flex_layout: true, align_items: :center) do |content_container|+ content_container.with_column(mr: 2) do+ render(Primer::OpenProject::DragHandle.new(classes: 'handle'))+ end+ content_container.with_column do+ render(Primer::Beta::Text.new(font_weight: :bold)) do+ "#{@section.position} #{@section.name}"+ end+ end+ end+ section_header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|+ actions_container.with_column do+ render(Primer::Alpha::ActionMenu.new) do |menu|+ menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_section_actions"), scheme: :invisible)+ edit_action_item(menu)+ move_actions(menu)+ if @project_custom_fields.empty?+ delete_action_item(menu)+ else+ disabled_delete_action_item(menu)+ end+ end+ end+ actions_container.with_column do+ render(Primer::Alpha::Dialog.new(+ id: "project-custom-field-section-dialog#{@section.id}", title: t('settings.project_attributes.label_new_section'),+ size: :medium_portrait+ )) do |dialog|+ render(Settings::ProjectAttributes::Section::DialogBodyFormComponent.new(section: @section))+ end+ end+ end+ end+ end+ if @project_custom_fields.empty?+ component.with_row do+ render(Primer::Beta::Text.new(color: :subtle)) { t("settings.project_attributes.label_no_project_custom_fields") }+ end+ else+ @project_custom_fields.each do |project_custom_field|+ component.with_row(+ data: draggable_item_config(project_custom_field)+ ) do+ render(Settings::ProjectAttributes::Section::ProjectCustomFieldComponent.new(project_custom_field:))+ end+ end+ end+ end+ end+%>diff --git a/app/components/settings/project_attributes/section_component.rb b/app/components/settings/project_attributes/section_component.rbnew file mode 100644index 00000000000..caee30afd3c--- /dev/null+++ b/app/components/settings/project_attributes/section_component.rb@@ -0,0 +1,114 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 Settings+ module ProjectAttributes+ class SectionComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(section:)+ super++ @section = section+ @project_custom_fields = section.project_custom_fields_ordered_by_postion_in_section+ end++ private++ def wrapper_uniq_by+ @section.id+ end++ 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': @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)+ }+ end++ def move_actions(menu)+ move_action_item(menu, :highest, t("label_agenda_item_move_to_top"), "move-to-top") unless @section.first?+ move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up") unless @section.first?+ move_action_item(menu, :lower, t("label_agenda_item_move_down"), "chevron-down") unless @section.last?+ unless @section.last?+ move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"),+ "move-to-bottom")+ end+ end++ 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(@section, move_to:),+ form_arguments: {+ method: :put, data: { 'turbo-stream': true }+ }) do |item|+ item.with_leading_visual_icon(icon:)+ end+ end++ def disabled_delete_action_item(menu)+ menu.with_item(label: t("text_destroy"),+ disabled: true) do |item|+ item.with_leading_visual_icon(icon: :trash)+ end+ end++ def edit_action_item(menu)+ menu.with_item(label: t("text_edit"),+ tag: :button,+ content_arguments: { 'data-show-dialog-id': "project-custom-field-section-dialog#{@section.id}" },+ value: "") do |item|+ item.with_leading_visual_icon(icon: :pencil)+ end+ end++ def delete_action_item(menu)+ menu.with_item(label: t("text_destroy"),+ scheme: :danger,+ href: admin_settings_project_custom_field_section_path(@section),+ form_arguments: {+ method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true }+ }) do |item|+ item.with_leading_visual_icon(icon: :trash)+ end+ end+ end+ end+enddiff --git a/app/controllers/admin/settings/project_custom_field_sections_controller.rb b/app/controllers/admin/settings/project_custom_field_sections_controller.rbnew file mode 100644index 00000000000..5f601238e95--- /dev/null+++ b/app/controllers/admin/settings/project_custom_field_sections_controller.rb@@ -0,0 +1,106 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 ProjectCustomFieldSectionsController < ::Admin::SettingsController+ include OpTurbo::ComponentStream+ include Admin::Settings::ProjectCustomFields::ComponentStreams++ before_action :set_project_custom_field_section, only: %i[move drop]++ def create+ @project_custom_field_section = ProjectCustomFieldSection.new(+ name: project_custom_field_section_params[:name],+ position: 1 # show new sections at the top of the list, otherwise might not be visible to user+ )++ if @project_custom_field_section.save+ update_header_via_turbo_stream # required to closed the dialog+ update_sections_via_turbo_stream(sections: ProjectCustomFieldSection.all)+ else+ update_section_dialog_body_form_via_turbo_stream(section: @project_custom_field_section)+ end++ respond_with_turbo_streams+ end++ def update+ @project_custom_field_section = ProjectCustomFieldSection.find(params[:id])++ if @project_custom_field_section.update(project_custom_field_section_params)+ update_section_via_turbo_stream(section: @project_custom_field_section)+ else+ update_section_dialog_body_form_via_turbo_stream(section: @project_custom_field_section)+ end++ respond_with_turbo_streams+ end++ def destroy+ @project_custom_field_section = ProjectCustomFieldSection.find(params[:id])++ if @project_custom_field_section.destroy+ update_sections_via_turbo_stream(sections: ProjectCustomFieldSection.all)+ end++ respond_with_turbo_streams+ end++ def move+ @project_custom_field_section.move_to = params[:move_to]&.to_sym++ if @project_custom_field_section.save+ update_sections_via_turbo_stream(sections: ProjectCustomFieldSection.all)+ end++ respond_with_turbo_streams+ end++ def drop+ if params[:position] == 'lowest'+ @project_custom_field_section.move_to = :lowest+ else+ @project_custom_field_section.insert_at(params[:position].to_i)+ end++ update_sections_via_turbo_stream(sections: ProjectCustomFieldSection.all)++ respond_with_turbo_streams+ end++ private++ def set_project_custom_field_section+ @project_custom_field_section = ProjectCustomFieldSection.find(params[:id])+ end++ def project_custom_field_section_params+ params.require(:project_custom_field_section).permit(:name)+ end+ end+enddiff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rbnew file mode 100644index 00000000000..999c32fb75a--- /dev/null+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb@@ -0,0 +1,98 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 ProjectCustomFieldsController < ::Admin::SettingsController+ include OpTurbo::ComponentStream+ include Admin::Settings::ProjectCustomFields::ComponentStreams++ menu_item :project_custom_field_settings++ before_action :set_sections, only: %i[index move drop]+ before_action :set_project_custom_field, only: %i[move drop]++ def default_breadcrumb+ t(:label_project_attributes_plural)+ end++ def index+ respond_to :html+ end++ def move+ mapping = @project_custom_field.project_custom_field_section_mapping+ mapping.move_to = params[:move_to]&.to_sym++ update_sections_via_turbo_stream(sections: @sections)++ respond_with_turbo_streams+ end++ def drop+ mapping = @project_custom_field.project_custom_field_section_mapping++ current_section = @project_custom_field.project_custom_field_section+ current_section_id = current_section.id+ new_section_id = params[:target_id].to_i++ if current_section_id != new_section_id+ section_changed = true+ old_section = current_section+ mapping.remove_from_list+ current_section = ProjectCustomFieldSection.find(params[:target_id].to_i)+ @project_custom_field.project_custom_field_section = current_section+ end++ mapping = @project_custom_field.reload.project_custom_field_section_mapping++ if params[:position] == 'lowest'+ mapping.move_to = :lowest+ else+ mapping.insert_at(params[:position].to_i)+ end++ update_section_via_turbo_stream(section: current_section)++ if section_changed+ update_section_via_turbo_stream(section: old_section)+ end++ respond_with_turbo_streams+ end++ private++ def set_sections+ @sections = ProjectCustomFieldSection.all+ end++ def set_project_custom_field+ @project_custom_field = ProjectCustomField.find(params[:id])+ end+ end+enddiff --git a/app/controllers/admin/settings/projects_settings_controller.rb b/app/controllers/admin/settings/projects_settings_controller.rbindex c10212545cd..dd5867cb871 100644--- a/app/controllers/admin/settings/projects_settings_controller.rb+++ b/app/controllers/admin/settings/projects_settings_controller.rb@@ -28,7 +28,7 @@module Admin::Settingsclass ProjectsSettingsController < ::Admin::SettingsController- menu_item :settings_projects+ menu_item :projects_settingsdef default_breadcrumbt(:label_project_plural)diff --git a/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rbnew file mode 100644index 00000000000..bd85e840446--- /dev/null+++ b/app/controllers/concerns/admin/settings/project_custom_fields/component_streams.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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+ module Settings+ module ProjectCustomFields+ module ComponentStreams+ extend ActiveSupport::Concern++ included do+ def update_header_via_turbo_stream+ update_via_turbo_stream(+ component: ::Settings::ProjectAttributes::HeaderComponent.new+ )+ end++ def update_section_via_turbo_stream(section:)+ update_via_turbo_stream(+ component: ::Settings::ProjectAttributes::SectionComponent.new(+ section:+ )+ )+ end++ def update_section_dialog_body_form_via_turbo_stream(section:)+ update_via_turbo_stream(+ component: ::Settings::ProjectAttributes::Section::DialogBodyFormComponent.new(+ section:+ )+ )+ end++ def update_sections_via_turbo_stream(sections:)+ replace_via_turbo_stream(+ component: ::Settings::ProjectAttributes::Section::IndexComponent.new(+ sections:+ )+ )+ end+ end+ end+ end+ end+enddiff --git a/app/forms/project_custom_field_sections/name_form.rb b/app/forms/project_custom_field_sections/name_form.rbnew file mode 100644index 00000000000..caba64f6b8f--- /dev/null+++ b/app/forms/project_custom_field_sections/name_form.rb@@ -0,0 +1,39 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 ProjectCustomFieldSections::NameForm < ApplicationForm+ form do |project_custom_field_section_form|+ project_custom_field_section_form.text_field(+ name: :name,+ placeholder: ProjectCustomFieldSection.human_attribute_name(:name),+ label: ProjectCustomFieldSection.human_attribute_name(:name),+ required: true,+ autofocus: true+ )+ end+enddiff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rbindex 23ad86cbbd8..be092d69dc5 100644--- a/app/helpers/settings_helper.rb+++ b/app/helpers/settings_helper.rb@@ -44,11 +44,6 @@ module SettingsHelpercontroller: '/admin/settings/languages_settings',label: :label_languages},- {- name: 'projects',- controller: '/admin/settings/projects_settings',- label: :label_project_plural- },{name: 'attachments',controller: '/admin/settings/attachments_settings',@@ -199,11 +194,11 @@ module SettingsHelperprivate- def wrap_field_outer(options, &block)+ def wrap_field_outer(options, &)if options[:label] == false- block.call+ yieldelse- content_tag(:span, class: 'form--field-container', &block)+ content_tag(:span, class: 'form--field-container', &)endend@@ -216,7 +211,7 @@ module SettingsHelperhidden_field_tag("settings[#{setting}][]", '') +I18n.t("setting_#{setting}")end- end.join.html_safe # rubocop:disable Rails/OutputSafety+ end.join.html_safeendenddiff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rbindex faa827c5280..33da45d776d 100644--- a/app/models/project_custom_field.rb+++ b/app/models/project_custom_field.rb@@ -58,6 +58,10 @@ class ProjectCustomField < CustomFieldendend+ def project_custom_field_section_mapping+ project_custom_field_section_mappings.first+ end+def project_custom_field_sectionproject_custom_field_sections.firstenddiff --git a/app/models/project_custom_field_section.rb b/app/models/project_custom_field_section.rbindex f849e376f09..5df3ab10531 100644--- a/app/models/project_custom_field_section.rb+++ b/app/models/project_custom_field_section.rb@@ -31,4 +31,12 @@ class ProjectCustomFieldSection < ApplicationRecordhas_many :project_custom_fields, through: :project_custom_field_section_mappingsacts_as_list++ validates :name, presence: true++ default_scope { order(:position) }++ def project_custom_fields_ordered_by_postion_in_section+ project_custom_fields.reorder('project_custom_field_section_mappings.position ASC')+ endenddiff --git a/app/views/admin/settings/project_custom_fields/index.html.erb b/app/views/admin/settings/project_custom_fields/index.html.erbnew file mode 100644index 00000000000..36e54678325--- /dev/null+++ b/app/views/admin/settings/project_custom_fields/index.html.erb@@ -0,0 +1,32 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 2012-2023 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 data-turbo="true">+ <%= render(Settings::ProjectAttributes::HeaderComponent.new()) %>+ <%= render(Settings::ProjectAttributes::Section::IndexComponent.new(sections: @sections)) %>+</div>diff --git a/app/views/admin/settings/projects_settings/show.html.erb b/app/views/admin/settings/projects_settings/show.html.erbindex e8d40db7d41..3fc54acc4be 100644--- a/app/views/admin/settings/projects_settings/show.html.erb+++ b/app/views/admin/settings/projects_settings/show.html.erb@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= toolbar title: t(:label_project_plural) %>-<%= styled_form_tag(admin_settings_update_projects_path, method: :patch) do %>+<%= styled_form_tag(admin_settings_projects_path, method: :patch) do %><section class="form--section"><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t('settings.projects.section_new_projects') %></legend>@@ -67,7 +67,7 @@ See COPYRIGHT and LICENSE files for more details.%></div><% end %>-+<div class="form--field"><%= setting_multiselect(:enabled_projects_columns, column_choices) %></div>diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 74b28188985..4cb63a19881 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -333,6 +333,24 @@ Redmine::MenuManager.map :admin_menu do |menu|caption: Proc.new { Workflow.model_name.human },parent: :admin_work_packages+ menu.push :admin_projects_settings,+ { controller: '/admin/settings/project_custom_fields', action: :index },+ if: Proc.new { User.current.admin? },+ caption: :label_project_plural,+ icon: 'projects'++ menu.push :project_custom_fields_settings,+ { controller: '/admin/settings/project_custom_fields', action: :index },+ if: Proc.new { User.current.admin? },+ caption: :label_project_attributes_plural,+ parent: :admin_projects_settings++ menu.push :projects_settings,+ { controller: '/admin/settings/projects_settings', action: :show },+ if: Proc.new { User.current.admin? },+ caption: :label_setting_plural,+ parent: :admin_projects_settings+menu.push :custom_fields,{ controller: '/custom_fields' },if: Proc.new { User.current.admin? },diff --git a/config/locales/en.yml b/config/locales/en.ymlindex e345a483c60..0978eeb62b1 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2032,7 +2032,9 @@ en:label_project_hierarchy: "Project hierarchy"label_project_new: "New project"label_project_plural: "Projects"+ label_project_attributes_plural: "Project attributes"label_project_settings: "Project settings"+ label_project_attributes_settings: "Project attributes settings"label_project_storage_plural: "File Storages"label_project_storage_project_folder: "File Storages: Project folders"label_projects_storage_information: "%{count} projects using %{storage} disk storage"@@ -2893,6 +2895,13 @@ en:delay_minutes_explanation: "Email sending can be delayed to allow users with configured in app notification to confirm the notification within the application before a mail is sent out. Users who read a notification within the application will not receive an email for the already read notification."other: "Other"passwords: "Passwords"+ project_attributes:+ heading: "Project attributes"+ label_new_attribute: "Project attribute"+ label_new_section: "Section"+ label_section_actions: "Section actions"+ heading_description: "These project attributes appear in the project overview of each project. You can add new attributes and group them into sections. Individual attributes can be enabled or disabled at a project level."+ label_project_custom_field_actions: "Project attribute actions"projects:section_new_projects: "Settings for new projects"section_project_overview: "Settings for project overview list"diff --git a/config/routes.rb b/config/routes.rbindex 072a4491568..9e1108ccf30 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -83,7 +83,7 @@ OpenProject::Application.routes.draw domatch '/account/register', action: 'register', via: %i[get post patch]get '/account/activate', action: 'activate'- match '/login', action: 'login', as: 'signin', via: %i[get post]+ match '/login', action: 'login', as: 'signin', via: %i[get post]get '/login/internal', action: 'internal_login', as: 'internal_signin'get '/logout', action: 'logout', as: 'signout'@@ -417,6 +417,21 @@ OpenProject::Application.routes.draw doresource :mail_notifications, controller: '/admin/settings/mail_notifications_settings', only: %i[show update]resource :api, controller: '/admin/settings/api_settings', only: %i[show update]resource :work_packages, controller: '/admin/settings/work_packages_settings', only: %i[show update]+ resource :projects, controller: '/admin/settings/projects_settings', only: %i[show update]+ resources :project_custom_fields, controller: '/admin/settings/project_custom_fields',+ only: %i[index show update] do+ member do+ put :move+ put :drop+ end+ end+ resources :project_custom_field_sections, controller: '/admin/settings/project_custom_field_sections',+ only: %i[create update destroy] do+ member do+ put :move+ put :drop+ end+ endresource :working_days, controller: '/admin/settings/working_days_settings', only: %i[show update]resource :users, controller: '/admin/settings/users_settings', only: %i[show update]resource :date_format, controller: '/admin/settings/date_format_settings', only: %i[show update]diff --git a/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts b/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.tsnew file mode 100644index 00000000000..2c5a6874370--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/generic-drag-and-drop.controller.ts@@ -0,0 +1,177 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2023 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.+ * +++ */++import * as Turbo from '@hotwired/turbo';+import { Controller } from '@hotwired/stimulus';+import { Drake } from 'dragula';+import { debugLog } from 'core-app/shared/helpers/debug_output';+import { dropRight } from 'lodash';++export default class extends Controller {+ drake:Drake|undefined;+ targetConfigs:Object[];++ containerTargets:Element[]++ connect() {+ this.initDrake();+ }++ initDrake() {+ this.setContainerTargetsAndConfigs();++ // reinit drake if it already exists+ if(this.drake){+ this.drake.destroy();+ }++ this.drake = dragula(this.containerTargets,+ {+ moves: (_el, _source, handle, _sibling) => !!handle?.classList.contains('octicon-grabber'),+ accepts: (el?: Element | null, target?: Element | null, source?: Element | null, sibling?: Element | null) => this.accepts(el!, target!, source!, sibling!),+ },+ )+ // eslint-disable-next-line @typescript-eslint/no-misused-promises+ .on('drag', this.drag.bind(this))+ .on('drop', this.drop.bind(this));+ }++ reInitDrakeContainers() {+ this.setContainerTargetsAndConfigs();+ if (this.drake) {+ this.drake.containers = this.containerTargets;+ }+ }++ setContainerTargetsAndConfigs(): void {+ const rawTargets = Array.from(+ this.element.querySelectorAll('[data-is-drag-and-drop-target="true"]')+ ) as Element[];+ this.targetConfigs = [];+ let processedTargets: Element[] = [];++ rawTargets.forEach((target: Element) => {+ let targetConfig: {+ container: Element,+ allowedDragType: string|null,+ targetId: string|null+ } = {+ container: target,+ allowedDragType: target.getAttribute('data-target-allowed-drag-type'),+ targetId: target.getAttribute('data-target-id')+ };++ // if the target has a container accessor, use that as the container instead of the element itself+ // we need this e.g. in Primer's boderbox component as we cannot add required data attributes to the ul element there+ const containerAccessor = target.getAttribute('data-target-container-accessor');++ if(containerAccessor){+ target = target.querySelector(containerAccessor) as Element+ targetConfig.container = target+ }++ // we need to save the targetConfigs separately as we need to pass the pure container elements to drake+ // but need the configuration of the targets when dropping elements+ this.targetConfigs.push(targetConfig);++ processedTargets = processedTargets.concat(target);+ });++ this.containerTargets = processedTargets;+ }++ accepts(el:Element, target:Element, _source:Element|null, _sibling:Element|null) {+ const targetConfig: any = this.targetConfigs.find((config: any) => config.container == target);+ const acceptedDragType = targetConfig?.allowedDragType as string | undefined;++ const draggableType = el.getAttribute('data-draggable-type');++ if (draggableType !== acceptedDragType) {+ debugLog('Element is not allowed to be dropped here');+ return false;+ }++ return true;+ }++ drag(el:Element, _source:Element|null) {+ // discover new target containers if they have been added to the DOM via Turbo streams+ this.reInitDrakeContainers();+ }++ async drop(el:Element, target:Element, _source:Element|null, sibling:Element|null) {+ const dropUrl = el.getAttribute('data-drop-url');++ const targetPosition = Array.from(target.children).indexOf(el);++ const targetConfig: any = this.targetConfigs.find((config: any) => config.container == target);+ const targetId = targetConfig?.targetId as string | undefined;++ const data = new FormData();++ data.append('position', (targetPosition + 1).toString());++ if(targetId){+ data.append('target_id', targetId.toString());+ }++ if(dropUrl){+ const response = await fetch(dropUrl, {+ method: 'PUT',+ body: data,+ headers: {+ 'X-CSRF-Token': (document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement).content,+ Accept: 'text/vnd.turbo-stream.html',+ },+ credentials: 'same-origin',+ });++ if (!response.ok) {+ debugLog('Failed to sort item');+ } else {+ const text = await response.text();+ Turbo.renderStreamMessage(text);+ // reinit drake containers as the DOM will be updated by Turbo streams+ // otherwise the DOM references in the Drake instance will be outdated+ setTimeout(()=> this.reInitDrakeContainers(), 100);+ }+ }++ if (this.drake) {+ this.drake.cancel(true); // necessary to prevent "copying" behaviour+ }+ }++ disconnect() {+ if (this.drake) {+ this.drake.destroy();+ }+ }+}