From f03d8ef909578bda91996d1d6afc59d419eda7aa Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 19 Jul 2017 16:53:31 +0200 Subject: [PATCH 1/4] NewDesign: add dossier instruction view --- .../new_design/dossier_instruction.scss | 17 +++++++++++++++++ .../new_gestionnaire/dossiers_controller.rb | 4 ++++ .../new_gestionnaire/dossiers/_header.html.haml | 2 +- .../dossiers/instruction.html.haml | 6 ++++++ config/routes.rb | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/new_design/dossier_instruction.scss create mode 100644 app/views/new_gestionnaire/dossiers/instruction.html.haml diff --git a/app/assets/stylesheets/new_design/dossier_instruction.scss b/app/assets/stylesheets/new_design/dossier_instruction.scss new file mode 100644 index 000000000..bfa5ceb20 --- /dev/null +++ b/app/assets/stylesheets/new_design/dossier_instruction.scss @@ -0,0 +1,17 @@ +@import "colors"; +@import "common"; +@import "constants"; + +#dossier-instruction { + h1 { + font-size: 18px; + font-weight: bold; + margin-bottom: $default-padding; + } + + .avis-notice { + font-size: 12px; + color: $grey; + margin-bottom: 2 * $default-padding; + } +} diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index c2e622386..6b37461f9 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -12,6 +12,10 @@ module NewGestionnaire @dossier = dossier end + def instruction + @dossier = dossier + end + def follow current_gestionnaire.follow(dossier) dossier.next_step!('gestionnaire', 'follow') diff --git a/app/views/new_gestionnaire/dossiers/_header.html.haml b/app/views/new_gestionnaire/dossiers/_header.html.haml index 9e503420f..f7aa7eda2 100644 --- a/app/views/new_gestionnaire/dossiers/_header.html.haml +++ b/app/views/new_gestionnaire/dossiers/_header.html.haml @@ -9,7 +9,7 @@ %li = link_to "Demande", dossier_path(dossier.procedure, dossier), class: ("selected" if current_page?(dossier_path(dossier.procedure, dossier))) %li - = link_to "Instruction", "#" + = link_to "Instruction", instruction_dossier_path(dossier.procedure, dossier), class: current_page?(instruction_dossier_path(dossier.procedure, dossier)) ? 'selected' : nil %li = link_to "Messagerie", messagerie_dossier_path(dossier.procedure, dossier), class: current_page?(messagerie_dossier_path(dossier.procedure, dossier)) ? 'selected' : nil %li diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml new file mode 100644 index 000000000..4323c8afa --- /dev/null +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -0,0 +1,6 @@ += render partial: "header", locals: { dossier: @dossier } + +#dossier-instruction.container + %section + %h1 Inviter une personne à donner son avis + %p.avis-notice Elle pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais elle ne pourra le modifier. diff --git a/config/routes.rb b/config/routes.rb index 66c9975d0..1b8eb1f22 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -243,6 +243,7 @@ Rails.application.routes.draw do member do get 'attestation' get 'messagerie' + get 'instruction' patch 'follow' patch 'unfollow' patch 'archive' From 2923d4448bdc8c40f006f24aa593052d8f4703f3 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 28 Aug 2017 14:16:13 +0200 Subject: [PATCH 2/4] NewDesign: can ask a new avis --- .../new_design/dossier_instruction.scss | 4 ++++ .../new_gestionnaire/dossiers_controller.rb | 9 +++++++++ .../dossiers/instruction.html.haml | 6 ++++++ config/routes.rb | 1 + .../dossiers_controller_spec.rb | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/app/assets/stylesheets/new_design/dossier_instruction.scss b/app/assets/stylesheets/new_design/dossier_instruction.scss index bfa5ceb20..68edfe61c 100644 --- a/app/assets/stylesheets/new_design/dossier_instruction.scss +++ b/app/assets/stylesheets/new_design/dossier_instruction.scss @@ -14,4 +14,8 @@ color: $grey; margin-bottom: 2 * $default-padding; } + + input[type=email] { + max-width: 500px; + } } diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 6b37461f9..af7eeaa7f 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -61,6 +61,11 @@ module NewGestionnaire render json: { lon: lon, lat: lat, zoom: zoom, dossier_id: params[:dossier_id] } end + def create_avis + Avis.create(avis_params.merge(claimant: current_gestionnaire, dossier: dossier)) + redirect_to instruction_dossier_path(dossier.procedure, dossier) + end + private def dossier @@ -70,5 +75,9 @@ module NewGestionnaire def commentaire_params params.require(:commentaire).permit(:body) end + + def avis_params + params.require(:avis).permit(:email, :introduction) + end end end diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index 4323c8afa..62c654281 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -4,3 +4,9 @@ %section %h1 Inviter une personne à donner son avis %p.avis-notice Elle pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais elle ne pourra le modifier. + + = form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| + = f.email_field :email, placeholder: 'Adresse email', required: true + = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true + .send-wrapper + = f.submit 'Demander un avis', class: 'button send' diff --git a/config/routes.rb b/config/routes.rb index 1b8eb1f22..ca60cdae1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -252,6 +252,7 @@ Rails.application.routes.draw do scope :carte do get 'position' end + post 'avis' => 'dossiers#create_avis' end end end diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index c1e5ac4c2..946a4e5aa 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -94,4 +94,22 @@ describe NewGestionnaire::DossiersController, type: :controller do it { expect(saved_commentaire.dossier).to eq(dossier) } it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) } end + + describe "#create_avis" do + let(:saved_avis) { dossier.avis.first } + + before do + post :create_avis, params: { + procedure_id: procedure.id, + dossier_id: dossier.id, + avis: { email: 'email@a.com', introduction: 'intro' } + } + end + + it { expect(saved_avis.email).to eq('email@a.com') } + it { expect(saved_avis.introduction).to eq('intro') } + it { expect(saved_avis.dossier).to eq(dossier) } + it { expect(saved_avis.claimant).to eq(gestionnaire) } + it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) } + end end From b94fc7c132e7f192878567e6fb62bb12186191bd Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 26 Jul 2017 11:22:04 +0200 Subject: [PATCH 3/4] NewDesign: list of avis --- app/assets/images/icons/bubble.svg | 1 + .../new_design/dossier_instruction.scss | 50 +++++++++++++++++++ .../dossiers/instruction.html.haml | 25 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/assets/images/icons/bubble.svg diff --git a/app/assets/images/icons/bubble.svg b/app/assets/images/icons/bubble.svg new file mode 100644 index 000000000..d423f2f4b --- /dev/null +++ b/app/assets/images/icons/bubble.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/stylesheets/new_design/dossier_instruction.scss b/app/assets/stylesheets/new_design/dossier_instruction.scss index 68edfe61c..6a4ec475c 100644 --- a/app/assets/stylesheets/new_design/dossier_instruction.scss +++ b/app/assets/stylesheets/new_design/dossier_instruction.scss @@ -18,4 +18,54 @@ input[type=email] { max-width: 500px; } + + .avis { + .title { + margin-bottom: $default-padding; + + .count { + display: inline-block; + width: 20px; + height: 20px; + border-radius: 10px; + border: 1px solid $grey; + text-align: center; + font-size: 12px; + font-weight: normal; + margin-left: 8px; + } + } + + .one-avis { + border-top: 1px solid $grey; + padding: $default-padding 0; + + h2 { + font-weight: bold; + margin-bottom: $default-spacer; + + span { + font-weight: normal; + } + } + + .answer { + margin-top: $default-padding; + } + + .avis-icon { + margin-right: $default-spacer; + } + } + + .date, + .waiting { + font-size: 12px; + color: $grey; + } + + .date { + float: right; + } + } } diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index 62c654281..7cc345d3b 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -10,3 +10,28 @@ = f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true .send-wrapper = f.submit 'Demander un avis', class: 'button send' + + - if @dossier.avis.present? + %section.avis + %h1.title + Avis des invités + %span.count= @dossier.avis.count + + %ul + - @dossier.avis.each do |avis| + %li.one-avis + %h2.claimant + = (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email + %span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')} + %p= avis.introduction + + .answer.flex.align-start + = image_tag 'icons/bubble.svg', class: 'avis-icon' + .width-100 + %h2.gestionnaire + = avis.gestionnaire.email + - if avis.answer.present? + %span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')} + - else + %span.waiting En attente de réponse + %p= avis.answer From 3e5d0dce6ac1648f0b7bb9acdec4d2489043051b Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 2 Aug 2017 15:33:23 +0200 Subject: [PATCH 4/4] NewDesign: can add annotations --- .../new_gestionnaire/dossiers_controller.rb | 10 ++++ app/models/dossier.rb | 1 + .../dossiers/instruction.html.haml | 13 ++++++ config/routes.rb | 1 + .../dossiers_controller_spec.rb | 46 +++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index af7eeaa7f..e76364587 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -66,6 +66,12 @@ module NewGestionnaire redirect_to instruction_dossier_path(dossier.procedure, dossier) end + def update_annotations + dossier = current_gestionnaire.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id]) + dossier.update_attributes(champs_private_params) + redirect_to instruction_dossier_path(dossier.procedure, dossier) + end + private def dossier @@ -79,5 +85,9 @@ module NewGestionnaire def avis_params params.require(:avis).permit(:email, :introduction) end + + def champs_private_params + params.require(:dossier).permit(champs_private_attributes: [:id, :value, value: []]) + end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index fd0a1279a..3c91b9bc7 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -44,6 +44,7 @@ class Dossier < ActiveRecord::Base belongs_to :user accepts_nested_attributes_for :champs + accepts_nested_attributes_for :champs_private default_scope { where(hidden_at: nil) } scope :state_brouillon, -> { where(state: BROUILLON) } diff --git a/app/views/new_gestionnaire/dossiers/instruction.html.haml b/app/views/new_gestionnaire/dossiers/instruction.html.haml index 7cc345d3b..652eda87a 100644 --- a/app/views/new_gestionnaire/dossiers/instruction.html.haml +++ b/app/views/new_gestionnaire/dossiers/instruction.html.haml @@ -35,3 +35,16 @@ - else %span.waiting En attente de réponse %p= avis.answer + + - if @dossier.ordered_champs_private.present? + %section + %h1.private-annotations Annotations privées + .card.featured + = form_for @dossier, url: annotations_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f| + = f.fields_for :champs_private, f.object.ordered_champs_private do |champ_form| + - champ = champ_form.object + = render partial: "new_gestionnaire/dossiers/champs/#{champ.type_champ}", + locals: { champ: champ, form: champ_form } + + .send-wrapper + = f.submit 'Sauvegarder', class: 'button send' diff --git a/config/routes.rb b/config/routes.rb index ca60cdae1..6d45eaa11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -248,6 +248,7 @@ Rails.application.routes.draw do patch 'unfollow' patch 'archive' patch 'unarchive' + patch 'annotations' => 'dossiers#update_annotations' post 'commentaire' => 'dossiers#create_commentaire' scope :carte do get 'position' diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 946a4e5aa..032cc83e9 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -112,4 +112,50 @@ describe NewGestionnaire::DossiersController, type: :controller do it { expect(saved_avis.claimant).to eq(gestionnaire) } it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) } end + + describe "#update_annotations" do + let(:champ_multiple_drop_down_list) do + type_de_champ = TypeDeChamp.create(type_champ: 'multiple_drop_down_list', libelle: 'libelle') + ChampPrivate.create(type_de_champ: type_de_champ) + end + + let(:champ_datetime) do + type_de_champ = TypeDeChamp.create(type_champ: 'datetime', libelle: 'libelle') + ChampPrivate.create(type_de_champ: type_de_champ) + end + + let(:dossier) do + create(:dossier, :replied, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_datetime]) + end + + before do + patch :update_annotations, params: { + procedure_id: procedure.id, + dossier_id: dossier.id, + dossier: { + champs_private_attributes: { + '0': { + id: champ_multiple_drop_down_list.id, + value: ['', 'un', 'deux'] + }, + '1': { + id: champ_datetime.id, + 'value(1i)': 2019, + 'value(2i)': 12, + 'value(3i)': 21, + 'value(4i)': 13, + 'value(5i)': 17 + } + } + } + } + + champ_multiple_drop_down_list.reload + champ_datetime.reload + end + + it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') } + it { expect(champ_datetime.value).to eq('21/12/2019 13:17') } + it { expect(response).to redirect_to(instruction_dossier_path(dossier.procedure, dossier)) } + end end