2020-08-06 16:35:45 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: procedure_revisions
|
|
|
|
#
|
2022-03-15 15:10:56 +01:00
|
|
|
# id :bigint not null, primary key
|
|
|
|
# published_at :datetime
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# attestation_template_id :bigint
|
2022-02-04 14:40:16 +01:00
|
|
|
# dossier_submitted_message_id :bigint
|
|
|
|
# procedure_id :bigint not null
|
2020-08-06 16:35:45 +02:00
|
|
|
#
|
2020-06-26 11:37:28 +02:00
|
|
|
class ProcedureRevision < ApplicationRecord
|
2020-07-22 11:56:19 +02:00
|
|
|
self.implicit_order_column = :created_at
|
2020-08-27 19:55:10 +02:00
|
|
|
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions, optional: false
|
2022-02-02 16:10:29 +01:00
|
|
|
belongs_to :attestation_template, inverse_of: :revisions, optional: true, dependent: :destroy
|
2022-02-04 14:40:16 +01:00
|
|
|
belongs_to :dossier_submitted_message, inverse_of: :revisions, optional: true, dependent: :destroy
|
2020-06-26 11:37:28 +02:00
|
|
|
|
2020-09-17 11:15:21 +02:00
|
|
|
has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id
|
|
|
|
|
2022-05-18 15:47:52 +02:00
|
|
|
has_many :revision_types_de_champ, -> { order(:position, :id) }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
2022-04-28 14:25:49 +02:00
|
|
|
has_many :revision_types_de_champ_public, -> { root.public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
2021-12-06 21:04:01 +01:00
|
|
|
has_many :revision_types_de_champ_private, -> { root.private_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
2022-05-02 10:36:16 +02:00
|
|
|
has_many :types_de_champ, through: :revision_types_de_champ, source: :type_de_champ
|
2022-04-28 14:25:49 +02:00
|
|
|
has_many :types_de_champ_public, through: :revision_types_de_champ_public, source: :type_de_champ
|
2020-06-26 11:37:28 +02:00
|
|
|
has_many :types_de_champ_private, through: :revision_types_de_champ_private, source: :type_de_champ
|
|
|
|
|
2021-05-27 12:17:10 +02:00
|
|
|
has_one :draft_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :draft_revision_id, dependent: :nullify, inverse_of: :draft_revision
|
|
|
|
has_one :published_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision
|
2021-04-13 20:24:12 +02:00
|
|
|
|
2021-12-06 21:04:01 +01:00
|
|
|
scope :ordered, -> { order(:created_at) }
|
|
|
|
|
2020-08-27 19:55:10 +02:00
|
|
|
def build_champs
|
2022-05-18 14:49:49 +02:00
|
|
|
types_de_champ_public.map { |tdc| tdc.build_champ(revision: self) }
|
2020-08-27 19:55:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_champs_private
|
2022-05-18 14:49:49 +02:00
|
|
|
types_de_champ_private.map { |tdc| tdc.build_champ(revision: self) }
|
2020-08-27 19:55:10 +02:00
|
|
|
end
|
|
|
|
|
2020-06-26 11:42:24 +02:00
|
|
|
def add_type_de_champ(params)
|
2022-05-24 15:57:31 +02:00
|
|
|
parent_stable_id = params.delete(:parent_id)
|
2022-05-12 14:18:28 +02:00
|
|
|
|
|
|
|
coordinate = {}
|
|
|
|
|
|
|
|
if parent_stable_id.present?
|
2022-05-17 22:04:53 +02:00
|
|
|
parent_coordinate, parent = coordinate_and_tdc(parent_stable_id)
|
2022-05-12 14:18:28 +02:00
|
|
|
|
|
|
|
coordinate[:parent_id] = parent_coordinate.id
|
|
|
|
coordinate[:position] = children_of(parent).count
|
|
|
|
elsif params[:private]
|
|
|
|
coordinate[:position] = revision_types_de_champ_private.count
|
2020-06-26 11:42:24 +02:00
|
|
|
else
|
2022-05-12 14:18:28 +02:00
|
|
|
coordinate[:position] = revision_types_de_champ_public.count
|
2020-06-26 11:42:24 +02:00
|
|
|
end
|
2022-05-12 14:18:28 +02:00
|
|
|
|
|
|
|
tdc = TypeDeChamp.new(params)
|
|
|
|
if tdc.save
|
|
|
|
coordinate[:type_de_champ] = tdc
|
|
|
|
revision_types_de_champ.create!(coordinate)
|
|
|
|
end
|
|
|
|
|
|
|
|
tdc
|
|
|
|
rescue => e
|
|
|
|
TypeDeChamp.new.tap { |tdc| tdc.errors.add(:base, e.message) }
|
2020-06-26 11:42:24 +02:00
|
|
|
end
|
|
|
|
|
2022-05-25 09:40:02 +02:00
|
|
|
def find_and_ensure_exclusive_use(stable_id)
|
2022-05-18 19:29:26 +02:00
|
|
|
coordinate, tdc = coordinate_and_tdc(stable_id)
|
2020-06-26 11:42:24 +02:00
|
|
|
|
2022-05-18 19:29:26 +02:00
|
|
|
if tdc.only_present_on_draft?
|
|
|
|
tdc
|
2020-06-26 11:42:24 +02:00
|
|
|
else
|
2022-05-24 15:57:31 +02:00
|
|
|
replace_type_de_champ_by_clone(coordinate)
|
2020-06-26 11:42:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-06 10:54:21 +02:00
|
|
|
def move_type_de_champ(stable_id, position)
|
2022-05-17 22:04:53 +02:00
|
|
|
coordinate, _ = coordinate_and_tdc(stable_id)
|
2020-06-26 11:42:24 +02:00
|
|
|
|
2022-05-11 20:22:52 +02:00
|
|
|
siblings = coordinate.siblings.to_a
|
2020-06-26 11:42:24 +02:00
|
|
|
|
2022-05-11 20:22:52 +02:00
|
|
|
siblings.insert(position, siblings.delete_at(siblings.index(coordinate)))
|
2022-05-02 10:36:16 +02:00
|
|
|
|
2022-05-11 20:22:52 +02:00
|
|
|
reorder(siblings)
|
2020-06-26 11:42:24 +02:00
|
|
|
end
|
|
|
|
|
2022-05-06 10:54:21 +02:00
|
|
|
def remove_type_de_champ(stable_id)
|
2022-05-17 22:04:53 +02:00
|
|
|
coordinate, tdc = coordinate_and_tdc(stable_id)
|
2022-05-11 20:22:52 +02:00
|
|
|
|
2022-05-24 15:57:31 +02:00
|
|
|
children = children_of(tdc).to_a
|
2022-05-11 20:22:52 +02:00
|
|
|
coordinate.destroy
|
|
|
|
|
2022-05-24 15:57:31 +02:00
|
|
|
children.each(&:destroy_if_orphan)
|
|
|
|
tdc.destroy_if_orphan
|
2022-05-11 20:22:52 +02:00
|
|
|
|
|
|
|
reorder(coordinate.siblings)
|
2020-06-26 11:42:24 +02:00
|
|
|
end
|
|
|
|
|
2020-06-26 11:37:28 +02:00
|
|
|
def draft?
|
|
|
|
procedure.draft_revision == self
|
|
|
|
end
|
|
|
|
|
|
|
|
def locked?
|
|
|
|
!draft?
|
|
|
|
end
|
2020-06-26 11:42:24 +02:00
|
|
|
|
2022-01-12 17:38:57 +01:00
|
|
|
def different_from?(revision)
|
2022-05-18 15:47:52 +02:00
|
|
|
revision_types_de_champ != revision.revision_types_de_champ ||
|
2022-02-10 19:42:39 +01:00
|
|
|
attestation_template != revision.attestation_template
|
2021-01-20 13:21:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def compare(revision)
|
|
|
|
changes = []
|
2022-05-18 15:47:52 +02:00
|
|
|
changes += compare_revision_types_de_champ(revision_types_de_champ, revision.revision_types_de_champ)
|
2022-02-10 19:42:39 +01:00
|
|
|
changes += compare_attestation_template(attestation_template, revision.attestation_template)
|
2021-01-20 13:21:23 +01:00
|
|
|
changes
|
|
|
|
end
|
|
|
|
|
2021-06-23 15:57:11 +02:00
|
|
|
def new_dossier
|
|
|
|
Dossier.new(
|
|
|
|
revision: self,
|
|
|
|
champs: build_champs,
|
|
|
|
champs_private: build_champs_private,
|
|
|
|
groupe_instructeur: procedure.defaut_groupe_instructeur
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-04-07 11:40:53 +02:00
|
|
|
def dossier_for_preview(user)
|
|
|
|
dossier = Dossier
|
|
|
|
.create_with(groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier)
|
|
|
|
.find_or_initialize_by(revision: self, user: user, for_procedure_preview: true, state: Dossier.states.fetch(:brouillon))
|
|
|
|
|
|
|
|
if dossier.new_record?
|
|
|
|
dossier.build_default_individual
|
|
|
|
dossier.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
dossier
|
|
|
|
end
|
|
|
|
|
2022-05-06 15:47:57 +02:00
|
|
|
def children_of(tdc)
|
2022-05-18 12:30:58 +02:00
|
|
|
parent_coordinate_id = revision_types_de_champ.where(type_de_champ: tdc).select(:id)
|
2022-05-06 15:47:57 +02:00
|
|
|
|
2022-05-18 12:30:58 +02:00
|
|
|
types_de_champ
|
|
|
|
.where(procedure_revision_types_de_champ: { parent_id: parent_coordinate_id })
|
|
|
|
.order("procedure_revision_types_de_champ.position")
|
2022-05-06 15:47:57 +02:00
|
|
|
end
|
|
|
|
|
2022-05-24 15:57:31 +02:00
|
|
|
def remove_children_of(tdc)
|
|
|
|
children_of(tdc).each do |child|
|
|
|
|
remove_type_de_champ(child.stable_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-20 12:27:26 +02:00
|
|
|
def types_de_champ_public_as_json
|
|
|
|
types_de_champ = types_de_champ_public.includes(piece_justificative_template_attachment: :blob)
|
|
|
|
tdcs_as_json = types_de_champ.map(&:as_json_for_editor)
|
|
|
|
children_types_de_champ_as_json(tdcs_as_json, types_de_champ.filter(&:repetition?))
|
|
|
|
tdcs_as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def types_de_champ_private_as_json
|
|
|
|
types_de_champ = types_de_champ_private.includes(piece_justificative_template_attachment: :blob)
|
|
|
|
tdcs_as_json = types_de_champ.map(&:as_json_for_editor)
|
|
|
|
children_types_de_champ_as_json(tdcs_as_json, types_de_champ.filter(&:repetition?))
|
|
|
|
tdcs_as_json
|
|
|
|
end
|
|
|
|
|
2022-05-24 14:17:10 +02:00
|
|
|
# Estimated duration to fill the form, in seconds.
|
|
|
|
#
|
|
|
|
# If the revision is locked (i.e. published), the result is cached (because type de champs can no longer be mutated).
|
2022-05-24 11:39:03 +02:00
|
|
|
def estimated_fill_duration
|
2022-05-24 14:17:10 +02:00
|
|
|
Rails.cache.fetch("#{cache_key_with_version}/estimated_fill_duration", expires_in: 12.hours, force: !locked?) do
|
|
|
|
compute_estimated_fill_duration
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def compute_estimated_fill_duration
|
2022-05-24 11:39:03 +02:00
|
|
|
tdc_durations = types_de_champ_public.fillable.map do |tdc|
|
|
|
|
duration = tdc.estimated_fill_duration(self)
|
|
|
|
tdc.mandatory ? duration : duration / 2
|
|
|
|
end
|
|
|
|
tdc_durations.sum
|
|
|
|
end
|
|
|
|
|
2022-05-20 12:27:26 +02:00
|
|
|
def children_types_de_champ_as_json(tdcs_as_json, parent_tdcs)
|
|
|
|
parent_tdcs.each do |parent_tdc|
|
|
|
|
tdc_as_json = tdcs_as_json.find { |json| json["id"] == parent_tdc.stable_id }
|
|
|
|
tdc_as_json&.merge!(types_de_champ: children_of(parent_tdc).includes(piece_justificative_template_attachment: :blob).map(&:as_json_for_editor))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-17 22:04:53 +02:00
|
|
|
def coordinate_and_tdc(stable_id)
|
|
|
|
coordinate = revision_types_de_champ
|
|
|
|
.joins(:type_de_champ)
|
|
|
|
.find_by(type_de_champ: { stable_id: stable_id })
|
|
|
|
|
|
|
|
[coordinate, coordinate.type_de_champ]
|
|
|
|
end
|
|
|
|
|
2022-05-11 20:22:52 +02:00
|
|
|
def reorder(siblings)
|
|
|
|
siblings.to_a.compact.each.with_index do |sibling, position|
|
2022-05-24 15:57:31 +02:00
|
|
|
sibling.update(position: position)
|
|
|
|
end
|
2022-05-11 20:22:52 +02:00
|
|
|
end
|
|
|
|
|
2022-02-10 19:42:39 +01:00
|
|
|
def compare_attestation_template(from_at, to_at)
|
|
|
|
changes = []
|
|
|
|
if from_at.nil? && to_at.present?
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :add
|
|
|
|
}
|
|
|
|
elsif to_at.present?
|
|
|
|
if from_at.title != to_at.title
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :update,
|
|
|
|
attribute: :title,
|
|
|
|
from: from_at.title,
|
|
|
|
to: to_at.title
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_at.body != to_at.body
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :update,
|
|
|
|
attribute: :body,
|
|
|
|
from: from_at.body,
|
|
|
|
to: to_at.body
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_at.footer != to_at.footer
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :update,
|
|
|
|
attribute: :footer,
|
|
|
|
from: from_at.footer,
|
|
|
|
to: to_at.footer
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_at.logo_checksum != to_at.logo_checksum
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :update,
|
|
|
|
attribute: :logo,
|
|
|
|
from: from_at.logo_filename,
|
|
|
|
to: to_at.logo_filename
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_at.signature_checksum != to_at.signature_checksum
|
|
|
|
changes << {
|
|
|
|
model: :attestation_template,
|
|
|
|
op: :update,
|
|
|
|
attribute: :signature,
|
|
|
|
from: from_at.signature_filename,
|
|
|
|
to: to_at.signature_filename
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
changes
|
|
|
|
end
|
|
|
|
|
2022-05-18 15:47:52 +02:00
|
|
|
def compare_revision_types_de_champ(from_coordinates, to_coordinates)
|
|
|
|
if from_coordinates == to_coordinates
|
2021-01-20 13:21:23 +01:00
|
|
|
[]
|
|
|
|
else
|
2022-05-18 15:47:52 +02:00
|
|
|
from_h = from_coordinates.index_by(&:stable_id)
|
|
|
|
to_h = to_coordinates.index_by(&:stable_id)
|
2021-01-20 13:21:23 +01:00
|
|
|
|
|
|
|
from_sids = from_h.keys
|
|
|
|
to_sids = to_h.keys
|
|
|
|
|
|
|
|
removed = (from_sids - to_sids).map do |sid|
|
2022-05-18 15:47:52 +02:00
|
|
|
{ model: :type_de_champ, op: :remove, label: from_h[sid].libelle, private: from_h[sid].private?, _position: from_sids.index(sid), stable_id: sid }
|
2021-01-20 13:21:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
added = (to_sids - from_sids).map do |sid|
|
2022-05-18 15:47:52 +02:00
|
|
|
{ model: :type_de_champ, op: :add, label: to_h[sid].libelle, private: to_h[sid].private?, _position: to_sids.index(sid), stable_id: sid }
|
2021-01-20 13:21:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
kept = from_sids.intersection(to_sids)
|
|
|
|
|
|
|
|
moved = kept
|
2022-05-18 15:47:52 +02:00
|
|
|
.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 }
|
2021-01-20 13:21:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
changed = kept
|
|
|
|
.map { |sid| [sid, from_h[sid], to_h[sid]] }
|
|
|
|
.flat_map do |sid, from, to|
|
2022-05-18 15:47:52 +02:00
|
|
|
compare_type_de_champ(from.type_de_champ, to.type_de_champ)
|
|
|
|
.each { |h| h[:_position] = to_sids.index(sid) }
|
|
|
|
end
|
2021-01-20 13:21:23 +01:00
|
|
|
|
|
|
|
(removed + added + moved + changed)
|
2022-05-18 15:47:52 +02:00
|
|
|
.sort_by { |h| h[:_position] }
|
|
|
|
.each { |h| h.delete(:_position) }
|
2021-01-20 13:21:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def compare_type_de_champ(from_type_de_champ, to_type_de_champ)
|
|
|
|
changes = []
|
|
|
|
if from_type_de_champ.type_champ != to_type_de_champ.type_champ
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :type_champ,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.type_champ,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.type_champ,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_type_de_champ.libelle != to_type_de_champ.libelle
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :libelle,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.libelle,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.libelle,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_type_de_champ.description != to_type_de_champ.description
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :description,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.description,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.description,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_type_de_champ.mandatory? != to_type_de_champ.mandatory?
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :mandatory,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.mandatory?,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.mandatory?,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
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 << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :drop_down_options,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.drop_down_list_options,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.drop_down_list_options,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-06-23 15:54:12 +02:00
|
|
|
}
|
|
|
|
end
|
2021-10-19 18:48:45 +02:00
|
|
|
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 << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-10-19 18:48:45 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if from_type_de_champ.drop_down_secondary_description != to_type_de_champ.drop_down_secondary_description
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-10-19 18:48:45 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-10-22 20:44:46 +02:00
|
|
|
if from_type_de_champ.drop_down_other != to_type_de_champ.drop_down_other
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-10-22 20:44:46 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
end
|
2021-06-23 15:54:12 +02:00
|
|
|
elsif to_type_de_champ.carte?
|
|
|
|
if from_type_de_champ.carte_optional_layers != to_type_de_champ.carte_optional_layers
|
|
|
|
changes << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-06-23 15:54:12 +02:00
|
|
|
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,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.carte_optional_layers,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
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 << {
|
2022-02-10 19:42:39 +01:00
|
|
|
model: :type_de_champ,
|
2021-01-20 13:21:23 +01:00
|
|
|
op: :update,
|
|
|
|
attribute: :piece_justificative_template,
|
|
|
|
label: from_type_de_champ.libelle,
|
2021-06-22 12:20:04 +02:00
|
|
|
private: from_type_de_champ.private?,
|
2021-01-20 13:21:23 +01:00
|
|
|
from: from_type_de_champ.piece_justificative_template_filename,
|
2021-09-20 16:24:40 +02:00
|
|
|
to: to_type_de_champ.piece_justificative_template_filename,
|
|
|
|
stable_id: from_type_de_champ.stable_id
|
2021-01-20 13:21:23 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
changes
|
|
|
|
end
|
|
|
|
|
2022-05-24 15:57:31 +02:00
|
|
|
def replace_type_de_champ_by_clone(coordinate)
|
|
|
|
cloned_type_de_champ = coordinate.type_de_champ.deep_clone do |original, kopy|
|
2021-07-01 13:33:22 +02:00
|
|
|
PiecesJustificativesService.clone_attachments(original, kopy)
|
|
|
|
end
|
2022-05-18 19:29:26 +02:00
|
|
|
coordinate.update!(type_de_champ: cloned_type_de_champ)
|
2020-09-08 15:53:07 +02:00
|
|
|
cloned_type_de_champ
|
|
|
|
end
|
2020-06-26 11:37:28 +02:00
|
|
|
end
|