refactor(revision): changes should be domain objects

This commit is contained in:
Paul Chavard 2022-12-23 13:01:18 +01:00
parent 7aa6f172dc
commit 9b3fa4dd3c
7 changed files with 209 additions and 252 deletions

View file

@ -22,33 +22,18 @@ module DossierRebaseConcern
revision.compare(procedure.published_revision)
end
def can_rebase_mandatory_change?(stable_id)
!champs.filter { _1.stable_id == stable_id }.any?(&:blank?)
end
private
def accepted_en_construction_changes?
en_construction? && pending_changes.all? { |change| accepted_change?(change) }
en_construction? && pending_changes.all? { _1.can_rebase?(self) }
end
def accepted_en_instruction_changes?
en_instruction? && pending_changes.all? { |change| accepted_change?(change) }
end
def accepted_change?(change)
return true if change[:private]
return true if change[:op].in?([:remove, :move])
return !change[:mandatory] if change[:op] == :add
case change[:attribute]
when :drop_down_options
(change[:from] - change[:to]).empty?
when :drop_down_other
!change[:from] && change[:to]
when :mandatory
(change[:from] && !change[:to]) || can_change_mandatory?(change)
when :type_champ, :condition
false
else
true
end
en_instruction? && pending_changes.all? { _1.can_rebase?(self) }
end
def rebase
@ -62,22 +47,21 @@ module DossierRebaseConcern
.index_by(&:stable_id)
changes_by_op = pending_changes
.filter { |change| change[:model] == :type_de_champ }
.group_by { |change| change[:op] }
.tap { |h| h.default = [] }
.group_by(&:op)
.tap { _1.default = [] }
# add champ
changes_by_op[:add]
.map { |change| change[:stable_id] }
.map { |stable_id| target_coordinates_by_stable_id[stable_id] }
.each { |coordinate| add_new_champs_for_revision(coordinate) }
.map(&:stable_id)
.map { target_coordinates_by_stable_id[_1] }
.each { add_new_champs_for_revision(_1) }
# remove champ
changes_by_op[:remove]
.each { |change| delete_champs_for_revision(change[:stable_id]) }
.each { delete_champs_for_revision(_1.stable_id) }
changes_by_op[:update]
.map { |change| [change, Champ.joins(:type_de_champ).where(dossier: self, type_de_champ: { stable_id: change[:stable_id] })] }
.map { |change| [change, champs.joins(:type_de_champ).where(type_de_champ: { stable_id: change.stable_id })] }
.each { |change, champs| apply(change, champs) }
# due to repetition tdc clone on update or erase
@ -85,22 +69,22 @@ module DossierRebaseConcern
Champ
.includes(:type_de_champ)
.where(dossier: self)
.map { |c| [c, target_coordinates_by_stable_id[c.stable_id].type_de_champ] }
.each { |c, target_tdc| c.update_columns(type_de_champ_id: target_tdc.id, rebased_at: Time.zone.now) }
.map { [_1, target_coordinates_by_stable_id[_1.stable_id].type_de_champ] }
.each { |champ, target_tdc| champ.update_columns(type_de_champ_id: target_tdc.id, rebased_at: Time.zone.now) }
# update dossier revision
self.update_column(:revision_id, target_revision.id)
end
def apply(change, champs)
case change[:attribute]
case change.attribute
when :type_champ
champs.each { |champ| purge_piece_justificative_file(champ) }
champs.each { purge_piece_justificative_file(_1) }
GeoArea.where(champ: champs).destroy_all
Etablissement.where(champ: champs).destroy_all
{
type: "Champs::#{change[:to].classify}Champ",
type: "Champs::#{change.to.classify}Champ",
value: nil,
value_json: nil,
external_id: nil,
@ -110,22 +94,22 @@ module DossierRebaseConcern
{ value: nil }
when :carte_layers
# if we are removing cadastres layer, we need to remove cadastre geo areas
if change[:from].include?(:cadastres) && !change[:to].include?(:cadastres)
champs.each { |champ| champ.cadastres.each(&:destroy) }
if change.from.include?(:cadastres) && !change.to.include?(:cadastres)
champs.each { _1.cadastres.each(&:destroy) }
end
nil
end
&.then { |update_params| champs.update_all(update_params) }
&.then { champs.update_all(_1) }
end
def add_new_champs_for_revision(target_coordinate)
if target_coordinate.child?
# If this type de champ is a child, we create a new champ for each row of the parent
parent_stable_id = target_coordinate.parent.stable_id
champs_repetition = Champ
champs_repetition = champs
.includes(:champs, :type_de_champ)
.where(dossier: self, type_de_champ: { stable_id: parent_stable_id })
.where(type_de_champ: { stable_id: parent_stable_id })
champs_repetition.each do |champ_repetition|
champ_repetition.champs.map(&:row).uniq.each do |row|
@ -147,17 +131,13 @@ module DossierRebaseConcern
end
def delete_champs_for_revision(stable_id)
Champ
champs
.joins(:type_de_champ)
.where(dossier: self, types_de_champ: { stable_id: stable_id })
.where(types_de_champ: { stable_id: })
.destroy_all
end
def purge_piece_justificative_file(champ)
ActiveStorage::Attachment.where(id: champ.piece_justificative_file.ids).delete_all
end
def can_change_mandatory?(change)
!champs.filter { _1.stable_id == change[:stable_id] }.any?(&:blank?)
end
end

View file

@ -247,198 +247,110 @@ class ProcedureRevision < ApplicationRecord
from_sids = from_h.keys
to_sids = to_h.keys
removed = (from_sids - to_sids).map do |sid|
{ model: :type_de_champ, op: :remove, label: from_h[sid].libelle, private: from_h[sid].private?, _position: from_sids.index(sid), stable_id: sid }
end
added = (to_sids - from_sids).map do |sid|
{ model: :type_de_champ, op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, mandatory: to_h[sid].mandatory?, _position: to_sids.index(sid), stable_id: sid }
end
removed = (from_sids - to_sids).map { ProcedureRevisionChange::RemoveChamp.new(from_h[_1]) }
added = (to_sids - from_sids).map { ProcedureRevisionChange::AddChamp.new(to_h[_1]) }
kept = from_sids.intersection(to_sids)
moved = kept
.map { |sid| [sid, from_h[sid], to_h[sid]] }
.filter { |_, from, to| from.position != to.position }
.map do |sid, from, to|
{ model: :type_de_champ, op: :move, label: from.libelle, private: from.private?, from: from.position, to: to.position, _position: to_sids.index(sid), stable_id: sid }
end
.map { [from_h[_1], to_h[_1]] }
.filter { |from, to| from.position != to.position }
.map { |from, to| ProcedureRevisionChange::MoveChamp.new(from, from.position, to.position) }
changed = kept
.map { |sid| [sid, from_h[sid], to_h[sid]] }
.flat_map do |sid, from, to|
compare_type_de_champ(from.type_de_champ, to.type_de_champ, from_coordinates, to_coordinates)
.each { |h| h[:_position] = to_sids.index(sid) }
end
.map { [from_h[_1], to_h[_1]] }
.flat_map { |from, to| compare_type_de_champ(from.type_de_champ, to.type_de_champ, from_coordinates, to_coordinates) }
(removed + added + moved + changed)
.sort_by { |h| h[:_position] }
.each { |h| h.delete(:_position) }
(removed + added + moved + changed).sort_by { _1.op == :remove ? from_sids[_1.stable_id] : to_sids[_1.stable_id] }
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
changes << {
model: :type_de_champ,
op: :update,
attribute: :type_champ,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.type_champ,
to: to_type_de_champ.type_champ,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:type_champ,
from_type_de_champ.type_champ,
to_type_de_champ.type_champ)
end
if from_type_de_champ.libelle != to_type_de_champ.libelle
changes << {
model: :type_de_champ,
op: :update,
attribute: :libelle,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.libelle,
to: to_type_de_champ.libelle,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:libelle,
from_type_de_champ.libelle,
to_type_de_champ.libelle)
end
if from_type_de_champ.collapsible_explanation_enabled? != to_type_de_champ.collapsible_explanation_enabled?
changes << {
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_enabled,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.collapsible_explanation_enabled?,
to: to_type_de_champ.collapsible_explanation_enabled?,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:collapsible_explanation_enabled,
from_type_de_champ.collapsible_explanation_enabled?,
to_type_de_champ.collapsible_explanation_enabled?)
end
if from_type_de_champ.collapsible_explanation_text != to_type_de_champ.collapsible_explanation_text
changes << {
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_text,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.collapsible_explanation_text,
to: to_type_de_champ.collapsible_explanation_text,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:collapsible_explanation_text,
from_type_de_champ.collapsible_explanation_text,
to_type_de_champ.collapsible_explanation_text)
end
if from_type_de_champ.description != to_type_de_champ.description
changes << {
model: :type_de_champ,
op: :update,
attribute: :description,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.description,
to: to_type_de_champ.description,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:description,
from_type_de_champ.description,
to_type_de_champ.description)
end
if from_type_de_champ.mandatory? != to_type_de_champ.mandatory?
changes << {
model: :type_de_champ,
op: :update,
attribute: :mandatory,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.mandatory?,
to: to_type_de_champ.mandatory?,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:mandatory,
from_type_de_champ.mandatory?,
to_type_de_champ.mandatory?)
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(from_coordinates.map(&:type_de_champ)),
to: to_type_de_champ.condition&.to_s(to_coordinates.map(&:type_de_champ)),
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:condition,
from_type_de_champ.condition&.to_s(from_coordinates.map(&:type_de_champ)),
to_type_de_champ.condition&.to_s(to_coordinates.map(&:type_de_champ)))
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 << {
model: :type_de_champ,
op: :update,
attribute: :drop_down_options,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.drop_down_list_options,
to: to_type_de_champ.drop_down_list_options,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:drop_down_options,
from_type_de_champ.drop_down_list_options,
to_type_de_champ.drop_down_list_options)
end
if to_type_de_champ.linked_drop_down_list?
if from_type_de_champ.drop_down_secondary_libelle != to_type_de_champ.drop_down_secondary_libelle
changes << {
model: :type_de_champ,
op: :update,
attribute: :drop_down_secondary_libelle,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.drop_down_secondary_libelle,
to: to_type_de_champ.drop_down_secondary_libelle
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:drop_down_secondary_libelle,
from_type_de_champ.drop_down_secondary_libelle,
to_type_de_champ.drop_down_secondary_libelle)
end
if from_type_de_champ.drop_down_secondary_description != to_type_de_champ.drop_down_secondary_description
changes << {
model: :type_de_champ,
op: :update,
attribute: :drop_down_secondary_description,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.drop_down_secondary_description,
to: to_type_de_champ.drop_down_secondary_description
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:drop_down_secondary_description,
from_type_de_champ.drop_down_secondary_description,
to_type_de_champ.drop_down_secondary_description)
end
end
if from_type_de_champ.drop_down_other? != to_type_de_champ.drop_down_other?
changes << {
model: :type_de_champ,
op: :update,
attribute: :drop_down_other,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.drop_down_other?,
to: to_type_de_champ.drop_down_other?,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:drop_down_other,
from_type_de_champ.drop_down_other?,
to_type_de_champ.drop_down_other?)
end
elsif to_type_de_champ.carte?
if from_type_de_champ.carte_optional_layers != to_type_de_champ.carte_optional_layers
changes << {
model: :type_de_champ,
op: :update,
attribute: :carte_layers,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.carte_optional_layers,
to: to_type_de_champ.carte_optional_layers,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:carte_layers,
from_type_de_champ.carte_optional_layers,
to_type_de_champ.carte_optional_layers)
end
elsif to_type_de_champ.piece_justificative?
if from_type_de_champ.piece_justificative_template_checksum != to_type_de_champ.piece_justificative_template_checksum
changes << {
model: :type_de_champ,
op: :update,
attribute: :piece_justificative_template,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.piece_justificative_template_filename,
to: to_type_de_champ.piece_justificative_template_filename,
stable_id: from_type_de_champ.stable_id
}
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
:piece_justificative_template,
from_type_de_champ.piece_justificative_template_filename,
to_type_de_champ.piece_justificative_template_filename)
end
end
changes

View file

@ -0,0 +1,77 @@
class ProcedureRevisionChange
def initialize(type_de_champ)
@type_de_champ = type_de_champ
end
def label = @type_de_champ.libelle
def stable_id = @type_de_champ.stable_id
def private? = @type_de_champ.private?
def to_h = { op:, stable_id:, label:, private: private? }
class AddChamp < ProcedureRevisionChange
def initialize(type_de_champ)
super(type_de_champ)
end
def op = :add
def mandatory? = @type_de_champ.mandatory?
def can_rebase?(dossier = nil) = !mandatory?
def to_h = super.merge(mandatory: mandatory?)
end
class RemoveChamp < ProcedureRevisionChange
def initialize(type_de_champ)
super(type_de_champ)
end
def op = :remove
def can_rebase?(dossier = nil) = true
end
class MoveChamp < ProcedureRevisionChange
attr_reader :from, :to
def initialize(type_de_champ, from, to)
super(type_de_champ)
@from = from
@to = to
end
def op = :move
def can_rebase?(dossier = nil) = true
def to_h = super.merge(from:, to:)
end
class UpdateChamp < ProcedureRevisionChange
attr_reader :attribute, :from, :to
def initialize(type_de_champ, attribute, from, to)
super(type_de_champ)
@attribute = attribute
@from = from
@to = to
end
def op = :update
def to_h = super.merge(attribute:, from:, to:)
def can_rebase?(dossier = nil)
return true if private?
case attribute
when :drop_down_options
(from - to).empty?
when :drop_down_other
!from && to
when :mandatory
(from && !to) || dossier&.can_rebase_mandatory_change?(stable_id)
when :type_champ, :condition
false
else
true
end
end
end
end

View file

@ -1,49 +1,52 @@
- postfix = change[:private] ? '_private' : ''
- case change[:op]
- postfix = change.private? ? '_private' : ''
- case change.op
- when :add
- list.with_item do
= t("add#{postfix}", label: change[:label], scope: [:administrateurs, :revision_changes])
- if change.mandatory?
= t("add_mandatory", label: change.label, scope: [:administrateurs, :revision_changes])
- else
= t("add#{postfix}", label: change.label, scope: [:administrateurs, :revision_changes])
- when :remove
- list.with_item do
= t("remove#{postfix}", label: change[:label], scope: [:administrateurs, :revision_changes])
= t("remove#{postfix}", label: change.label, scope: [:administrateurs, :revision_changes])
- when :update
- case change[:attribute]
- case change.attribute
- when :libelle
- list.with_item do
= t("update_libelle#{postfix}", label: change[:label], to: change[:to], scope: [:administrateurs, :revision_changes])
= t("update_libelle#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes])
- when :type_champ
- list.with_item do
= t("update_type_champ#{postfix}", label: change[:label], to: t("activerecord.attributes.type_de_champ.type_champs.#{change[:to]}"), scope: [:administrateurs, :revision_changes])
= t("update_type_champ#{postfix}", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}"), scope: [:administrateurs, :revision_changes])
- when :description
- list.with_item do
= t("update_description#{postfix}", label: change[:label], to: change[:to], scope: [:administrateurs, :revision_changes])
= t("update_description#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes])
- when :drop_down_secondary_libelle
- list.with_item do
= t("update_drop_down_secondary_libelle#{postfix}", label: change[:label], to: change[:to], scope: [:administrateurs, :revision_changes])
= t("update_drop_down_secondary_libelle#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes])
- when :drop_down_secondary_description
- list.with_item do
= t("update_drop_down_secondary_description#{postfix}", label: change[:label], to: change[:to], scope: [:administrateurs, :revision_changes])
= t("update_drop_down_secondary_description#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes])
- when :mandatory
- if change[:from] == false
- if change.from == false
-# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory.enabled')
-# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory_private.enabled')
- list.with_item do
= t("administrateurs.revision_changes.update_mandatory#{postfix}.enabled", label: change[:label])
= t("administrateurs.revision_changes.update_mandatory#{postfix}.enabled", label: change.label)
- else
-# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory.disabled')
-# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory_private.disabled')
- list.with_item do
= t("administrateurs.revision_changes.update_mandatory#{postfix}.disabled", label: change[:label])
= t("administrateurs.revision_changes.update_mandatory#{postfix}.disabled", label: change.label)
- when :piece_justificative_template
-# i18n-tasks-use t('administrateurs.revision_changes.update_piece_justificative_template')
-# i18n-tasks-use t('administrateurs.revision_changes.update_piece_justificative_template_private')
- list.with_item do
= t("administrateurs.revision_changes.update_piece_justificative_template#{postfix}", label: change[:label])
= t("administrateurs.revision_changes.update_piece_justificative_template#{postfix}", label: change.label)
- when :drop_down_options
- added = change[:to].sort - change[:from].sort
- removed = change[:from].sort - change[:to].sort
- added = change.to.sort - change.from.sort
- removed = change.from.sort - change.to.sort
- list.with_item do
= t("update_drop_down_options#{postfix}", scope: [:administrateurs, :revision_changes], label: change[:label])
= t("update_drop_down_options#{postfix}", scope: [:administrateurs, :revision_changes], label: change.label)
= render Dsfr::ListComponent.new do |list|
- if added.present?
- list.with_item do
@ -52,17 +55,17 @@
- list.with_item do
= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{term.strip} »" }.join(", "))
- when :drop_down_other
- if change[:from] == false
- if change.from == false
- list.with_item do
= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.enabled", label: change[:label])
= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.enabled", label: change.label)
- else
- list.with_item do
= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.disabled", label: change[:label])
= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.disabled", label: change.label)
- when :carte_layers
- added = change[:to].sort - change[:from].sort
- removed = change[:from].sort - change[:to].sort
- added = change.to.sort - change.from.sort
- removed = change.from.sort - change.to.sort
- list.with_item do
= t("update_carte_layers#{postfix}", scope: [:administrateurs, :revision_changes], label: change[:label])
= t("update_carte_layers#{postfix}", scope: [:administrateurs, :revision_changes], label: change.label)
= render Dsfr::ListComponent.new do |list|
- if added.present?
- list.with_item do
@ -71,23 +74,23 @@
- list.with_item do
= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
- when :collapsible_explanation_enabled
- if change[:to]
- if change.to
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.enabled", label: change[:label])
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.enabled", label: change.label)
- else
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.disabled", label: change[:label])
= t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.disabled", label: change.label)
- when :collapsible_explanation_text
- list.with_item do
= t("administrateurs.revision_changes.update_collapsible_explanation_text#{postfix}", label: change[:label], text: change[:to])
= t("administrateurs.revision_changes.update_collapsible_explanation_text#{postfix}", label: change.label, text: change.to)
- when :condition
- if change[:from].nil?
- if change.from.nil?
- list.with_item do
= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
- elsif change[:to].nil?
= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change.label, to: change.to)
- elsif change.to.nil?
- list.with_item do
= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label])
= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change.label)
- else
- list.with_item do
= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change.label, to: change.to)

View file

@ -2,8 +2,8 @@
- list.with_empty do
= t(:no_changes, scope: [:administrateurs, :revision_changes])
= render partial: "administrateurs/procedures/revision_change_type_de_champ", collection: changes.filter { |change| change[:model] == :type_de_champ }, as: :change, locals: { list: list }
- move_changes, move_private_changes = changes.filter { |change| change[:op] == :move }.partition { |change| !change[:private] }
= render partial: "administrateurs/procedures/revision_change_type_de_champ", collection: changes, as: :change, locals: { list: list }
- move_changes, move_private_changes = changes.filter { _1.op == :move }.partition { !_1.private? }
- if move_changes.present?
- list.with_item do
= t(:move, scope: [:administrateurs, :revision_changes], count: move_changes.size)

View file

@ -27,6 +27,7 @@ fr:
disabled: "Le texte complementaire affichable au clique du champ « %{label} » a été supprimée"
update_collapsible_explanation_text: "Le texte complementaire affichable au clique du champ « %{label} » a été modifié. Il est maintenant « %{text} »."
add_private: Lannotation privée « %{label} » a été ajoutée
add_mandatory: Le champ obligatoire « %{label} » a été ajouté
remove_private: Lannotation privée « %{label} » a été supprimée
move_private:
one: La position dune annotation privée a été modifiée

View file

@ -332,7 +332,7 @@ describe ProcedureRevision do
let(:second_tdc) { draft.types_de_champ_public.second }
let(:new_draft) { procedure.create_new_revision }
subject { procedure.active_revision.compare(new_draft.reload) }
subject { procedure.active_revision.compare(new_draft.reload).map(&:to_h) }
context 'with a procedure with 2 tdcs' do
let(:procedure) do
@ -354,7 +354,6 @@ describe ProcedureRevision do
attribute: :condition,
from: nil,
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
@ -379,7 +378,6 @@ describe ProcedureRevision do
attribute: :condition,
from: "(l1 == 2)",
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
@ -404,7 +402,6 @@ describe ProcedureRevision do
attribute: :condition,
from: "(l1 == 2)",
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
@ -429,7 +426,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :add,
label: "Un champ text",
private: false,
@ -453,7 +449,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :libelle,
label: first_tdc.libelle,
@ -463,7 +458,6 @@ describe ProcedureRevision do
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :description,
label: first_tdc.libelle,
@ -473,7 +467,6 @@ describe ProcedureRevision do
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :mandatory,
label: first_tdc.libelle,
@ -497,7 +490,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_enabled,
label: first_tdc.libelle,
@ -507,7 +499,6 @@ describe ProcedureRevision do
stable_id: first_tdc.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :collapsible_explanation_text,
label: first_tdc.libelle,
@ -535,22 +526,20 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :move,
label: new_draft_third_tdc.libelle,
private: false,
from: 2,
to: 1,
stable_id: new_draft_third_tdc.stable_id
},
{
model: :type_de_champ,
op: :move,
label: new_draft_second_tdc.libelle,
private: false,
from: 1,
to: 2,
stable_id: new_draft_second_tdc.stable_id
},
{
op: :move,
label: new_draft_third_tdc.libelle,
private: false,
from: 2,
to: 1,
stable_id: new_draft_third_tdc.stable_id
}
])
end
@ -566,7 +555,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :remove,
label: first_tdc.libelle,
private: false,
@ -587,7 +575,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :type_champ,
label: "sub type de champ",
@ -597,7 +584,6 @@ describe ProcedureRevision do
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :drop_down_options,
label: "sub type de champ",
@ -621,7 +607,6 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
model: :type_de_champ,
op: :update,
attribute: :type_champ,
label: "sub type de champ",
@ -631,7 +616,6 @@ describe ProcedureRevision do
stable_id: new_draft.children_of(new_draft.types_de_champ_public.last).first.stable_id
},
{
model: :type_de_champ,
op: :update,
attribute: :carte_layers,
label: "sub type de champ",