Skip to content

Commit

Permalink
wip(procedure_revision.compare): includes transitions_rules diff
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed Apr 24, 2024
1 parent 5cb5ec5 commit a4e6423
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 214 deletions.
14 changes: 14 additions & 0 deletions app/models/procedure_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def locked?
def compare(revision)
changes = []
changes += compare_revision_types_de_champ(revision_types_de_champ, revision.revision_types_de_champ)
changes += compare_transitions_rules(transitions_rules, revision.transitions_rules)
changes
end

Expand Down Expand Up @@ -325,6 +326,19 @@ def compare_revision_types_de_champ(from_coordinates, to_coordinates)
end
end

def compare_transitions_rules(from_transitions_rules, to_transitions_rules)
from_h = from_transitions_rules
to_h = to_transitions_rules

if from_h.present? && !to_h.present?
[ProcedureRevisionChange::RemoveTransitionsRule.new(from_h)]
elsif !from_h.present? && to_h.present?
[ProcedureRevisionChange::AddTransitionsRule.new(to_h)]
else
[ProcedureRevisionChange::ChangeTransitionsRule.new(from_h, to_h)]
end
end

def compare_type_de_champ(from_type_de_champ, to_type_de_champ, from_coordinates, to_coordinates)
changes = []
if from_type_de_champ.type_champ != to_type_de_champ.type_champ
Expand Down
15 changes: 15 additions & 0 deletions app/models/procedure_revision_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@ def can_rebase?(dossier = nil)
end
end
end

class AddTransitionsRule < ProcedureRevisionChange
def op = :add
end

class RemoveTransitionsRule < ProcedureRevisionChange
def op = :remove
end

class ChangeTransitionsRule < ProcedureRevisionChange
def initialize(from, to)
end

def op = :update
end
end
Loading

0 comments on commit a4e6423

Please sign in to comment.