2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class RegistrationsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2015-03-13 00:43:09 +01:00
|
|
|
load_and_authorize_resource :registration, through: :conference
|
2017-09-05 22:23:34 +03:00
|
|
|
before_action :set_user, except: [:index]
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def index
|
2014-08-12 11:51:59 +03:00
|
|
|
authorize! :show, Registration.new(conference_id: @conference.id)
|
2014-06-23 19:07:50 +03:00
|
|
|
@pdf_filename = "#{@conference.title}.pdf"
|
2014-08-22 15:08:54 +02:00
|
|
|
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
|
2014-06-24 12:14:53 +03:00
|
|
|
@attended = @conference.registrations.where('attended = ?', true).count
|
2016-06-12 00:20:28 +02:00
|
|
|
|
|
|
|
|
@registration_distribution = @conference.registration_distribution
|
|
|
|
|
@affiliation_distribution = @conference.affiliation_distribution
|
2018-03-16 16:23:01 -07:00
|
|
|
@code_of_conduct = @conference.code_of_conduct.present?
|
2019-03-27 19:12:50 +05:30
|
|
|
@file_name = "registrations_for_#{@conference.short_title}"
|
2018-09-21 17:32:41 -07:00
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
format.json do
|
2022-03-18 08:46:52 -07:00
|
|
|
render json: RegistrationDatatable.new(params, conference: @conference, view_context: view_context)
|
2018-09-21 17:32:41 -07:00
|
|
|
end
|
2019-03-27 19:12:50 +05:30
|
|
|
format.pdf { render 'index', layout: false }
|
|
|
|
|
format.xlsx do
|
|
|
|
|
response.headers['Content-Disposition'] = "attachment; filename=\"#{@file_name}.xlsx\""
|
|
|
|
|
render 'index', layout: false
|
|
|
|
|
end
|
|
|
|
|
format.csv do
|
|
|
|
|
response.headers['Content-Disposition'] = "attachment; filename=\"#{@file_name}.csv\""
|
|
|
|
|
render 'index', layout: false
|
|
|
|
|
end
|
2018-09-21 17:32:41 -07:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|
2013-07-12 10:45:40 +03:00
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
def edit; end
|
2013-07-12 11:43:31 +03:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def update
|
2022-02-14 17:53:58 +01:00
|
|
|
@user.update(user_params)
|
2016-05-01 18:50:07 +03:00
|
|
|
|
2022-02-14 17:53:58 +01:00
|
|
|
@registration.update(registration_params)
|
2014-06-23 19:07:50 +03:00
|
|
|
if @registration.save
|
2014-08-22 15:08:54 +02:00
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title),
|
2015-10-06 14:15:38 +03:00
|
|
|
notice: "Successfully updated registration for #{@registration.user.email}!"
|
2014-06-23 19:07:50 +03:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "An error prohibited the Registration for #{@registration.user.email}: "\
|
2014-08-22 15:08:54 +02:00
|
|
|
"#{@registration.errors.full_messages.join('. ')}."
|
|
|
|
|
render :edit
|
2013-07-16 16:03:36 +02:00
|
|
|
end
|
|
|
|
|
end
|
2013-07-12 17:40:27 +03:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def destroy
|
2014-08-12 11:51:59 +03:00
|
|
|
if can? :destroy, @registration
|
2014-08-22 15:08:54 +02:00
|
|
|
@registration.destroy
|
|
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title),
|
|
|
|
|
notice: "Deleted registration for #{@user.name}!"
|
2014-06-23 19:07:50 +03:00
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_registrations_path(@conference.short_title),
|
|
|
|
|
error: 'You must be an admin to delete a registration.'
|
2013-07-12 11:06:16 +03:00
|
|
|
end
|
2013-07-12 10:54:59 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
|
2015-07-10 15:40:11 +02:00
|
|
|
def toggle_attendance
|
|
|
|
|
@registration.attended = !@registration.attended
|
2014-11-25 10:47:18 +01:00
|
|
|
if @registration.save
|
2015-07-10 15:40:11 +02:00
|
|
|
head :ok
|
2014-11-25 10:47:18 +01:00
|
|
|
else
|
2015-07-10 15:40:11 +02:00
|
|
|
head :unprocessable_entity
|
2014-11-25 10:47:18 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-28 18:05:15 +02:00
|
|
|
private
|
2014-06-24 12:14:53 +03:00
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
def set_user
|
2014-08-28 15:21:05 +02:00
|
|
|
@user = User.find_by(id: @registration.user_id)
|
2014-06-24 12:14:53 +03:00
|
|
|
end
|
|
|
|
|
|
2016-05-02 18:02:57 +03:00
|
|
|
def user_params
|
|
|
|
|
params.require(:user).permit(:name, :nickname, :affiliation)
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
def registration_params
|
2018-03-16 16:23:01 -07:00
|
|
|
params.require(:registration).permit(
|
2018-12-29 15:36:17 -08:00
|
|
|
:user_id, :conference_id, :attended,
|
2018-03-16 16:23:01 -07:00
|
|
|
:volunteer, :other_special_needs, :accepted_code_of_conduct,
|
|
|
|
|
vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: []
|
|
|
|
|
)
|
2014-06-24 12:14:53 +03:00
|
|
|
end
|
2013-07-12 10:54:59 +03:00
|
|
|
end
|
2014-06-23 19:07:50 +03:00
|
|
|
end
|