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

Fix enumeration sorting links

Oliver Günther1c9318547f0d
diff --git a/app/components/enumerations/row_component.rb b/app/components/enumerations/row_component.rb
index 4b9230ade04..60dd4041ca9 100644
--- a/app/components/enumerations/row_component.rb
+++ b/app/components/enumerations/row_component.rb
@@ -51,7 +51,7 @@ module Enumerations
end
def sort
- helpers.reorder_links('enumeration', { action: 'update', id: enumeration }, method: :put)
+ helpers.reorder_links('enumeration', { action: 'move', id: enumeration }, method: :post)
end
def button_links
diff --git a/app/components/enumerations/table_component.rb b/app/components/enumerations/table_component.rb
index 7283ed7597e..9d2ca664cb9 100644
--- a/app/components/enumerations/table_component.rb
+++ b/app/components/enumerations/table_component.rb
@@ -38,6 +38,10 @@ module Enumerations
end
end
+ def sortable?
+ false
+ end
+
def headers
[
['name', { caption: Enumeration.human_attribute_name(:name) }],
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index eaca5109b56..f72ea6235b3 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -30,7 +30,7 @@ class EnumerationsController < ApplicationController
layout 'admin'
before_action :require_admin
- before_action :find_enumeration, only: %i[edit update destroy]
+ before_action :find_enumeration, only: %i[edit update move destroy]
include CustomFieldsHelper
@@ -90,6 +90,16 @@ class EnumerationsController < ApplicationController
@enumerations = @enumeration.class.all - [@enumeration]
end
+ def move
+ if @enumeration.update(permitted_params.enumerations_move)
+ flash[:notice] = I18n.t(:notice_successful_update)
+ redirect_to enumerations_path
+ else
+ flash.now[:error] = I18n.t(:error_type_could_not_be_saved)
+ render action: 'edit'
+ end
+ end
+
protected
def default_breadcrumb
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 0eb47da4726..614c629acee 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -240,6 +240,10 @@ class PermittedParams
params.require(:type).permit(*self.class.permitted_attributes[:move_to])
end
+ def enumerations_move
+ params.require(:enumeration).permit(*self.class.permitted_attributes[:move_to])
+ end
+
def search
params.permit(*self.class.permitted_attributes[:search])
end
diff --git a/config/routes.rb b/config/routes.rb
index a84dc7af56f..c4fb99c4d53 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -352,7 +352,9 @@ OpenProject::Application.routes.draw do
delete 'enterprise/delete_trial_key' => 'enterprises#delete_trial_key'
end
end
- resources :enumerations
+ resources :enumerations do
+ post 'move/:id', action: 'move', on: :collection
+ end
delete 'design/logo' => 'custom_styles#logo_delete', as: 'custom_style_logo_delete'
delete 'design/export_logo' => 'custom_styles#export_logo_delete', as: 'custom_style_export_logo_delete'