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

WIP[Op#54456]: Started implementation on unlinking a project attribute from a project

Andreas Pfohl135fa305610c
diff --git a/app/components/projects/row_component.html.erb b/app/components/projects/row_component.html.erb
index 8ed51f18924..62d5bdb79e1 100644
--- a/app/components/projects/row_component.html.erb
+++ b/app/components/projects/row_component.html.erb
@@ -27,10 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<tr
- <%= "id=\"#{row_css_id}\"".html_safe if row_css_id %>
- <%= "class=\"#{row_css_class}\"".html_safe if row_css_class %>
->
+<%= component_wrapper(tag: "tr", class: row_css_class, data: { turbo: true }) do %>
<% columns.each do |column| %>
<td class="<%= column_css_class(column) %>">
<%= column_value(column) %>
@@ -41,4 +38,4 @@ See COPYRIGHT and LICENSE files for more details.
<%= link %>
<% end %>
</td>
-</tr>
+<% end %>
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index 6dd80c99c2c..09b1b658a90 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -29,6 +29,8 @@
#++
module Projects
class RowComponent < ::RowComponent
+ include OpTurbo::Streamable
+
delegate :favored_project_ids, to: :table
def project
@@ -168,7 +170,7 @@ module Projects
classes.join(" ")
end
- def row_css_id
+ def wrapper_uniq_by
"project-#{project.id}"
end
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
index fb90b8b7ab5..bb0c47418ef 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
+++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
@@ -42,7 +42,15 @@ module Settings
scheme: :danger,
icon: :trash,
label: I18n.t(:button_delete),
- href: confirm_destroy_project_path(project)
+ href: unlink_admin_settings_project_custom_field_path(
+ id: @table.params[:custom_field].id,
+ project_custom_field_project_mapping: { project_id: model.first.id }
+ ),
+ data: {
+ method: :delete,
+ turbo: true,
+ 'turbo-stream': true
+ }
}
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 9bfe0ebff1c..6d776b66ea0 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -34,10 +34,8 @@ module Admin::Settings
menu_item :project_custom_fields_settings
- before_action :set_sections, only: %i[show index edit update move drop]
- before_action :find_custom_field, only: %i(show edit update destroy delete_option reorder_alphabetical move drop)
- before_action :prepare_custom_option_position, only: %i(update create)
- before_action :find_custom_option, only: :delete_option
+ before_action :set_sections, only: %i[show index edit move drop]
+ before_action :find_custom_field, only: %i(show edit destroy move drop)
def show_local_breadcrumb
false
@@ -68,6 +66,19 @@ module Admin::Settings
end
end
+ def unlink
+ # call = ProjectCustomFieldProjectMappings::ToggleService
+ # .new(user: current_user)
+ # .call(permitted_params.project_custom_field_project_mapping)
+
+ project = Project.find(permitted_params.project_custom_field_project_mapping["project_id"])
+ remove_via_turbo_stream(
+ component: Settings::ProjectCustomFields::ProjectCustomFieldMapping::RowComponent
+ .new(row: [project, 0], table: OpenStruct.new(columns: [], favored_project_ids: [])))
+
+ respond_to_with_turbo_streams(status: true ? :ok : :unprocessable_entity)
+ end
+
def move
call = CustomFields::UpdateService.new(user: current_user, model: @custom_field).call(
move_to: params[:move_to]&.to_sym
@@ -109,8 +120,8 @@ module Admin::Settings
def set_sections
@project_custom_field_sections = ProjectCustomFieldSection
- .includes(custom_fields: :project_custom_field_project_mappings)
- .all
+ .includes(custom_fields: :project_custom_field_project_mappings)
+ .all
end
def find_custom_field
diff --git a/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb b/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb
index 9481e1df02e..1fbdd903eb3 100644
--- a/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb
+++ b/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb
@@ -27,4 +27,4 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(query:, params: {})) %>
+<%= render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(query:, params: { custom_field: })) %>
diff --git a/config/routes.rb b/config/routes.rb
index cb7d74789d1..38e3d7796d4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -454,6 +454,7 @@ Rails.application.routes.draw do
post :reorder_alphabetical
put :move
put :drop
+ delete :unlink
end
end
resources :project_custom_field_sections, controller: "/admin/settings/project_custom_field_sections",