Merge pull request #7263 from tchak/refactor-revison-fix-names

refactor(revision): rename revision methods params to reflect usage of stable_id
This commit is contained in:
Paul Chavard 2022-05-06 11:13:33 +02:00 committed by GitHub
commit b629db2b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View file

@ -53,23 +53,23 @@ class ProcedureRevision < ApplicationRecord
end end
end end
def find_or_clone_type_de_champ(id) def find_or_clone_type_de_champ(stable_id)
type_de_champ = find_type_de_champ_by_id(id) type_de_champ = find_type_de_champ_by_stable_id(stable_id)
if type_de_champ.revision == self if type_de_champ.only_present_on_draft?
type_de_champ type_de_champ
elsif type_de_champ.parent.present? elsif type_de_champ.parent.present?
find_or_clone_type_de_champ(type_de_champ.parent.stable_id).types_de_champ.find_by!(stable_id: id) find_or_clone_type_de_champ(type_de_champ.parent.stable_id).types_de_champ.find_by!(stable_id: stable_id)
else else
revise_type_de_champ(type_de_champ) revise_type_de_champ(type_de_champ)
end end
end end
def move_type_de_champ(id, position) def move_type_de_champ(stable_id, position)
type_de_champ = find_type_de_champ_by_id(id) type_de_champ = find_type_de_champ_by_stable_id(stable_id)
if type_de_champ.parent.present? if type_de_champ.parent.present?
repetition_type_de_champ = find_or_clone_type_de_champ(id).parent repetition_type_de_champ = find_or_clone_type_de_champ(stable_id).parent
move_type_de_champ_hash(repetition_type_de_champ.types_de_champ.to_a, type_de_champ, position).each do |(id, position)| move_type_de_champ_hash(repetition_type_de_champ.types_de_champ.to_a, type_de_champ, position).each do |(id, position)|
type_de_champ = repetition_type_de_champ.types_de_champ.find(id) type_de_champ = repetition_type_de_champ.types_de_champ.find(id)
@ -85,13 +85,13 @@ class ProcedureRevision < ApplicationRecord
end end
end end
def remove_type_de_champ(id) def remove_type_de_champ(stable_id)
type_de_champ = find_type_de_champ_by_id(id) type_de_champ = find_type_de_champ_by_stable_id(stable_id)
if type_de_champ.revision == self if type_de_champ.only_present_on_draft?
type_de_champ.destroy type_de_champ.destroy
elsif type_de_champ.parent.present? elsif type_de_champ.parent.present?
find_or_clone_type_de_champ(id).destroy find_or_clone_type_de_champ(stable_id).destroy
else else
types_de_champ.delete(type_de_champ) types_de_champ.delete(type_de_champ)
end end
@ -384,8 +384,8 @@ class ProcedureRevision < ApplicationRecord
cloned_type_de_champ cloned_type_de_champ
end end
def find_type_de_champ_by_id(id) def find_type_de_champ_by_stable_id(stable_id)
types_de_champ.find_by(stable_id: id) types_de_champ.find_by(stable_id: stable_id)
end end
def types_de_champ_in_repetition def types_de_champ_in_repetition

View file

@ -164,6 +164,10 @@ class TypeDeChamp < ApplicationRecord
end end
end end
def only_present_on_draft?
revisions.size == 1
end
def non_fillable? def non_fillable?
type_champ.in?([ type_champ.in?([
TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:header_section),