From 2f66625f184b7a823bf5a5721647c989e4e1b8b3 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Feb 2019 12:38:33 +0100 Subject: [PATCH 01/13] Manager: improve dossier view --- app/dashboards/dossier_dashboard.rb | 4 ++-- app/fields/champ_collection_field.rb | 7 ++++++ app/models/champ.rb | 16 ++++++------- .../champ_collection_field/_show.html.haml | 24 +++++++++++++++++++ .../_show.html.haml | 9 +++++++ 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 app/fields/champ_collection_field.rb create mode 100644 app/views/fields/champ_collection_field/_show.html.haml diff --git a/app/dashboards/dossier_dashboard.rb b/app/dashboards/dossier_dashboard.rb index 456b3f3a4..698106704 100644 --- a/app/dashboards/dossier_dashboard.rb +++ b/app/dashboards/dossier_dashboard.rb @@ -16,7 +16,7 @@ class DossierDashboard < Administrate::BaseDashboard created_at: Field::DateTime, updated_at: Field::DateTime, hidden_at: Field::DateTime, - types_de_champ: TypesDeChampCollectionField + champs: ChampCollectionField }.freeze # COLLECTION_ATTRIBUTES @@ -38,7 +38,7 @@ class DossierDashboard < Administrate::BaseDashboard :state, :procedure, :user, - :types_de_champ, + :champs, :created_at, :updated_at, :hidden_at diff --git a/app/fields/champ_collection_field.rb b/app/fields/champ_collection_field.rb new file mode 100644 index 000000000..ed6dbe634 --- /dev/null +++ b/app/fields/champ_collection_field.rb @@ -0,0 +1,7 @@ +require "administrate/field/base" + +class ChampCollectionField < Administrate::Field::Base + def to_s + data + end +end diff --git a/app/models/champ.rb b/app/models/champ.rb index e0d7b35f1..c88e0fe3f 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -23,15 +23,15 @@ class Champ < ApplicationRecord end def mandatory_and_blank? - if mandatory? - case type_de_champ.type_champ - when TypeDeChamp.type_champs.fetch(:carte) - value.blank? || value == '[]' - else - value.blank? - end + mandatory? && blank? + end + + def blank? + case type_de_champ.type_champ + when TypeDeChamp.type_champs.fetch(:carte) + value.blank? || value == '[]' else - false + value.blank? end end diff --git a/app/views/fields/champ_collection_field/_show.html.haml b/app/views/fields/champ_collection_field/_show.html.haml new file mode 100644 index 000000000..f5528c9e9 --- /dev/null +++ b/app/views/fields/champ_collection_field/_show.html.haml @@ -0,0 +1,24 @@ +- if field.data.any? + %table.collection-data{ "aria-labelledby": "page-title" } + %thead + %tr + %td.cell-label Libelle + %td.cell-label Type de champ + %td.cell-label Rempli + %tbody + - field.data.each do |f| + %tr + %td.cell-data + = f.libelle + - if f.mandatory? + %span.mandatory{ style: 'color: #A10005;' } * + %td.cell-data + = I18n.t("activerecord.attributes.type_de_champ.type_champs.#{f.type_champ}") + + %td.cell-data + - if f.blank? + vide + - else + rempli +- else + Aucun diff --git a/app/views/fields/types_de_champ_collection_field/_show.html.haml b/app/views/fields/types_de_champ_collection_field/_show.html.haml index c54bb1c64..86b298e54 100644 --- a/app/views/fields/types_de_champ_collection_field/_show.html.haml +++ b/app/views/fields/types_de_champ_collection_field/_show.html.haml @@ -4,12 +4,21 @@ %tr %td.cell-label Libelle %td.cell-label Type de champ + %td.cell-label Rempli %tbody - field.data.order(:order_place).each do |f| %tr %td.cell-data = f.libelle + - if f.mandatory? + %span.mandatory{ style: 'color: #A10005;' } * %td.cell-data = I18n.t("activerecord.attributes.type_de_champ.type_champs.#{f.type_champ}") + + %td.cell-data + - if f.blank? + vide + - else + rempli - else Aucun From aad685bb79582dbcbb3782968f697f8ed07e8aea Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 19 Feb 2019 16:14:42 +0100 Subject: [PATCH 02/13] Show preview with correct type de champ options fix #3439 --- app/controllers/champs/carte_controller.rb | 15 ++++++--------- app/helpers/champ_helper.rb | 8 ++++++++ .../dossiers/editable_champs/_carte.html.haml | 2 +- .../new_administrateur/types_de_champ_spec.rb | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/controllers/champs/carte_controller.rb b/app/controllers/champs/carte_controller.rb index 5374c5111..d214f30d0 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -13,19 +13,16 @@ class Champs::CarteController < ApplicationController coordinates = params[:dossier][:champs_private_attributes][params[:position]][:value] end - if params[:champ_id].present? - @champ = Champ + @champ = if params[:champ_id].present? + Champ .joins(:dossier) .where(dossiers: { user_id: logged_user_ids }) .find(params[:champ_id]) else - @champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new( - type_champ: TypeDeChamp.type_champs.fetch(:carte), - options: { - quartiers_prioritaires: true, - cadastres: true - } - )) + TypeDeChamp + .joins(:procedure) + .where(procedures: { administrateur_id: logged_user_ids }) + .find(params[:type_de_champ_id]).champ.build end geo_areas = [] diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 573a8defe..ba376d8bb 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -9,4 +9,12 @@ module ChampHelper raw(champ.to_render_data.to_json) # rubocop:enable Rails/OutputSafety end + + def champ_carte_params(champ) + if champ.persisted? + { champ_id: champ.id } + else + { type_de_champ_id: champ.type_de_champ_id } + end + end end diff --git a/app/views/shared/dossiers/editable_champs/_carte.html.haml b/app/views/shared/dossiers/editable_champs/_carte.html.haml index eb218fa97..23c7c4e2e 100644 --- a/app/views/shared/dossiers/editable_champs/_carte.html.haml +++ b/app/views/shared/dossiers/editable_champs/_carte.html.haml @@ -8,4 +8,4 @@ = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, error: false } = form.hidden_field :value, - data: { remote: true, url: champs_carte_path(form.index), params: { champ_id: champ&.id }.to_query, method: 'post' } + data: { remote: true, url: champs_carte_path(form.index), params: champ_carte_params(champ).to_query, method: 'post' } diff --git a/spec/features/new_administrateur/types_de_champ_spec.rb b/spec/features/new_administrateur/types_de_champ_spec.rb index 1ad203998..801f3c070 100644 --- a/spec/features/new_administrateur/types_de_champ_spec.rb +++ b/spec/features/new_administrateur/types_de_champ_spec.rb @@ -117,4 +117,19 @@ feature 'As an administrateur I can edit types de champ', js: true do expect(page).to have_content('Supprimer', count: 3) end + + it "Add carte champ" do + select('Carte', from: 'procedure_types_de_champ_attributes_0_type_champ') + fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libellé de champ carte' + blur + check 'Quartiers prioritaires' + expect(page).to have_content('Formulaire enregistré') + + preview_window = window_opened_by { click_on 'Prévisualiser le formulaire' } + within_window(preview_window) do + expect(page).to have_content('libellé de champ carte') + expect(page).to have_content('Quartiers prioritaires') + expect(page).not_to have_content('Cadastres') + end + end end From 272a6b700d38587de4f1568d794c6bc2f406ed5f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 19 Feb 2019 15:47:42 +0100 Subject: [PATCH 03/13] Improve wording --- app/views/admin/procedures/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 34408d6a7..b51fcde0e 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -65,7 +65,7 @@ pour y accéder vous pouvez utiliser le lien : = link_to procedure_lien(@procedure), sanitize_url(procedure_lien(@procedure)), target: :blank %p - Tout personne ayant la connaissance de ce lien pourra ainsi remplir des dossiers sur votre démarche. + Tout personne ayant la connaissance de ce lien pourra ainsi remplir des dossiers de test sur votre démarche. %br %h4 Ce que vous pouvez faire lorsque vous êtes en test From 11078b7f71a6b433c38fb457ec54b28f594c61d9 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 19 Feb 2019 16:33:23 +0100 Subject: [PATCH 04/13] Add rake task to activate publish draft --- lib/tasks/support.rake | 24 ++++++++++++++ spec/lib/tasks/activate_publish_draft_spec.rb | 31 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 spec/lib/tasks/activate_publish_draft_spec.rb diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index 3c00b017d..6bf178709 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -130,4 +130,28 @@ namespace :support do user.update(email: new_email) end + + desc <<~EOD + Activate feature publish draft + EOD + task activate_publish_draft: :environment do + start_with = ENV['START_WITH'] + + administrateurs = Administrateur.where("email like ?", "#{start_with}%") + + rake_puts("Activating publish draft for #{administrateurs.count} administrateurs...") + + administrateurs.each do |a| + rake_puts("Activating publish draft for #{a.email}") + a.features["publish_draft"] = true + a.save + + a.procedures.brouillon.each do |p| + if p.path.nil? + p.path = SecureRandom.uuid + p.save + end + end + end + end end diff --git a/spec/lib/tasks/activate_publish_draft_spec.rb b/spec/lib/tasks/activate_publish_draft_spec.rb new file mode 100644 index 000000000..567fdefed --- /dev/null +++ b/spec/lib/tasks/activate_publish_draft_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'activate_publish_draft#clean' do + let(:rake_task) { Rake::Task['support:activate_publish_draft'] } + + let(:administrateur) { create(:administrateur) } + let!(:procedure) { create(:procedure, administrateur: administrateur) } + let!(:procedure2) { create(:simple_procedure, administrateur: administrateur) } + + before do + ENV['START_WITH'] = administrateur.email + rake_task.invoke + administrateur.reload + end + + after { rake_task.reenable } + + it 'activate feature for administrateur' do + expect(administrateur.features["publish_draft"]).to eq(true) + end + + it 'create a path for his brouillon procedure' do + expect(administrateur.procedures.brouillon.count).to eq(1) + expect(administrateur.procedures.brouillon.first.path).not_to eq(nil) + end + + it 'does not change the path of his published procedure' do + expect(administrateur.procedures.publiee.count).to eq(1) + expect(administrateur.procedures.publiee.first.path).to eq(procedure2.path) + end +end From 15e055ff3a5ed3586344fbad8b5e4e621577e381 Mon Sep 17 00:00:00 2001 From: philemon95 <40801449+philemon95@users.noreply.github.com> Date: Tue, 19 Feb 2019 15:52:45 +0100 Subject: [PATCH 05/13] add of links to FAQ + gitbook --- app/views/layouts/_footer.html.haml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 7ce15a032..667a2e5a7 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -10,3 +10,9 @@ = link_to 'CGU / Mentions légales', CGU_URL \- = contact_link 'Contact' + \- + = link_to 'FAQ', "https://faq.demarches-simplifiees.fr" + = Time.zone.now.year + \- + = link_to 'Documentation', "http://doc.demarches-simplifiees.fr" + = Time.zone.now.year From ab728466124241294966a60d65d8aa0e408ff1b0 Mon Sep 17 00:00:00 2001 From: philemon95 <40801449+philemon95@users.noreply.github.com> Date: Tue, 19 Feb 2019 16:07:14 +0100 Subject: [PATCH 06/13] Update _footer.html.haml --- app/views/layouts/_footer.html.haml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 667a2e5a7..331b30681 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -12,7 +12,5 @@ = contact_link 'Contact' \- = link_to 'FAQ', "https://faq.demarches-simplifiees.fr" - = Time.zone.now.year \- = link_to 'Documentation', "http://doc.demarches-simplifiees.fr" - = Time.zone.now.year From d159d72aab9c416d8b2a274eeac789ec1ae1ff82 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 18 Feb 2019 16:42:32 +0000 Subject: [PATCH 07/13] stylesheet: add a "small" button variant --- app/assets/stylesheets/new_design/buttons.scss | 5 +++++ app/views/root/patron.html.haml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index 5092221ff..8597e720a 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -100,6 +100,11 @@ } } + &.small { + line-height: 14px; + padding: 5px 10px 6px 10px; + } + &.large { font-size: 18px; line-height: 26px; diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index 048804ceb..2988473e2 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -78,6 +78,11 @@ = link_to ".button.without-continuation", "#", class: "button without-continuation" + %p + = link_to ".button.small", "#", class: "button small" + + = link_to ".button.small.primary", "#", class: "button small primary" + %p = link_to ".button.large", "#", class: "button large" From 62ef02183c067e94d5e5b892364afcc4495122e3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 18 Feb 2019 17:58:48 +0100 Subject: [PATCH 08/13] pj_link: add an "attachment" icon to the link --- .../champs/piece_justificative/_pj_link.html.haml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/views/shared/champs/piece_justificative/_pj_link.html.haml b/app/views/shared/champs/piece_justificative/_pj_link.html.haml index d808058a4..5e7fd5dc8 100644 --- a/app/views/shared/champs/piece_justificative/_pj_link.html.haml +++ b/app/views/shared/champs/piece_justificative/_pj_link.html.haml @@ -1,7 +1,13 @@ - pj = champ.piece_justificative_file -- if champ.virus_scan.present? - - if champ.virus_scan.safe? - = link_to pj.filename.to_s, url_for(pj), target: '_blank' + +.pj-link + - if champ.virus_scan.safe? || champ.virus_scan.blank? + = link_to url_for(pj), target: '_blank', title: "Télécharger la pièce jointe" do + %span.icon.attachment + = pj.filename.to_s + - if champ.virus_scan.blank? + (ce fichier n'a pas été analysé par notre antivirus, téléchargez-le avec précaution) + - else = pj.filename.to_s - if champ.virus_scan.pending? @@ -13,6 +19,3 @@ (virus détecté, merci d'envoyer un autre fichier) - else (virus détecté, le téléchargement de ce fichier est bloqué) -- else - = link_to pj.filename.to_s, url_for(pj), target: '_blank' - (ce fichier n'a pas été analysé par notre antivirus, téléchargez-le avec précaution) From ae5e8810a5476cc8004567cc1ad8e2dbe85ade21 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 18 Feb 2019 18:00:37 +0100 Subject: [PATCH 09/13] piece_justificative: style links as buttons, and improve layout --- .../editable_champs/piece_justificative.scss | 17 ++++++++++ app/assets/stylesheets/new_design/forms.scss | 8 ++--- .../_piece_justificative.html.haml | 34 +++++++++---------- 3 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss diff --git a/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss b/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss new file mode 100644 index 000000000..df4a68720 --- /dev/null +++ b/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss @@ -0,0 +1,17 @@ +@import "../constants"; + +.piece-justificative-actions { + display: flex; +} + +.piece-justificative-action { + margin-right: $default-spacer; + + .button { + text-transform: lowercase; + } +} + +.piece-justificative-input.hidden { + display: none; +} diff --git a/app/assets/stylesheets/new_design/forms.scss b/app/assets/stylesheets/new_design/forms.scss index 0e6954664..58547b25d 100644 --- a/app/assets/stylesheets/new_design/forms.scss +++ b/app/assets/stylesheets/new_design/forms.scss @@ -100,9 +100,9 @@ input[type=date], input[type=number], input[type=tel], - input[type=file], textarea, - select { + select, + .piece-justificative { display: block; margin-bottom: 2 * $default-padding; @@ -111,10 +111,6 @@ } } - .direct-upload { - margin-bottom: 2 * $default-padding; - } - .add-row { margin-bottom: 2 * $default-padding; } diff --git a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml index 95df8fb56..65daa61ea 100644 --- a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml +++ b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml @@ -1,24 +1,22 @@ - pj = champ.piece_justificative_file -- if champ.type_de_champ.piece_justificative_template.attached? - %p.edit-pj-template.mb-1 - Veuillez télécharger, remplir et joindre - = link_to('le modèle suivant', url_for(champ.type_de_champ.piece_justificative_template), target: '_blank') +.piece-justificative + - if champ.type_de_champ.piece_justificative_template.attached? + %p.edit-pj-template.mb-1 + Veuillez télécharger, remplir et joindre + = link_to('le modèle suivant', url_for(champ.type_de_champ.piece_justificative_template), target: '_blank') + + - if pj.attached? + .piece-justificative-actions{ id: "piece_justificative_#{champ.id}" } + .piece-justificative-action + = render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true } + .piece-justificative-action + - if champ.private? + = link_to 'Supprimer', gestionnaire_champ_purge_champ_piece_justificative_path(procedure_id: champ.dossier.procedure_id, dossier_id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger' + - else + = link_to 'Supprimer', champ_purge_champ_piece_justificative_path(id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger' -- if !pj.attached? - = form.file_field :piece_justificative_file, - id: "champs_#{champ.id}", - direct_upload: true -- else - %div{ id: "piece_justificative_#{champ.id}" } - = render partial: "shared/champs/piece_justificative/pj_link", locals: { champ: champ, user_can_upload: true } - %br - - if champ.private? - = link_to 'supprimer', gestionnaire_champ_purge_champ_piece_justificative_path(procedure_id: champ.dossier.procedure_id, dossier_id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete - - else - = link_to 'supprimer', champ_purge_champ_piece_justificative_path(id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete - %br - Modifier : = form.file_field :piece_justificative_file, id: "champs_#{champ.id}", + class: "piece-justificative-input", direct_upload: true From 1f636e4d598c67e9711f6a6ceda7523fe671ed63 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Feb 2019 13:29:06 +0000 Subject: [PATCH 10/13] piece_justificative: toggle file upload control --- .../editable_champs/piece_justificative.scss | 1 + app/javascript/packs/application.js | 1 + app/javascript/shared/toggle-target.js | 20 +++++++++++++++++++ .../purge_champ_piece_justificative.js.erb | 3 +++ .../_piece_justificative.html.haml | 4 +++- 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/javascript/shared/toggle-target.js diff --git a/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss b/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss index df4a68720..906f9dc6c 100644 --- a/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss +++ b/app/assets/stylesheets/new_design/editable_champs/piece_justificative.scss @@ -2,6 +2,7 @@ .piece-justificative-actions { display: flex; + margin-bottom: $default-spacer; } .piece-justificative-action { diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index df838bc5a..8bac1343f 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -12,6 +12,7 @@ import '../shared/safari-11-file-xhr-workaround'; import '../shared/autocomplete'; import '../shared/remote-input'; import '../shared/franceconnect'; +import '../shared/toggle-target'; import '../new_design/spinner'; import '../new_design/dropdown'; diff --git a/app/javascript/shared/toggle-target.js b/app/javascript/shared/toggle-target.js new file mode 100644 index 000000000..0b4faf0f5 --- /dev/null +++ b/app/javascript/shared/toggle-target.js @@ -0,0 +1,20 @@ +import { delegate, toggle } from '@utils'; + +// Unobtrusive Javascript for allowing an element to toggle +// the visibility of another element. +// +// Usage: +// +//
Content
+ +const TOGGLE_SOURCE_SELECTOR = '[data-toggle-target]'; + +delegate('click', TOGGLE_SOURCE_SELECTOR, evt => { + evt.preventDefault(); + + const targetSelector = evt.target.dataset.toggleTarget; + const targetElements = document.querySelectorAll(targetSelector); + for (let target of targetElements) { + toggle(target); + } +}); diff --git a/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb b/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb index b564293b9..0aae810ba 100644 --- a/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb +++ b/app/views/new_user/dossiers/purge_champ_piece_justificative.js.erb @@ -1,2 +1,5 @@ <%= render_flash(timeout: 5000, sticky: true) %> <%= remove_element("#piece_justificative_#{@champ.id}") %> + +let fileInputSelector = '<%= "#champs_#{@champ.id}" %>'; +document.querySelector(fileInputSelector).classList.remove('hidden'); diff --git a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml index 65daa61ea..da1785fb2 100644 --- a/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml +++ b/app/views/shared/dossiers/editable_champs/_piece_justificative.html.haml @@ -15,8 +15,10 @@ = link_to 'Supprimer', gestionnaire_champ_purge_champ_piece_justificative_path(procedure_id: champ.dossier.procedure_id, dossier_id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger' - else = link_to 'Supprimer', champ_purge_champ_piece_justificative_path(id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger' + .piece-justificative-action + = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#champs_#{champ.id}" } = form.file_field :piece_justificative_file, id: "champs_#{champ.id}", - class: "piece-justificative-input", + class: "piece-justificative-input #{'hidden' if pj.attached?}", direct_upload: true From d51cc8bfa2f8a41123054c11cce0d52bf2154ee0 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Feb 2019 16:20:47 +0100 Subject: [PATCH 11/13] spec: fix ActiveRecord queue not being set --- spec/features/new_user/brouillon_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 16c2d82ba..02b3b0a38 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' feature 'The user' do let(:password) { 'secret_password' } From a3c0f3ccd6a8e3be93461d711b21daea8f551f3b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Feb 2019 16:21:14 +0100 Subject: [PATCH 12/13] spec: wait for the page to be rendered before checking values --- spec/features/new_user/brouillon_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 02b3b0a38..5d2841af4 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -42,6 +42,7 @@ feature 'The user' do # find('form input[type="file"]').set(Rails.root.join('spec/fixtures/files/white.png')) click_on 'Enregistrer le brouillon' + expect(page).to have_content('Votre brouillon a bien été sauvegardé') # check data on the dossier expect(user_dossier.brouillon?).to be true From ffda67c1d81fdce265a6d582d9f94ab8336c22e9 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 19 Feb 2019 17:36:02 +0100 Subject: [PATCH 13/13] spec: add specs for attachments --- spec/features/new_user/brouillon_spec.rb | 50 ++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 5d2841af4..c0a495ade 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -10,7 +10,6 @@ feature 'The user' do # TODO: check # the order # there are no extraneous input - # attached file works scenario 'fill a dossier', js: true do allow(Champs::RegionChamp).to receive(:regions).and_return(['region1', 'region2']).at_least(:once) allow(Champs::DepartementChamp).to receive(:departements).and_return(['dep1', 'dep2']).at_least(:once) @@ -38,8 +37,7 @@ feature 'The user' do select('dep2', from: 'departements') check('engagement') fill_in('dossier_link', with: '123') - # do not know how to make it work... - # find('form input[type="file"]').set(Rails.root.join('spec/fixtures/files/white.png')) + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') click_on 'Enregistrer le brouillon' expect(page).to have_content('Votre brouillon a bien été sauvegardé') @@ -63,8 +61,10 @@ feature 'The user' do expect(champ_value_for('departements')).to eq('dep2') expect(champ_value_for('engagement')).to eq('on') expect(champ_value_for('dossier_link')).to eq('123') + expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet ## check data on the gui + expect(page).to have_field('text', with: 'super texte') expect(page).to have_field('textarea', with: 'super textarea') expect(page).to have_field('date', with: '2012-12-12') @@ -82,6 +82,8 @@ feature 'The user' do expect(page).to have_select('departement', selected: 'dep2') expect(page).to have_checked_field('engagement') expect(page).to have_field('dossier_link', with: '123') + expect(page).to have_text('file.pdf') + expect(page).to have_text('analyse antivirus en cours') end let(:procedure_with_repetition) do @@ -148,6 +150,48 @@ feature 'The user' do expect(page).to have_current_path(merci_dossier_path(user_dossier)) end + let(:procedure_with_pj) do + tdcs = [create(:type_de_champ_piece_justificative, mandatory: true, libelle: 'Pièce justificative')] + create(:procedure, :published, :for_individual, types_de_champ: tdcs) + end + + scenario 'adding, replacing and removing attachments', js: true do + log_in(user.email, password, procedure_with_pj) + fill_individual + + # Add an attachment + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf') + click_on 'Enregistrer le brouillon' + expect(page).to have_content('Votre brouillon a bien été sauvegardé') + expect(page).to have_text('file.pdf') + expect(page).to have_text('analyse antivirus en cours') + + # Mark file as scanned and clean + virus_scan = VirusScan.last + virus_scan.update(scanned_at: Time.zone.now, status: VirusScan.statuses.fetch(:safe)) + within '.piece-justificative' do + click_on 'rafraichir' + end + expect(page).to have_link('file.pdf') + expect(page).to have_no_content('analyse antivirus en cours') + + # Replace the attachment + within '.piece-justificative' do + click_on 'Remplacer' + end + find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf') + click_on 'Enregistrer le brouillon' + expect(page).to have_no_text('file.pdf') + expect(page).to have_text('RIB.pdf') + + # Remove the attachment + within '.piece-justificative' do + click_on 'Supprimer' + end + expect(page).to have_content('La pièce jointe a bien été supprimée') + expect(page).to have_no_text('RIB.pdf') + end + private def log_in(email, password, procedure)