From 8e1cfd50dd615e284ba6944f62e5eda7a602230c Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 4 Jul 2024 20:59:35 +0200 Subject: [PATCH 1/7] feat(procedure): improve dossier_for_preview with last dossier, excluding hidden by user --- app/models/procedure.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 43512a928..d55d239a2 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1007,10 +1007,12 @@ class Procedure < ApplicationRecord def dossier_for_preview(user) # Try to use a preview or a dossier filled by current user - dossiers.where(for_procedure_preview: true).or(dossiers.not_brouillon) + dossiers.where(for_procedure_preview: true).or(dossiers.visible_by_administration) .order(Arel.sql("CASE WHEN user_id = #{user.id} THEN 1 ELSE 0 END DESC, CASE WHEN state = 'accepte' THEN 1 ELSE 0 END DESC, - CASE WHEN for_procedure_preview = True THEN 1 ELSE 0 END DESC")) \ + CASE WHEN state = 'brouillon' THEN 0 ELSE 1 END DESC, + CASE WHEN for_procedure_preview = True THEN 1 ELSE 0 END DESC, + id DESC")) \ .first end From ae207ac2e635678fa5c3fd2ef393ee2c209c3b2f Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 4 Jul 2024 21:00:23 +0200 Subject: [PATCH 2/7] chore(attestation): link to new test dossier --- .../administrateurs/attestation_template_v2s/edit.html.haml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/administrateurs/attestation_template_v2s/edit.html.haml b/app/views/administrateurs/attestation_template_v2s/edit.html.haml index a8ffbc919..61c76a36d 100644 --- a/app/views/administrateurs/attestation_template_v2s/edit.html.haml +++ b/app/views/administrateurs/attestation_template_v2s/edit.html.haml @@ -127,7 +127,9 @@ %iframe.attestation-preview{ title: "Aperçu", src: admin_procedure_attestation_template_v2_path(@procedure, format: :pdf), data: { attestation_target: 'preview' } } %p.fr-hint-text L’aperçu est mis à jour automatiquement après chaque modification. - Pour générer un aperçu fidèle avec tous les champs et les dates, créez-vous un dossier et acceptez-le : l’aperçu l’utilisera. + Pour générer un aperçu fidèle avec champs et dates, + = link_to("créez-vous un dossier", new_dossier_path(procedure_id: @procedure, brouillon: true), **external_link_attributes) + et acceptez-le : l’aperçu l’utilisera. - if @procedure.feature_enabled?(:attestation_v2) && @attestation_template.draft? - content_for(:sticky_header) do From 09581ad028c73a0d1d1006601d5c1485c78feb22 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 4 Jul 2024 21:02:07 +0200 Subject: [PATCH 3/7] feat(attestation): render multiple drop down list as list --- .../multiple_drop_down_list_presentation.rb | 35 +++++++++++++++++++ .../multiple_drop_down_list_type_de_champ.rb | 2 +- app/services/tiptap_service.rb | 7 +++- ...ltiple_drop_down_list_presentation_spec.rb | 27 ++++++++++++++ .../multiple_drop_down_list_champ_spec.rb | 5 +++ spec/services/tiptap_service_spec.rb | 18 ++++++++-- 6 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 app/models/champ_presentations/multiple_drop_down_list_presentation.rb create mode 100644 spec/models/champ_presentations/multiple_drop_down_list_presentation_spec.rb diff --git a/app/models/champ_presentations/multiple_drop_down_list_presentation.rb b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb new file mode 100644 index 000000000..21290193e --- /dev/null +++ b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class ChampPresentations::MultipleDropDownListPresentation + attr_reader :selected_options + + def initialize(selected_options) + @selected_options = selected_options + end + + def to_s + selected_options.join(', ') + end + + def to_tiptap_node + { + type: 'bulletList', + content: selected_options.map do |text| + { + type: 'listItem', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text: text + } + ] + } + ] + } + end + } + end +end diff --git a/app/models/types_de_champ/multiple_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/multiple_drop_down_list_type_de_champ.rb index 9a4b54679..2e8adf47d 100644 --- a/app/models/types_de_champ/multiple_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/multiple_drop_down_list_type_de_champ.rb @@ -7,7 +7,7 @@ class TypesDeChamp::MultipleDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampB end def champ_value_for_tag(champ, path = :value) - champ.selected_options.join(', ') + ChampPresentations::MultipleDropDownListPresentation.new(champ.selected_options) end def champ_value_for_export(champ, path = :value) diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index d86415d93..6fd0a4e35 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -90,7 +90,12 @@ class TiptapService text end in type: 'mention', attrs: { id: }, **rest - text = substitutions.fetch(id) { "--#{id}--" } + text_or_representation = substitutions.fetch(id) { "--#{id}--" } + text = if text_or_representation.respond_to?(:to_tiptap_node) + node_to_html(text_or_representation.to_tiptap_node, substitutions, level + 1) + else + text_or_representation + end if rest[:marks].present? apply_marks(text, rest[:marks]) diff --git a/spec/models/champ_presentations/multiple_drop_down_list_presentation_spec.rb b/spec/models/champ_presentations/multiple_drop_down_list_presentation_spec.rb new file mode 100644 index 000000000..5a23f6ae1 --- /dev/null +++ b/spec/models/champ_presentations/multiple_drop_down_list_presentation_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +describe ChampPresentations::MultipleDropDownListPresentation do + let(:options) { ["Option 1", "Option 2", "Option 3"] } + let(:representation) { described_class.new(options) } + + describe '#to_s' do + it 'returns a comma-separated string of options' do + expect(representation.to_s).to eq("Option 1, Option 2, Option 3") + end + end + + describe '#to_tiptap_node' do + it 'returns the correct node structure' do + expected_node = { + type: "bulletList", + content: [ + { content: [{ content: [{ :text => "Option 1", type: "text" }], type: "paragraph" }], type: "listItem" }, + { content: [{ content: [{ :text => "Option 2", type: "text" }], type: "paragraph" }], type: "listItem" }, + { content: [{ content: [{ :text => "Option 3", type: "text" }], type: "paragraph" }], type: "listItem" } + ] + } + + expect(representation.to_tiptap_node).to eq(expected_node) + end + end +end diff --git a/spec/models/champs/multiple_drop_down_list_champ_spec.rb b/spec/models/champs/multiple_drop_down_list_champ_spec.rb index 7702f9494..6ee9805c3 100644 --- a/spec/models/champs/multiple_drop_down_list_champ_spec.rb +++ b/spec/models/champs/multiple_drop_down_list_champ_spec.rb @@ -84,4 +84,9 @@ describe Champs::MultipleDropDownListChamp do it { expect(champ.next_checkbox_id("val1")).to eq(nil) } end end + + describe "#for_tag" do + let(:value) { ["val1", "val2"] } + it { expect(champ.for_tag.to_s).to eq("val1, val2") } + end end diff --git a/spec/services/tiptap_service_spec.rb b/spec/services/tiptap_service_spec.rb index 93d6fc91c..669a70329 100644 --- a/spec/services/tiptap_service_spec.rb +++ b/spec/services/tiptap_service_spec.rb @@ -138,6 +138,19 @@ RSpec.describe TiptapService do } ] }, + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Langages de prédilection:' + }, + { + type: 'mention', + attrs: { id: 'languages', label: 'Langages' } + } + ] + }, { type: 'footer', content: [{ type: 'text', text: 'Footer' }] @@ -147,7 +160,7 @@ RSpec.describe TiptapService do end describe '.to_html' do - let(:substitutions) { { 'name' => 'Paul' } } + let(:substitutions) { { 'name' => 'Paul', 'languages' => ChampPresentations::MultipleDropDownListPresentation.new(['ruby', 'rust']) } } let(:html) do [ '
Left
Right
', @@ -158,6 +171,7 @@ RSpec.describe TiptapService do '

Bonjour Paul !

', '
  • Item 1

  • Item 2

', '
  1. Item 1

  2. Item 2

', + '

Langages de prédilection:

  • ruby

  • rust

', # TODO: fix this markup,
    should not be under

    '

    Footer
    ' ].join end @@ -191,7 +205,7 @@ RSpec.describe TiptapService do describe '#used_tags' do it 'returns used tags' do - expect(described_class.used_tags_and_libelle_for(json)).to eq(Set.new([['name', 'Nom']])) + expect(described_class.used_tags_and_libelle_for(json)).to eq(Set.new([['name', 'Nom'], ['languages', 'Langages']])) end end From c9956c4881d7d678f7e2d955792959a5b6dad697 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 25 Jul 2024 11:42:50 +0200 Subject: [PATCH 4/7] feat(attestation): better presentation of repetition champs --- app/assets/stylesheets/attestation.scss | 10 +++ .../repetition_presentation.rb | 58 +++++++++++++ app/models/champs/repetition_champ.rb | 8 -- .../repetition_type_de_champ.rb | 7 ++ app/services/tiptap_service.rb | 16 +++- .../repetition_presentation_spec.rb | 86 +++++++++++++++++++ spec/models/champs/repetition_champ_spec.rb | 35 ++++++++ spec/services/tiptap_service_spec.rb | 34 ++++++++ 8 files changed, 244 insertions(+), 10 deletions(-) create mode 100644 app/models/champ_presentations/repetition_presentation.rb create mode 100644 spec/models/champ_presentations/repetition_presentation_spec.rb create mode 100644 spec/models/champs/repetition_champ_spec.rb diff --git a/app/assets/stylesheets/attestation.scss b/app/assets/stylesheets/attestation.scss index e01a9168b..33cb38c48 100644 --- a/app/assets/stylesheets/attestation.scss +++ b/app/assets/stylesheets/attestation.scss @@ -178,4 +178,14 @@ bottom: 0; } } + + .tdc-repetition li { + margin-bottom: 5mm; + + dl { + display: grid; + grid-template-columns: auto 1fr; + gap: 1mm 5mm; + } + } } diff --git a/app/models/champ_presentations/repetition_presentation.rb b/app/models/champ_presentations/repetition_presentation.rb new file mode 100644 index 000000000..6a9c2bcb6 --- /dev/null +++ b/app/models/champ_presentations/repetition_presentation.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +class ChampPresentations::RepetitionPresentation + attr_reader :libelle + attr_reader :rows + + def initialize(libelle, rows) + @libelle = libelle + @rows = rows + end + + def to_s + ([libelle] + rows.map do |champs| + champs.map do |champ| + "#{champ.libelle} : #{champ}" + end.join("\n") + end).join("\n\n") + end + + def to_tiptap_node + { + type: 'orderedList', + attrs: { class: 'tdc-repetition' }, + content: rows.map do |champs| + { + type: 'listItem', + content: [ + { + type: 'descriptionList', + content: champs.map do |champ| + [ + { + type: 'descriptionTerm', + content: [ + { + type: 'text', + text: champ.libelle + } + ] + }, + { + type: 'descriptionDetails', + content: [ + { + type: 'text', + text: champ.to_s + } + ] + } + ] + end.flatten + } + ] + } + end + } + end +end diff --git a/app/models/champs/repetition_champ.rb b/app/models/champs/repetition_champ.rb index 1bae90913..7ea9d83cd 100644 --- a/app/models/champs/repetition_champ.rb +++ b/app/models/champs/repetition_champ.rb @@ -44,14 +44,6 @@ class Champs::RepetitionChamp < Champ # The user cannot enter any information here so it doesn’t make much sense to search end - def for_tag(path = :value) - ([libelle] + rows.map do |champs| - champs.map do |champ| - "#{champ.libelle} : #{champ}" - end.join("\n") - end).join("\n\n") - end - def rows_for_export row_ids.map.with_index(1) do |row_id, index| Champs::RepetitionChamp::Row.new(index:, row_id:, dossier:) diff --git a/app/models/types_de_champ/repetition_type_de_champ.rb b/app/models/types_de_champ/repetition_type_de_champ.rb index 492cfa0f2..740e572b1 100644 --- a/app/models/types_de_champ/repetition_type_de_champ.rb +++ b/app/models/types_de_champ/repetition_type_de_champ.rb @@ -1,6 +1,13 @@ # frozen_string_literal: true class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase + def self.champ_value_for_tag(champ, path = :value) + return nil if path != :value + return champ_default_value if champ.rows.blank? + + ChampPresentations::RepetitionPresentation.new(champ.libelle, champ.rows) + end + def estimated_fill_duration(revision) estimated_rows_in_repetition = 2.5 diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index 6fd0a4e35..a55644353 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -79,10 +79,16 @@ class TiptapService "#{children(content, substitutions, level + 1)}" in type: 'bulletList', content: "
      #{children(content, substitutions, level + 1)}
    " - in type: 'orderedList', content: - "
      #{children(content, substitutions, level + 1)}
    " + in type: 'orderedList', content:, **rest + "#{children(content, substitutions, level + 1)}" in type: 'listItem', content: "
  • #{children(content, substitutions, level + 1)}
  • " + in type: 'descriptionList', content: + "
    #{children(content, substitutions, level + 1)}
    " + in type: 'descriptionTerm', content: + "
    #{children(content, substitutions, level + 1)}
    " + in type: 'descriptionDetails', content: + "
    #{children(content, substitutions, level + 1)}
    " in type: 'text', text:, **rest if rest[:marks].present? apply_marks(text, rest[:marks]) @@ -115,6 +121,12 @@ class TiptapService end end + def class_list(attrs) + if attrs.present? && attrs[:class].present? + " class=\"#{attrs[:class]}\"" + end + end + def apply_marks(text, marks) marks.reduce(text) do |text, mark| case mark diff --git a/spec/models/champ_presentations/repetition_presentation_spec.rb b/spec/models/champ_presentations/repetition_presentation_spec.rb new file mode 100644 index 000000000..de815b327 --- /dev/null +++ b/spec/models/champ_presentations/repetition_presentation_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +describe ChampPresentations::RepetitionPresentation do + let(:libelle) { "Langages de programmation" } + let(:procedure) { + create(:procedure, types_de_champ_public: [ + { + type: :repetition, + children: [ + { type: :text, libelle: "nom" }, + { type: :integer_number, libelle: "stars" } + ] + } + ]) + } + + let(:dossier) { create(:dossier, procedure:) } + + before do + nom, stars = dossier.champs[0].rows.first + nom.update(value: "ruby") + stars.update(value: 5) + + nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision) + nom.update(value: "rust") + stars.update(value: 4) + end + + let(:representation) { described_class.new(libelle, dossier.champs[0].reload.rows) } + + describe '#to_s' do + it 'returns a key-value representation' do + expect(representation.to_s).to eq( + <<~TXT.strip + Langages de programmation + + nom : ruby + stars : 5 + + nom : rust + stars : 4 + TXT + ) + end + end + + describe '#to_tiptap_node' do + it 'returns the correct HTML structure, without libelle' do + expected_node = { + type: "orderedList", + attrs: { class: "tdc-repetition" }, + content: [ + { + type: "listItem", + content: [ + { + type: "descriptionList", + content: [ + { content: [{ text: "nom", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "ruby", type: "text" }], type: "descriptionDetails" }, + { content: [{ text: "stars", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "5", type: "text" }], type: "descriptionDetails" } + ] + } + ] + }, { + type: "listItem", + content: [ + { + type: "descriptionList", + content: [ + { content: [{ text: "nom", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "rust", type: "text" }], type: "descriptionDetails" }, + { content: [{ text: "stars", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "4", type: "text" }], type: "descriptionDetails" } + ] + } + ] + } + ] + } + + expect(representation.to_tiptap_node).to eq(expected_node) + end + end +end diff --git a/spec/models/champs/repetition_champ_spec.rb b/spec/models/champs/repetition_champ_spec.rb new file mode 100644 index 000000000..d63dec474 --- /dev/null +++ b/spec/models/champs/repetition_champ_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +describe Champs::RepetitionChamp do + let(:procedure) { + create(:procedure, + types_de_champ_public: [ + { + type: :repetition, + children: [{ type: :text, libelle: "Ext" }], libelle: "Languages" + } + ]) + } + let(:dossier) { create(:dossier, procedure:) } + let(:champ) { dossier.champs.first } + + describe "#for_tag" do + before do + champ.rows[0][0].update(value: "rb") + end + + it "can render as string" do + expect(champ.for_tag.to_s).to eq( + <<~TXT.strip + Languages + + Ext : rb + TXT + ) + end + + it "as tiptap node" do + expect(champ.for_tag.to_tiptap_node).to include(type: 'orderedList') + end + end +end diff --git a/spec/services/tiptap_service_spec.rb b/spec/services/tiptap_service_spec.rb index 669a70329..287e76985 100644 --- a/spec/services/tiptap_service_spec.rb +++ b/spec/services/tiptap_service_spec.rb @@ -201,6 +201,40 @@ RSpec.describe TiptapService do expect(described_class.new.to_html(json, substitutions)).to eq("

    The Title

    First paragraph

    ") end end + + context 'ordered list with custom classes' do + let(:json) do + { + type: 'doc', + content: [ + { + type: 'orderedList', + attrs: { class: "my-class" }, + content: [ + { + type: 'listItem', + content: [ + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Item 1' + } + ] + } + ] + } + ] + } + ] + } + end + + it "set class attribute" do + expect(described_class.new.to_html(json, substitutions)).to eq('
    1. Item 1

    ') + end + end end describe '#used_tags' do From 4db4cf1513012ef2f3726083d4d45b7f874fa44d Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Fri, 30 Aug 2024 13:00:13 +0200 Subject: [PATCH 5/7] fix(attestation): don't render block levels presentation elements into a p --- .../champ_presentations/base_presentation.rb | 9 +++++++++ .../multiple_drop_down_list_presentation.rb | 2 +- .../repetition_presentation.rb | 2 +- app/services/tiptap_service.rb | 18 ++++++++++++++---- spec/services/tiptap_service_spec.rb | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 app/models/champ_presentations/base_presentation.rb diff --git a/app/models/champ_presentations/base_presentation.rb b/app/models/champ_presentations/base_presentation.rb new file mode 100644 index 000000000..6b043219b --- /dev/null +++ b/app/models/champ_presentations/base_presentation.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module ChampPresentations + class BasePresentation + def block_level? + true + end + end +end diff --git a/app/models/champ_presentations/multiple_drop_down_list_presentation.rb b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb index 21290193e..8660b06a2 100644 --- a/app/models/champ_presentations/multiple_drop_down_list_presentation.rb +++ b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ChampPresentations::MultipleDropDownListPresentation +class ChampPresentations::MultipleDropDownListPresentation < ChampPresentations::BasePresentation attr_reader :selected_options def initialize(selected_options) diff --git a/app/models/champ_presentations/repetition_presentation.rb b/app/models/champ_presentations/repetition_presentation.rb index 6a9c2bcb6..41bf2c2ad 100644 --- a/app/models/champ_presentations/repetition_presentation.rb +++ b/app/models/champ_presentations/repetition_presentation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ChampPresentations::RepetitionPresentation +class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePresentation attr_reader :libelle attr_reader :rows diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index a55644353..1779f827d 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -96,11 +96,11 @@ class TiptapService text end in type: 'mention', attrs: { id: }, **rest - text_or_representation = substitutions.fetch(id) { "--#{id}--" } - text = if text_or_representation.respond_to?(:to_tiptap_node) - node_to_html(text_or_representation.to_tiptap_node, substitutions, level + 1) + text_or_presentation = substitutions.fetch(id) { "--#{id}--" } + text = if text_or_presentation.respond_to?(:to_tiptap_node) + handle_presentation_node(text_or_presentation, substitutions, level + 1) else - text_or_representation + text_or_presentation end if rest[:marks].present? @@ -113,6 +113,16 @@ class TiptapService end end + def handle_presentation_node(presentation, substitutions, level) + node = presentation.to_tiptap_node + content = node_to_html(node, substitutions, level) + if presentation.block_level? + "

    #{content}

    " + else + content + end + end + def text_align(attrs) if attrs.present? && attrs[:textAlign].present? " style=\"text-align: #{attrs[:textAlign]}\"" diff --git a/spec/services/tiptap_service_spec.rb b/spec/services/tiptap_service_spec.rb index 287e76985..86ae1bbb2 100644 --- a/spec/services/tiptap_service_spec.rb +++ b/spec/services/tiptap_service_spec.rb @@ -171,7 +171,7 @@ RSpec.describe TiptapService do '

    Bonjour Paul !

    ', '
    • Item 1

    • Item 2

    ', '
    1. Item 1

    2. Item 2

    ', - '

    Langages de prédilection:

    • ruby

    • rust

    ', # TODO: fix this markup,
      should not be under

      + '

      Langages de prédilection:

      • ruby

      • rust

      ', # TODO: remove empty

      ? '

      Footer
      ' ].join end From 9f9720d65beca8e21a3791ca23e096827de29aab Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 4 Sep 2024 15:04:07 +0200 Subject: [PATCH 6/7] fix(attestation): delete empty paragraphs --- app/services/tiptap_service.rb | 2 +- spec/services/tiptap_service_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index 1779f827d..ee50bb458 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -18,7 +18,7 @@ class TiptapService def to_html(node, substitutions = {}) return '' if node.nil? - children(node[:content], substitutions, 0) + children(node[:content], substitutions, 0).gsub('

      ', '') end def to_texts_and_tags(node, substitutions = {}) diff --git a/spec/services/tiptap_service_spec.rb b/spec/services/tiptap_service_spec.rb index 86ae1bbb2..254cd6751 100644 --- a/spec/services/tiptap_service_spec.rb +++ b/spec/services/tiptap_service_spec.rb @@ -171,7 +171,7 @@ RSpec.describe TiptapService do '

      Bonjour Paul !

      ', '
      • Item 1

      • Item 2

      ', '
      1. Item 1

      2. Item 2

      ', - '

      Langages de prédilection:

      • ruby

      • rust

      ', # TODO: remove empty

      ? + '

      Langages de prédilection:

      • ruby

      • rust

      ', '
      Footer
      ' ].join end From 247bb6f8c6a76b61bd6c9cb953e68258385eb483 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 4 Sep 2024 17:32:21 +0200 Subject: [PATCH 7/7] refactor(attestation): hide libelle of empty repetitions --- app/assets/stylesheets/attestation.scss | 8 ++++++- .../repetition_presentation.rb | 3 ++- app/services/tiptap_service.rb | 4 ++-- .../repetition_presentation_spec.rb | 23 ++++++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/attestation.scss b/app/assets/stylesheets/attestation.scss index 33cb38c48..7af3840f3 100644 --- a/app/assets/stylesheets/attestation.scss +++ b/app/assets/stylesheets/attestation.scss @@ -181,11 +181,17 @@ .tdc-repetition li { margin-bottom: 5mm; + padding-left: 3mm; dl { display: grid; grid-template-columns: auto 1fr; - gap: 1mm 5mm; + gap: 1mm 10mm; + } + + .invisible { + visibility: hidden; + height: 0; } } } diff --git a/app/models/champ_presentations/repetition_presentation.rb b/app/models/champ_presentations/repetition_presentation.rb index 41bf2c2ad..000f74430 100644 --- a/app/models/champ_presentations/repetition_presentation.rb +++ b/app/models/champ_presentations/repetition_presentation.rb @@ -31,13 +31,14 @@ class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePrese [ { type: 'descriptionTerm', + attrs: champ.blank? ? { class: 'invisible' } : nil, # still render libelle so width & alignment are preserved content: [ { type: 'text', text: champ.libelle } ] - }, + }.compact, { type: 'descriptionDetails', content: [ diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index ee50bb458..c63ee7f0a 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -85,8 +85,8 @@ class TiptapService "
    • #{children(content, substitutions, level + 1)}
    • " in type: 'descriptionList', content: "
      #{children(content, substitutions, level + 1)}
      " - in type: 'descriptionTerm', content: - "
      #{children(content, substitutions, level + 1)}
      " + in type: 'descriptionTerm', content:, **rest + "#{children(content, substitutions, level + 1)}" in type: 'descriptionDetails', content: "
      #{children(content, substitutions, level + 1)}
      " in type: 'text', text:, **rest diff --git a/spec/models/champ_presentations/repetition_presentation_spec.rb b/spec/models/champ_presentations/repetition_presentation_spec.rb index de815b327..37c7fec5a 100644 --- a/spec/models/champ_presentations/repetition_presentation_spec.rb +++ b/spec/models/champ_presentations/repetition_presentation_spec.rb @@ -21,6 +21,9 @@ describe ChampPresentations::RepetitionPresentation do nom.update(value: "ruby") stars.update(value: 5) + nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision) + nom.update(value: "js") + nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision) nom.update(value: "rust") stars.update(value: 4) @@ -37,6 +40,9 @@ describe ChampPresentations::RepetitionPresentation do nom : ruby stars : 5 + nom : js + stars :#{' '} + nom : rust stars : 4 TXT @@ -63,7 +69,22 @@ describe ChampPresentations::RepetitionPresentation do ] } ] - }, { + }, + { + type: "listItem", + content: [ + { + type: "descriptionList", + content: [ + { content: [{ text: "nom", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "js", type: "text" }], type: "descriptionDetails" }, + { content: [{ text: "stars", type: "text" }], type: "descriptionTerm", attrs: { class: "invisible" } }, + { content: [{ text: "", type: "text" }], type: "descriptionDetails" } + ] + } + ] + }, + { type: "listItem", content: [ {