Add vote functionality to tracks

This commit is contained in:
Rishabh Singh 2019-08-09 17:33:42 +05:30
parent 8b2f2b538e
commit 92b09c7de4
18 changed files with 237 additions and 19 deletions

View file

@ -0,0 +1,12 @@
- if show_votes
%div{ data: { toggle: 'tooltip' }, title: rating_tooltip(track, max_rating) }<
= rating_stars(track.average_rating, max_rating, avgrate: true)
.clearfix
- if track.voted?(current_user)
%span.label.label-success
You voted:
= rating_fraction(track.user_rating(current_user), max_rating)
- else
%span.label.label-danger
Not rated

View file

@ -0,0 +1,62 @@
%table.table#myrating
- if show_votes
%tr
%td.col-md-2
%b Rating
%td
#{track.average_rating}/#{max_rating}
= rating_stars(track.average_rating, max_rating, avgrate: true)
%tr
%td
%b Voters
%td
= votes.length
- if votes.present?
(
= votes.collect(&:name).to_sentence
)
%tr
%td.col-md-2
%b Your vote
%td
- if voting_period
- max_rating.times do |counter|
- if track.user_rating(current_user) > counter
= link_to '', vote_admin_conference_program_track_path(conference_id, track, rating: counter + 1),
remote: true,
id: "label#{counter + 1}",
class: 'rating myrating bright',
voted: true
- else
= link_to '', vote_admin_conference_program_track_path(conference_id, track, rating: counter + 1),
remote: true,
id: "label#{counter + 1}",
class: 'rating myrating'
- else
= rating_stars(track.user_rating(current_user), max_rating, voted: true)
(Voting period is closed)
- if show_votes
- if votes.present?
- votes.each do |vote|
- unless vote.user_id == current_user.id
%tr
%td
= vote.name
%td
= rating_stars(vote.rating, max_rating)
:javascript
$(".myrating").hover(
function() { // mouseover
$(this).prevAll().andSelf().addClass('glow');
},
function() { // mouseout
$(this).siblings().andSelf().removeClass('glow');
}
);
$(".myrating").click(function() {
$(this).siblings().removeClass("bright");
$(this).prevAll().andSelf().addClass("bright");
});

View file

@ -37,6 +37,9 @@
%thead
%th ID
%th Name
- if @program.rating_enabled?
%th
%b Rating
%th Description
%th Room
%th Start Date
@ -54,6 +57,12 @@
= link_to admin_conference_program_track_path(@conference.short_title, track), class: 'btn' do
%span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"}
= track.name
- if @program.rating_enabled?
%td.col-md-1{ data: { order: track.average_rating } }
= render 'datatable_row_rating',
track: track,
show_votes: @program.show_voting?,
max_rating: @program.rating
%td
%p
= markdown(truncate(track.description))

View file

@ -104,6 +104,14 @@
%b Relevance
%td
= markdown(@track.relevance)
- if @conference.program.rating_enabled?
= render 'voting',
track: @track,
show_votes: @program.show_voting?,
max_rating: @program.rating,
voting_period: @program.voting_period?,
votes: @votes,
conference_id: @conference.short_title
.tab-pane#events
.col-md-12

View file

@ -0,0 +1,10 @@
$('table#myrating').replaceWith(
"<%= escape_javascript(render 'voting', \
track: @track, \
show_votes: @program.show_voting?, \
max_rating: @program.rating, \
voting_period: @program.voting_period?, \
votes: @votes, \
conference_id: @conference.short_title \
) %>"
);

View file

@ -70,7 +70,7 @@
- when 'EventsRegistration', 'Comment', 'Vote', 'Event'
event
- event_id = object.try(:event_id) || object.try(:commentable_id) || object.id
- event_id = object.try(:votable_id) || object.try(:event_id) || object.try(:commentable_id) || object.id
= link_to (current_or_last_object_state('Event', event_id).try(:title) || 'deleted event'),
admin_conference_program_event_path(conference_short_title, event_id)