From 6eaf870cbfd78e474eed7d9bf2f092ed260b1673 Mon Sep 17 00:00:00 2001 From: mfo Date: Wed, 19 Jun 2024 18:19:52 +0200 Subject: [PATCH 1/2] feat(administrateurs/procedure#annotations): add summary --- app/models/procedure.rb | 6 +++- .../procedures/_champs_summary.html.haml | 6 ++-- .../procedures/annotations.html.haml | 1 + .../procedures/champs.html.haml | 2 +- .../types_de_champ/_insert.turbo_stream.haml | 2 +- .../administrateurs/annotations_spec.rb | 33 ++++++++++++++++--- .../administrateurs/types_de_champ_spec.rb | 7 +++- 7 files changed, 46 insertions(+), 11 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7995bd49a..11f422718 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1002,10 +1002,14 @@ class Procedure < ApplicationRecord lien_dpo.present? && lien_dpo.match?(/@/) end - def header_sections + def draft_revision_header_sections_public draft_revision.revision_types_de_champ_public.filter { _1.type_de_champ.header_section? } end + def draft_revision_header_sections_private + draft_revision.revision_types_de_champ_private.filter { _1.type_de_champ.header_section? } + end + 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) diff --git a/app/views/administrateurs/procedures/_champs_summary.html.haml b/app/views/administrateurs/procedures/_champs_summary.html.haml index 2db332926..8c662691b 100644 --- a/app/views/administrateurs/procedures/_champs_summary.html.haml +++ b/app/views/administrateurs/procedures/_champs_summary.html.haml @@ -1,8 +1,8 @@ -#summary{ class: @procedure.header_sections.present? ? 'fr-col-12 fr-col-md-3' : '' } - - if @procedure.header_sections.present? +#summary{ class: header_sections.present? ? 'fr-col-12 fr-col-md-3' : '' } + - if header_sections.present? %nav.fr-sidemenu.sticky.fr-hidden.fr-unhidden-md{ "aria-labelledby" => "fr-summary-title", role: "navigation" } %ul.fr-sidemenu__list - - @procedure.header_sections.each do |header| + - header_sections.each do |header| %li.fr-sidemenu__item - level = header.type_de_champ.header_section_level_value.to_i - if level == 1 diff --git a/app/views/administrateurs/procedures/annotations.html.haml b/app/views/administrateurs/procedures/annotations.html.haml index a903ae638..b9a1c24a0 100644 --- a/app/views/administrateurs/procedures/annotations.html.haml +++ b/app/views/administrateurs/procedures/annotations.html.haml @@ -7,6 +7,7 @@ %h1.fr-h2 Annotations privées = render NestedForms::FormOwnerComponent.new .fr-grid-row + = render partial: 'champs_summary', locals: { header_sections: @procedure.draft_revision_header_sections_private } .fr-col = render TypesDeChampEditor::EditorComponent.new(revision: @procedure.draft_revision, is_annotation: true) diff --git a/app/views/administrateurs/procedures/champs.html.haml b/app/views/administrateurs/procedures/champs.html.haml index 9f29496ca..1c2da20dd 100644 --- a/app/views/administrateurs/procedures/champs.html.haml +++ b/app/views/administrateurs/procedures/champs.html.haml @@ -11,7 +11,7 @@ = render NestedForms::FormOwnerComponent.new .fr-grid-row - = render partial: 'champs_summary' + = render partial: 'champs_summary', locals: { header_sections: @procedure.draft_revision_header_sections_public } .fr-col = render TypesDeChampEditor::EditorComponent.new(revision: @procedure.draft_revision, is_annotation: false) 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 ad121dedd..8aa818989 100644 --- a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml @@ -14,7 +14,7 @@ = turbo_stream.replace 'errors-summary', render(Procedure::ErrorsSummary.new(procedure: @procedure, validation_context: @coordinate&.private? ? :types_de_champ_private_editor : :types_de_champ_public_editor)) -= turbo_stream.replace 'summary', render(partial: 'administrateurs/procedures/champs_summary') += turbo_stream.replace 'summary', render(partial: 'administrateurs/procedures/champs_summary', locals: { header_sections: @coordinate&.private? ? @procedure.draft_revision_header_sections_private : @procedure.draft_revision_header_sections_public}) - unless flash.alert = turbo_stream.show 'autosave-notice' diff --git a/spec/system/administrateurs/annotations_spec.rb b/spec/system/administrateurs/annotations_spec.rb index bb053b43d..6f5ac50e5 100644 --- a/spec/system/administrateurs/annotations_spec.rb +++ b/spec/system/administrateurs/annotations_spec.rb @@ -1,4 +1,5 @@ describe 'As an administrateur I can edit annotation', js: true do + include ActionView::RecordIdentifier let(:administrateur) { procedure.administrateurs.first } let(:procedure) { create(:procedure) } @@ -7,11 +8,35 @@ describe 'As an administrateur I can edit annotation', js: true do visit annotations_admin_procedure_path(procedure) end - scenario "adding a new champ" do + scenario 'with private tdc, having invalid order, it pops up errors summary' do click_on 'Ajouter une annotation' - select('Carte', from: 'Type de champ') - # ensure UI update is ok - check 'Cadastres' + select('Titre de section', from: 'Type de champ') + wait_until { procedure.reload.active_revision.types_de_champ_private.first&.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } + first_header = procedure.active_revision.types_de_champ_private.first + select('Titre de niveau 1', from: dom_id(first_header, :header_section_level)) + + within(find('.type-de-champ-add-button', match: :first)) { + click_on 'Ajouter une annotation' + } + + wait_until { procedure.reload.active_revision.types_de_champ_private.count == 2 } + second_header = procedure.active_revision.types_de_champ_private.last + select('Titre de section', from: dom_id(second_header, :type_champ)) + wait_until { procedure.reload.active_revision.types_de_champ_private.last&.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } + select('Titre de niveau 2', from: dom_id(second_header, :header_section_level)) + + within(".types-de-champ-block li:first-child") do + page.accept_alert do + click_on 'Supprimer' + end + end + + expect(page).to have_content("devrait être précédé d'un titre de niveau 1") + + # check summary + procedure.reload.active_revision.types_de_champ_private.each do |header_section| + expect(page).to have_link(header_section.libelle) + end end end diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index 28023d9b8..c63335e8a 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -206,7 +206,7 @@ describe 'As an administrateur I can edit types de champ', js: true do end context 'header section' do - scenario 'invalid order, it pops up errors summary' do + scenario 'with public tdc, having invalid order, it pops up errors summary' do add_champ select('Titre de section', from: 'Type de champ') wait_until { procedure.reload.active_revision.types_de_champ_public.first&.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } @@ -229,6 +229,11 @@ describe 'As an administrateur I can edit types de champ', js: true do end end expect(page).to have_content("devrait être précédé d'un titre de niveau 1") + + # check summary refresh + procedure.reload.active_revision.types_de_champ_private.each do |header_section| + expect(page).to have_link(header_section.libelle) + end end end From 25ffd902ff20cf223f580b87dd0186b0857f8492 Mon Sep 17 00:00:00 2001 From: mfo Date: Thu, 20 Jun 2024 14:42:55 +0200 Subject: [PATCH 2/2] feat(admin/annotations): add link to show annotations history --- app/views/administrateurs/procedures/annotations.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/administrateurs/procedures/annotations.html.haml b/app/views/administrateurs/procedures/annotations.html.haml index b9a1c24a0..efd7199d7 100644 --- a/app/views/administrateurs/procedures/annotations.html.haml +++ b/app/views/administrateurs/procedures/annotations.html.haml @@ -4,7 +4,11 @@ ['Annotations privées']], preview: true } .fr-container - %h1.fr-h2 Annotations privées + .flex.justify-between.align-center.fr-mb-3w + %h1.fr-h2 Annotations privées + - if @procedure.revised? + = link_to "Voir l'historique des modifications des annotations", modifications_admin_procedure_path(@procedure), class: 'fr-link' + = render NestedForms::FormOwnerComponent.new .fr-grid-row = render partial: 'champs_summary', locals: { header_sections: @procedure.draft_revision_header_sections_private }