update conditions_controller
This commit is contained in:
parent
faa2797d80
commit
0179a0a826
8 changed files with 48 additions and 39 deletions
|
@ -6,54 +6,58 @@ module Administrateurs
|
|||
|
||||
def update
|
||||
condition = condition_form.to_condition
|
||||
tdc.update!(condition: condition)
|
||||
@tdc.update!(condition: condition)
|
||||
|
||||
render 'administrateurs/types_de_champ/update.turbo_stream.haml'
|
||||
@condition_component = build_condition_component
|
||||
end
|
||||
|
||||
def add_row
|
||||
condition = Logic.add_empty_condition_to(tdc.condition)
|
||||
tdc.update!(condition: condition)
|
||||
condition = Logic.add_empty_condition_to(@tdc.condition)
|
||||
@tdc.update!(condition: condition)
|
||||
|
||||
render 'administrateurs/types_de_champ/update.turbo_stream.haml'
|
||||
@condition_component = build_condition_component
|
||||
end
|
||||
|
||||
def delete_row
|
||||
condition = condition_form.delete_row(row_index).to_condition
|
||||
tdc.update!(condition: condition)
|
||||
@tdc.update!(condition: condition)
|
||||
|
||||
render 'administrateurs/types_de_champ/update.turbo_stream.haml'
|
||||
@condition_component = build_condition_component
|
||||
end
|
||||
|
||||
def destroy
|
||||
tdc.update!(condition: nil)
|
||||
@tdc.update!(condition: nil)
|
||||
|
||||
render 'administrateurs/types_de_champ/update.turbo_stream.haml'
|
||||
@condition_component = build_condition_component
|
||||
end
|
||||
|
||||
def change_targeted_champ
|
||||
condition = condition_form.change_champ(row_index).to_condition
|
||||
tdc.update!(condition: condition)
|
||||
@tdc.update!(condition: condition)
|
||||
|
||||
render 'administrateurs/types_de_champ/update.turbo_stream.haml'
|
||||
@condition_component = build_condition_component
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_condition_component
|
||||
TypesDeChampEditor::ConditionsComponent.new(
|
||||
tdc: @tdc,
|
||||
upper_tdcs: @upper_tdcs,
|
||||
procedure_id: @procedure.id
|
||||
)
|
||||
end
|
||||
|
||||
def condition_form
|
||||
ConditionForm.new(condition_params)
|
||||
end
|
||||
|
||||
def retrieve_coordinate_and_uppers
|
||||
@coordinate = draft_revision.coordinate_for(tdc)
|
||||
@upper_coordinates = draft_revision
|
||||
.revision_types_de_champ_public
|
||||
.includes(:type_de_champ)
|
||||
.take_while { |c| c != @coordinate }
|
||||
end
|
||||
|
||||
def tdc
|
||||
@tdc ||= draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
|
||||
@tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
|
||||
@coordinate = draft_revision.coordinate_for(@tdc)
|
||||
@upper_tdcs = draft_revision
|
||||
.upper_coordinates(@coordinate.position)
|
||||
.map(&:type_de_champ)
|
||||
end
|
||||
|
||||
def draft_revision
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
- rendered = render @condition_component
|
||||
|
||||
- if rendered.present?
|
||||
= turbo_stream.morph dom_id(@tdc, :conditions) do
|
||||
- rendered
|
||||
end
|
||||
- else
|
||||
= turbo_stream.remove dom_id(@tdc, :conditions)
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'update'
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'update'
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'update'
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'update'
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'update'
|
|
@ -5,9 +5,7 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
let(:first_coordinate) { procedure.draft_revision.revision_types_de_champ.first }
|
||||
let(:second_tdc) { procedure.draft_revision.types_de_champ.second }
|
||||
|
||||
before do
|
||||
sign_in(procedure.administrateurs.first.user)
|
||||
end
|
||||
before { sign_in(procedure.administrateurs.first.user) }
|
||||
|
||||
let(:default_params) do
|
||||
{
|
||||
|
@ -17,9 +15,7 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#update' do
|
||||
before do
|
||||
post :update, params: params
|
||||
end
|
||||
before { post :update, params: params, format: :turbo_stream }
|
||||
|
||||
let(:params) { default_params.merge(type_de_champ: { condition_form: condition_form }) }
|
||||
|
||||
|
@ -38,26 +34,22 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
it do
|
||||
expect(second_tdc.reload.condition).to eq(ds_eq(champ_value(1), constant(2)))
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(second_tdc))
|
||||
expect(assigns(:upper_coordinates)).to eq([first_coordinate])
|
||||
expect(assigns(:upper_tdcs)).to eq([first_coordinate.type_de_champ])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add_row' do
|
||||
before do
|
||||
post :add_row, params: default_params
|
||||
end
|
||||
before { post :add_row, params: default_params, format: :turbo_stream }
|
||||
|
||||
it do
|
||||
expect(second_tdc.reload.condition).to eq(empty_operator(empty, empty))
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(second_tdc))
|
||||
expect(assigns(:upper_coordinates)).to eq([first_coordinate])
|
||||
expect(assigns(:upper_tdcs)).to eq([first_coordinate.type_de_champ])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_row' do
|
||||
before do
|
||||
delete :delete_row, params: params.merge(row_index: 0)
|
||||
end
|
||||
before { delete :delete_row, params: params.merge(row_index: 0), format: :turbo_stream }
|
||||
|
||||
let(:params) { default_params.merge(type_de_champ: { condition_form: condition_form }) }
|
||||
|
||||
|
@ -76,20 +68,20 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
it do
|
||||
expect(second_tdc.reload.condition).to eq(nil)
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(second_tdc))
|
||||
expect(assigns(:upper_coordinates)).to eq([first_coordinate])
|
||||
expect(assigns(:upper_tdcs)).to eq([first_coordinate.type_de_champ])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
before do
|
||||
second_tdc.update(condition: empty_operator(empty, empty))
|
||||
delete :destroy, params: default_params
|
||||
delete :destroy, params: default_params, format: :turbo_stream
|
||||
end
|
||||
|
||||
it do
|
||||
expect(second_tdc.reload.condition).to eq(nil)
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(second_tdc))
|
||||
expect(assigns(:upper_coordinates)).to eq([first_coordinate])
|
||||
expect(assigns(:upper_tdcs)).to eq([first_coordinate.type_de_champ])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,7 +90,7 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
|
||||
before do
|
||||
second_tdc.update(condition: empty_operator(empty, empty))
|
||||
patch :change_targeted_champ, params: params
|
||||
patch :change_targeted_champ, params: params, format: :turbo_stream
|
||||
end
|
||||
|
||||
let(:params) { default_params.merge(type_de_champ: { condition_form: condition_form }) }
|
||||
|
@ -118,7 +110,7 @@ describe Administrateurs::ConditionsController, type: :controller do
|
|||
it do
|
||||
expect(second_tdc.reload.condition).to eq(ds_eq(champ_value(number_tdc.stable_id), constant(0)))
|
||||
expect(assigns(:coordinate)).to eq(procedure.draft_revision.coordinate_for(second_tdc))
|
||||
expect(assigns(:upper_coordinates)).to eq([first_coordinate])
|
||||
expect(assigns(:upper_tdcs)).to eq([first_coordinate.type_de_champ])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue