Feedback in the event-related views

This commit is contained in:
Petko Bordjukov 2019-04-29 13:39:02 +03:00
parent b774cb9b11
commit 2d19046d35
10 changed files with 106 additions and 6 deletions

View File

@ -63,4 +63,24 @@ module ApplicationHelper
output.html_safe output.html_safe
end end
def rating_label_color(rating)
case rating.round
when (0...3) then 'danger'
when 3 then 'warning'
when 4 then 'info'
when 5 then 'primary'
when 6 then 'success'
end
end
def human_rating(rating)
case rating.round
when (0...3) then t('ratings.poor')
when 3 then t('ratings.average')
when 4 then t('ratings.good')
when 5 then t('ratings.very_good')
when 6 then t('ratings.excellent')
end
end
end end

View File

@ -11,7 +11,8 @@ class Event < ActiveRecord::Base
has_many :participants, through: :approved_participations has_many :participants, through: :approved_participations
has_many :participants_with_personal_profiles, through: :approved_participations, source: :participant_with_personal_profile has_many :participants_with_personal_profiles, through: :approved_participations, source: :participant_with_personal_profile
has_many :conflict_counts, -> { order(number_of_conflicts: :desc) }, foreign_key: :left_id has_many :conflict_counts, -> { order(number_of_conflicts: :desc) }, foreign_key: :left_id
has_many :feedbacks, as: :feedback_receiving, dependent: :destroy has_many :feedbacks, as: :feedback_receiving
has_many :feedbacks_with_comment, -> { where.not(comment: [nil, ""]) }, as: :feedback_receiving, class_name: 'Feedback'
belongs_to :event_type belongs_to :event_type
@ -35,6 +36,14 @@ class Event < ActiveRecord::Base
accepts_nested_attributes_for :participations, allow_destroy: true accepts_nested_attributes_for :participations, allow_destroy: true
def average_rating
feedbacks.average(:rating)
end
def rated?
feedbacks.size > 0
end
def all_participants_have_profiles? def all_participants_have_profiles?
participants_with_personal_profiles.all? { |participant| participant.has_personal_profile? } participants_with_personal_profiles.all? { |participant| participant.has_personal_profile? }
end end

View File

@ -20,9 +20,12 @@
.label.label-info .label.label-info
= event.rank = event.rank
=< number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2) =< number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2)
- if event.rated?
dt = t(".average_rating")
dd
=> human_rating(event.average_rating)
.badge class="badge-#{rating_label_color(event.average_rating)}"
= number_with_precision event.average_rating, precision: 2, strip_insignificant_zeros: true
td.visible-md.visible-lg.visible-xl td.visible-md.visible-lg.visible-xl
= links_to_event_participants_for(event) = links_to_event_participants_for(event)
td.action td.action

View File

@ -0,0 +1,12 @@
tr
td.text-center
.huge
.label.label-info
= feedback.rating
td
blockquote
= simple_format feedback.comment
- if feedback.author_email.present?
footer = feedback.author_email
- else
footer = t(".anonymous")

View File

@ -50,6 +50,8 @@
tr tr
th th
= Event.human_attribute_name :title = Event.human_attribute_name :title
th.text-center
= t '.rating'
th.text-center th.text-center
= Event.human_attribute_name :rank = Event.human_attribute_name :rank
th th
@ -62,6 +64,11 @@
- speaker.events_participated_in.where.not(id: @event.id).order(created_at: :desc).each do |event| - speaker.events_participated_in.where.not(id: @event.id).order(created_at: :desc).each do |event|
tr tr
td = event.title td = event.title
td.text-center
- if event.rated?
.large
.label class="label-#{rating_label_color(event.average_rating)}"
= number_with_precision event.average_rating, precision: 2, strip_insignificant_zeros: true
td.text-center td.text-center
- if event.ranked? - if event.ranked?
.large .large

View File

@ -65,6 +65,33 @@
h3 = Event.human_attribute_name :participants h3 = Event.human_attribute_name :participants
= render partial: 'speaker', collection: @event.participants = render partial: 'speaker', collection: @event.participants
.row
.col-xs-12
h3 = Event.human_attribute_name :feedbacks
- if @event.rated?
.row
.col-md-10
.panel.panel-default
.panel-heading = t('.comments')
- if @event.feedbacks_with_comment.size > 0
table.table.table-striped
tbody
= render partial: 'feedback', collection: @event.feedbacks.where.not(comment: [nil, ''])
- else
.panel-body
= t ('.no_comments_received')
.col-md-2
.panel.panel-info
.panel-heading
= t '.average_grade'
.panel-body.text-right
.huge
= number_with_precision(@event.average_rating, precision: 2, strip_insignificant_zeros: true) || ''
= t('.total_feedback_grades', total_grades: @event.feedbacks.count, count: @event.feedbacks.count)
- else
p = t '.no_feedback_received'
- if @conference.has_vote_results? or @conference.has_voting_endpoint? - if @conference.has_vote_results? or @conference.has_voting_endpoint?
.row .row
.col-xs-12 .col-xs-12

View File

@ -158,6 +158,7 @@ bg:
rank: "Класиране" rank: "Класиране"
user: "Лектор" user: "Лектор"
participants: "Участници" participants: "Участници"
feedbacks: "Обратна връзка"
event_type: event_type:
description: "Описание" description: "Описание"
name: "Име" name: "Име"

View File

@ -67,6 +67,7 @@ en:
title: Title title: Title
track: Track track: Track
user: Speaker user: Speaker
feedbacks: Feedback
event_type: event_type:
description: Description description: Description
name: Name name: Name

View File

@ -9,4 +9,14 @@ bg:
rejected: Отхвърлен rejected: Отхвърлен
backup: Резерва backup: Резерва
events: events:
metadata: "%{type} на %{language} с продължителност %{length} минути" metadata: "%{type} на %{language} с продължителност %{length} минути"
management:
events:
show:
average_grade: Средна оценка
total_feedback_grades:
one: от %{total_grades} оценка
other: от %{total_grades} оценки
no_feedback_received: Все още няма обратна връзка
no_comments_received: Все още няма коментари
comments: Коментари

View File

@ -6,4 +6,14 @@ en:
undecided: Undecided undecided: Undecided
approved: Approved approved: Approved
rejected: Rejected rejected: Rejected
backup: Back-up backup: Back-up
management:
events:
show:
average_grade: Average grade
total_feedback_grades:
one: out of %{total_grades} grade
other: out of %{total_grades} grades
no_feedback_received: No feedback received (yet)
no_comments_received: No comments received (yet)
comments: Comments