-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Event Ratings #1204
Implement Event Ratings #1204
Conversation
app/models/event.rb
Outdated
@@ -84,6 +85,10 @@ def registration_possible? | |||
registrations.count < max_attendees | |||
end | |||
|
|||
def ended? | |||
Time.now.to_i > event_schedules.find_by(schedule_id: program.selected_schedule_id).end_time.to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is the right way to compute if an event has ended .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use the timezone of the conference this event belongs to. And you can compare times directly without converting them to string.
timezone = program.conference.timezone
Time.find_zone(timezone).now > event_schedules.find_by(schedule: program.selected_schedule).end_time
app/models/event.rb
Outdated
@@ -84,6 +85,10 @@ def registration_possible? | |||
registrations.count < max_attendees | |||
end | |||
|
|||
def ended? | |||
Time.now.to_i > event_schedules.find_by(schedule_id: program.selected_schedule_id).end_time.to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use the timezone of the conference this event belongs to. And you can compare times directly without converting them to string.
timezone = program.conference.timezone
Time.find_zone(timezone).now > event_schedules.find_by(schedule: program.selected_schedule).end_time
@shlok007 did you review other gems for this as well? |
Sorry for the late response. Yes, i stumbled upon letsrate gem as well. There is always a possibility to write our own rating system to rate proposals. |
Nah we don't have to do that, if there is something well maintained with updates that suits our needs. But I would like to know what other gems you evaluated and what the one you chose offers us. So can you provide some more details about your choice of gem? What advantages/disadvantages it has in comparison with other alternatives? Things like that which will help us make a conscious decision. We will use voting extensively, so we should choose the gem wisely and then use it for all the places we have/will have voting. |
I stumbled upon This poster lists the additional features that ratyrate has over letsrate. At the end of the day, all the rating gems wraps the JQuery Raty library so if none works for us we have an option to manually add and use the library ourself. |
Do let me know what should be appropriate here. I'll proceed with this PR and try fixing the Hakiri test failures as well if we decide to use |
Please rebase! |
2799ad2
to
c511f19
Compare
@@ -0,0 +1,760 @@ | |||
/*! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this file here?
app/models/event.rb
Outdated
@@ -1,5 +1,6 @@ | |||
class Event < ActiveRecord::Base | |||
include ActiveRecord::Transitions | |||
ratyrate_rateable 'speaker_quality', 'competence', 'slides' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this custom? Meaning an organizer chooses the qualities to rate on.
What about making this available on the admin side as well? Let's first decide on how to implement it, in a way that does not disrupt too much conferences using the current way of voting (and only want 1 point of voting, overall voting - not voting on multiple qualities). |
@@ -0,0 +1,62 @@ | |||
$.fn.raty.defaults.half = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this file if we have the gem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gem seems to have included it by itself. I am wondering the same. Although, I'll give it a check if the gem still works the same when I get rid of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to work without it.
app/models/rate.rb
Outdated
belongs_to :rater, class_name: 'User' | ||
belongs_to :rateable, polymorphic: true | ||
|
||
# attr_accessible :rate, :dimension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we do. This is automatically generated code. I'll look up more for comments/things like these that can be safely removed. Although, I shouldn't change much except comments as I won't know reason things were introduced.
Do we truly need to introduce all those new models? |
app/models/votable_field.rb
Outdated
validates :title, :votable_type, presence: true | ||
|
||
# ratyrate does not allow criterias to have spaces in them | ||
validate :no_spaces_in_title |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another solution could be to replace spaces with another character like underscore ( _ ) and convert them back to spaces while rendering them in proposals#show . But this could be a problem if the user actually defines a field that has a underscore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ask for proper names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By proper names you mean names without spaces, the way it is currently done, right? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You commented on the code that ratyrate does not allow votable_fields to have spaces, so that's what's proper. No spaces. This is very similar to the validation we do for conference.short_title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better if I use regexp instead of this to check for no spaces ?
app/models/votable_field.rb
Outdated
end | ||
|
||
def correct_votable_type | ||
errors.add(:votable_type, "should be one of the following: 'Event'") unless ['Event'].include? votable_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
available votable_types should be in a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed .. 😅
config/routes.rb
Outdated
@@ -1,5 +1,6 @@ | |||
Osem::Application.routes.draw do | |||
|
|||
post '/rate' => 'rater#create', :as => 'rate' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as: 'rate'
8f8fa24
to
b348de8
Compare
So I guess the remaining things to take into account here are:
|
It seems like ratyrate does not allow using same names ( Ticket in ratyrate to address the same: wazery/ratyrate#143 . |
The two drawbacks of using this gem are:
In both the cases we have an option to just go with the default behaviour although, it might reduce the usability. |
@@ -23,6 +23,9 @@ gem 'mysql2' | |||
# for observing records | |||
gem 'rails-observers' | |||
|
|||
# for rating | |||
gem 'ratyrate', github: 'wazery/ratyrate', branch: 'master' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I am really unsure about. The released version of ratyrate contains a bug in the rating_for_user method that shows a particular user's rating. This method is required for blind voting. However, the master is quite stable and does not contain the bug. This could be a temporary change until we get a response regarding wazery/ratyrate#125 ( issue asking for a new version release )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does using the gem from the master branch instead of the released version something we can agree upon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this master branch version you guys are talking about? I'm trying the master, but keep comes the alpha, is there another file to download?
I'm having a lot of issues with this gem for helper rating_for_user
. I can't record at overrall_averages
and average_cache
tables, as long record the rater_id
at rate table.
The method on this file is also comment:
https://github.com/wazery/ratyrate/blob/master/lib/ratyrate/model.rb
tks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the master branch is as simple as using this line above in the Gemfile. It would be great if we can discuss this more on the issue itself rather than here. 🙂
b374e0d
to
9ab074c
Compare
9e4d2ef
to
6110406
Compare
Except tests, the work on this PR should be complete. Can it be please temporarily deployed to heroku at this stage for everyone else to review ? |
@shlok007 it would be useful if you added the necessary records in the review app. |
Please rebase, and feel free to squash those commits to make rebasing easier (you can leave a couple of commits, if you think that's useful). |
202b072
to
53d89f8
Compare
edeadc4
to
c07fd30
Compare
Documenting the new rating feature: https://docs.google.com/document/d/1sWImuP14RFeTWrs3nqdRZt8xfD0-xr0hBj10B2_KCQQ/edit?usp=sharing |
width: 24px; | ||
height: 24px; | ||
display: inline-block; | ||
img.raty-cancel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cancel button doesn't cancel the rating but instead clicking on cancel changes the rating to '0' stars. This property is to prevent the cancel button from being displayed.
|
||
private | ||
|
||
def remove_rates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To delete the existing rating for a votable field so when a new field of same title is created, it does not have any previous rating present already.
bad1373
to
360a764
Compare
I am thinking that if we manually have to introduce the custom votable fields we want, then we might as well not use the gem, and just extend the capabilities of the existing voting options we have, and refactor where needed. |
end | ||
|
||
it 'is not valid without a votable field' do | ||
should validate_presence_of(:votable_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(".disabled-rate .star").each(function(){ | ||
$(this).raty('readOnly', true); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line
@@ -22,7 +22,7 @@ class Conference < ActiveRecord::Base | |||
has_many :supporters, through: :ticket_purchases, source: :user | |||
has_many :tickets, dependent: :destroy | |||
has_many :resources, dependent: :destroy | |||
|
|||
has_many :votable_fields, dependent: :destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be in Program?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then probably we should move VotableField to be a program option instead of conference in all places including views and routes of the app as well. I should do that also. :)
@@ -1,5 +1,8 @@ | |||
class Event < ActiveRecord::Base | |||
include ActiveRecord::Transitions | |||
|
|||
scope :vote, ->(votable_fields) { votable_fields.each { |field| ratyrate_rateable field.title } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can name this better, as vote
does not really convey the meaning of what we are doing here. votable_on
?
end | ||
|
||
## | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line
@@ -1,14 +1,2 @@ | |||
class Vote < ActiveRecord::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we keeping this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a rake task to migrate old votes into new. The Vote model class is required for that task. If this class is removed we might have to write raw SQL inside the task to access the old votes data table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other ways to do that. Eg. https://github.com/openSUSE/osem/blob/master/db/migrate/20140610165551_migrate_data_person_to_user.rb#L2
= f.input :title | ||
= f.input :votable_type, collection: options_for_select(['Event']) | ||
= f.input :stars, label: 'Add the total number of stars for the field' | ||
= f.input :for_admin, label: 'Add this field for voting in admin side only' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we have 2 boolean options, one for admin namespace, one for attendees? That way we can have votable fields available only for admin, or only for attendees, or for both.
= f.input :blind_voting, hint: 'Enable this feature if you do not want to show voting results and voters prior to user submitting a vote. For the feature to work you need to set the voting dates below as well' | ||
= f.input :voting_start_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_start_date.to_formatted_s(:db_without_seconds) unless f.object.voting_start_date.nil?) } | ||
= f.input :voting_end_date, as: :string, input_html: { id: 'datetimepicker-voting_start_date', readonly: true, value: (f.object.voting_end_date.to_formatted_s(:db_without_seconds) unless f.object.voting_end_date.nil?) } | ||
= f.input :rating_enabled, label: 'Enable voting', hint: 'To enable voting you need to set voting dates as well' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a new section to separate the voting options from the rest.
I would like to close this PR:
|
What I had in mind was to keep the stars rating, but maybe we should indeed look into integrating something specifically for this reason into surveys. Indeed it's been a while since we worked on this. Closing. |
Refers to issue #1158 .
Rfc: https://docs.google.com/document/d/1sWImuP14RFeTWrs3nqdRZt8xfD0-xr0hBj10B2_KCQQ/edit?usp=sharing
To-Do: