mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-02 21:20:08 +08:00
Use act_as_list for reordering result elements, localize title for result reordering modal [SCI-9182]
This commit is contained in:
parent
6bf0c6cb2f
commit
56744e2dcd
6 changed files with 19 additions and 10 deletions
|
@ -5,17 +5,19 @@ class ResultOrderableElementsController < ApplicationController
|
|||
before_action :check_manage_permissions
|
||||
|
||||
def reorder
|
||||
@result.with_lock do
|
||||
params[:result_orderable_element_positions].each do |id, position|
|
||||
@result.result_orderable_elements.find(id).update_column(:position, position)
|
||||
params[:result_orderable_element_positions].each do |id, position|
|
||||
result_element = @result.result_orderable_elements.find(id)
|
||||
ActiveRecord::Base.transaction do
|
||||
result_element.insert_at(position)
|
||||
end
|
||||
|
||||
log_activity(:result_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
|
||||
@result.touch
|
||||
end
|
||||
|
||||
log_activity(:result_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
@result.touch
|
||||
|
||||
render json: params[:result_orderable_element_positions], status: :ok
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
render json: { errors: result_element.errors }, status: :conflict
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -39,7 +41,7 @@ class ResultOrderableElementsController < ApplicationController
|
|||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
subject: @result,
|
||||
team: @@my_module.team,
|
||||
team: @my_module.team,
|
||||
project: project,
|
||||
message_items: message_items)
|
||||
end
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
</div>
|
||||
|
||||
<ReorderableItemsModal v-if="reordering"
|
||||
title="Placeholder title for this modal"
|
||||
:title="i18n.t('my_modules.modals.reorder_results.title')"
|
||||
:items="reorderableElements"
|
||||
@reorder="updateElementOrder"
|
||||
@close="closeReorderModal"
|
||||
|
|
|
@ -8,6 +8,7 @@ class ResultOrderableElement < ApplicationRecord
|
|||
|
||||
belongs_to :result, inverse_of: :result_orderable_elements, touch: true
|
||||
belongs_to :orderable, polymorphic: true, inverse_of: :result_orderable_element
|
||||
acts_as_list scope: :result, top_of_list: 0, sequential_updates: true
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -79,7 +79,8 @@ class ResultSerializer < ActiveModel::Serializer
|
|||
update_asset_view_mode_url: update_asset_view_mode_my_module_result_path(object.my_module, object),
|
||||
update_view_state_url: update_view_state_my_module_result_path(object.my_module, object),
|
||||
direct_upload_url: rails_direct_uploads_url,
|
||||
upload_attachment_url: upload_attachment_my_module_result_path(object.my_module, object)
|
||||
upload_attachment_url: upload_attachment_my_module_result_path(object.my_module, object),
|
||||
reorder_elements_url: reorder_result_result_orderable_elements_path(result_id: object.id)
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -1387,6 +1387,8 @@ en:
|
|||
snapshot_error:
|
||||
title: "Snapshot error"
|
||||
body_html: "<strong>%{repository}</strong> inventory snapshot failed to generate. Please contact support if this problem persists."
|
||||
reorder_results:
|
||||
title: "Rearrange result content"
|
||||
modules_list_partial:
|
||||
private_tasks_html: 'Assigned to <strong>%{nr}</strong> private task(s)'
|
||||
no_results:
|
||||
|
|
|
@ -614,6 +614,9 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :results, only: [:update, :destroy] do
|
||||
resources :result_orderable_elements do
|
||||
post :reorder, on: :collection
|
||||
end
|
||||
resources :result_comments,
|
||||
path: '/comments',
|
||||
only: %i(create index update destroy)
|
||||
|
|
Loading…
Reference in a new issue