fix: make edition annotation work again
This commit is contained in:
parent
28a18e3912
commit
6f7fb9841c
4 changed files with 18 additions and 20 deletions
|
@ -55,9 +55,7 @@ module Administrateurs
|
|||
def retrieve_coordinate_and_uppers
|
||||
@tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
|
||||
@coordinate = draft_revision.coordinate_for(@tdc)
|
||||
@upper_tdcs = draft_revision
|
||||
.upper_coordinates(@coordinate.position)
|
||||
.map(&:type_de_champ)
|
||||
@upper_tdcs = @coordinate.upper_siblings.map(&:type_de_champ)
|
||||
end
|
||||
|
||||
def draft_revision
|
||||
|
|
|
@ -8,7 +8,7 @@ module Administrateurs
|
|||
if type_de_champ.valid?
|
||||
@coordinate = draft.coordinate_for(type_de_champ)
|
||||
@created = champ_component_from(@coordinate, focused: true)
|
||||
@morphed = champ_components_starting_at(@coordinate.position + 1)
|
||||
@morphed = champ_components_starting_at(@coordinate, 1)
|
||||
|
||||
reset_procedure
|
||||
flash.notice = "Formulaire enregistré"
|
||||
|
@ -22,7 +22,7 @@ module Administrateurs
|
|||
|
||||
if type_de_champ.update(type_de_champ_update_params)
|
||||
@coordinate = draft.coordinate_for(type_de_champ)
|
||||
@morphed = champ_components_starting_at(@coordinate.position)
|
||||
@morphed = champ_components_starting_at(@coordinate)
|
||||
|
||||
reset_procedure
|
||||
flash.notice = "Formulaire enregistré"
|
||||
|
@ -42,7 +42,7 @@ module Administrateurs
|
|||
@destroyed = @coordinate
|
||||
@created = champ_component_from(@coordinate)
|
||||
# update the one component below
|
||||
@morphed = champ_components_starting_at(@coordinate.position + 1).take(1)
|
||||
@morphed = champ_components_starting_at(@coordinate, 1).take(1)
|
||||
end
|
||||
|
||||
def move_down
|
||||
|
@ -51,7 +51,7 @@ module Administrateurs
|
|||
@destroyed = @coordinate
|
||||
@created = champ_component_from(@coordinate)
|
||||
# update the one component above
|
||||
@morphed = champ_components_starting_at(@coordinate.position - 1).take(1)
|
||||
@morphed = champ_components_starting_at(@coordinate, - 1).take(1)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -60,14 +60,14 @@ module Administrateurs
|
|||
flash.notice = "Formulaire enregistré"
|
||||
|
||||
@destroyed = @coordinate
|
||||
@morphed = champ_components_starting_at(@coordinate.position)
|
||||
@morphed = champ_components_starting_at(@coordinate)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_components_starting_at(position)
|
||||
draft
|
||||
.coordinates_starting_at(position)
|
||||
def champ_components_starting_at(coordinate, offset = 0)
|
||||
coordinate
|
||||
.siblings_starting_at(offset)
|
||||
.lazy
|
||||
.map { |c| champ_component_from(c) }
|
||||
end
|
||||
|
@ -75,7 +75,7 @@ module Administrateurs
|
|||
def champ_component_from(coordinate, focused: false)
|
||||
TypesDeChampEditor::ChampComponent.new(
|
||||
coordinate: coordinate,
|
||||
upper_coordinates: draft.upper_coordinates(coordinate.position),
|
||||
upper_coordinates: coordinate.upper_siblings,
|
||||
focused: focused
|
||||
)
|
||||
end
|
||||
|
|
|
@ -197,14 +197,6 @@ class ProcedureRevision < ApplicationRecord
|
|||
revision_types_de_champ.find_by!(type_de_champ: tdc)
|
||||
end
|
||||
|
||||
def upper_coordinates(position)
|
||||
revision_types_de_champ_public.filter { |c| c.position < position }
|
||||
end
|
||||
|
||||
def coordinates_starting_at(position)
|
||||
revision_types_de_champ_public.reload.filter { |c| position <= c.position }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compute_estimated_fill_duration
|
||||
|
|
|
@ -47,6 +47,14 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def upper_siblings
|
||||
siblings.filter { |s| s.position < position }
|
||||
end
|
||||
|
||||
def siblings_starting_at(offset)
|
||||
siblings.filter { |s| (position + offset) <= s.position }
|
||||
end
|
||||
|
||||
def previous_sibling
|
||||
index = siblings.index(self)
|
||||
if index > 0
|
||||
|
|
Loading…
Reference in a new issue