mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
star voting system for proposals
This commit is contained in:
parent
2314d943e1
commit
834362491e
17 changed files with 157 additions and 3 deletions
BIN
app/assets/images/star-bright.png
Normal file
BIN
app/assets/images/star-bright.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
app/assets/images/star-glow.png
Normal file
BIN
app/assets/images/star-glow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1,015 B |
BIN
app/assets/images/star.png
Normal file
BIN
app/assets/images/star.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 620 B |
|
|
@ -60,6 +60,12 @@ $(function() {
|
|||
$(".comment-reply").hide();
|
||||
$(".user-details-popover").popover();
|
||||
$("#comments-div").hide();
|
||||
|
||||
$("#votes-div").hide();
|
||||
$("#votes-link").click(function(){
|
||||
$("#votes-div").toggle();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function word_count(text, divId, maxcount) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,23 @@
|
|||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
/* Styling for voting on proposals*/
|
||||
.myrating.bright { background-image: url(../assets/star-bright.png); }
|
||||
.myrating.glow { background-image: url(../assets/star-glow.png); }
|
||||
.othersrating.bright { background-image: url(../assets/star-bright.png); }
|
||||
.avgrating.bright { background-image: url(../assets/star-bright.png); }
|
||||
.avgrating {
|
||||
background: url(../assets/star.png) 0 0;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
display: block;
|
||||
}
|
||||
.myrating, .othersrating {
|
||||
background: url(../assets/star.png) 0 0;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class Admin::EventsController < ApplicationController
|
|||
@event_types = @conference.event_types
|
||||
@comments = @event.root_comments
|
||||
@comment_count = @event.comment_threads.count
|
||||
@ratings = @event.votes.includes(:person)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
@ -76,4 +77,18 @@ class Admin::EventsController < ApplicationController
|
|||
expire_page :controller => '/schedule', :action => :index
|
||||
redirect_to(admin_conference_events_path(:conference_id => @conference.short_title), :notice => "Updated state")
|
||||
end
|
||||
|
||||
def vote
|
||||
event = Event.find(params[:id])
|
||||
|
||||
if votes = current_user.person.votes.find_by_event_id(params[:id])
|
||||
votes.update_attributes(:rating => params[:rating])
|
||||
else
|
||||
@myvote = event.votes.build
|
||||
@myvote.person = current_user.person
|
||||
@myvote.rating = params[:rating]
|
||||
@myvote.save
|
||||
end
|
||||
redirect_to admin_conference_event_path(@conference.short_title, event)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ class Event < ActiveRecord::Base
|
|||
has_many :event_attachments, :dependent => :destroy
|
||||
has_many :people, :through => :event_people
|
||||
has_many :speakers, :through => :event_people, :source => :person, :conditions => {"event_people.event_role" => "speaker"}
|
||||
has_many :votes
|
||||
has_many :voters, :through => :votes, :source => :person
|
||||
belongs_to :event_type
|
||||
|
||||
|
||||
has_and_belongs_to_many :registrations
|
||||
|
||||
belongs_to :track
|
||||
|
|
@ -62,6 +64,19 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def voted?(event, person)
|
||||
event.votes.where("person_id = ?", person).first
|
||||
end
|
||||
|
||||
def average_rating
|
||||
@total_rating = 0
|
||||
self.votes.each do |vote|
|
||||
@total_rating = @total_rating + vote.rating
|
||||
end
|
||||
@total = self.votes.size
|
||||
number_with_precision(@total_rating / @total.to_f, :precision => 2, :strip_insignificant_zeros => true)
|
||||
end
|
||||
|
||||
def submitter
|
||||
result = self.event_people.where(:event_role => "submitter").first
|
||||
if !result.nil?
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ class Person < ActiveRecord::Base
|
|||
has_many :event_people, :dependent => :destroy
|
||||
has_many :events, :through => :event_people, :uniq => true
|
||||
has_many :registrations, :dependent => :destroy
|
||||
has_many :votes, :dependent => :destroy
|
||||
has_many :voted_events, :through => :votes, :source => :events
|
||||
|
||||
validates :first_name, :presence => true
|
||||
validates :last_name, :presence => true
|
||||
|
|
|
|||
10
app/models/vote.rb
Normal file
10
app/models/vote.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class Vote < ActiveRecord::Base
|
||||
attr_accessible :rating
|
||||
|
||||
belongs_to :person
|
||||
belongs_to :event
|
||||
|
||||
delegate :first_name, :to => :person
|
||||
delegate :last_name, :to => :person
|
||||
delegate :public_name, :to => :person
|
||||
end
|
||||
|
|
@ -142,7 +142,10 @@
|
|||
%td
|
||||
= link_to "Delete", conference_proposal_event_attachment_path(@conference.short_title, @event.id, a.id),
|
||||
:method => :delete, :confirm => "Are you sure you want to delete this attachment? It's permanant!"
|
||||
|
||||
.row-fluid
|
||||
= link_to "Votes (#{@event.voters.length})", "#", :id => "votes-link"
|
||||
#votes-div
|
||||
= render :partial => 'voting'
|
||||
.row-fluid
|
||||
= link_to "Comments (#{@comment_count})", "#", :id => "event-comment-link"
|
||||
#comments-div
|
||||
|
|
@ -156,4 +159,4 @@
|
|||
%br
|
||||
- @comments.each do |comment|
|
||||
%div
|
||||
= raw format_comments(comment)
|
||||
= raw format_comments(comment)
|
||||
47
app/views/admin/events/_voting.html.haml
Normal file
47
app/views/admin/events/_voting.html.haml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
%table#myeventratings{:style=>"width: 20%"}
|
||||
%tr
|
||||
%td
|
||||
%b You voted:
|
||||
%td
|
||||
- @conference.call_for_papers.rating.times do |counter|
|
||||
- voted = @event.voted?(@event, current_user.person)
|
||||
- if voted && voted.rating == counter+1
|
||||
= link_to "", vote_admin_conference_event_path(@conference.short_title, @event, :rating => counter+1), :remote => true, :id =>"label#{counter+1}", :class => "myrating", :voted => true
|
||||
- else
|
||||
= link_to "", vote_admin_conference_event_path(@conference.short_title, @event, :rating => counter+1), :remote => true, :id =>"label#{counter+1}", :class => "myrating"
|
||||
%br
|
||||
|
||||
- if @ratings.length > 0
|
||||
- @ratings.each do |rate|
|
||||
- unless rate.person_id == current_user.person.id
|
||||
%tr
|
||||
%td
|
||||
= rate.first_name
|
||||
= rate.last_name
|
||||
%td
|
||||
- @conference.call_for_papers.rating.times do |counter|
|
||||
- voted = @event.voted?(@event, rate.person)
|
||||
- if voted && voted.rating == 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
|
||||
$(function () {
|
||||
var checkedId = $("a[voted='true']").attr('id');
|
||||
$('a[id=' + checkedId + ']').prevAll().andSelf().addClass('bright');
|
||||
});
|
||||
|
||||
$(".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");
|
||||
});
|
||||
|
|
@ -115,6 +115,18 @@
|
|||
= event.id
|
||||
%td
|
||||
=link_to event.title, admin_conference_event_path(@conference.short_title, event)
|
||||
- if event.average_rating.to_f > 0
|
||||
Rating: (#{event.average_rating}/#{@conference.call_for_papers.rating})
|
||||
- else
|
||||
Rating: (0/#{@conference.call_for_papers.rating})
|
||||
|
||||
- @conference.call_for_papers.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"
|
||||
|
||||
- if event.submitter.registrations.count < 1
|
||||
- bgcolor="#F7819F"
|
||||
- else
|
||||
|
|
|
|||
1
app/views/admin/events/vote.js.erb
Normal file
1
app/views/admin/events/vote.js.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
$('table#myeventratings').replaceWith("<%= escape_javascript(render :partial => 'voting') %>");
|
||||
|
|
@ -40,6 +40,7 @@ Osem::Application.routes.draw do
|
|||
post :comment
|
||||
put :update_state
|
||||
put :update_track
|
||||
get :vote
|
||||
end
|
||||
resource :speaker, :only => [:edit, :update]
|
||||
end
|
||||
|
|
|
|||
15
db/migrate/20130815085420_create_votes.rb
Normal file
15
db/migrate/20130815085420_create_votes.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class CreateVotes < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :votes do |t|
|
||||
t.references :person
|
||||
t.references :event
|
||||
t.integer :rating
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :votes
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddRatingToCallForPapers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :call_for_papers, :rating, :integer
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddRatingDescToCallForPapers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :call_for_papers, :rating_desc, :text
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue