fix: make edition annotation work again

This commit is contained in:
simon lehericey 2022-07-12 13:56:32 +02:00
parent 28a18e3912
commit 6f7fb9841c
4 changed files with 18 additions and 20 deletions

View file

@ -55,9 +55,7 @@ module Administrateurs
def retrieve_coordinate_and_uppers def retrieve_coordinate_and_uppers
@tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id]) @tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
@coordinate = draft_revision.coordinate_for(@tdc) @coordinate = draft_revision.coordinate_for(@tdc)
@upper_tdcs = draft_revision @upper_tdcs = @coordinate.upper_siblings.map(&:type_de_champ)
.upper_coordinates(@coordinate.position)
.map(&:type_de_champ)
end end
def draft_revision def draft_revision

View file

@ -8,7 +8,7 @@ module Administrateurs
if type_de_champ.valid? if type_de_champ.valid?
@coordinate = draft.coordinate_for(type_de_champ) @coordinate = draft.coordinate_for(type_de_champ)
@created = champ_component_from(@coordinate, focused: true) @created = champ_component_from(@coordinate, focused: true)
@morphed = champ_components_starting_at(@coordinate.position + 1) @morphed = champ_components_starting_at(@coordinate, 1)
reset_procedure reset_procedure
flash.notice = "Formulaire enregistré" flash.notice = "Formulaire enregistré"
@ -22,7 +22,7 @@ module Administrateurs
if type_de_champ.update(type_de_champ_update_params) if type_de_champ.update(type_de_champ_update_params)
@coordinate = draft.coordinate_for(type_de_champ) @coordinate = draft.coordinate_for(type_de_champ)
@morphed = champ_components_starting_at(@coordinate.position) @morphed = champ_components_starting_at(@coordinate)
reset_procedure reset_procedure
flash.notice = "Formulaire enregistré" flash.notice = "Formulaire enregistré"
@ -42,7 +42,7 @@ module Administrateurs
@destroyed = @coordinate @destroyed = @coordinate
@created = champ_component_from(@coordinate) @created = champ_component_from(@coordinate)
# update the one component below # 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 end
def move_down def move_down
@ -51,7 +51,7 @@ module Administrateurs
@destroyed = @coordinate @destroyed = @coordinate
@created = champ_component_from(@coordinate) @created = champ_component_from(@coordinate)
# update the one component above # 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 end
def destroy def destroy
@ -60,14 +60,14 @@ module Administrateurs
flash.notice = "Formulaire enregistré" flash.notice = "Formulaire enregistré"
@destroyed = @coordinate @destroyed = @coordinate
@morphed = champ_components_starting_at(@coordinate.position) @morphed = champ_components_starting_at(@coordinate)
end end
private private
def champ_components_starting_at(position) def champ_components_starting_at(coordinate, offset = 0)
draft coordinate
.coordinates_starting_at(position) .siblings_starting_at(offset)
.lazy .lazy
.map { |c| champ_component_from(c) } .map { |c| champ_component_from(c) }
end end
@ -75,7 +75,7 @@ module Administrateurs
def champ_component_from(coordinate, focused: false) def champ_component_from(coordinate, focused: false)
TypesDeChampEditor::ChampComponent.new( TypesDeChampEditor::ChampComponent.new(
coordinate: coordinate, coordinate: coordinate,
upper_coordinates: draft.upper_coordinates(coordinate.position), upper_coordinates: coordinate.upper_siblings,
focused: focused focused: focused
) )
end end

View file

@ -197,14 +197,6 @@ class ProcedureRevision < ApplicationRecord
revision_types_de_champ.find_by!(type_de_champ: tdc) revision_types_de_champ.find_by!(type_de_champ: tdc)
end 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 private
def compute_estimated_fill_duration def compute_estimated_fill_duration

View file

@ -47,6 +47,14 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
end end
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 def previous_sibling
index = siblings.index(self) index = siblings.index(self)
if index > 0 if index > 0