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

203 lines
7.3 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
2014-02-23 14:56:09 +02:00
2016-08-21 15:22:31 +05:30
before_action :get_event, except: [:index, :create, :reports]
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
@events = @program.events
@tracks = @program.tracks
@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
@tracks = @program.tracks
@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(commercialable_id: @event.id, commercialable_type: 'Event') |
PaperTrail::Version.where(item_type: 'Commercial').where_object_changes(commercialable_id: @event.id, commercialable_type: 'Event')
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
@tracks = Track.all
@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
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)
2016-04-22 18:18:46 +03:00
flash[: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; 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
2016-08-21 15:22:31 +05:30
def reports
@events = @program.events
@events_commercials = Commercial.where(commercialable_type: 'Event', commercialable_id: @events.pluck(:id))
@events_missing_commercial = @events.where.not(id: @events_commercials.pluck(:commercialable_id))
@events_with_requirements = @events.where.not(description: ['', nil])
2016-09-26 17:01:39 +05:30
attended_registrants_ids = @conference.registrations.where(attended: true).pluck(:user_id)
@missing_event_speakers = EventUser.joins(:event).where('event_role = ? and program_id = ?', 'submitter', @program.id).
where.not(user_id: attended_registrants_ids).includes(:user, :event)
2016-08-21 15:22:31 +05:30
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)
end
def comment_params
params.require(:comment).permit(:commentable, :body, :user_id)
end
def get_event
@event = @conference.program.events.find(params[:id])
unless @event
redirect_to admin_conference_program_events_path(conference_id: @conference.short_title),
error: 'Error! Could not find event!'
return
2014-06-23 19:07:50 +03:00
end
@event
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
end
2013-01-07 09:04:09 +01:00
end