diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 80e407a..e5090c6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -63,4 +63,24 @@ module ApplicationHelper output.html_safe 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 diff --git a/app/models/event.rb b/app/models/event.rb index bba82f9..2b98f81 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,7 +11,8 @@ class Event < ActiveRecord::Base has_many :participants, through: :approved_participations 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 :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 @@ -35,6 +36,14 @@ class Event < ActiveRecord::Base 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? participants_with_personal_profiles.all? { |participant| participant.has_personal_profile? } end diff --git a/app/views/management/events/_event.slim b/app/views/management/events/_event.slim index 1241239..81a29d7 100644 --- a/app/views/management/events/_event.slim +++ b/app/views/management/events/_event.slim @@ -20,9 +20,12 @@ .label.label-info = event.rank =< 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 = links_to_event_participants_for(event) td.action diff --git a/app/views/management/events/_feedback.html.slim b/app/views/management/events/_feedback.html.slim new file mode 100644 index 0000000..ca1eb6e --- /dev/null +++ b/app/views/management/events/_feedback.html.slim @@ -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") diff --git a/app/views/management/events/_speaker.slim b/app/views/management/events/_speaker.slim index fad9fb5..a849de4 100644 --- a/app/views/management/events/_speaker.slim +++ b/app/views/management/events/_speaker.slim @@ -50,6 +50,8 @@ tr th = Event.human_attribute_name :title + th.text-center + = t '.rating' th.text-center = Event.human_attribute_name :rank th @@ -62,6 +64,11 @@ - speaker.events_participated_in.where.not(id: @event.id).order(created_at: :desc).each do |event| tr 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 - if event.ranked? .large diff --git a/app/views/management/events/show.html.slim b/app/views/management/events/show.html.slim index 1c411fa..377732a 100644 --- a/app/views/management/events/show.html.slim +++ b/app/views/management/events/show.html.slim @@ -65,6 +65,33 @@ h3 = Event.human_attribute_name :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? .row .col-xs-12 diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 9f07eae..69b50a5 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -158,6 +158,7 @@ bg: rank: "Класиране" user: "Лектор" participants: "Участници" + feedbacks: "Обратна връзка" event_type: description: "Описание" name: "Име" diff --git a/config/locales/en.yml b/config/locales/en.yml index 79ee6fe..eec3ff1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -67,6 +67,7 @@ en: title: Title track: Track user: Speaker + feedbacks: Feedback event_type: description: Description name: Name diff --git a/config/locales/management.bg.yml b/config/locales/management.bg.yml index d91b381..afdb60e 100644 --- a/config/locales/management.bg.yml +++ b/config/locales/management.bg.yml @@ -9,4 +9,14 @@ bg: rejected: Отхвърлен backup: Резерва events: - metadata: "%{type} на %{language} с продължителност %{length} минути" \ No newline at end of file + 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: Коментари diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 649379b..5009f1b 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -6,4 +6,14 @@ en: undecided: Undecided approved: Approved rejected: Rejected - backup: Back-up \ No newline at end of file + 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