Skip to content

Commit

Permalink
feat(conditional): annotations can be conditioned by champs
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Oct 31, 2023
1 parent 0f60844 commit 8e91305
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%ul.types-de-champ-block{ id: block_id, data: sortable_options }
- @coordinates.each.with_index do |coordinate, i|
= render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: @upper_coordinates + @coordinates.take(i))
- @coordinates.each do |coordinate|
= render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: coordinate.upper_coordinates)
5 changes: 5 additions & 0 deletions app/controllers/administrateurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ def annotations
revision: [],
procedure: []
},
revision_types_de_champ_public: {
type_de_champ: { piece_justificative_template_attachment: :blob, revision: [], procedure: [] },
revision: [],
procedure: []
},
procedure: []
}).find(@procedure.id)
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/procedure_revision_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) }
scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) }

delegate :stable_id, :libelle, :description, :type_champ, :mandatory?, :private?, :to_typed_id, to: :type_de_champ
delegate :stable_id, :libelle, :description, :type_champ, :mandatory?, :private?, :block?, :to_typed_id, to: :type_de_champ

def child?
parent_id.present?
Expand Down Expand Up @@ -46,6 +46,10 @@ def upper_coordinates
upper += parent.upper_coordinates
end

if type_de_champ.private?
upper += revision.revision_types_de_champ_public.filter { !_1.block? && !_1.child? }
end

upper
end

Expand Down
28 changes: 28 additions & 0 deletions spec/models/procedure_revision_type_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,33 @@

it { expect(l2_2.upper_coordinates.map(&:libelle)).to match_array(["l1", "l2.1"]) }
end

context 'when the coordinate is an annotation' do
let(:procedure) do
create(:procedure,
types_de_champ_private: [
{ libelle: 'a1' },
{ libelle: 'a2' }
],
types_de_champ_public: [
{ libelle: 'l1' },
{
type: :repetition, children: [
{ libelle: 'l2.1' },
{ libelle: 'l2.2' }
]
}
])
end

let(:a2) do
procedure
.draft_revision
.revision_types_de_champ.joins(:type_de_champ)
.find_by(type_de_champ: { libelle: 'a2' })
end

it { expect(a2.upper_coordinates.map(&:libelle)).to match_array(["a1", "l1"]) }
end
end
end

0 comments on commit 8e91305

Please sign in to comment.