osem-fcy/app/controllers/admin/events_controller.rb

205 lines
7.5 KiB
Ruby
Raw Normal View History

2014-06-23 19:07:50 +03:00
module Admin
class EventsController < Admin::BaseController
2014-08-12 11:51:59 +03:00
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource :event, through: :program
2016-04-22 18:18:46 +03:00
load_and_authorize_resource :events_registration, only: :toggle_attendance
# For some reason this doesn't work, so a workaround is used
# load_and_authorize_resource :track, through: :program, only: [:index, :show, :edit]
before_action :get_tracks, only: [:index, :show, :edit]
2014-02-23 14:56:09 +02:00
2014-06-23 19:07:50 +03:00
# FIXME: The timezome should only be applied on output, otherwise
# you get lost in timezone conversions...
# around_filter :set_timezone_for_this_request
2014-06-23 19:07:50 +03:00
def set_timezone_for_this_request(&block)
Time.use_zone(@conference.timezone, &block)
end
2013-01-07 09:04:09 +01:00
2014-06-23 19:07:50 +03:00
def index
@difficulty_levels = @program.difficulty_levels
@event_types = @program.event_types
2016-06-11 14:09:23 +02:00
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)
@event_distribution = @conference.event_distribution
@scheduled_event_distribution = @conference.scheduled_event_distribution
@file_name = "events_for_#{@conference.short_title}"
@event_export_option = params[:event_export_option]
2014-06-23 19:07:50 +03:00
respond_to do |format|
format.html
# Explicity call #to_json to avoid the use of EventSerializer
format.json { render json: Event.where(state: :confirmed, program: @program).to_json }
format.xlsx do
response.headers['Content-Disposition'] = "attachment; filename=\"#{@file_name}.xlsx\""
render 'events'
end
format.pdf {render 'events'}
format.csv do
response.headers['Content-Disposition'] = "attachment; filename=\"#{@file_name}.csv\""
render 'events'
end
2014-06-23 19:07:50 +03:00
end
end
2013-01-07 09:04:09 +01:00
2014-06-23 19:07:50 +03:00
def show
@event_types = @program.event_types
2014-06-23 19:07:50 +03:00
@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 LIKE ?', "%commercialable_id: #{@event.id}\ncommercialable_type: Event%") |
PaperTrail::Version.where(item_type: 'Commercial').where('object_changes LIKE ?', "%commercialable_id:\n- \n- #{@event.id}\ncommercialable_type:\n- \n- Event%") |
2017-03-02 17:07:19 +05:30
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%")
2014-06-23 19:07:50 +03:00
end
2013-01-07 09:04:09 +01:00
2014-06-23 19:07:50 +03:00
def edit
@event_types = @program.event_types
2014-06-23 19:07:50 +03:00
@comments = @event.root_comments
@comment_count = @event.comment_threads.count
@user = @event.submitter
@url = admin_conference_program_event_path(@conference.short_title, @event)
@languages = @program.languages_list
2013-01-07 09:04:09 +01:00
end
2014-06-23 19:07:50 +03:00
def comment
comment = Comment.new(comment_params)
comment.commentable = @event
comment.user_id = current_user.id
2014-06-23 19:07:50 +03:00
comment.save!
unless params[:parent].nil?
2014-06-23 19:07:50 +03:00
comment.move_to_child_of(params[:parent])
end
redirect_to admin_conference_program_event_path(@conference.short_title, @event)
2014-02-23 16:09:09 +02:00
end
2014-04-19 16:40:09 +03:00
2014-06-23 19:07:50 +03:00
def update
@languages = @program.languages_list
2015-10-28 18:05:15 +02:00
if @event.update_attributes(event_params)
2014-12-13 21:13:19 +02:00
if request.xhr?
render js: 'index'
else
2014-12-09 21:40:34 +02:00
flash[:notice] = "Successfully updated event with ID #{@event.id}."
redirect_back_or_to(admin_conference_program_event_path(@conference.short_title, @event))
2014-12-13 21:13:19 +02:00
end
2014-06-23 19:07:50 +03:00
else
@url = admin_conference_program_event_path(@conference.short_title, @event)
flash.now[:error] = 'Update not successful. ' + @event.errors.full_messages.to_sentence
2014-12-09 21:40:34 +02:00
render :edit
2014-06-23 19:07:50 +03:00
end
end
2014-06-06 10:23:01 +02:00
def create
@url = admin_conference_program_events_path(@conference.short_title, @event)
@languages = @program.languages_list
@event.submitter = current_user
if @event.save
ahoy.track 'Event submission', title: 'New submission'
redirect_to admin_conference_program_events_path(@conference.short_title), notice: 'Event was successfully submitted.'
else
flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}"
render action: 'new'
end
end
def new
@url = admin_conference_program_events_path(@conference.short_title, @event)
@languages = @program.languages_list
end
2014-06-06 10:23:01 +02:00
2014-06-23 19:07:50 +03:00
def accept
send_mail = @event.program.conference.email_settings.send_on_accepted
subject = @event.program.conference.email_settings.accepted_subject.blank?
update_state(:accept, 'Event accepted!', true, subject, send_mail)
2014-06-23 19:07:50 +03:00
end
2014-06-06 10:23:01 +02:00
2014-06-23 19:07:50 +03:00
def confirm
update_state(:confirm, 'Event confirmed!')
2014-06-23 19:07:50 +03:00
end
2014-06-06 10:23:01 +02:00
2014-06-23 19:07:50 +03:00
def cancel
update_state(:cancel, 'Event canceled!')
2014-06-23 19:07:50 +03:00
end
2013-08-27 12:38:57 +03:00
2014-06-23 19:07:50 +03:00
def reject
send_mail = @event.program.conference.email_settings.send_on_rejected
subject = @event.program.conference.email_settings.rejected_subject.blank?
update_state(:reject, 'Event rejected!', true, subject, send_mail)
2013-08-16 12:46:49 +03:00
end
2014-02-23 14:56:09 +02:00
2014-06-23 19:07:50 +03:00
def restart
update_state(:restart, 'Review started!')
2014-02-23 14:56:09 +02:00
end
2014-06-06 10:23:01 +02:00
2014-06-23 19:07:50 +03:00
def vote
@ratings = @event.votes.includes(:user)
2014-07-21 14:27:32 +02:00
if (votes = current_user.votes.find_by_event_id(params[:id]))
2014-06-23 19:07:50 +03:00
votes.update_attributes(rating: params[:rating])
else
@myvote = @event.votes.build
@myvote.user = current_user
@myvote.rating = params[:rating]
@myvote.save
end
2014-06-06 10:23:01 +02:00
2014-06-23 19:07:50 +03:00
respond_to do |format|
format.html { redirect_to admin_conference_program_event_path(@conference.short_title, @event) }
2014-06-23 19:07:50 +03:00
format.js
end
2014-06-06 10:23:01 +02:00
end
2014-06-23 19:07:50 +03:00
2016-04-22 18:18:46 +03:00
def registrations
@event_registrations = @event.events_registrations
end
def toggle_attendance
@events_registration.attended = !@events_registration.attended
if @events_registration.save
head :ok
else
head :unprocessable_entity
end
end
2014-06-23 19:07:50 +03:00
private
2015-10-28 18:05:15 +02:00
def event_params
params.require(:event).permit(
# Set also in proposals controller
:title, :subtitle, :event_type_id, :abstract, :description, :require_registration, :difficulty_level_id,
# Set only in admin/events controller
:track_id, :state, :language, :is_highlight, :max_attendees,
2015-10-28 18:05:15 +02:00
# Not used anymore?
:proposal_additional_speakers, :user, :users_attributes,
speaker_ids: [])
2015-10-28 18:05:15 +02:00
end
def comment_params
params.require(:comment).permit(:commentable, :body, :user_id)
end
def update_state(transition, notice, mail = false, subject = false, send_mail = false)
alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?)
2015-10-06 14:15:38 +03:00
if alert.blank?
2014-12-09 21:40:34 +02:00
flash[:notice] = notice
redirect_back_or_to(admin_conference_program_events_path(conference_id: @conference.short_title)) && return
2015-10-06 14:15:38 +03:00
else
flash[:error] = alert
return redirect_back_or_to(admin_conference_program_events_path(conference_id: @conference.short_title)) && return
2014-06-23 19:07:50 +03:00
end
2014-06-06 10:23:01 +02:00
end
def get_tracks
@tracks = Track.accessible_by(current_ability).where(program: @program).confirmed.cfp_active
end
2014-06-06 10:23:01 +02:00
end
2013-01-07 09:04:09 +01:00
end