display condition change between version

This commit is contained in:
simon lehericey 2022-07-13 12:35:11 +02:00
parent 00c4076b32
commit 2cad0e11d3
6 changed files with 125 additions and 3 deletions

View file

@ -33,7 +33,7 @@ class Logic::ChampValue < Logic::Term
end
end
def to_s = "#{type_de_champ&.libelle}#{stable_id}" # TODO: gerer le cas ou un tdc est supprimé
def to_s = type_de_champ&.libelle # TODO: gerer le cas ou un tdc est supprimé
def type
case type_de_champ&.type_champ # TODO: gerer le cas ou un tdc est supprimé

View file

@ -377,6 +377,30 @@ class ProcedureRevision < ApplicationRecord
stable_id: from_type_de_champ.stable_id
}
end
from_condition = from_type_de_champ.condition
to_condition = to_type_de_champ.condition
if from_condition != to_condition
condition_change = {
model: :type_de_champ,
op: :update,
attribute: :condition,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.condition.to_s,
to: to_type_de_champ.condition.to_s,
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
if to_type_de_champ.drop_down_list?
if from_type_de_champ.drop_down_list_options != to_type_de_champ.drop_down_list_options
changes << {

View file

@ -1,8 +1,8 @@
- rendered = render @condition_component
- if rendered.present?
= turbo_stream.morph dom_id(@tdc, :conditions) do
= turbo_stream.morph "conditions_type_de_champ_#{@tdc.stable_id}" do
- rendered
end
- else
= turbo_stream.remove dom_id(@tdc, :conditions)
= turbo_stream.remove "conditions_type_de_champ_#{@tdc.stable_id}"

View file

@ -54,3 +54,11 @@
%li= t(:add_option, scope: [:administrateurs, :revision_changes], items: added.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
- if removed.present?
%li= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
- when :condition
- case change[:condition_op]
- when :add
%li= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
- when :remove
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
- when :update
%li= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])

View file

@ -46,6 +46,9 @@ fr:
update_carte_layers_private: Les référentiels cartographiques de lannotation privée « %{label} » ont été modifiés
add_option: "ajoutés : %{items}"
remove_option: "supprimés : %{items}"
add_condition: Une condition a été ajoutée sur le champ « %{label} ». La nouvelle condition est « %{to} »
remove_condition: La condition du champ « %{label} » a été supprimée.
update_condition: La condition du champ « %{label} » a été modifiée. La nouvelle condition est « %{to} »
carte_layers:
unesco: UNESCO
arretes_protection: Arrêtés de protection

View file

@ -322,11 +322,98 @@ describe ProcedureRevision do
end
describe '#compare' do
include Logic
let(:first_tdc) { draft.types_de_champ_public.first }
let(:second_tdc) { draft.types_de_champ_public.second }
let(:new_draft) { procedure.create_new_revision }
subject { procedure.active_revision.compare(new_draft.reload) }
context 'with a procedure with 2 tdcs' do
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l2')
end
end
context 'when a condition is added' do
before do
second = new_draft.find_and_ensure_exclusive_use(second_tdc.stable_id)
second.update(condition: ds_eq(champ_value(first_tdc.stable_id), constant(3)))
end
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :add,
:from => "",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => "(l1 == 3)"
}
])
end
end
context 'when a condition is removed' do
before do
second_tdc.update(condition: ds_eq(champ_value(first_tdc.stable_id), constant(2)))
draft.reload
second = new_draft.find_and_ensure_exclusive_use(second_tdc.stable_id)
second.update(condition: nil)
end
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :remove,
:from => "(l1 == 2)",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => ""
}
])
end
end
context 'when a condition is changed' do
before do
second_tdc.update(condition: ds_eq(champ_value(first_tdc.stable_id), constant(2)))
draft.reload
second = new_draft.find_and_ensure_exclusive_use(second_tdc.stable_id)
second.update(condition: ds_eq(champ_value(first_tdc.stable_id), constant(3)))
end
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :update,
:from => "(l1 == 2)",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => "(l1 == 3)"
}
])
end
end
end
context 'when a type de champ is added' do
let(:procedure) { create(:procedure) }
let(:new_tdc) do