feat(revisions): add stable_id to changes
This commit is contained in:
parent
7cf82c6dfb
commit
67e98f79c9
2 changed files with 65 additions and 34 deletions
|
@ -134,11 +134,11 @@ class ProcedureRevision < ApplicationRecord
|
|||
to_sids = to_h.keys
|
||||
|
||||
removed = (from_sids - to_sids).map do |sid|
|
||||
{ op: :remove, label: from_h[sid].libelle, private: from_h[sid].private?, position: from_sids.index(sid) }
|
||||
{ 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|
|
||||
{ op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, position: to_sids.index(sid) }
|
||||
{ op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, position: to_sids.index(sid), stable_id: sid }
|
||||
end
|
||||
|
||||
kept = from_sids.intersection(to_sids)
|
||||
|
@ -147,7 +147,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, private: from_h[sid].private?, 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, stable_id: sid }
|
||||
end
|
||||
|
||||
changed = kept
|
||||
|
@ -172,7 +172,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
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
|
||||
to: to_type_de_champ.type_champ,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
if from_type_de_champ.libelle != to_type_de_champ.libelle
|
||||
|
@ -182,7 +183,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
label: from_type_de_champ.libelle,
|
||||
private: from_type_de_champ.private?,
|
||||
from: from_type_de_champ.libelle,
|
||||
to: to_type_de_champ.libelle
|
||||
to: to_type_de_champ.libelle,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
if from_type_de_champ.description != to_type_de_champ.description
|
||||
|
@ -192,7 +194,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
label: from_type_de_champ.libelle,
|
||||
private: from_type_de_champ.private?,
|
||||
from: from_type_de_champ.description,
|
||||
to: to_type_de_champ.description
|
||||
to: to_type_de_champ.description,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
if from_type_de_champ.mandatory? != to_type_de_champ.mandatory?
|
||||
|
@ -202,7 +205,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
label: from_type_de_champ.libelle,
|
||||
private: from_type_de_champ.private?,
|
||||
from: from_type_de_champ.mandatory?,
|
||||
to: to_type_de_champ.mandatory?
|
||||
to: to_type_de_champ.mandatory?,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
if to_type_de_champ.drop_down_list?
|
||||
|
@ -213,7 +217,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
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
|
||||
to: to_type_de_champ.drop_down_list_options,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
elsif to_type_de_champ.carte?
|
||||
|
@ -224,7 +229,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
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
|
||||
to: to_type_de_champ.carte_optional_layers,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
elsif to_type_de_champ.piece_justificative?
|
||||
|
@ -235,7 +241,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
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
|
||||
to: to_type_de_champ.piece_justificative_template_filename,
|
||||
stable_id: from_type_de_champ.stable_id
|
||||
}
|
||||
end
|
||||
elsif to_type_de_champ.repetition?
|
||||
|
|
|
@ -174,7 +174,8 @@ describe ProcedureRevision do
|
|||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -186,12 +187,14 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_first.libelle,
|
||||
private: false,
|
||||
from: type_de_champ_first.libelle,
|
||||
to: "modifier le libelle"
|
||||
to: "modifier le libelle",
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
}
|
||||
])
|
||||
expect(new_revision.types_de_champ.first.revision).to eq(new_revision)
|
||||
|
@ -204,19 +207,22 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_first.libelle,
|
||||
private: false,
|
||||
from: type_de_champ_first.libelle,
|
||||
to: "modifier le libelle"
|
||||
to: "modifier le libelle",
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
},
|
||||
{
|
||||
op: :move,
|
||||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: 1,
|
||||
to: 2
|
||||
to: 2,
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
}
|
||||
])
|
||||
expect(new_revision.types_de_champ.last.revision).to eq(revision)
|
||||
|
@ -226,12 +232,14 @@ describe ProcedureRevision do
|
|||
{
|
||||
op: :remove,
|
||||
label: type_de_champ_first.libelle,
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -241,12 +249,14 @@ describe ProcedureRevision do
|
|||
{
|
||||
op: :remove,
|
||||
label: type_de_champ_first.libelle,
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -254,7 +264,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: type_de_champ_second.description,
|
||||
to: "une description"
|
||||
to: "une description",
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -262,7 +273,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: false,
|
||||
to: true
|
||||
to: true,
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -272,12 +284,14 @@ describe ProcedureRevision do
|
|||
{
|
||||
op: :remove,
|
||||
label: type_de_champ_first.libelle,
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -285,7 +299,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: type_de_champ_second.description,
|
||||
to: "une description"
|
||||
to: "une description",
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -293,7 +308,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: false,
|
||||
to: true
|
||||
to: true,
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -301,7 +317,8 @@ describe ProcedureRevision do
|
|||
label: "sub type de champ",
|
||||
private: false,
|
||||
from: "text",
|
||||
to: "drop_down_list"
|
||||
to: "drop_down_list",
|
||||
stable_id: new_revision.types_de_champ.last.types_de_champ.first.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -309,7 +326,8 @@ describe ProcedureRevision do
|
|||
label: "sub type de champ",
|
||||
private: false,
|
||||
from: [],
|
||||
to: ["one", "two"]
|
||||
to: ["one", "two"],
|
||||
stable_id: new_revision.types_de_champ.last.types_de_champ.first.stable_id
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -319,12 +337,14 @@ describe ProcedureRevision do
|
|||
{
|
||||
op: :remove,
|
||||
label: type_de_champ_first.libelle,
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: type_de_champ_first.stable_id
|
||||
},
|
||||
{
|
||||
op: :add,
|
||||
label: "Un champ text",
|
||||
private: false
|
||||
private: false,
|
||||
stable_id: new_type_de_champ.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -332,7 +352,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: type_de_champ_second.description,
|
||||
to: "une description"
|
||||
to: "une description",
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -340,7 +361,8 @@ describe ProcedureRevision do
|
|||
label: type_de_champ_second.libelle,
|
||||
private: false,
|
||||
from: false,
|
||||
to: true
|
||||
to: true,
|
||||
stable_id: type_de_champ_second.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -348,7 +370,8 @@ describe ProcedureRevision do
|
|||
label: "sub type de champ",
|
||||
private: false,
|
||||
from: "text",
|
||||
to: "carte"
|
||||
to: "carte",
|
||||
stable_id: new_revision.types_de_champ.last.types_de_champ.first.stable_id
|
||||
},
|
||||
{
|
||||
op: :update,
|
||||
|
@ -356,7 +379,8 @@ describe ProcedureRevision do
|
|||
label: "sub type de champ",
|
||||
private: false,
|
||||
from: [],
|
||||
to: [:cadastres, :znieff]
|
||||
to: [:cadastres, :znieff],
|
||||
stable_id: new_revision.types_de_champ.last.types_de_champ.first.stable_id
|
||||
}
|
||||
])
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue