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:
commit
b629db2b51
2 changed files with 17 additions and 13 deletions
|
@ -53,23 +53,23 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def find_or_clone_type_de_champ(id)
|
||||
type_de_champ = find_type_de_champ_by_id(id)
|
||||
def find_or_clone_type_de_champ(stable_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
|
||||
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
|
||||
revise_type_de_champ(type_de_champ)
|
||||
end
|
||||
end
|
||||
|
||||
def move_type_de_champ(id, position)
|
||||
type_de_champ = find_type_de_champ_by_id(id)
|
||||
def move_type_de_champ(stable_id, position)
|
||||
type_de_champ = find_type_de_champ_by_stable_id(stable_id)
|
||||
|
||||
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)|
|
||||
type_de_champ = repetition_type_de_champ.types_de_champ.find(id)
|
||||
|
@ -85,13 +85,13 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def remove_type_de_champ(id)
|
||||
type_de_champ = find_type_de_champ_by_id(id)
|
||||
def remove_type_de_champ(stable_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
|
||||
elsif type_de_champ.parent.present?
|
||||
find_or_clone_type_de_champ(id).destroy
|
||||
find_or_clone_type_de_champ(stable_id).destroy
|
||||
else
|
||||
types_de_champ.delete(type_de_champ)
|
||||
end
|
||||
|
@ -384,8 +384,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
cloned_type_de_champ
|
||||
end
|
||||
|
||||
def find_type_de_champ_by_id(id)
|
||||
types_de_champ.find_by(stable_id: id)
|
||||
def find_type_de_champ_by_stable_id(stable_id)
|
||||
types_de_champ.find_by(stable_id: stable_id)
|
||||
end
|
||||
|
||||
def types_de_champ_in_repetition
|
||||
|
|
|
@ -164,6 +164,10 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def only_present_on_draft?
|
||||
revisions.size == 1
|
||||
end
|
||||
|
||||
def non_fillable?
|
||||
type_champ.in?([
|
||||
TypeDeChamp.type_champs.fetch(:header_section),
|
||||
|
|
Loading…
Reference in a new issue