Show separate blocks for types de champ and annotation changes

This commit is contained in:
Paul Chavard 2021-06-22 12:20:04 +02:00
parent 19195008e8
commit 35eccb5630
6 changed files with 73 additions and 19 deletions

View file

@ -368,6 +368,14 @@ class Procedure < ApplicationRecord
published_revision.compare(draft_revision)
end
def revision_types_de_champ_private_changes
revision_changes.filter { |change| change[:private] }
end
def revision_types_de_champ_changes
revision_changes.filter { |change| !change[:private] }
end
def accepts_new_dossiers?
publiee? || brouillon?
end

View file

@ -125,11 +125,11 @@ class ProcedureRevision < ApplicationRecord
to_sids = to_h.keys
removed = (from_sids - to_sids).map do |sid|
{ op: :remove, label: from_h[sid].libelle, position: from_sids.index(sid) }
{ op: :remove, label: from_h[sid].libelle, private: from_h[sid].private?, position: from_sids.index(sid) }
end
added = (to_sids - from_sids).map do |sid|
{ op: :add, label: to_h[sid].libelle, position: to_sids.index(sid) }
{ op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, position: to_sids.index(sid) }
end
kept = from_sids.intersection(to_sids)
@ -138,7 +138,7 @@ class ProcedureRevision < ApplicationRecord
.map { |sid| [sid, from_sids.index(sid), to_sids.index(sid)] }
.filter { |_, from_index, to_index| from_index != to_index }
.map do |sid, from_index, to_index|
{ op: :move, label: from_h[sid].libelle, from: from_index, to: to_index, position: to_index }
{ op: :move, label: from_h[sid].libelle, private: from_h[sid].private?, from: from_index, to: to_index, position: to_index }
end
changed = kept
@ -161,6 +161,7 @@ class ProcedureRevision < ApplicationRecord
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
}
@ -170,6 +171,7 @@ class ProcedureRevision < ApplicationRecord
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
}
@ -179,6 +181,7 @@ class ProcedureRevision < ApplicationRecord
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
}
@ -188,6 +191,7 @@ class ProcedureRevision < ApplicationRecord
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?
}
@ -198,6 +202,7 @@ class ProcedureRevision < ApplicationRecord
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
}
@ -208,6 +213,7 @@ class ProcedureRevision < ApplicationRecord
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
}

View file

@ -30,5 +30,6 @@
%li= "Valeurs ajoutés : #{added.map{ |term| "« #{term.strip} »" }.join(", ")}."
- if removed.present?
%li= "Valeurs supprimés : #{removed.map{ |term| "« #{term.strip} »" }.join(", ")}."
- if changes.any? { |change| change[:op] == :move }
%li.mb-1 Des champs ont changé de position
- move_changes = changes.filter { |change| change[:op] == :move }.size
- if move_changes != 0
%li.mb-1= t(:has_move_changes, count: move_changes, scope: [:new_administrateur, :revision_changes])

View file

@ -33,11 +33,22 @@
= link_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'button primary', id: 'publish-procedure-link', data: { disable_with: "Publication..." }
- if @procedure.draft_changed?
- types_de_champ_changes = @procedure.revision_types_de_champ_changes
- types_de_champ_private_changes = @procedure.revision_types_de_champ_private_changes
- if types_de_champ_changes.present?
.container
.card.featured
.card-title
Des champs ont été changés
= render partial: 'revision_changes', locals: { changes: @procedure.revision_changes }
= t(:has_changes, count: types_de_champ_changes.size, scope: [:new_administrateur, :revision_changes])
= render partial: 'revision_changes', locals: { changes: types_de_champ_changes }
- if types_de_champ_private_changes.present?
.container
.card.featured
.card-title
= t(:has_private_changes, count: types_de_champ_private_changes.size, scope: [:new_administrateur, :revision_changes])
= render partial: 'revision_changes', locals: { changes: types_de_champ_private_changes }
.container
%h2.procedure-admin-explanation Indispensable avant publication

View file

@ -27,3 +27,13 @@ fr:
existing_groupe:
one: "%{count} groupe existe"
other: "%{count} groupes existent"
revision_changes:
has_changes:
one: Un champ a été changé
other: "%{count} champs ont été changés"
has_private_changes:
one: Une annotation privée a été changée
other: "%{count} deux annotations privées ont été changées"
has_move_changes:
one: Un champ a changé de position
other: "%{count} champs ont changé de position"

View file

@ -173,7 +173,8 @@ describe ProcedureRevision do
expect(procedure.active_revision.compare(new_revision)).to eq([
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
}
])
@ -183,12 +184,14 @@ describe ProcedureRevision do
op: :update,
attribute: :libelle,
label: type_de_champ_first.libelle,
private: false,
from: type_de_champ_first.libelle,
to: "modifier le libelle"
},
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
}
])
expect(new_revision.types_de_champ.first.revision).to eq(new_revision)
@ -199,16 +202,19 @@ describe ProcedureRevision do
op: :update,
attribute: :libelle,
label: type_de_champ_first.libelle,
private: false,
from: type_de_champ_first.libelle,
to: "modifier le libelle"
},
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
},
{
op: :move,
label: type_de_champ_second.libelle,
private: false,
from: 1,
to: 2
}
@ -219,11 +225,13 @@ describe ProcedureRevision do
expect(procedure.active_revision.compare(new_revision.reload)).to eq([
{
op: :remove,
label: type_de_champ_first.libelle
label: type_de_champ_first.libelle,
private: false
},
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
}
])
@ -232,16 +240,19 @@ describe ProcedureRevision do
expect(procedure.active_revision.compare(new_revision.reload)).to eq([
{
op: :remove,
label: type_de_champ_first.libelle
label: type_de_champ_first.libelle,
private: false
},
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
},
{
op: :update,
attribute: :description,
label: type_de_champ_second.libelle,
private: false,
from: type_de_champ_second.description,
to: "une description"
},
@ -249,6 +260,7 @@ describe ProcedureRevision do
op: :update,
attribute: :mandatory,
label: type_de_champ_second.libelle,
private: false,
from: false,
to: true
}
@ -259,16 +271,19 @@ describe ProcedureRevision do
expect(procedure.active_revision.compare(new_revision.reload)).to eq([
{
op: :remove,
label: type_de_champ_first.libelle
label: type_de_champ_first.libelle,
private: false
},
{
op: :add,
label: "Un champ text"
label: "Un champ text",
private: false
},
{
op: :update,
attribute: :description,
label: type_de_champ_second.libelle,
private: false,
from: type_de_champ_second.description,
to: "une description"
},
@ -276,6 +291,7 @@ describe ProcedureRevision do
op: :update,
attribute: :mandatory,
label: type_de_champ_second.libelle,
private: false,
from: false,
to: true
},
@ -283,6 +299,7 @@ describe ProcedureRevision do
op: :update,
attribute: :type_champ,
label: "sub type de champ",
private: false,
from: "text",
to: "drop_down_list"
},
@ -290,6 +307,7 @@ describe ProcedureRevision do
op: :update,
attribute: :drop_down_options,
label: "sub type de champ",
private: false,
from: [],
to: ["one", "two"]
}