feat(champ): can condition on other option
This commit is contained in:
parent
a53688ce23
commit
a24885c2ee
9 changed files with 39 additions and 16 deletions
|
@ -176,7 +176,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
|||
in [:boolean, :boolean] | [:number, :number] | [:empty, :empty]
|
||||
true
|
||||
in [:enum, :string]
|
||||
left.options.include?(right.value)
|
||||
left.options.map(&:second).include?(right.value)
|
||||
else
|
||||
false
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ class Champ < ApplicationRecord
|
|||
:mandatory?,
|
||||
:description,
|
||||
:drop_down_list_options,
|
||||
:drop_down_other,
|
||||
:drop_down_other?,
|
||||
:drop_down_list_options?,
|
||||
:drop_down_list_disabled_options,
|
||||
:drop_down_list_enabled_non_empty_options,
|
||||
|
|
|
@ -56,10 +56,6 @@ class Champs::DropDownListChamp < Champ
|
|||
drop_down_other? && value.present? && drop_down_list_options.exclude?(value)
|
||||
end
|
||||
|
||||
def drop_down_other?
|
||||
drop_down_other == "1" || drop_down_other == true
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
if value != OTHER
|
||||
write_attribute(:value, value)
|
||||
|
|
|
@ -36,7 +36,7 @@ module Logic
|
|||
when :empty
|
||||
Empty.new
|
||||
when :enum
|
||||
Constant.new(left.options.first)
|
||||
Constant.new(left.options.first.second)
|
||||
when :number
|
||||
Constant.new(0)
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ module Logic
|
|||
in [a, ^a] # syntax for same type
|
||||
true
|
||||
in [:enum, :string]
|
||||
left.options.include?(right.value)
|
||||
left.options.map(&:second).include?(right.value)
|
||||
else
|
||||
false
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ class Logic::ChampValue < Logic::Term
|
|||
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||
targeted_champ.for_api
|
||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
||||
targeted_champ.value
|
||||
targeted_champ.selected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -78,7 +78,12 @@ class Logic::ChampValue < Logic::Term
|
|||
end
|
||||
|
||||
def options
|
||||
type_de_champ.drop_down_list_enabled_non_empty_options
|
||||
opts = type_de_champ.drop_down_list_enabled_non_empty_options.map { |option| [option, option] }
|
||||
if type_de_champ.drop_down_other?
|
||||
opts + [["Autre", Champs::DropDownListChamp::OTHER]]
|
||||
else
|
||||
opts
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -428,15 +428,15 @@ class ProcedureRevision < ApplicationRecord
|
|||
}
|
||||
end
|
||||
end
|
||||
if from_type_de_champ.drop_down_other != to_type_de_champ.drop_down_other
|
||||
if from_type_de_champ.drop_down_other? != to_type_de_champ.drop_down_other?
|
||||
changes << {
|
||||
model: :type_de_champ,
|
||||
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,
|
||||
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
|
||||
|
|
|
@ -182,6 +182,10 @@ class TypeDeChamp < ApplicationRecord
|
|||
revisions.size == 1
|
||||
end
|
||||
|
||||
def drop_down_other?
|
||||
drop_down_other == "1" || drop_down_other == true
|
||||
end
|
||||
|
||||
def non_fillable?
|
||||
type_champ.in?([
|
||||
TypeDeChamp.type_champs.fetch(:header_section),
|
||||
|
|
|
@ -87,7 +87,11 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
factory :champ_drop_down_list, class: 'Champs::DropDownListChamp' do
|
||||
type_de_champ { association :type_de_champ_drop_down_list, procedure: dossier.procedure }
|
||||
transient do
|
||||
other { false }
|
||||
end
|
||||
|
||||
type_de_champ { association :type_de_champ_drop_down_list, procedure: dossier.procedure, drop_down_other: other }
|
||||
value { 'choix 1' }
|
||||
end
|
||||
|
||||
|
|
|
@ -49,10 +49,24 @@ describe Logic::ChampValue do
|
|||
end
|
||||
|
||||
context 'dropdown tdc' do
|
||||
let(:champ) { create(:champ_drop_down_list, value: 'choix 1') }
|
||||
let(:champ) { create(:champ_drop_down_list, value: 'val1') }
|
||||
|
||||
it { expect(champ_value(champ.stable_id).type).to eq(:enum) }
|
||||
it { is_expected.to eq('choix 1') }
|
||||
it { is_expected.to eq('val1') }
|
||||
it { expect(champ_value(champ.stable_id).options).to match_array([["val1", "val1"], ["val2", "val2"], ["val3", "val3"]]) }
|
||||
|
||||
context 'with other enabled' do
|
||||
let(:champ) { create(:champ_drop_down_list, value: 'val1', other: true) }
|
||||
|
||||
it { is_expected.to eq('val1') }
|
||||
it { expect(champ_value(champ.stable_id).options).to match_array([["val1", "val1"], ["val2", "val2"], ["val3", "val3"], ["Autre", "__other__"]]) }
|
||||
end
|
||||
|
||||
context 'with other filled' do
|
||||
let(:champ) { create(:champ_drop_down_list, value: 'other value', other: true) }
|
||||
|
||||
it { is_expected.to eq(Champs::DropDownListChamp::OTHER) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'checkbox tdc' do
|
||||
|
|
Loading…
Reference in a new issue