mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 19:24:48 +08:00
Fix moving result elements [SCI-9430]
This commit is contained in:
parent
8e420181ac
commit
7c0e8221c1
6 changed files with 6 additions and 21 deletions
|
@ -108,7 +108,7 @@
|
|||
<component
|
||||
v-for="(element, index) in orderedElements"
|
||||
:is="elements[index].attributes.orderable_type"
|
||||
:key="index"
|
||||
:key="element.id"
|
||||
:element.sync="elements[index]"
|
||||
:inRepository="inRepository"
|
||||
:reorderElementUrl="elements.length > 1 ? urls.reorder_elements_url : ''"
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
@close="closeReorderModal"
|
||||
/>
|
||||
<div class="collapse in pl-10" :id="'resultBody' + result.id">
|
||||
<div v-for="(element, index) in orderedElements" :key="index">
|
||||
<div v-for="(element, index) in orderedElements" :key="element.id">
|
||||
<component
|
||||
:is="elements[index].attributes.orderable_type"
|
||||
:element.sync="elements[index]"
|
||||
|
@ -427,7 +427,7 @@
|
|||
},
|
||||
moveElement(position, target_id) {
|
||||
this.elements.splice(position, 1)
|
||||
let unorderedElements = this.elements.map( e => {
|
||||
this.elements.map( e => {
|
||||
if (e.attributes.position >= position) {
|
||||
e.attributes.position -= 1;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
||||
<h4 class="modal-title" id="modal-destroy-team-label">
|
||||
<h4 class="modal-title" id="modal-delete-result-element">
|
||||
{{ i18n.t('protocols.steps.modals.delete_element.title')}}
|
||||
</h4>
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
||||
<h4 class="modal-title" id="modal-destroy-team-label">
|
||||
<h4 class="modal-title" id="modal-move-result-element">
|
||||
{{ i18n.t(`protocols.steps.modals.move_element.${parent_type}.title`) }}
|
||||
</h4>
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" @click="cancel" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
||||
<h4 class="modal-title" id="modal-destroy-team-label">
|
||||
<h4 class="modal-title" id="modal-table-name">
|
||||
{{ i18n.t('protocols.steps.table.name_modal.title')}}
|
||||
</h4>
|
||||
</div>
|
||||
|
|
|
@ -4,8 +4,6 @@ class ResultOrderableElement < ApplicationRecord
|
|||
validates :position, uniqueness: { scope: :result }
|
||||
validate :check_result_relations
|
||||
|
||||
around_destroy :decrement_following_elements_positions
|
||||
|
||||
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
|
||||
|
@ -20,17 +18,4 @@ class ResultOrderableElement < ApplicationRecord
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
def decrement_following_elements_positions
|
||||
result.with_lock do
|
||||
yield
|
||||
result.result_orderable_elements
|
||||
.where('position > ?', position)
|
||||
.order(position: :asc).each do |result_orderable_element|
|
||||
# find_each ignore any ordering
|
||||
result_orderable_element.position -= 1
|
||||
result_orderable_element.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue