Merge pull request #2464 from betagouv/improve-feedback

Improve feedback
This commit is contained in:
gregoirenovel 2018-08-27 17:19:38 +02:00 committed by GitHub
commit 1a76836461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 12 deletions

View file

@ -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 à <a href='mailto:#{CONTACT_EMAIL}' target='_blank'>nous contacter par email</a>."
end
end

View file

@ -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

View file

@ -1,3 +1,9 @@
class Feedback < ApplicationRecord
belongs_to :user
enum rating: {
happy: 'happy',
neutral: 'neutral',
unhappy: 'unhappy'
}
end

View file

@ -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

View file

@ -0,0 +1,5 @@
class AddRatingToFeedbacks < ActiveRecord::Migration[5.2]
def change
add_column :feedbacks, :rating, :string
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,5 @@
FactoryBot.define do
factory :feedback do
mark 3
rating Feedback.ratings.fetch(:happy)
end
end