refactor(condition): use standard revision change ops
This commit is contained in:
parent
2cad0e11d3
commit
0adfd92213
3 changed files with 32 additions and 46 deletions
|
@ -378,27 +378,17 @@ class ProcedureRevision < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
from_condition = from_type_de_champ.condition
|
if from_type_de_champ.condition != to_type_de_champ.condition
|
||||||
to_condition = to_type_de_champ.condition
|
changes << {
|
||||||
if from_condition != to_condition
|
|
||||||
condition_change = {
|
|
||||||
model: :type_de_champ,
|
model: :type_de_champ,
|
||||||
op: :update,
|
op: :update,
|
||||||
attribute: :condition,
|
attribute: :condition,
|
||||||
label: from_type_de_champ.libelle,
|
label: from_type_de_champ.libelle,
|
||||||
private: from_type_de_champ.private?,
|
private: from_type_de_champ.private?,
|
||||||
from: from_type_de_champ.condition.to_s,
|
from: from_type_de_champ.condition&.to_s,
|
||||||
to: to_type_de_champ.condition.to_s,
|
to: to_type_de_champ.condition&.to_s,
|
||||||
stable_id: from_type_de_champ.stable_id
|
stable_id: from_type_de_champ.stable_id
|
||||||
}
|
}
|
||||||
if from_condition.nil?
|
|
||||||
condition_change[:condition_op] = :add
|
|
||||||
elsif to_condition.nil?
|
|
||||||
condition_change[:condition_op] = :remove
|
|
||||||
else
|
|
||||||
condition_change[:condition_op] = :update
|
|
||||||
end
|
|
||||||
changes << condition_change
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if to_type_de_champ.drop_down_list?
|
if to_type_de_champ.drop_down_list?
|
||||||
|
|
|
@ -55,10 +55,9 @@
|
||||||
- if removed.present?
|
- if removed.present?
|
||||||
%li= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
|
%li= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
|
||||||
- when :condition
|
- when :condition
|
||||||
- case change[:condition_op]
|
- if change[:from].nil?
|
||||||
- when :add
|
|
||||||
%li= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
%li= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
||||||
- when :remove
|
- elsif change[:to].nil?
|
||||||
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label])
|
||||||
- when :update
|
- else
|
||||||
%li= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
%li= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
||||||
|
|
|
@ -347,15 +347,14 @@ describe ProcedureRevision do
|
||||||
it do
|
it do
|
||||||
is_expected.to eq([
|
is_expected.to eq([
|
||||||
{
|
{
|
||||||
:attribute => :condition,
|
attribute: :condition,
|
||||||
:condition_op => :add,
|
from: nil,
|
||||||
:from => "",
|
label: "l2",
|
||||||
:label => "l2",
|
model: :type_de_champ,
|
||||||
:model => :type_de_champ,
|
op: :update,
|
||||||
:op => :update,
|
private: false,
|
||||||
:private => false,
|
stable_id: second_tdc.stable_id,
|
||||||
:stable_id => second_tdc.stable_id,
|
to: "(l1 == 3)"
|
||||||
:to => "(l1 == 3)"
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
@ -373,15 +372,14 @@ describe ProcedureRevision do
|
||||||
it do
|
it do
|
||||||
is_expected.to eq([
|
is_expected.to eq([
|
||||||
{
|
{
|
||||||
:attribute => :condition,
|
attribute: :condition,
|
||||||
:condition_op => :remove,
|
from: "(l1 == 2)",
|
||||||
:from => "(l1 == 2)",
|
label: "l2",
|
||||||
:label => "l2",
|
model: :type_de_champ,
|
||||||
:model => :type_de_champ,
|
op: :update,
|
||||||
:op => :update,
|
private: false,
|
||||||
:private => false,
|
stable_id: second_tdc.stable_id,
|
||||||
:stable_id => second_tdc.stable_id,
|
to: nil
|
||||||
:to => ""
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
@ -399,15 +397,14 @@ describe ProcedureRevision do
|
||||||
it do
|
it do
|
||||||
is_expected.to eq([
|
is_expected.to eq([
|
||||||
{
|
{
|
||||||
:attribute => :condition,
|
attribute: :condition,
|
||||||
:condition_op => :update,
|
from: "(l1 == 2)",
|
||||||
:from => "(l1 == 2)",
|
label: "l2",
|
||||||
:label => "l2",
|
model: :type_de_champ,
|
||||||
:model => :type_de_champ,
|
op: :update,
|
||||||
:op => :update,
|
private: false,
|
||||||
:private => false,
|
stable_id: second_tdc.stable_id,
|
||||||
:stable_id => second_tdc.stable_id,
|
to: "(l1 == 3)"
|
||||||
:to => "(l1 == 3)"
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue