Implement Event Ratings
This commit is contained in:
parent
5be1ad52ee
commit
20f4853487
67 changed files with 1298 additions and 378 deletions
|
|
@ -47,13 +47,12 @@ module Admin
|
|||
@event_types = @program.event_types
|
||||
@comments = @event.root_comments
|
||||
@comment_count = @event.comment_threads.count
|
||||
@ratings = @event.votes.includes(:user)
|
||||
@difficulty_levels = @program.difficulty_levels
|
||||
@versions = @event.versions |
|
||||
PaperTrail::Version.where(item_type: 'Commercial').where_object(commercialable_id: @event.id, commercialable_type: 'Event') |
|
||||
PaperTrail::Version.where(item_type: 'Commercial').where_object_changes(commercialable_id: @event.id, commercialable_type: 'Event') |
|
||||
PaperTrail::Version.where(item_type: 'Vote').where('object_changes LIKE ?', "%\nevent_id:\n- \n- #{@event.id}\n%") |
|
||||
PaperTrail::Version.where(item_type: 'Vote').where('object LIKE ?', "%\nevent_id: #{@event.id}\n%")
|
||||
PaperTrail::Version.where(item_type: 'Commercial').where_object_changes(commercialable_id: @event.id, commercialable_type: 'Event')
|
||||
@votable_fields = VotableField.where(votable_type: 'Event', conference: @event.program.conference, enabled: true, for_admin: true)
|
||||
Event.vote(@votable_fields)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
@ -142,24 +141,6 @@ module Admin
|
|||
update_state(:restart, 'Review started!')
|
||||
end
|
||||
|
||||
def vote
|
||||
@ratings = @event.votes.includes(:user)
|
||||
|
||||
if (votes = current_user.votes.find_by_event_id(params[:id]))
|
||||
votes.update_attributes(rating: params[:rating])
|
||||
else
|
||||
@myvote = @event.votes.build
|
||||
@myvote.user = current_user
|
||||
@myvote.rating = params[:rating]
|
||||
@myvote.save
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_conference_program_event_path(@conference.short_title, @event) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def registrations
|
||||
@event_registrations = @event.events_registrations
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ module Admin
|
|||
private
|
||||
|
||||
def program_params
|
||||
params.require(:program).permit(:rating, :schedule_public, :schedule_interval, :schedule_fluid, :languages, :blind_voting, :voting_start_date, :voting_end_date, :selected_schedule_id)
|
||||
params.require(:program).permit(:rating, :rating_enabled, :schedule_public, :schedule_interval, :schedule_fluid, :languages, :blind_voting, :voting_start_date, :voting_end_date, :selected_schedule_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
57
app/controllers/admin/votable_fields_controller.rb
Normal file
57
app/controllers/admin/votable_fields_controller.rb
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
module Admin
|
||||
class VotableFieldsController < ApplicationController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :votable_field
|
||||
after_action :remove_rates, only: :destroy
|
||||
|
||||
def index; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@votable_field = @conference.votable_fields.new
|
||||
end
|
||||
|
||||
def create
|
||||
@votable_field = @conference.votable_fields.new(votable_field_params)
|
||||
if @votable_field.save
|
||||
redirect_to admin_conference_votable_fields_path(@conference.short_title),
|
||||
notice: 'Votable field successfully created.'
|
||||
else
|
||||
flash[:error] = "Creating votable field failed: #{@votable_field.errors.full_messages.join('. ')}."
|
||||
redirect_to new_admin_conference_votable_field_path(@conference.short_title)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @votable_field.update_attributes(votable_field_params)
|
||||
flash[:notice] = 'Votable field successfully updated'
|
||||
redirect_to admin_conference_votable_fields_path(@conference.short_title)
|
||||
else
|
||||
flash[:error] = "Votable field update failed: #{@votable_field.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @votable_field.destroy
|
||||
redirect_to admin_conference_votable_fields_path(@conference.short_title),
|
||||
notice: 'Votable field successfully destroyed.'
|
||||
else
|
||||
redirect_to admin_conference_votable_fields_path(@conference.short_title),
|
||||
error: 'Votable field could not be destroyed.' \
|
||||
"#{@votable_field.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_rates
|
||||
false unless Rate.where(dimension: @votable_field.title).destroy_all && RatingCache.where(dimension: @votable_field.title).destroy_all
|
||||
end
|
||||
|
||||
def votable_field_params
|
||||
params.require(:votable_field).permit(:title, :enabled, :votable_type, :conference_id, :for_admin, :stars)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue