diff --git a/app/assets/stylesheets/management/_record_tables.scss b/app/assets/stylesheets/management/_record_tables.scss index 41f9ca1..4ce85c4 100644 --- a/app/assets/stylesheets/management/_record_tables.scss +++ b/app/assets/stylesheets/management/_record_tables.scss @@ -22,6 +22,10 @@ th.action, td.action { } } +th.main { + width: 100%; +} + .conference-title { display: inline-block; @include button-size($padding-base-vertical, $padding-base-horizontal, $font-size-base, $line-height-base, $btn-border-radius-base); diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e5090c6..b8758cd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -66,10 +66,10 @@ module ApplicationHelper 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 (0...3) then 'primary' + when 3 then 'danger' + when 4 then 'warning' + when 5 then 'info' when 6 then 'success' end end diff --git a/app/models/concerns/feedback_receiving.rb b/app/models/concerns/feedback_receiving.rb new file mode 100644 index 0000000..12e639f --- /dev/null +++ b/app/models/concerns/feedback_receiving.rb @@ -0,0 +1,11 @@ +module FeedbackReceiving + extend ActiveSupport::Concern + + def average_rating + feedbacks.average(:rating) + end + + def rated? + feedbacks.size > 0 + end +end diff --git a/app/models/event.rb b/app/models/event.rb index 2b98f81..a170803 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,8 +11,10 @@ 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 has_many :feedbacks_with_comment, -> { where.not(comment: [nil, ""]) }, as: :feedback_receiving, class_name: 'Feedback' + include FeedbackReceiving belongs_to :event_type @@ -36,14 +38,6 @@ 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/models/user.rb b/app/models/user.rb index b27f8ca..950a5f1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,10 +9,22 @@ class User < ActiveRecord::Base has_many :workshops has_many :propositions, foreign_key: :proposer_id has_many :events, through: :propositions, source: :proposable, source_type: "Event" + has_many :feedbacks, through: :events + has_many :feedbacks_with_comment, -> { where.not(comment: [nil, '']) }, through: :events + has_many :participations, foreign_key: :participant_id has_many :events_participated_in, through: :participations, source: :event has_many :volunteerships, foreign_key: :volunteer_id + include FeedbackReceiving + + def average_rating + return nil unless rated? + ratings_per_event = feedbacks.group(:feedback_receiving_type, + :feedback_receiving_id).average(:rating).values + BigDecimal(ratings_per_event.reduce(&:+)) / BigDecimal(ratings_per_event.size) + end + def find_or_build_personal_profile(conference, params = {}) current_profile = personal_profile(conference) if current_profile.present? diff --git a/app/views/management/events/_feedback.html.slim b/app/views/management/events/_feedback.html.slim deleted file mode 100644 index ca1eb6e..0000000 --- a/app/views/management/events/_feedback.html.slim +++ /dev/null @@ -1,12 +0,0 @@ -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/show.html.slim b/app/views/management/events/show.html.slim index 377732a..59a00bf 100644 --- a/app/views/management/events/show.html.slim +++ b/app/views/management/events/show.html.slim @@ -76,7 +76,7 @@ - if @event.feedbacks_with_comment.size > 0 table.table.table-striped tbody - = render partial: 'feedback', collection: @event.feedbacks.where.not(comment: [nil, '']) + = render partial: '/management/shared/feedback', collection: @event.feedbacks_with_comment - else .panel-body = t ('.no_comments_received') diff --git a/app/views/management/personal_profiles/show.html.slim b/app/views/management/personal_profiles/show.html.slim index 2bf3b43..81f6822 100644 --- a/app/views/management/personal_profiles/show.html.slim +++ b/app/views/management/personal_profiles/show.html.slim @@ -45,14 +45,40 @@ .btn-group.btn-group-sm = action_buttons @conference, @profile, [:edit, :destroy] .col-sm-7.col-md-8 + .row + .col-md-6 + .panel.panel-info + .panel-heading + .row + .col-xs-3 + = icon 'files-o', '', class: 'fa-5x' + .col-xs-9.text-right + .huge + = @user.events_participated_in.size + div + = Event.model_name.human(count: @user.events_participated_in.size) + .col-md-6 + .panel class="panel-#{rating_label_color(@user.average_rating || 5)}" title=human_rating(@user.average_rating) + .panel-heading + .row + .col-xs-3 + = icon 'star', '', class: 'fa-5x' + .col-xs-9.text-right + .huge + = number_with_precision(@user.average_rating, precision: 2, strip_insignificant_zeros: true) || '–' + div + = User.human_attribute_name(:average_rating).downcase + h2 = t '.talk_history' .panel.panel-default - if @user.events_participated_in.any? table.table.table-striped.table-hover.record-table thead tr - th + th.main = Event.human_attribute_name :title + th.text-center + = Event.human_attribute_name :rating th.text-center.hidden-md.hidden-sm.hidden-xs = Event.human_attribute_name :rank th.hidden-md.hidden-sm.hidden-xs @@ -64,6 +90,11 @@ - @user.events_participated_in.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)}" title=human_rating(event.average_rating) + = number_with_precision event.average_rating, precision: 2, strip_insignificant_zeros: true td.text-center.hidden-md.hidden-sm.hidden-xs - if event.ranked? .large @@ -77,3 +108,11 @@ td.actions .btn-group.btn-group-sm = action_buttons event.conference, event, [:show] + h2 = t '.comments_from_the_audience' + - if @user.feedbacks_with_comment.size > 0 + .panel.panel-default + table.table.table-striped + tbody + = render partial: '/management/shared/feedback', collection: @user.feedbacks_with_comment.order(created_at: :desc) + - else + p = t '.no_comments_received' diff --git a/app/views/management/shared/_feedback.html.slim b/app/views/management/shared/_feedback.html.slim new file mode 100644 index 0000000..3ee7ed6 --- /dev/null +++ b/app/views/management/shared/_feedback.html.slim @@ -0,0 +1,16 @@ +tr + td.text-center + .huge + .label class="label-#{rating_label_color(feedback.rating)}" title=human_rating(feedback.rating) + = feedback.rating + td + blockquote + = simple_format feedback.comment + footer + - if feedback.author_email.present? + = feedback.author_email + - else + = t(".anonymous") + - if !local_assigns[:show_title] + span<> = t '.about' + = link_to feedback.feedback_receiving.title, [:management, feedback.feedback_receiving.conference, feedback.feedback_receiving] diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 69b50a5..b686793 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -118,6 +118,9 @@ bg: view: button: "Прегледай %{model}" title: "Преглед на %{model}" + attributes: + average_rating: Средна оценка + rating: Оценка activerecord: attributes: feedback: diff --git a/config/locales/management.bg.yml b/config/locales/management.bg.yml index afdb60e..9b7d2c2 100644 --- a/config/locales/management.bg.yml +++ b/config/locales/management.bg.yml @@ -11,6 +11,16 @@ bg: events: metadata: "%{type} на %{language} с продължителност %{length} минути" management: + shared: + feedback: + anonymous: Анонимен + about: относно + personal_profiles: + show: + talk_history: Събития с участието на лектора + comments_from_the_audience: Коментари от аудиторията + no_comments_received: Все още няма коментари. + private_email: Личен e-mail events: show: average_grade: Средна оценка @@ -20,3 +30,9 @@ bg: no_feedback_received: Все още няма обратна връзка no_comments_received: Все още няма коментари comments: Коментари + ratings: + poor: Слаб + average: Среден + good: Добър + very_good: Мн. добър + excellent: Отличен