From 5f60e204d11fbcf66310545f52075a9d4bde7066 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 09:21:20 +0200 Subject: [PATCH 01/23] Use parentheses --- config/initializers/lograge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/lograge.rb b/config/initializers/lograge.rb index 8fec7ceea..cee0b7bd8 100644 --- a/config/initializers/lograge.rb +++ b/config/initializers/lograge.rb @@ -33,6 +33,6 @@ Rails.application.configure do config.lograge.logger = ActiveSupport::Logger.new Rails.root.join('log', "logstash_#{Rails.env}.log") if config.lograge.enabled - ActiveJobLogSubscriber.attach_to :active_job + ActiveJobLogSubscriber.attach_to(:active_job) end end From 23aab2d044c2ca40ba10fb950ebcac504563d136 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 09:24:26 +0200 Subject: [PATCH 02/23] Use a period at the end of a sentence --- app/views/notification_mailer/refused_mail.html.haml | 2 +- .../notification_mailer/without_continuation_mail.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/notification_mailer/refused_mail.html.haml b/app/views/notification_mailer/refused_mail.html.haml index 79f5991c6..e7503723e 100644 --- a/app/views/notification_mailer/refused_mail.html.haml +++ b/app/views/notification_mailer/refused_mail.html.haml @@ -5,7 +5,7 @@ Votre dossier nº --numéro du dossier-- a été refusé le --date de décision--. %p - Le motif de refus est le suivant : --motivation-- + Le motif de refus est le suivant : --motivation--. %p Pour en savoir plus sur le motif du refus, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- diff --git a/app/views/notification_mailer/without_continuation_mail.html.haml b/app/views/notification_mailer/without_continuation_mail.html.haml index c0721aee1..4240a4e2a 100644 --- a/app/views/notification_mailer/without_continuation_mail.html.haml +++ b/app/views/notification_mailer/without_continuation_mail.html.haml @@ -5,7 +5,7 @@ Votre dossier nº --numéro du dossier-- a été classé sans suite le --date de décision--. %p - Le motif est le suivant : --motivation-- + Le motif est le suivant : --motivation--. %p Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter votre dossier et les éventuels messages de l'administration à cette adresse : --lien dossier-- From 9292e243eff6bdd1c9d131a8daba435be0da2adf Mon Sep 17 00:00:00 2001 From: lucien mollard Date: Mon, 13 Aug 2018 14:46:22 +0200 Subject: [PATCH 03/23] Add a button to download the stats in CSV --- app/controllers/stats_controller.rb | 37 +++++++++++++++++++++++++++++ app/views/stats/index.html.haml | 4 ++++ config/routes.rb | 3 ++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 62094ec17..5566bf18f 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -1,6 +1,8 @@ class StatsController < ApplicationController layout "new_application" + before_action :authenticate_administration!, only: [:download] + MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0 def index @@ -36,6 +38,41 @@ class StatsController < ApplicationController @cloned_from_library_procedures_ratio = cloned_from_library_procedures_ratio end + def download + headers = [ + 'ID du dossier', + 'ID de la procédure', + 'Nom de la procédure', + 'ID utilisateur', + 'Etat du fichier', + 'Durée en brouillon', + 'Durée en construction', + 'Durée en instruction' + ] + + data = Dossier + .includes(:procedure, :user) + .in_batches + .flat_map do |dossiers| + + dossiers + .pluck( + "dossiers.id", + "procedures.id", + "procedures.libelle", + "users.id", + "dossiers.state", + "dossiers.en_construction_at - dossiers.created_at", + "dossiers.en_instruction_at - dossiers.en_construction_at", + "dossiers.processed_at - dossiers.en_instruction_at" + ) + end + + respond_to do |format| + format.csv { send_data(SpreadsheetArchitect.to_xlsx(headers: headers, data: data), filename: "statistiques.csv") } + end + end + private def cloned_from_library_procedures_ratio diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 8267176d3..ace030822 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -112,3 +112,7 @@ = column_chart @cloned_from_library_procedures_ratio, ytitle: 'procédures clonées / total procédure', xtitle: 'semaines' .clearfix + + %h2.new-h2 Téléchargement + + = link_to "Télécharger les statistiques (CSV)", stats_download_path(format: :csv), class: 'button secondary' diff --git a/config/routes.rb b/config/routes.rb index 3d58ea508..b159b8e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,7 +99,8 @@ Rails.application.routes.draw do get 'users' => 'users#index' get 'admin' => 'admin#index' - resources :stats, only: [:index] + get '/stats' => 'stats#index' + get '/stats/download' => 'stats#download' resources :accessibilite, only: [:index] resources :demandes, only: [:new, :create] From f381d45d1a990456a89cf7fb9fa6876efd3df072 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 24 Aug 2018 17:10:27 +0200 Subject: [PATCH 04/23] Add a chart showing the dossiers state repartition --- app/controllers/stats_controller.rb | 11 +++++++++++ app/views/stats/index.html.haml | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 5566bf18f..d91ee4882 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -12,6 +12,8 @@ class StatsController < ApplicationController @procedures_count = procedures.count @dossiers_count = dossiers.count + @dossiers_states = dossiers_states + @procedures_cumulative = cumulative_hash(procedures, :published_at) @procedures_in_the_last_4_months = last_four_months_hash(procedures, :published_at) @@ -75,6 +77,15 @@ class StatsController < ApplicationController private + def dossiers_states + { + 'Brouilllon' => Dossier.state_brouillon.count, + 'En construction' => Dossier.state_en_construction.count, + 'En instruction' => Dossier.state_en_instruction.count, + 'Terminé' => Dossier.state_termine.count + } + end + def cloned_from_library_procedures_ratio [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date| min_date = date.beginning_of_week diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index ace030822..a56f5a0c1 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -15,6 +15,15 @@ %span.big-number-card-number = number_with_delimiter(@dossiers_count) + .stat-card.stat-card-half.pull-left + %span.stat-card-title + Répartition des dossiers + + .chart-container + .chart + = pie_chart @dossiers_states, + colors: ["rgba(222, 238, 265, 1)", "rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"] + .stat-card.stat-card-half.pull-left %ul.segmented-control.pull-right %li.segmented-control-item.segmented-control-item-active{ :onclick => "DS.toggleChart(event, '.monthly-procedures-chart');" } From c6a839cd64452c1f6dece806b72bf6ecd9c57eac Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 24 Aug 2018 17:30:35 +0200 Subject: [PATCH 05/23] Add the groupdate gem --- Gemfile | 2 ++ Gemfile.lock | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index b0b7133c9..a2dcf01fe 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,8 @@ gem "premailer-rails" gem 'smart_listing' +gem 'groupdate' + gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8' gem 'spreadsheet_architect', '~> 1.4.8' # https://github.com/westonganger/spreadsheet_architect/issues/14 diff --git a/Gemfile.lock b/Gemfile.lock index 47f448442..2d43f9b81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -369,6 +369,8 @@ GEM formatador (0.2.5) globalid (0.4.1) activesupport (>= 4.2.0) + groupdate (4.0.1) + activesupport (>= 4.2) guard (2.14.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -834,6 +836,7 @@ DEPENDENCIES fog fog-openstack font-awesome-rails + groupdate guard guard-livereload guard-rspec From b158a92493e4518e18754c47fd6b175812e80b9d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 24 Aug 2018 17:57:04 +0200 Subject: [PATCH 06/23] Add a graph showing the user satisfaction --- app/controllers/stats_controller.rb | 32 +++++++++++++++++++++++++++++ app/views/stats/index.html.haml | 9 ++++++++ 2 files changed, 41 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index d91ee4882..11de1eaa5 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -12,6 +12,7 @@ class StatsController < ApplicationController @procedures_count = procedures.count @dossiers_count = dossiers.count + @satisfaction_usagers = satisfaction_usagers @dossiers_states = dossiers_states @procedures_cumulative = cumulative_hash(procedures, :published_at) @@ -86,6 +87,37 @@ class StatsController < ApplicationController } end + def satisfaction_usagers + legend = { + "0" => "Mécontents", + "1" => "Neutres", + "2" => "Satisfaits" + } + + totals = Feedback.where(created_at: 5.weeks.ago..Time.now).group_by_week(:created_at).count + + (0..2).map do |mark| + data = Feedback + .where(created_at: 5.weeks.ago..Time.now, mark: mark) + .group_by_week(:created_at) + .count + .map do |week, count| + total = totals[week] + + if total > 0 + [week, (count.to_f / total).round(2)] + else + 0 + end + end.to_h + + { + name: legend[mark.to_s], + data: data + } + end + end + def cloned_from_library_procedures_ratio [3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date| min_date = date.beginning_of_week diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index a56f5a0c1..666c3033c 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -15,6 +15,15 @@ %span.big-number-card-number = number_with_delimiter(@dossiers_count) + .stat-card.stat-card-half.pull-left + %span.stat-card-title + Satisfaction usager + + .chart-container + .chart + = line_chart @satisfaction_usagers, + colors: ["#F28900", "rgba(161, 0, 5, 0.9)", "#15AD70"] + .stat-card.stat-card-half.pull-left %span.stat-card-title Répartition des dossiers From 1578c3bca600b35e664da4ccddc2f72f6e7b5aa6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 10:48:05 +0200 Subject: [PATCH 07/23] Stop having several class that do the exact same things --- .../stylesheets/new_design/landing.scss | 37 +++++-------------- app/views/root/landing.html.haml | 4 +- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/app/assets/stylesheets/new_design/landing.scss b/app/assets/stylesheets/new_design/landing.scss index 6c5260c28..20182eb7e 100644 --- a/app/assets/stylesheets/new_design/landing.scss +++ b/app/assets/stylesheets/new_design/landing.scss @@ -349,7 +349,7 @@ $cta-panel-button-border-size: 2px; } } -.cta-panel-button { +.cta-panel-button-black { @include horizontal-padding(40px); @include vertical-padding(15px); display: block; @@ -358,36 +358,17 @@ $cta-panel-button-border-size: 2px; text-align: center; cursor: pointer; margin-top: 20px; + border: $cta-panel-button-border-size solid #000000; + color: #000000; - &.black { - border: $cta-panel-button-border-size solid #000000; - color: #000000; - - &:hover { - text-decoration: none; - background-color: #F8F8F8; - } - - &:focus { - color: #F8F8F8; - text-decoration: none; - } + &:hover { + text-decoration: none; + background-color: #F8F8F8; } - &.white { - border: $cta-panel-button-border-size solid #FFFFFF; - color: #FFFFFF; - - &:hover { - color: #FFFFFF; - text-decoration: none; - background-color: rgba(255, 255, 255, 0.2); - } - - &:focus { - color: #FFFFFF; - text-decoration: none; - } + &:focus { + color: #F8F8F8; + text-decoration: none; } } diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 43fbfe30a..baa26f31d 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -72,7 +72,7 @@ %div = link_to "Contactez-nous", "mailto:#{CONTACT_EMAIL}?subject=Question%20à%20propos%20de%20demarches-simplifiees.fr", - class: "cta-panel-button white", + class: "cta-panel-button-white", target: "_blank", rel: "noopener noreferrer" @@ -85,4 +85,4 @@ %div = link_to "Découvrez notre outil", administration_path, - class: "cta-panel-button black" + class: "cta-panel-button-black" From df6d9151b82672ea641d0b5e56f1a6f1ccd0dc2f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 10:51:49 +0200 Subject: [PATCH 08/23] Factorize code in a mixin In this file we factorise with a mixing, not several classes --- app/assets/stylesheets/new_design/landing.scss | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/new_design/landing.scss b/app/assets/stylesheets/new_design/landing.scss index 20182eb7e..0d3ed3f30 100644 --- a/app/assets/stylesheets/new_design/landing.scss +++ b/app/assets/stylesheets/new_design/landing.scss @@ -325,7 +325,7 @@ $users-breakpoint: 950px; $cta-panel-button-border-size: 2px; -.cta-panel-button-white { +@mixin cta-panel-button { @include horizontal-padding(40px); @include vertical-padding(15px); display: block; @@ -334,6 +334,10 @@ $cta-panel-button-border-size: 2px; text-align: center; cursor: pointer; margin-top: 20px; +} + +.cta-panel-button-white { + @include cta-panel-button; border: $cta-panel-button-border-size solid #FFFFFF; color: #FFFFFF; @@ -350,14 +354,7 @@ $cta-panel-button-border-size: 2px; } .cta-panel-button-black { - @include horizontal-padding(40px); - @include vertical-padding(15px); - display: block; - border-radius: 100px; - font-size: 24px; - text-align: center; - cursor: pointer; - margin-top: 20px; + @include cta-panel-button; border: $cta-panel-button-border-size solid #000000; color: #000000; From d240be8948a7f148ece0e60c039cae276c68c468 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 10:56:01 +0200 Subject: [PATCH 09/23] Fix the focus state of .cta-panel-button-black --- app/assets/stylesheets/new_design/landing.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/landing.scss b/app/assets/stylesheets/new_design/landing.scss index 0d3ed3f30..f571f09d6 100644 --- a/app/assets/stylesheets/new_design/landing.scss +++ b/app/assets/stylesheets/new_design/landing.scss @@ -364,7 +364,7 @@ $cta-panel-button-border-size: 2px; } &:focus { - color: #F8F8F8; + color: #000000; text-decoration: none; } } From 40da6ccf40cf26f7ea34b4bf462023e8aca989c8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 10:58:08 +0200 Subject: [PATCH 10/23] Use a blue button for the admin CTA --- app/assets/stylesheets/new_design/landing.scss | 15 ++++++++++----- app/views/root/landing.html.haml | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/new_design/landing.scss b/app/assets/stylesheets/new_design/landing.scss index f571f09d6..3b9f35a0d 100644 --- a/app/assets/stylesheets/new_design/landing.scss +++ b/app/assets/stylesheets/new_design/landing.scss @@ -353,18 +353,23 @@ $cta-panel-button-border-size: 2px; } } -.cta-panel-button-black { +.cta-panel-button-blue { @include cta-panel-button; - border: $cta-panel-button-border-size solid #000000; - color: #000000; + border: $cta-panel-button-border-size solid $light-blue; + color: $light-blue; &:hover { + color: #FFFFFF; + background-color: $light-blue; text-decoration: none; - background-color: #F8F8F8; + + &:focus { + color: #FFFFFF; + } } &:focus { - color: #000000; + color: $light-blue; text-decoration: none; } } diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index baa26f31d..f0d36673c 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -85,4 +85,4 @@ %div = link_to "Découvrez notre outil", administration_path, - class: "cta-panel-button-black" + class: "cta-panel-button-blue" From 100974ff9a2e6d291ac617df3d7c9f1e8d510ead Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:03:05 +0200 Subject: [PATCH 11/23] Do not open the admin account form in a new tab --- app/views/root/administration.html.haml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/root/administration.html.haml b/app/views/root/administration.html.haml index 5e8a3b29b..52c01ab51 100644 --- a/app/views/root/administration.html.haml +++ b/app/views/root/administration.html.haml @@ -26,7 +26,6 @@ = link_to "Demander un compte administrateur", new_demande_path, class: "role-panel-button-primary", - target: "_blank", rel: "noopener noreferrer", onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" From 83e081426cae9ea91e0b87bb2e9479f3f887ec25 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:04:50 +0200 Subject: [PATCH 12/23] Redirect admins requests to the admin page after the form submission --- app/controllers/demandes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/demandes_controller.rb b/app/controllers/demandes_controller.rb index c381df1ae..ead68d3fc 100644 --- a/app/controllers/demandes_controller.rb +++ b/app/controllers/demandes_controller.rb @@ -18,7 +18,7 @@ class DemandesController < ApplicationController demande_params[:deadline] ) flash.notice = 'Votre demande a bien été enregistrée, nous vous contacterons rapidement.' - redirect_to root_path + redirect_to administration_path end private From 047d022c8a28d824a864c468fe236d25adfc8315 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:09:22 +0200 Subject: [PATCH 13/23] Add a CTA at the bottom of the admin landing page --- app/views/root/administration.html.haml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/root/administration.html.haml b/app/views/root/administration.html.haml index 52c01ab51..0d32db974 100644 --- a/app/views/root/administration.html.haml +++ b/app/views/root/administration.html.haml @@ -188,3 +188,14 @@ class: "cta-panel-button-white", target: "_blank", rel: "noopener noreferrer" + + .landing-panel + .container + .cta-panel-wrapper + %div + %h1.cta-panel-title Vous êtes prêt pour dématérialiser ? + %p.cta-panel-explanation Réduisez vos temps d'instruction de 50 % + %div + = link_to "Demander un compte administrateur", + new_demande_path, + class: "cta-panel-button-blue" From a700fc16cf4338c8ebaa84e452ff0b0e99f31ad6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:09:30 +0200 Subject: [PATCH 14/23] Remove a now useless GA call --- app/views/root/administration.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/root/administration.html.haml b/app/views/root/administration.html.haml index 0d32db974..5820a7458 100644 --- a/app/views/root/administration.html.haml +++ b/app/views/root/administration.html.haml @@ -26,8 +26,7 @@ = link_to "Demander un compte administrateur", new_demande_path, class: "role-panel-button-primary", - rel: "noopener noreferrer", - onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" + rel: "noopener noreferrer" = link_to "Voir la documentation", DOC_URL, From 98f70cc815f45e475242e483f80b47c6b8caf313 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:41:38 +0200 Subject: [PATCH 15/23] Allow a user to rate the service each month --- app/views/new_user/dossiers/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index ce0f01392..3760e8bb0 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -54,7 +54,7 @@ = dossier.updated_at.localtime.strftime("%d/%m/%Y") = paginate(@dossiers) - - if current_user.feedbacks.empty? + - if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago #user-satisfaction %h3 Que pensez-vous de ce service ? .icons From 3d7b239f2b5896a9873e41eeb7410f8a8b72142a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:49:36 +0200 Subject: [PATCH 16/23] Improve the feedback form question --- app/views/new_user/dossiers/index.html.haml | 2 +- spec/views/new_user/dossiers/index.html.haml_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index 3760e8bb0..dcd145289 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -56,7 +56,7 @@ - if current_user.feedbacks.empty? || current_user.feedbacks.last.created_at < 1.month.ago #user-satisfaction - %h3 Que pensez-vous de ce service ? + %h3 Que pensez-vous de la facilité d'utilisation de ce service ? .icons = link_to feedback_path(mark: 0), data: { remote: true, method: :post } do %span.icon.frown diff --git a/spec/views/new_user/dossiers/index.html.haml_spec.rb b/spec/views/new_user/dossiers/index.html.haml_spec.rb index 9ee653464..3ba7f6882 100644 --- a/spec/views/new_user/dossiers/index.html.haml_spec.rb +++ b/spec/views/new_user/dossiers/index.html.haml_spec.rb @@ -74,7 +74,7 @@ describe 'new_user/dossiers/index.html.haml', type: :view do context "quand le user n'a aucun feedback" do it "affiche le formulaire de satisfaction" do - expect(rendered).to have_selector('#user-satisfaction', text: 'Que pensez-vous de ce service ?') + expect(rendered).to have_selector('#user-satisfaction', text: 'Que pensez-vous de la facilité d\'utilisation de ce service ?') end end From 62878f9c5ade559ac3d82a932de334ef8018c80b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 11:49:51 +0200 Subject: [PATCH 17/23] Encourage users that give us feedback to write to us --- app/controllers/new_user/feedbacks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/new_user/feedbacks_controller.rb b/app/controllers/new_user/feedbacks_controller.rb index 9e7ca19f5..e3b952b91 100644 --- a/app/controllers/new_user/feedbacks_controller.rb +++ b/app/controllers/new_user/feedbacks_controller.rb @@ -1,6 +1,6 @@ class NewUser::FeedbacksController < ApplicationController def create current_user.feedbacks.create!(mark: params[:mark]) - flash.notice = "Merci de votre retour" + flash.notice = "Merci de votre retour, si vous souhaitez nous en dire plus, n'hésitez pas à nous contacter par email." end end From c81206f4d12eb6e937ab6629be30ae555a7f8a1d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 12:00:08 +0200 Subject: [PATCH 18/23] Scroll to top after having given feedback --- app/views/new_user/feedbacks/create.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/new_user/feedbacks/create.js.erb b/app/views/new_user/feedbacks/create.js.erb index de4c271b3..c2b5f9c9f 100644 --- a/app/views/new_user/feedbacks/create.js.erb +++ b/app/views/new_user/feedbacks/create.js.erb @@ -1,2 +1,3 @@ +window.scroll({ top: 0, left: 0, behavior: 'smooth' }); <%= remove_element('#user-satisfaction') %> <%= render_flash %> From 4103861f9088d5d5131ec4961edbd1d00ca595cf Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 12:59:22 +0200 Subject: [PATCH 19/23] Add the rating column to feedbacks --- app/models/feedback.rb | 6 ++++++ db/migrate/20180827102828_add_rating_to_feedbacks.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180827102828_add_rating_to_feedbacks.rb diff --git a/app/models/feedback.rb b/app/models/feedback.rb index 63affddde..d697541d9 100644 --- a/app/models/feedback.rb +++ b/app/models/feedback.rb @@ -1,3 +1,9 @@ class Feedback < ApplicationRecord belongs_to :user + + enum rating: { + happy: 'happy', + neutral: 'neutral', + unhappy: 'unhappy' + } end diff --git a/db/migrate/20180827102828_add_rating_to_feedbacks.rb b/db/migrate/20180827102828_add_rating_to_feedbacks.rb new file mode 100644 index 000000000..cc3c0c97d --- /dev/null +++ b/db/migrate/20180827102828_add_rating_to_feedbacks.rb @@ -0,0 +1,5 @@ +class AddRatingToFeedbacks < ActiveRecord::Migration[5.2] + def change + add_column :feedbacks, :rating, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 492fe9f51..f3ed94862 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_22_162952) do +ActiveRecord::Schema.define(version: 2018_08_27_102828) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -323,6 +323,7 @@ ActiveRecord::Schema.define(version: 2018_08_22_162952) do t.integer "mark" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "rating" t.index ["user_id"], name: "index_feedbacks_on_user_id" end From e9a262947fda3705162fc766064f069444294bd7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 13:06:04 +0200 Subject: [PATCH 20/23] Migrate marks to ratings on feedbacks --- lib/tasks/2018_08_27_migrate_feedbacks.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/tasks/2018_08_27_migrate_feedbacks.rake diff --git a/lib/tasks/2018_08_27_migrate_feedbacks.rake b/lib/tasks/2018_08_27_migrate_feedbacks.rake new file mode 100644 index 000000000..f57a3bd3a --- /dev/null +++ b/lib/tasks/2018_08_27_migrate_feedbacks.rake @@ -0,0 +1,19 @@ +require Rails.root.join("lib", "tasks", "task_helper") + +namespace :'2018_08_27_migrate_feedbacks' do + task run: :environment do + MAPPING = { + 0 => Feedback.ratings.fetch(:unhappy), + 1 => Feedback.ratings.fetch(:neutral), + 2 => Feedback.ratings.fetch(:happy) + } + + MAPPING.keys.each do |mark| + rating = MAPPING[mark] + + Feedback + .where(mark: mark) + .update_all(rating: rating) + end + end +end From 3ba4ce0d378a1d16a9b89593fabe95f0cc21e467 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 13:06:23 +0200 Subject: [PATCH 21/23] Create feedbacks with ratings instead of marks --- app/controllers/new_user/feedbacks_controller.rb | 2 +- app/views/new_user/dossiers/index.html.haml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/new_user/feedbacks_controller.rb b/app/controllers/new_user/feedbacks_controller.rb index e3b952b91..d7db41189 100644 --- a/app/controllers/new_user/feedbacks_controller.rb +++ b/app/controllers/new_user/feedbacks_controller.rb @@ -1,6 +1,6 @@ class NewUser::FeedbacksController < ApplicationController def create - current_user.feedbacks.create!(mark: params[:mark]) + current_user.feedbacks.create!(rating: params[:rating]) flash.notice = "Merci de votre retour, si vous souhaitez nous en dire plus, n'hésitez pas à nous contacter par email." end end diff --git a/app/views/new_user/dossiers/index.html.haml b/app/views/new_user/dossiers/index.html.haml index dcd145289..aecf834f0 100644 --- a/app/views/new_user/dossiers/index.html.haml +++ b/app/views/new_user/dossiers/index.html.haml @@ -58,11 +58,11 @@ #user-satisfaction %h3 Que pensez-vous de la facilité d'utilisation de ce service ? .icons - = link_to feedback_path(mark: 0), data: { remote: true, method: :post } do + = link_to feedback_path(rating: Feedback.ratings.fetch(:unhappy)), data: { remote: true, method: :post } do %span.icon.frown - = link_to feedback_path(mark: 1), data: { remote: true, method: :post } do + = link_to feedback_path(rating: Feedback.ratings.fetch(:neutral)), data: { remote: true, method: :post } do %span.icon.meh - = link_to feedback_path(mark: 2), data: { remote: true, method: :post } do + = link_to feedback_path(rating: Feedback.ratings.fetch(:happy)), data: { remote: true, method: :post } do %span.icon.smile - else From 18624ff8723e954a6142d6141ed9b6164dd71f9b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 14:12:38 +0200 Subject: [PATCH 22/23] Update the stats code to use ratings instead of marks --- app/controllers/stats_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 11de1eaa5..7b5605e0e 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -89,16 +89,16 @@ class StatsController < ApplicationController def satisfaction_usagers legend = { - "0" => "Mécontents", - "1" => "Neutres", - "2" => "Satisfaits" + Feedback.ratings.fetch(:unhappy) => "Mécontents", + Feedback.ratings.fetch(:neutral) => "Neutres", + Feedback.ratings.fetch(:happy) => "Satisfaits" } totals = Feedback.where(created_at: 5.weeks.ago..Time.now).group_by_week(:created_at).count - (0..2).map do |mark| + Feedback::rating.values.map do |rating| data = Feedback - .where(created_at: 5.weeks.ago..Time.now, mark: mark) + .where(created_at: 5.weeks.ago..Time.now, rating: rating) .group_by_week(:created_at) .count .map do |week, count| @@ -112,7 +112,7 @@ class StatsController < ApplicationController end.to_h { - name: legend[mark.to_s], + name: legend[rating], data: data } end From d6748bde20b36b3afde4b2bb1a9fa290221bd748 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 27 Aug 2018 15:04:20 +0200 Subject: [PATCH 23/23] Update a factory so that it uses rating instead of mark --- spec/factories/feedback.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/feedback.rb b/spec/factories/feedback.rb index 231989f34..d332d2eae 100644 --- a/spec/factories/feedback.rb +++ b/spec/factories/feedback.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :feedback do - mark 3 + rating Feedback.ratings.fetch(:happy) end end