Merge pull request #7569 from betagouv/make_condition_revisable
feat(condition): rend les modifications de conditions visibles entre révisions
This commit is contained in:
commit
ee545a82ca
9 changed files with 122 additions and 9 deletions
|
@ -22,7 +22,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
||||||
|
|
||||||
def logic_conditionnel_button
|
def logic_conditionnel_button
|
||||||
if @condition.nil?
|
if @condition.nil?
|
||||||
submit_tag(t('.enable_conditionnel'), formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id))
|
submit_tag(t('.enable_conditionnel'), formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.stable_id))
|
||||||
else
|
else
|
||||||
submit_tag(
|
submit_tag(
|
||||||
t('.disable_conditionnel'),
|
t('.disable_conditionnel'),
|
||||||
|
@ -185,7 +185,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
||||||
def add_condition_tag
|
def add_condition_tag
|
||||||
tag.button(
|
tag.button(
|
||||||
tag.span('', class: 'icon add') + tag.span(t('.add_condition')),
|
tag.span('', class: 'icon add') + tag.span(t('.add_condition')),
|
||||||
formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.id),
|
formaction: add_row_admin_procedure_condition_path(@procedure_id, @tdc.stable_id),
|
||||||
formnovalidate: true,
|
formnovalidate: true,
|
||||||
class: 'add-row'
|
class: 'add-row'
|
||||||
)
|
)
|
||||||
|
@ -194,7 +194,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
||||||
def delete_condition_tag(row_index)
|
def delete_condition_tag(row_index)
|
||||||
tag.button(
|
tag.button(
|
||||||
tag.span('', class: 'icon delete') + tag.span(t('.remove_a_row'), class: 'sr-only'),
|
tag.span('', class: 'icon delete') + tag.span(t('.remove_a_row'), class: 'sr-only'),
|
||||||
formaction: delete_row_admin_procedure_condition_path(@procedure_id, @tdc.id, row_index: row_index),
|
formaction: delete_row_admin_procedure_condition_path(@procedure_id, @tdc.stable_id, row_index: row_index),
|
||||||
formmethod: 'delete',
|
formmethod: 'delete',
|
||||||
formnovalidate: true
|
formnovalidate: true
|
||||||
)
|
)
|
||||||
|
@ -209,7 +209,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_id_for(name, row_index)
|
def input_id_for(name, row_index)
|
||||||
"#{@tdc.id}-#{name}-#{row_index}"
|
"#{@tdc.stable_id}-#{name}-#{row_index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_prefix
|
def input_prefix
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.flex.justify-start.section{ id: dom_id(@tdc, :conditions) }
|
.flex.justify-start.section{ id: dom_id(@tdc.stable_self, :conditions) }
|
||||||
= form_with url: admin_procedure_condition_path(@procedure_id, @tdc), method: :patch, class: 'form width-100' do |f|
|
= form_with url: admin_procedure_condition_path(@procedure_id, @tdc.stable_id), method: :patch, class: 'form width-100' do |f|
|
||||||
.conditionnel.mt-2.width-100
|
.conditionnel.mt-2.width-100
|
||||||
.flex
|
.flex
|
||||||
%p.mr-2 Logique conditionnelle
|
%p.mr-2 Logique conditionnelle
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s = "#{type_de_champ&.libelle} Nº#{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
|
def type
|
||||||
case type_de_champ&.type_champ # TODO: gerer le cas ou un tdc est supprimé
|
case type_de_champ&.type_champ # TODO: gerer le cas ou un tdc est supprimé
|
||||||
|
|
|
@ -377,6 +377,20 @@ class ProcedureRevision < ApplicationRecord
|
||||||
stable_id: from_type_de_champ.stable_id
|
stable_id: from_type_de_champ.stable_id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if from_type_de_champ.condition != to_type_de_champ.condition
|
||||||
|
changes << {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
if to_type_de_champ.drop_down_list?
|
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
|
if from_type_de_champ.drop_down_list_options != to_type_de_champ.drop_down_list_options
|
||||||
changes << {
|
changes << {
|
||||||
|
|
|
@ -360,6 +360,11 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stable_self
|
||||||
|
OpenStruct.new(to_key: [stable_id],
|
||||||
|
model_name: OpenStruct.new(param_key: model_name.param_key))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
DEFAULT_EMPTY = ['']
|
DEFAULT_EMPTY = ['']
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
- rendered = render @condition_component
|
- rendered = render @condition_component
|
||||||
|
|
||||||
- if rendered.present?
|
- if rendered.present?
|
||||||
= turbo_stream.morph dom_id(@tdc, :conditions) do
|
= turbo_stream.morph dom_id(@tdc.stable_self, :conditions) do
|
||||||
- rendered
|
- rendered
|
||||||
end
|
end
|
||||||
- else
|
- else
|
||||||
= turbo_stream.remove dom_id(@tdc, :conditions)
|
= turbo_stream.remove dom_id(@tdc.stable_self, :conditions)
|
||||||
|
|
|
@ -54,3 +54,10 @@
|
||||||
%li= t(:add_option, scope: [:administrateurs, :revision_changes], items: added.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
|
%li= t(:add_option, scope: [:administrateurs, :revision_changes], items: added.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
|
||||||
- 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
|
||||||
|
- if change[:from].nil?
|
||||||
|
%li= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
||||||
|
- elsif change[:to].nil?
|
||||||
|
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label])
|
||||||
|
- else
|
||||||
|
%li= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
|
||||||
|
|
|
@ -46,6 +46,9 @@ fr:
|
||||||
update_carte_layers_private: Les référentiels cartographiques de l’annotation privée « %{label} » ont été modifiés
|
update_carte_layers_private: Les référentiels cartographiques de l’annotation privée « %{label} » ont été modifiés
|
||||||
add_option: "ajoutés : %{items}"
|
add_option: "ajoutés : %{items}"
|
||||||
remove_option: "supprimé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:
|
carte_layers:
|
||||||
unesco: UNESCO
|
unesco: UNESCO
|
||||||
arretes_protection: Arrêtés de protection
|
arretes_protection: Arrêtés de protection
|
||||||
|
|
|
@ -322,11 +322,95 @@ describe ProcedureRevision do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#compare' do
|
describe '#compare' do
|
||||||
|
include Logic
|
||||||
|
|
||||||
let(:first_tdc) { draft.types_de_champ_public.first }
|
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 }
|
let(:new_draft) { procedure.create_new_revision }
|
||||||
|
|
||||||
subject { procedure.active_revision.compare(new_draft.reload) }
|
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,
|
||||||
|
from: nil,
|
||||||
|
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,
|
||||||
|
from: "(l1 == 2)",
|
||||||
|
label: "l2",
|
||||||
|
model: :type_de_champ,
|
||||||
|
op: :update,
|
||||||
|
private: false,
|
||||||
|
stable_id: second_tdc.stable_id,
|
||||||
|
to: nil
|
||||||
|
}
|
||||||
|
])
|
||||||
|
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,
|
||||||
|
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
|
context 'when a type de champ is added' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:new_tdc) do
|
let(:new_tdc) do
|
||||||
|
|
Loading…
Add table
Reference in a new issue