Merge pull request #7653 from tchak/feat-other-with-condition
feat(champ): can condition on other option
This commit is contained in:
commit
29e3b3f831
9 changed files with 39 additions and 16 deletions
|
@ -176,7 +176,7 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
||||||
in [:boolean, :boolean] | [:number, :number] | [:empty, :empty]
|
in [:boolean, :boolean] | [:number, :number] | [:empty, :empty]
|
||||||
true
|
true
|
||||||
in [:enum, :string]
|
in [:enum, :string]
|
||||||
left.options.include?(right.value)
|
left.options.map(&:second).include?(right.value)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Champ < ApplicationRecord
|
||||||
:mandatory?,
|
:mandatory?,
|
||||||
:description,
|
:description,
|
||||||
:drop_down_list_options,
|
:drop_down_list_options,
|
||||||
:drop_down_other,
|
:drop_down_other?,
|
||||||
:drop_down_list_options?,
|
:drop_down_list_options?,
|
||||||
:drop_down_list_disabled_options,
|
:drop_down_list_disabled_options,
|
||||||
:drop_down_list_enabled_non_empty_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)
|
drop_down_other? && value.present? && drop_down_list_options.exclude?(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_down_other?
|
|
||||||
drop_down_other == "1" || drop_down_other == true
|
|
||||||
end
|
|
||||||
|
|
||||||
def value=(value)
|
def value=(value)
|
||||||
if value != OTHER
|
if value != OTHER
|
||||||
write_attribute(:value, value)
|
write_attribute(:value, value)
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Logic
|
||||||
when :empty
|
when :empty
|
||||||
Empty.new
|
Empty.new
|
||||||
when :enum
|
when :enum
|
||||||
Constant.new(left.options.first)
|
Constant.new(left.options.first.second)
|
||||||
when :number
|
when :number
|
||||||
Constant.new(0)
|
Constant.new(0)
|
||||||
end
|
end
|
||||||
|
@ -50,7 +50,7 @@ module Logic
|
||||||
in [a, ^a] # syntax for same type
|
in [a, ^a] # syntax for same type
|
||||||
true
|
true
|
||||||
in [:enum, :string]
|
in [:enum, :string]
|
||||||
left.options.include?(right.value)
|
left.options.map(&:second).include?(right.value)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
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)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||||
targeted_champ.for_api
|
targeted_champ.for_api
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
||||||
targeted_champ.value
|
targeted_champ.selected
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +78,12 @@ class Logic::ChampValue < Logic::Term
|
||||||
end
|
end
|
||||||
|
|
||||||
def options
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -428,15 +428,15 @@ class ProcedureRevision < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
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 << {
|
changes << {
|
||||||
model: :type_de_champ,
|
model: :type_de_champ,
|
||||||
op: :update,
|
op: :update,
|
||||||
attribute: :drop_down_other,
|
attribute: :drop_down_other,
|
||||||
label: from_type_de_champ.libelle,
|
label: from_type_de_champ.libelle,
|
||||||
private: from_type_de_champ.private?,
|
private: from_type_de_champ.private?,
|
||||||
from: from_type_de_champ.drop_down_other,
|
from: from_type_de_champ.drop_down_other?,
|
||||||
to: to_type_de_champ.drop_down_other,
|
to: to_type_de_champ.drop_down_other?,
|
||||||
stable_id: from_type_de_champ.stable_id
|
stable_id: from_type_de_champ.stable_id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -182,6 +182,10 @@ class TypeDeChamp < ApplicationRecord
|
||||||
revisions.size == 1
|
revisions.size == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def drop_down_other?
|
||||||
|
drop_down_other == "1" || drop_down_other == true
|
||||||
|
end
|
||||||
|
|
||||||
def non_fillable?
|
def non_fillable?
|
||||||
type_champ.in?([
|
type_champ.in?([
|
||||||
TypeDeChamp.type_champs.fetch(:header_section),
|
TypeDeChamp.type_champs.fetch(:header_section),
|
||||||
|
|
|
@ -87,7 +87,11 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :champ_drop_down_list, class: 'Champs::DropDownListChamp' do
|
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' }
|
value { 'choix 1' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,24 @@ describe Logic::ChampValue do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'dropdown tdc' do
|
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 { 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
|
end
|
||||||
|
|
||||||
context 'checkbox tdc' do
|
context 'checkbox tdc' do
|
||||||
|
|
Loading…
Reference in a new issue