Revamp the personal profile details view

This commit is contained in:
Petko Bordjukov 2019-04-30 01:04:40 +03:00
parent 7bb4ba478c
commit 9930665156
11 changed files with 109 additions and 26 deletions

View File

@ -22,6 +22,10 @@ th.action, td.action {
} }
} }
th.main {
width: 100%;
}
.conference-title { .conference-title {
display: inline-block; display: inline-block;
@include button-size($padding-base-vertical, $padding-base-horizontal, $font-size-base, $line-height-base, $btn-border-radius-base); @include button-size($padding-base-vertical, $padding-base-horizontal, $font-size-base, $line-height-base, $btn-border-radius-base);

View File

@ -66,10 +66,10 @@ module ApplicationHelper
def rating_label_color(rating) def rating_label_color(rating)
case rating.round case rating.round
when (0...3) then 'danger' when (0...3) then 'primary'
when 3 then 'warning' when 3 then 'danger'
when 4 then 'info' when 4 then 'warning'
when 5 then 'primary' when 5 then 'info'
when 6 then 'success' when 6 then 'success'
end end
end end

View File

@ -0,0 +1,11 @@
module FeedbackReceiving
extend ActiveSupport::Concern
def average_rating
feedbacks.average(:rating)
end
def rated?
feedbacks.size > 0
end
end

View File

@ -11,8 +11,10 @@ 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 has_many :feedbacks, as: :feedback_receiving
has_many :feedbacks_with_comment, -> { where.not(comment: [nil, ""]) }, as: :feedback_receiving, class_name: 'Feedback' has_many :feedbacks_with_comment, -> { where.not(comment: [nil, ""]) }, as: :feedback_receiving, class_name: 'Feedback'
include FeedbackReceiving
belongs_to :event_type belongs_to :event_type
@ -36,14 +38,6 @@ 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

@ -9,10 +9,22 @@ class User < ActiveRecord::Base
has_many :workshops has_many :workshops
has_many :propositions, foreign_key: :proposer_id has_many :propositions, foreign_key: :proposer_id
has_many :events, through: :propositions, source: :proposable, source_type: "Event" 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 :participations, foreign_key: :participant_id
has_many :events_participated_in, through: :participations, source: :event has_many :events_participated_in, through: :participations, source: :event
has_many :volunteerships, foreign_key: :volunteer_id 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 = {}) def find_or_build_personal_profile(conference, params = {})
current_profile = personal_profile(conference) current_profile = personal_profile(conference)
if current_profile.present? if current_profile.present?

View File

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

View File

@ -76,7 +76,7 @@
- if @event.feedbacks_with_comment.size > 0 - if @event.feedbacks_with_comment.size > 0
table.table.table-striped table.table.table-striped
tbody tbody
= render partial: 'feedback', collection: @event.feedbacks.where.not(comment: [nil, '']) = render partial: '/management/shared/feedback', collection: @event.feedbacks_with_comment
- else - else
.panel-body .panel-body
= t ('.no_comments_received') = t ('.no_comments_received')

View File

@ -45,14 +45,40 @@
.btn-group.btn-group-sm .btn-group.btn-group-sm
= action_buttons @conference, @profile, [:edit, :destroy] = action_buttons @conference, @profile, [:edit, :destroy]
.col-sm-7.col-md-8 .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' h2 = t '.talk_history'
.panel.panel-default .panel.panel-default
- if @user.events_participated_in.any? - if @user.events_participated_in.any?
table.table.table-striped.table-hover.record-table table.table.table-striped.table-hover.record-table
thead thead
tr tr
th th.main
= Event.human_attribute_name :title = Event.human_attribute_name :title
th.text-center
= Event.human_attribute_name :rating
th.text-center.hidden-md.hidden-sm.hidden-xs th.text-center.hidden-md.hidden-sm.hidden-xs
= Event.human_attribute_name :rank = Event.human_attribute_name :rank
th.hidden-md.hidden-sm.hidden-xs th.hidden-md.hidden-sm.hidden-xs
@ -64,6 +90,11 @@
- @user.events_participated_in.order(created_at: :desc).each do |event| - @user.events_participated_in.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)}" 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 td.text-center.hidden-md.hidden-sm.hidden-xs
- if event.ranked? - if event.ranked?
.large .large
@ -77,3 +108,11 @@
td.actions td.actions
.btn-group.btn-group-sm .btn-group.btn-group-sm
= action_buttons event.conference, event, [:show] = 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'

View File

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

View File

@ -118,6 +118,9 @@ bg:
view: view:
button: "Прегледай %{model}" button: "Прегледай %{model}"
title: "Преглед на %{model}" title: "Преглед на %{model}"
attributes:
average_rating: Средна оценка
rating: Оценка
activerecord: activerecord:
attributes: attributes:
feedback: feedback:

View File

@ -11,6 +11,16 @@ bg:
events: events:
metadata: "%{type} на %{language} с продължителност %{length} минути" metadata: "%{type} на %{language} с продължителност %{length} минути"
management: management:
shared:
feedback:
anonymous: Анонимен
about: относно
personal_profiles:
show:
talk_history: Събития с участието на лектора
comments_from_the_audience: Коментари от аудиторията
no_comments_received: Все още няма коментари.
private_email: Личен e-mail
events: events:
show: show:
average_grade: Средна оценка average_grade: Средна оценка
@ -20,3 +30,9 @@ bg:
no_feedback_received: Все още няма обратна връзка no_feedback_received: Все още няма обратна връзка
no_comments_received: Все още няма коментари no_comments_received: Все още няма коментари
comments: Коментари comments: Коментари
ratings:
poor: Слаб
average: Среден
good: Добър
very_good: Мн. добър
excellent: Отличен