Merge pull request #5406 from tchak/revisions-fixes
Différent fix lié au types_de_champ (surtout révisions)
This commit is contained in:
commit
d55bc3cc7a
8 changed files with 32 additions and 14 deletions
|
@ -27,7 +27,7 @@ module NewAdministrateur
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
def move
|
||||||
@procedure.draft_revision.move_type_de_champ(type_de_champ_stable_id, params[:position].to_i)
|
@procedure.draft_revision.move_type_de_champ(type_de_champ_stable_id, (params[:position] || params[:order_place]).to_i)
|
||||||
|
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ function TypeDeChampCarteOptions({ isVisible, children }) {
|
||||||
|
|
||||||
TypeDeChampCarteOptions.propTypes = {
|
TypeDeChampCarteOptions.propTypes = {
|
||||||
isVisible: PropTypes.bool,
|
isVisible: PropTypes.bool,
|
||||||
children: PropTypes.array
|
children: PropTypes.node
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TypeDeChampCarteOptions;
|
export default TypeDeChampCarteOptions;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class ProcedureRevision < ApplicationRecord
|
class ProcedureRevision < ApplicationRecord
|
||||||
|
self.implicit_order_column = :created_at
|
||||||
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions
|
belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions
|
||||||
|
|
||||||
has_many :revision_types_de_champ, -> { public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
has_many :revision_types_de_champ, -> { public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision
|
||||||
|
@ -14,12 +15,18 @@ class ProcedureRevision < ApplicationRecord
|
||||||
find_or_clone_type_de_champ(params.delete(:parent_id))
|
find_or_clone_type_de_champ(params.delete(:parent_id))
|
||||||
.types_de_champ
|
.types_de_champ
|
||||||
.tap do |types_de_champ|
|
.tap do |types_de_champ|
|
||||||
params[:order_place] = types_de_champ.size
|
params[:order_place] = types_de_champ.present? ? types_de_champ.last.order_place + 1 : 0
|
||||||
end.create(params)
|
end.create(params)
|
||||||
elsif params[:private]
|
elsif params[:private]
|
||||||
types_de_champ_private.create(params)
|
types_de_champ_private.tap do |types_de_champ|
|
||||||
|
# FIXUP: needed during transition to revisions
|
||||||
|
params[:order_place] = types_de_champ.present? ? types_de_champ.last.order_place + 1 : 0
|
||||||
|
end.create(params)
|
||||||
else
|
else
|
||||||
types_de_champ.create(params)
|
types_de_champ.tap do |types_de_champ|
|
||||||
|
# FIXUP: needed during transition to revisions
|
||||||
|
params[:order_place] = types_de_champ.present? ? types_de_champ.last.order_place + 1 : 0
|
||||||
|
end.create(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,17 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
|
||||||
|
|
||||||
def set_position
|
def set_position
|
||||||
self.position ||= if private?
|
self.position ||= if private?
|
||||||
revision.types_de_champ_private.size
|
if revision.types_de_champ_private.present?
|
||||||
|
revision.revision_types_de_champ_private.filter(&:persisted?).last.position + 1
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
else
|
else
|
||||||
revision.types_de_champ.size
|
if revision.types_de_champ.present?
|
||||||
|
revision.revision_types_de_champ.filter(&:persisted?).last.position + 1
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -261,6 +261,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
:parent_id,
|
:parent_id,
|
||||||
:private,
|
:private,
|
||||||
:procedure_id,
|
:procedure_id,
|
||||||
|
:revision_id,
|
||||||
:stable_id,
|
:stable_id,
|
||||||
:type,
|
:type,
|
||||||
:updated_at
|
:updated_at
|
||||||
|
|
|
@ -10,15 +10,12 @@ class RevisionsMigration
|
||||||
add_types_de_champs_to_revision(procedure, :types_de_champ)
|
add_types_de_champs_to_revision(procedure, :types_de_champ)
|
||||||
add_types_de_champs_to_revision(procedure, :types_de_champ_private)
|
add_types_de_champs_to_revision(procedure, :types_de_champ_private)
|
||||||
|
|
||||||
if procedure.publiee?
|
if !procedure.brouillon?
|
||||||
published_revision = procedure.draft_revision
|
published_revision = procedure.draft_revision
|
||||||
|
|
||||||
procedure.draft_revision = procedure.create_new_revision
|
procedure.draft_revision = procedure.create_new_revision
|
||||||
procedure.published_revision = published_revision
|
procedure.published_revision = published_revision
|
||||||
procedure.save!(validate: false)
|
procedure.save!(validate: false)
|
||||||
elsif procedure.close? || procedure.depubliee?
|
|
||||||
procedure.draft_revision = procedure.create_new_revision
|
|
||||||
procedure.save!(validate: false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -16,13 +16,18 @@ describe ProcedureRevision do
|
||||||
describe '#add_type_de_champ' do
|
describe '#add_type_de_champ' do
|
||||||
it 'type_de_champ' do
|
it 'type_de_champ' do
|
||||||
expect(revision.types_de_champ.size).to eq(2)
|
expect(revision.types_de_champ.size).to eq(2)
|
||||||
revision.add_type_de_champ({
|
new_type_de_champ = revision.add_type_de_champ({
|
||||||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||||
libelle: "Un champ text"
|
libelle: "Un champ text"
|
||||||
})
|
})
|
||||||
procedure.reload
|
procedure.reload
|
||||||
expect(revision.types_de_champ.size).to eq(3)
|
expect(revision.types_de_champ.size).to eq(3)
|
||||||
expect(procedure.types_de_champ.size).to eq(3)
|
expect(procedure.types_de_champ.size).to eq(3)
|
||||||
|
|
||||||
|
expect(procedure.types_de_champ.last).to eq(new_type_de_champ)
|
||||||
|
expect(revision.types_de_champ.last).to eq(new_type_de_champ)
|
||||||
|
expect(revision.revision_types_de_champ.last.position).to eq(2)
|
||||||
|
expect(revision.revision_types_de_champ.last.type_de_champ).to eq(new_type_de_champ)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'type_de_champ_private' do
|
it 'type_de_champ_private' do
|
||||||
|
|
|
@ -687,7 +687,7 @@ describe Procedure do
|
||||||
expect(procedure.published_revision).not_to be_nil
|
expect(procedure.published_revision).not_to be_nil
|
||||||
expect(procedure.draft_revision).not_to be_nil
|
expect(procedure.draft_revision).not_to be_nil
|
||||||
expect(procedure.revisions.count).to eq(2)
|
expect(procedure.revisions.count).to eq(2)
|
||||||
expect(procedure.revisions.last).to eq(procedure.draft_revision)
|
expect(procedure.revisions).to eq([procedure.published_revision, procedure.draft_revision])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -768,7 +768,7 @@ describe Procedure do
|
||||||
expect(procedure.published_revision).not_to be_nil
|
expect(procedure.published_revision).not_to be_nil
|
||||||
expect(procedure.draft_revision).not_to be_nil
|
expect(procedure.draft_revision).not_to be_nil
|
||||||
expect(procedure.revisions.count).to eq(2)
|
expect(procedure.revisions.count).to eq(2)
|
||||||
expect(procedure.revisions.last).to eq(procedure.draft_revision)
|
expect(procedure.revisions).to eq([procedure.published_revision, procedure.draft_revision])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue