From 2df9d8ba9891836113ef65295a16d7cf74ecf1fc Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 8 Jul 2022 11:04:58 +0200 Subject: [PATCH] use condition_condition_component in editor --- .../block_component/block_component.html.haml | 4 ++-- app/components/types_de_champ_editor/champ_component.rb | 3 ++- .../champ_component/champ_component.html.haml | 2 ++ .../types_de_champ/_insert.turbo_stream.haml | 9 +++++++-- .../types_de_champ/create.turbo_stream.haml | 2 +- .../types_de_champ/destroy.turbo_stream.haml | 5 +++++ .../types_de_champ/move_down.turbo_stream.haml | 2 +- .../types_de_champ/move_up.turbo_stream.haml | 2 +- .../types_de_champ/update.turbo_stream.haml | 7 ++++++- 9 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/components/types_de_champ_editor/block_component/block_component.html.haml b/app/components/types_de_champ_editor/block_component/block_component.html.haml index a1b9a7eed..59d07c80a 100644 --- a/app/components/types_de_champ_editor/block_component/block_component.html.haml +++ b/app/components/types_de_champ_editor/block_component/block_component.html.haml @@ -1,3 +1,3 @@ %ul.types-de-champ-block{ id: block_id, data: sortable_options } - - @coordinates.each do |coordinate| - = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate) + - @coordinates.each.with_index do |coordinate, i| + = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: @coordinates.take(i)) diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index 6cd02e2ee..0dd631504 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -1,7 +1,8 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent - def initialize(coordinate:, focused: false) + def initialize(coordinate:, upper_coordinates:, focused: false) @coordinate = coordinate @focused = focused + @upper_coordinates = upper_coordinates end private diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index 5d455e87d..ec2aaff5d 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -83,3 +83,5 @@ .editor-block.flex-grow.cell = render TypesDeChampEditor::BlockComponent.new(block: coordinate, coordinates: coordinate.revision_types_de_champ) = render TypesDeChampEditor::AddChampButtonComponent.new(revision: coordinate.revision, parent: coordinate, is_annotation: coordinate.private?) + + = render(TypesDeChampEditor::ConditionsComponent.new(tdc: type_de_champ, upper_tdcs: @upper_coordinates.map(&:type_de_champ), procedure_id: procedure.id)) diff --git a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml index d6c3e2276..dcfd571ce 100644 --- a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml @@ -2,8 +2,13 @@ - if sibling.present? = turbo_stream.after dom_id(sibling, :type_de_champ_editor) do - = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, focused: true) + = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: upper_coordinates, focused: true) - else = turbo_stream.prepend dom_id(coordinate.block, :types_de_champ_editor_block) do - = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, focused: true) + = render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: upper_coordinates, focused: true) = turbo_stream.dispatch 'sortable:sort' + +- if @lower_coordinates_and_dep.present? + - @lower_coordinates_and_dep.each do |other_coordinate, other_upper_coordinates| + = turbo_stream.morph dom_id(other_coordinate, :type_de_champ_editor) do + = render TypesDeChampEditor::ChampComponent.new(coordinate: other_coordinate, upper_coordinates: other_upper_coordinates) diff --git a/app/views/administrateurs/types_de_champ/create.turbo_stream.haml b/app/views/administrateurs/types_de_champ/create.turbo_stream.haml index 9f08077a1..958466e7f 100644 --- a/app/views/administrateurs/types_de_champ/create.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/create.turbo_stream.haml @@ -1,2 +1,2 @@ - if @coordinate&.type_de_champ&.valid? - = render partial: 'insert', locals: { coordinate: @coordinate } + = render partial: 'insert', locals: { coordinate: @coordinate, upper_coordinates: @upper_coordinates } diff --git a/app/views/administrateurs/types_de_champ/destroy.turbo_stream.haml b/app/views/administrateurs/types_de_champ/destroy.turbo_stream.haml index 88038a9a9..e8c8de1fc 100644 --- a/app/views/administrateurs/types_de_champ/destroy.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/destroy.turbo_stream.haml @@ -2,3 +2,8 @@ = turbo_stream.dispatch 'sortable:sort' = turbo_stream.morph dom_id(@coordinate.revision, :estimated_fill_duration) do = render TypesDeChampEditor::EstimatedFillDurationComponent.new(revision: @coordinate.revision, is_annotation: @coordinate.private?) + +- if @lower_coordinates_and_dep.present? + - @lower_coordinates_and_dep.each do |other_coordinate, other_upper_coordinates| + = turbo_stream.morph dom_id(other_coordinate, :type_de_champ_editor) do + = render TypesDeChampEditor::ChampComponent.new(coordinate: other_coordinate, upper_coordinates: other_upper_coordinates) diff --git a/app/views/administrateurs/types_de_champ/move_down.turbo_stream.haml b/app/views/administrateurs/types_de_champ/move_down.turbo_stream.haml index e17f946fc..893fb25d8 100644 --- a/app/views/administrateurs/types_de_champ/move_down.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/move_down.turbo_stream.haml @@ -1,2 +1,2 @@ = turbo_stream.remove dom_id(@coordinate, :type_de_champ_editor) -= render partial: 'insert', locals: { coordinate: @coordinate } += render partial: 'insert', locals: { coordinate: @coordinate, upper_coordinates: @upper_coordinates } diff --git a/app/views/administrateurs/types_de_champ/move_up.turbo_stream.haml b/app/views/administrateurs/types_de_champ/move_up.turbo_stream.haml index e17f946fc..893fb25d8 100644 --- a/app/views/administrateurs/types_de_champ/move_up.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/move_up.turbo_stream.haml @@ -1,2 +1,2 @@ = turbo_stream.remove dom_id(@coordinate, :type_de_champ_editor) -= render partial: 'insert', locals: { coordinate: @coordinate } += render partial: 'insert', locals: { coordinate: @coordinate, upper_coordinates: @upper_coordinates } diff --git a/app/views/administrateurs/types_de_champ/update.turbo_stream.haml b/app/views/administrateurs/types_de_champ/update.turbo_stream.haml index 5809cd5f2..1f7de5784 100644 --- a/app/views/administrateurs/types_de_champ/update.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/update.turbo_stream.haml @@ -1,5 +1,10 @@ - if @coordinate&.type_de_champ&.valid? = turbo_stream.morph dom_id(@coordinate, :type_de_champ_editor) do - = render TypesDeChampEditor::ChampComponent.new(coordinate: @coordinate) + = render TypesDeChampEditor::ChampComponent.new(coordinate: @coordinate, upper_coordinates: @upper_coordinates) = turbo_stream.morph dom_id(@coordinate.revision, :estimated_fill_duration) do = render TypesDeChampEditor::EstimatedFillDurationComponent.new(revision: @coordinate.revision, is_annotation: @coordinate.private?) + +- if @lower_coordinates_and_dep.present? + - @lower_coordinates_and_dep.each do |other_coordinate, other_upper_coordinates| + = turbo_stream.morph dom_id(other_coordinate, :type_de_champ_editor) do + = render TypesDeChampEditor::ChampComponent.new(coordinate: other_coordinate, upper_coordinates: other_upper_coordinates)