one less indirection
This commit is contained in:
parent
f046f31dcc
commit
2f64fe5e4c
16 changed files with 35 additions and 35 deletions
|
@ -117,7 +117,7 @@ module Types
|
||||||
|
|
||||||
def options
|
def options
|
||||||
if type_de_champ.drop_down_list?
|
if type_de_champ.drop_down_list?
|
||||||
type_de_champ.drop_down_list_options.reject(&:empty?)
|
type_de_champ.drop_down_options.reject(&:empty?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Types::Champs::Descriptor
|
||||||
end
|
end
|
||||||
|
|
||||||
def options
|
def options
|
||||||
object.type_de_champ.drop_down_list_options.reject(&:empty?)
|
object.type_de_champ.drop_down_options.reject(&:empty?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Types::Champs::Descriptor
|
||||||
field :options, [String], "List des options d’un champ avec selection.", null: true
|
field :options, [String], "List des options d’un champ avec selection.", null: true
|
||||||
|
|
||||||
def options
|
def options
|
||||||
object.type_de_champ.drop_down_list_options.reject(&:empty?)
|
object.type_de_champ.drop_down_options.reject(&:empty?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Types::Champs::Descriptor
|
||||||
field :options, [String], "List des options d’un champ avec selection.", null: true
|
field :options, [String], "List des options d’un champ avec selection.", null: true
|
||||||
|
|
||||||
def options
|
def options
|
||||||
object.type_de_champ.drop_down_list_options.reject(&:empty?)
|
object.type_de_champ.drop_down_options.reject(&:empty?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,9 +29,9 @@ class Champ < ApplicationRecord
|
||||||
delegate :libelle,
|
delegate :libelle,
|
||||||
:type_champ,
|
:type_champ,
|
||||||
:description,
|
:description,
|
||||||
:drop_down_list_options,
|
:drop_down_options,
|
||||||
:drop_down_other?,
|
:drop_down_other?,
|
||||||
:drop_down_list_options?,
|
:drop_down_options?,
|
||||||
:drop_down_list_enabled_non_empty_options,
|
:drop_down_list_enabled_non_empty_options,
|
||||||
:drop_down_secondary_libelle,
|
:drop_down_secondary_libelle,
|
||||||
:drop_down_secondary_description,
|
:drop_down_secondary_description,
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Champs::DropDownListChamp < Champ
|
||||||
end
|
end
|
||||||
|
|
||||||
def options?
|
def options?
|
||||||
drop_down_list_options?
|
drop_down_options?
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_label?
|
def html_label?
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Champs::LinkedDropDownListChamp < Champ
|
||||||
delegate :primary_options, :secondary_options, to: :type_de_champ
|
delegate :primary_options, :secondary_options, to: :type_de_champ
|
||||||
|
|
||||||
def options?
|
def options?
|
||||||
drop_down_list_options?
|
drop_down_options?
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary_value
|
def primary_value
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Champs::MultipleDropDownListChamp < Champ
|
||||||
validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? }
|
validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? }
|
||||||
|
|
||||||
def options?
|
def options?
|
||||||
drop_down_list_options?
|
drop_down_options?
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_non_empty_options
|
def enabled_non_empty_options
|
||||||
|
|
|
@ -407,11 +407,11 @@ class ProcedureRevision < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
if to_type_de_champ.drop_down_list?
|
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
|
if from_type_de_champ.drop_down_options != to_type_de_champ.drop_down_options
|
||||||
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
|
changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ,
|
||||||
:drop_down_options,
|
:drop_down_options,
|
||||||
from_type_de_champ.drop_down_list_options,
|
from_type_de_champ.drop_down_options,
|
||||||
to_type_de_champ.drop_down_list_options)
|
to_type_de_champ.drop_down_options)
|
||||||
end
|
end
|
||||||
if to_type_de_champ.linked_drop_down_list?
|
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
|
if from_type_de_champ.drop_down_secondary_libelle != to_type_de_champ.drop_down_secondary_libelle
|
||||||
|
|
|
@ -475,8 +475,8 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_down_list_value
|
def drop_down_list_value
|
||||||
if drop_down_list_options.present?
|
if drop_down_options.present?
|
||||||
drop_down_list_options.reject(&:empty?).join("\r\n")
|
drop_down_options.reject(&:empty?).join("\r\n")
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
|
@ -564,16 +564,16 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_down_list_options?
|
def drop_down_options?
|
||||||
drop_down_list_options.any?
|
drop_down_options.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_down_list_options
|
def drop_down_options
|
||||||
drop_down_options.presence || []
|
Array.wrap(super)
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_down_list_enabled_non_empty_options(other: false)
|
def drop_down_list_enabled_non_empty_options(other: false)
|
||||||
list_options = drop_down_list_options.reject(&:empty?)
|
list_options = drop_down_options.reject(&:empty?)
|
||||||
|
|
||||||
if other && drop_down_other?
|
if other && drop_down_other?
|
||||||
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
|
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||||
PRIMARY_PATTERN = /^--(.*)--$/
|
PRIMARY_PATTERN = /^--(.*)--$/
|
||||||
|
|
||||||
delegate :drop_down_list_options, to: :@type_de_champ
|
delegate :drop_down_options, to: :@type_de_champ
|
||||||
validate :check_presence_of_primary_options
|
validate :check_presence_of_primary_options
|
||||||
|
|
||||||
def libelles_for_export
|
def libelles_for_export
|
||||||
|
@ -89,7 +89,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpack_options
|
def unpack_options
|
||||||
_, *options = drop_down_list_options
|
_, *options = drop_down_options
|
||||||
chunked = options.slice_before(PRIMARY_PATTERN)
|
chunked = options.slice_before(PRIMARY_PATTERN)
|
||||||
chunked.map do |chunk|
|
chunked.map do |chunk|
|
||||||
primary, *secondary = chunk
|
primary, *secondary = chunk
|
||||||
|
@ -99,7 +99,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_presence_of_primary_options
|
def check_presence_of_primary_options
|
||||||
if !PRIMARY_PATTERN.match?(drop_down_list_options.second)
|
if !PRIMARY_PATTERN.match?(drop_down_options.second)
|
||||||
errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
|
errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -219,7 +219,7 @@ describe API::V2::GraphqlController do
|
||||||
description: tdc.description,
|
description: tdc.description,
|
||||||
required: tdc.mandatory?,
|
required: tdc.mandatory?,
|
||||||
champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { { id: _1.to_typed_id, __typename: format_type_champ(_1.type_champ) } } : nil,
|
champDescriptors: tdc.repetition? ? procedure.active_revision.children_of(tdc.reload).map { { id: _1.to_typed_id, __typename: format_type_champ(_1.type_champ) } } : nil,
|
||||||
options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil
|
options: tdc.drop_down_list? ? tdc.drop_down_options.reject(&:empty?) : nil
|
||||||
}.compact
|
}.compact
|
||||||
end,
|
end,
|
||||||
dossiers: {
|
dossiers: {
|
||||||
|
@ -1445,8 +1445,8 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'drop_down_list' do
|
describe 'drop_down_list' do
|
||||||
let(:drop_down_list_options) { ['bijour'] }
|
let(:drop_down_options) { ['bijour'] }
|
||||||
let(:types_de_champ_private) { [{ type: :drop_down_list, options: drop_down_list_options }] }
|
let(:types_de_champ_private) { [{ type: :drop_down_list, options: drop_down_options }] }
|
||||||
let(:query) do
|
let(:query) do
|
||||||
"mutation {
|
"mutation {
|
||||||
dossierModifierAnnotationDropDownList(input: {
|
dossierModifierAnnotationDropDownList(input: {
|
||||||
|
@ -1466,7 +1466,7 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "success" do
|
context "success" do
|
||||||
let(:value) { drop_down_list_options.first }
|
let(:value) { drop_down_options.first }
|
||||||
it 'should be a success' do
|
it 'should be a success' do
|
||||||
expect(gql_errors).to eq(nil)
|
expect(gql_errors).to eq(nil)
|
||||||
|
|
||||||
|
@ -1479,7 +1479,7 @@ describe API::V2::GraphqlController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "failure" do
|
context "failure" do
|
||||||
let(:value) { drop_down_list_options.first.reverse }
|
let(:value) { drop_down_options.first.reverse }
|
||||||
it 'should be a success' do
|
it 'should be a success' do
|
||||||
expect(gql_errors).to eq(nil)
|
expect(gql_errors).to eq(nil)
|
||||||
|
|
||||||
|
|
|
@ -1243,7 +1243,7 @@ describe API::V2::GraphqlController do
|
||||||
expect(gql_errors).to be_nil
|
expect(gql_errors).to be_nil
|
||||||
expect(gql_data[:groupeInstructeurModifier][:errors]).to be_nil
|
expect(gql_data[:groupeInstructeurModifier][:errors]).to be_nil
|
||||||
expect(gql_data[:groupeInstructeurModifier][:groupeInstructeur][:id]).to eq(dossier.groupe_instructeur.to_typed_id)
|
expect(gql_data[:groupeInstructeurModifier][:groupeInstructeur][:id]).to eq(dossier.groupe_instructeur.to_typed_id)
|
||||||
expect(routing_champ.reload.drop_down_list_options).to match_array(procedure.groupe_instructeurs.active.map(&:label))
|
expect(routing_champ.reload.drop_down_options).to match_array(procedure.groupe_instructeurs.active.map(&:label))
|
||||||
expect(procedure.groupe_instructeurs.active.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.active.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) })
|
expect(procedure.groupe_instructeurs.active.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.active.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) })
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1297,7 +1297,7 @@ describe API::V2::GraphqlController do
|
||||||
expect(gql_errors).to be_nil
|
expect(gql_errors).to be_nil
|
||||||
expect(gql_data[:groupeInstructeurCreer][:errors]).to be_nil
|
expect(gql_data[:groupeInstructeurCreer][:errors]).to be_nil
|
||||||
expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:id]).not_to be_nil
|
expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:id]).not_to be_nil
|
||||||
expect(routing_champ.reload.drop_down_list_options).to match_array(procedure.groupe_instructeurs.map(&:label))
|
expect(routing_champ.reload.drop_down_options).to match_array(procedure.groupe_instructeurs.map(&:label))
|
||||||
expect(procedure.groupe_instructeurs.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) })
|
expect(procedure.groupe_instructeurs.map(&:routing_rule)).to match_array(procedure.groupe_instructeurs.map { ds_eq(champ_value(routing_champ.stable_id), constant(_1.label)) })
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,7 +107,7 @@ describe TypeDeChamp do
|
||||||
context 'when the target type_champ is not drop_down_list' do
|
context 'when the target type_champ is not drop_down_list' do
|
||||||
let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) }
|
||||||
|
|
||||||
it { expect(tdc.drop_down_options).to be_nil }
|
it { expect(tdc.drop_down_options).to be_empty }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the target type_champ is linked_drop_down_list' do
|
context 'when the target type_champ is linked_drop_down_list' do
|
||||||
|
@ -192,7 +192,7 @@ describe TypeDeChamp do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#drop_down_list_options' do
|
describe '#drop_down_options' do
|
||||||
let(:value) do
|
let(:value) do
|
||||||
<<~EOS
|
<<~EOS
|
||||||
Cohésion sociale
|
Cohésion sociale
|
||||||
|
@ -203,7 +203,7 @@ describe TypeDeChamp do
|
||||||
end
|
end
|
||||||
let(:type_de_champ) { create(:type_de_champ_drop_down_list, drop_down_list_value: value) }
|
let(:type_de_champ) { create(:type_de_champ_drop_down_list, drop_down_list_value: value) }
|
||||||
|
|
||||||
it { expect(type_de_champ.drop_down_list_options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
it { expect(type_de_champ.drop_down_options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||||
|
|
||||||
context 'when one value is empty' do
|
context 'when one value is empty' do
|
||||||
let(:value) do
|
let(:value) do
|
||||||
|
@ -214,7 +214,7 @@ describe TypeDeChamp do
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(type_de_champ.drop_down_list_options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
it { expect(type_de_champ.drop_down_options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ describe 'As an administrateur I can edit types de champ', js: true do
|
||||||
fill_in 'Options de la liste', with: 'Un menu', fill_options: { clear: :backspace }
|
fill_in 'Options de la liste', with: 'Un menu', fill_options: { clear: :backspace }
|
||||||
check "Proposer une option « autre » avec un texte libre"
|
check "Proposer une option « autre » avec un texte libre"
|
||||||
|
|
||||||
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_list_options == ['', 'Un menu'] }
|
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_options == ['', 'Un menu'] }
|
||||||
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_other == "1" }
|
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_other == "1" }
|
||||||
expect(page).to have_content('Formulaire enregistré')
|
expect(page).to have_content('Formulaire enregistré')
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe 'shared/dossiers/edit', type: :view do
|
||||||
let(:types_de_champ_public) { [{ type: :multiple_drop_down_list, options: }] }
|
let(:types_de_champ_public) { [{ type: :multiple_drop_down_list, options: }] }
|
||||||
let(:champ) { dossier.champs.first }
|
let(:champ) { dossier.champs.first }
|
||||||
let(:type_de_champ) { champ.type_de_champ }
|
let(:type_de_champ) { champ.type_de_champ }
|
||||||
let(:options) { type_de_champ.drop_down_list_options }
|
let(:options) { type_de_champ.drop_down_options }
|
||||||
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
let(:enabled_options) { type_de_champ.drop_down_list_enabled_non_empty_options }
|
||||||
|
|
||||||
context 'when the list is short' do
|
context 'when the list is short' do
|
||||||
|
|
Loading…
Reference in a new issue