Add vote functionality to tracks
This commit is contained in:
parent
8b2f2b538e
commit
92b09c7de4
18 changed files with 237 additions and 19 deletions
12
app/views/admin/tracks/_datatable_row_rating.haml
Normal file
12
app/views/admin/tracks/_datatable_row_rating.haml
Normal 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
|
||||
62
app/views/admin/tracks/_voting.html.haml
Normal file
62
app/views/admin/tracks/_voting.html.haml
Normal 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");
|
||||
});
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
10
app/views/admin/tracks/vote.js.erb
Normal file
10
app/views/admin/tracks/vote.js.erb
Normal 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 \
|
||||
) %>"
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue