Clean up rating partials
This commit is contained in:
parent
73c5c3c97a
commit
9e10678542
10 changed files with 131 additions and 92 deletions
|
|
@ -1,19 +1,16 @@
|
||||||
/* Styling for voting on proposals*/
|
/* Styling for voting on proposals*/
|
||||||
.myrating.bright { background-image: image-url("star-bright.png"); }
|
.rating {
|
||||||
.myrating.glow { background-image: image-url("star-glow.png"); }
|
|
||||||
.othersrating.bright { background-image: image-url("star-bright.png"); }
|
|
||||||
.avgrating.bright { background-image: image-url("star-bright.png"); }
|
|
||||||
.avgrating {
|
|
||||||
background: image-url("star.png") 0 0;
|
background: image-url("star.png") 0 0;
|
||||||
margin-right: -2px;
|
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
|
||||||
.myrating, .othersrating {
|
|
||||||
background: image-url("star.png") 0 0;
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
float: left;
|
float: left;
|
||||||
}
|
|
||||||
|
|
||||||
|
&.bright {
|
||||||
|
background-image: image-url("star-bright.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
&.glow {
|
||||||
|
background-image: image-url("star-glow.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ module Admin
|
||||||
@event_types = @program.event_types
|
@event_types = @program.event_types
|
||||||
@comments = @event.root_comments
|
@comments = @event.root_comments
|
||||||
@comment_count = @event.comment_threads.count
|
@comment_count = @event.comment_threads.count
|
||||||
@ratings = @event.votes.includes(:user)
|
@votes = @event.votes.includes(:user)
|
||||||
@difficulty_levels = @program.difficulty_levels
|
@difficulty_levels = @program.difficulty_levels
|
||||||
@versions = @event.versions |
|
@versions = @event.versions |
|
||||||
PaperTrail::Version.where(item_type: 'Commercial').where('object LIKE ?', "%commercialable_id: #{@event.id}\ncommercialable_type: Event%") |
|
PaperTrail::Version.where(item_type: 'Commercial').where('object LIKE ?', "%commercialable_id: #{@event.id}\ncommercialable_type: Event%") |
|
||||||
|
|
@ -146,7 +146,7 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote
|
def vote
|
||||||
@ratings = @event.votes.includes(:user)
|
@votes = @event.votes.includes(:user)
|
||||||
|
|
||||||
if (votes = current_user.votes.find_by_event_id(params[:id]))
|
if (votes = current_user.votes.find_by_event_id(params[:id]))
|
||||||
votes.update_attributes(rating: params[:rating])
|
votes.update_attributes(rating: params[:rating])
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,19 @@ module EventsHelper
|
||||||
"Registered: #{event.registrations.count}"
|
"Registered: #{event.registrations.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
def rating_stars(rating, max, options = {})
|
||||||
# Checks if the voting has already started, or if it has already ended
|
Array.new(max) do |counter|
|
||||||
#
|
content_tag(
|
||||||
def voting_open_or_close(program)
|
'label',
|
||||||
return if program.voting_period?
|
'',
|
||||||
if program.voting_start_date > Time.current
|
class: "rating#{' bright' if rating.to_f > counter}",
|
||||||
return 'Voting period has not started yet!'
|
**options
|
||||||
else # voting_end_date > Date.today because voting_start_date < voting_end_date
|
)
|
||||||
return 'Voting period is over!'
|
end.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rating_fraction(rating, max, options = {})
|
||||||
|
content_tag('span', "#{rating}/#{max}", **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replacement_event_notice(event_schedule)
|
def replacement_event_notice(event_schedule)
|
||||||
|
|
@ -47,4 +50,8 @@ module EventsHelper
|
||||||
include_blank: '(Please select)'
|
include_blank: '(Please select)'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rating_tooltip(event, max_rating)
|
||||||
|
"#{event.average_rating}/#{max_rating}, #{pluralize(event.voters.length, 'vote')}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
12
app/views/admin/events/_datatable_row_rating.haml
Normal file
12
app/views/admin/events/_datatable_row_rating.haml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
- if show_votes
|
||||||
|
%div{ data: { toggle: 'tooltip' }, title: rating_tooltip(event, max_rating) }<
|
||||||
|
= rating_stars(event.average_rating, max_rating, avgrate: true)
|
||||||
|
|
||||||
|
.clearfix
|
||||||
|
- if event.voted?(current_user)
|
||||||
|
%span.label.label-success
|
||||||
|
You voted:
|
||||||
|
= rating_fraction(event.user_rating(current_user), max_rating)
|
||||||
|
- else
|
||||||
|
%span.label.label-danger
|
||||||
|
Not rated
|
||||||
|
|
@ -168,8 +168,14 @@
|
||||||
%b Requirements
|
%b Requirements
|
||||||
%td= simple_format(@event.description)
|
%td= simple_format(@event.description)
|
||||||
|
|
||||||
- if @conference.program && @conference.program.rating && @conference.program.rating > 0
|
- if @conference.program.rating_enabled?
|
||||||
= render partial: 'voting'
|
= render 'voting',
|
||||||
|
event: @event,
|
||||||
|
show_votes: @program.show_voting?,
|
||||||
|
max_rating: @program.rating,
|
||||||
|
voting_period: @program.voting_period?,
|
||||||
|
votes: @votes,
|
||||||
|
conference_id: @conference.short_title
|
||||||
|
|
||||||
.row
|
.row
|
||||||
= link_to "Comments (#{@comment_count})", '#', id: 'event-comment-link'
|
= link_to "Comments (#{@comment_count})", '#', id: 'event-comment-link'
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,56 @@
|
||||||
%table.table#myrating
|
%table.table#myrating
|
||||||
- if @program.show_voting?
|
- if show_votes
|
||||||
%tr
|
%tr
|
||||||
%td.col-md-2
|
%td.col-md-2
|
||||||
%b Rating
|
%b Rating
|
||||||
%td
|
%td
|
||||||
- if @event.average_rating.to_f > 0
|
#{event.average_rating}/#{max_rating}
|
||||||
#{@event.average_rating}/#{@program.rating}
|
= rating_stars(event.average_rating, max_rating, avgrate: true )
|
||||||
- else
|
|
||||||
Rating: 0/#{@program.rating}
|
|
||||||
|
|
||||||
- @program.rating.times do |counter|
|
|
||||||
- if @event.average_rating.to_f.round == counter + 1
|
|
||||||
= label_tag 'label_rating', '', class: 'avgrating', avgrate: true
|
|
||||||
= javascript_tag "$('label[avgrate=true]').prevAll().andSelf().addClass('bright');"
|
|
||||||
- else
|
|
||||||
= label_tag 'label_rating', '', class: 'avgrating'
|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
%b Voters
|
%b Voters
|
||||||
%td
|
%td
|
||||||
= @event.voters.length
|
= votes.length
|
||||||
- if @event.voters.length > 0
|
- unless votes.blank?
|
||||||
(
|
(
|
||||||
= @ratings.map {|x| "#{x.name}"}.join ', '
|
= votes.collect(&:name).to_sentence
|
||||||
)
|
)
|
||||||
%tr
|
%tr
|
||||||
%td.col-md-2
|
%td.col-md-2
|
||||||
%b Your vote
|
%b Your vote
|
||||||
%td
|
%td
|
||||||
- if @program.voting_period?
|
- if voting_period
|
||||||
- @program.rating.times do |counter|
|
- max_rating.times do |counter|
|
||||||
- if @event.voted?(current_user) && @event.user_rating(current_user) == counter + 1
|
- if event.user_rating(current_user) > counter
|
||||||
= link_to '', vote_admin_conference_program_event_path(@conference.short_title, @event, rating: counter + 1), remote: true, id: "label#{counter + 1}", class: 'myrating', voted: true
|
= link_to '',
|
||||||
|
vote_admin_conference_program_event_path(conference_id,
|
||||||
|
event, rating: counter + 1),
|
||||||
|
remote: true,
|
||||||
|
id: "label#{counter + 1}",
|
||||||
|
class: 'rating myrating bright',
|
||||||
|
voted: true
|
||||||
- else
|
- else
|
||||||
= link_to '', vote_admin_conference_program_event_path(@conference.short_title, @event, rating: counter + 1), remote: true, id: "label#{counter + 1}", class: 'myrating'
|
= link_to '',
|
||||||
%br
|
vote_admin_conference_program_event_path(conference_id,
|
||||||
|
event, rating: counter + 1),
|
||||||
|
remote: true,
|
||||||
|
id: "label#{counter + 1}",
|
||||||
|
class: 'rating myrating'
|
||||||
- else
|
- else
|
||||||
- @conference.program.rating.times do |counter|
|
= rating_stars(event.user_rating(current_user), max_rating, voted: true)
|
||||||
- if @event.voted?(current_user) && @event.user_rating(current_user) == counter + 1
|
= (Voting period is closed)
|
||||||
= label_tag "label#{counter + 1}", '', class: 'othersrating', voted: true
|
|
||||||
= javascript_tag "$('label[voted=true]').prevAll().andSelf().addClass('bright');"
|
|
||||||
- else
|
|
||||||
= label_tag "label#{counter + 1}", '', class: 'othersrating'
|
|
||||||
(#{voting_open_or_close(@program)})
|
|
||||||
|
|
||||||
- if @program.show_voting?
|
- if show_votes
|
||||||
- if @ratings.length > 0
|
- unless votes.blank?
|
||||||
- @ratings.each do |rate|
|
- votes.each do |vote|
|
||||||
- unless rate.user_id == current_user.id
|
- unless vote.user_id == current_user.id
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= rate.name
|
= vote.name
|
||||||
%td
|
%td
|
||||||
- @conference.program.rating.times do |counter|
|
= rating_stars(vote, max_rating )
|
||||||
|
|
||||||
- if @event.voted?(rate.user) && @event.user_rating(rate.user) == counter + 1
|
|
||||||
= label_tag "label#{counter + 1}", "", class: 'othersrating', voted: true
|
|
||||||
= javascript_tag "$('label[voted=true]').prevAll().andSelf().addClass('bright');"
|
|
||||||
- else
|
|
||||||
= label_tag "label#{counter + 1}", "", class: 'othersrating'
|
|
||||||
:javascript
|
:javascript
|
||||||
$(function () {
|
|
||||||
var checkedId = $("a[voted='true']").attr('id');
|
|
||||||
$('a[id=' + checkedId + ']').prevAll().andSelf().addClass('bright');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".myrating").hover(
|
$(".myrating").hover(
|
||||||
function() { // mouseover
|
function() { // mouseover
|
||||||
$(this).prevAll().andSelf().addClass('glow');
|
$(this).prevAll().andSelf().addClass('glow');
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
- if @program.show_voting?
|
|
||||||
#{event.average_rating}/#{@program.rating}
|
|
||||||
%br
|
|
||||||
#{pluralize(event.voters.length, 'voter')}
|
|
||||||
%br
|
|
||||||
- @program.rating.times do |counter|
|
|
||||||
- if event.average_rating.to_f.round == counter + 1
|
|
||||||
= label_tag 'label_rating', '', class: 'avgrating', avgrate: true
|
|
||||||
= javascript_tag "$('label[avgrate=true]').prevAll().andSelf().addClass('bright');"
|
|
||||||
- else
|
|
||||||
= label_tag 'label_rating', '', class: 'avgrating'
|
|
||||||
%br
|
|
||||||
|
|
||||||
- if event.voted?(current_user)
|
|
||||||
%span.label.label-success
|
|
||||||
Your rating: #{ event.user_rating(current_user) }
|
|
||||||
- else
|
|
||||||
%span.label.label-danger
|
|
||||||
Not rated
|
|
||||||
|
|
@ -106,8 +106,11 @@
|
||||||
= link_to event.title, admin_conference_program_event_path(@conference.short_title, event)
|
= link_to event.title, admin_conference_program_event_path(@conference.short_title, event)
|
||||||
|
|
||||||
- if @program.rating_enabled?
|
- if @program.rating_enabled?
|
||||||
%td.col-md-1{ 'data-order' => "#{event.average_rating}" }
|
%td.col-md-1{ data: { order: event.average_rating } }
|
||||||
= render partial: 'voting_index', locals: { event: event }
|
= render 'datatable_row_rating',
|
||||||
|
event: event,
|
||||||
|
show_votes: @program.show_voting?,
|
||||||
|
max_rating: @program.rating
|
||||||
|
|
||||||
- if event.submitter && event.submitter.registrations && event.submitter.registrations.count < 1
|
- if event.submitter && event.submitter.registrations && event.submitter.registrations.count < 1
|
||||||
- bgcolor = '#F7819F'
|
- bgcolor = '#F7819F'
|
||||||
|
|
|
||||||
|
|
@ -1 +1,10 @@
|
||||||
$('table#myrating').replaceWith("<%= escape_javascript(render :partial => 'voting') %>");
|
$('table#myrating').replaceWith(
|
||||||
|
"<%= escape_javascript(render 'voting', \
|
||||||
|
event: @event, \
|
||||||
|
show_votes: @program.show_voting?, \
|
||||||
|
max_rating: @program.rating, \
|
||||||
|
voting_period: @program.voting_period?, \
|
||||||
|
votes: @votes, \
|
||||||
|
conference_id: @conference.short_title \
|
||||||
|
) %>"
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,13 @@ require 'spec_helper'
|
||||||
describe EventsHelper, type: :helper do
|
describe EventsHelper, type: :helper do
|
||||||
let(:conference) { create(:conference) }
|
let(:conference) { create(:conference) }
|
||||||
let(:event) { create(:event, program: conference.program) }
|
let(:event) { create(:event, program: conference.program) }
|
||||||
|
let(:my_vote) { 3 }
|
||||||
|
let(:max_rating) { 5 }
|
||||||
|
let(:fraction) { my_vote.to_s + '/' + max_rating.to_s }
|
||||||
|
|
||||||
|
setup do
|
||||||
|
allow(event).to receive(:average_rating) { my_vote }
|
||||||
|
end
|
||||||
|
|
||||||
describe '#registered_text' do
|
describe '#registered_text' do
|
||||||
describe 'returns correct string' do
|
describe 'returns correct string' do
|
||||||
|
|
@ -18,4 +25,35 @@ describe EventsHelper, type: :helper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#rating_tooltip' do
|
||||||
|
let(:vote_count) { pluralize(event.voters.length, 'vote') }
|
||||||
|
|
||||||
|
it 'includes the average rating' do
|
||||||
|
expect(rating_tooltip(event, max_rating)).to match(fraction)
|
||||||
|
end
|
||||||
|
it 'includes the vote count' do
|
||||||
|
expect(rating_tooltip(event, max_rating)).to match(vote_count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#rating_fraction' do
|
||||||
|
it 'represents the rating as a fraction of the max' do
|
||||||
|
expect(rating_fraction(my_vote, max_rating)).to match(fraction)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'rating_stars' do
|
||||||
|
it 'renders labels for each value of max_rating' do
|
||||||
|
expect(
|
||||||
|
rating_stars(my_vote, max_rating).scan('<label class="rating').size
|
||||||
|
).to eq(max_rating)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders bright labels for each value of vote' do
|
||||||
|
expect(
|
||||||
|
rating_stars(my_vote, max_rating).scan('<label class="rating bright').size
|
||||||
|
).to eq(my_vote)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue