2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
module Admin
|
2016-09-14 22:42:04 -04:00
|
|
|
class ConferencesController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2015-10-25 13:29:02 +02:00
|
|
|
load_resource :program, through: :conference, singleton: true, except: :index
|
2014-08-13 16:05:54 +03:00
|
|
|
load_resource :user, only: [:remove_user]
|
2014-06-11 09:31:13 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def index
|
|
|
|
|
# Redirect to new form if there is no conference
|
|
|
|
|
if Conference.count == 0
|
|
|
|
|
redirect_to new_admin_conference_path
|
|
|
|
|
return
|
|
|
|
|
end
|
2014-06-03 16:27:10 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@total_user = User.count
|
|
|
|
|
@new_user = User.where('created_at > ?', current_user.last_sign_in_at).count
|
2014-06-03 16:27:10 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@total_reg = Registration.count
|
|
|
|
|
@new_reg = Registration.where('created_at > ?', current_user.last_sign_in_at).count
|
2014-05-30 10:10:47 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@total_submissions = Event.count
|
|
|
|
|
@new_submissions = Event.where('created_at > ?', current_user.last_sign_in_at).count
|
2014-06-02 12:37:57 +02:00
|
|
|
|
2018-02-18 16:17:29 -03:00
|
|
|
@total_withdrawn = Event.where(state: :withdrawn).count
|
|
|
|
|
@new_withdrawn = Event
|
|
|
|
|
.where('state = ? and created_at > ?', 'withdrawn', current_user.last_sign_in_at).count
|
|
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@active_conferences = Conference.get_active_conferences_for_dashboard # pending or the last two
|
2017-04-06 23:19:58 -04:00
|
|
|
@deactive_conferences = Conference
|
|
|
|
|
.get_conferences_without_active_for_dashboard(@active_conferences) # conferences without active
|
2014-08-06 21:14:00 +03:00
|
|
|
@conferences = @active_conferences + @deactive_conferences
|
2014-06-04 16:11:33 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@recent_users = User.limit(5).order(created_at: :desc)
|
|
|
|
|
@recent_events = Event.limit(5).order(created_at: :desc)
|
|
|
|
|
@recent_registrations = Registration.limit(5).order(created_at: :desc)
|
2014-06-04 16:11:33 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@top_submitter = Conference.get_top_submitter
|
2014-06-02 12:37:57 +02:00
|
|
|
|
2018-12-19 12:59:52 -08:00
|
|
|
@registrations = []
|
|
|
|
|
@submissions = []
|
|
|
|
|
@tickets = []
|
2017-04-20 09:47:19 +03:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@conferences.each do |c|
|
|
|
|
|
# Conference registrations over time chart
|
2018-12-19 12:59:52 -08:00
|
|
|
@registrations << {
|
|
|
|
|
name: c.short_title,
|
|
|
|
|
data: c.get_registrations_per_week
|
|
|
|
|
}
|
|
|
|
|
# Event submissions over time chart
|
|
|
|
|
@submissions << {
|
|
|
|
|
name: c.short_title,
|
|
|
|
|
data: c.get_submissions_per_week
|
|
|
|
|
}
|
2017-04-20 09:47:19 +03:00
|
|
|
# Tickets sold over time chart
|
2018-12-19 12:59:52 -08:00
|
|
|
@tickets << {
|
|
|
|
|
name: c.short_title,
|
|
|
|
|
data: c.get_tickets_sold_per_week
|
|
|
|
|
}
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
2014-06-02 12:37:57 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@event_distribution = Conference.event_distribution
|
2018-12-19 12:59:52 -08:00
|
|
|
@event_distribution_colors = Event::COLORS.values
|
|
|
|
|
|
|
|
|
|
@user_distribution = User.distribution
|
|
|
|
|
@user_distribution_colors = User::DISTRIBUTION_COLORS.values
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def new
|
|
|
|
|
@conference = Conference.new
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def create
|
2017-06-07 14:14:42 +05:30
|
|
|
@conference = Conference.new(conference_params)
|
2017-08-13 02:31:46 +05:30
|
|
|
|
2015-01-12 23:13:10 +02:00
|
|
|
if @conference.save
|
2014-08-12 11:51:59 +03:00
|
|
|
# user that creates the conference becomes organizer of that conference
|
|
|
|
|
current_user.add_role :organizer, @conference
|
2015-01-12 23:13:10 +02:00
|
|
|
|
2016-03-10 14:25:38 +05:30
|
|
|
redirect_to admin_conference_path(id: @conference.short_title),
|
|
|
|
|
notice: 'Conference was successfully created.'
|
2014-08-06 21:14:00 +03:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = 'Could not create conference. ' + @conference.errors.full_messages.to_sentence
|
2014-08-06 21:14:00 +03:00
|
|
|
render action: 'new'
|
|
|
|
|
end
|
2014-05-09 14:44:18 +02:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-12 16:04:24 +05:30
|
|
|
def update
|
|
|
|
|
short_title = @conference.short_title
|
2015-10-28 18:05:15 +02:00
|
|
|
@conference.assign_attributes(conference_params)
|
2014-08-18 14:33:02 +02:00
|
|
|
send_mail_on_conf_update = @conference.notify_on_dates_changed?
|
2014-08-12 16:04:24 +05:30
|
|
|
|
2022-02-14 17:53:58 +01:00
|
|
|
if @conference.update(conference_params)
|
2016-04-21 15:08:00 +02:00
|
|
|
ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to edit_admin_conference_path(id: @conference.short_title),
|
|
|
|
|
notice: 'Conference was successfully updated.'
|
2014-08-12 16:04:24 +05:30
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to edit_admin_conference_path(id: short_title),
|
2016-03-16 11:20:56 +05:30
|
|
|
error: 'Updating conference failed. ' \
|
2016-03-11 02:08:00 +05:30
|
|
|
"#{@conference.errors.full_messages.join('. ')}."
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
|
|
|
|
end
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def show
|
2018-02-22 21:23:41 -08:00
|
|
|
@program = @conference.program || Program.new(conference_id: @conference.id)
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
# Overview and since last login information
|
|
|
|
|
@total_reg = @conference.registrations.count
|
|
|
|
|
@new_reg = @conference.registrations.where('created_at > ?', current_user.last_sign_in_at).count
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2018-02-18 16:17:29 -03:00
|
|
|
@all_events = @program.events
|
|
|
|
|
|
|
|
|
|
@total_submissions = @all_events.count
|
|
|
|
|
@new_submissions = @all_events
|
2017-04-06 23:19:58 -04:00
|
|
|
.where('created_at > ?', current_user.last_sign_in_at).count
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@program_length = @conference.current_program_hours
|
|
|
|
|
@new_program_length = @conference.new_program_hours(current_user.last_sign_in_at)
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2018-02-18 16:17:29 -03:00
|
|
|
@total_withdrawn = @all_events.where(state: :withdrawn).count
|
2018-02-25 20:11:09 -08:00
|
|
|
@new_withdrawn = @all_events.where(state: :withdrawn).where(
|
|
|
|
|
'events.created_at > ?',
|
|
|
|
|
current_user.last_sign_in_at
|
|
|
|
|
).count
|
2018-02-18 16:17:29 -03:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
# Step by step list
|
|
|
|
|
@conference_progress = @conference.get_status
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
# Line charts
|
2018-12-19 12:59:52 -08:00
|
|
|
@registrations = @conference.get_registrations_per_week
|
|
|
|
|
@submissions = @conference.get_submissions_data
|
|
|
|
|
@tickets = @conference.get_tickets_data
|
2017-04-20 09:47:19 +03:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
# Doughnut charts
|
|
|
|
|
@event_type_distribution = @conference.event_type_distribution
|
|
|
|
|
@event_type_distribution_confirmed = @conference.event_type_distribution(:confirmed)
|
2018-02-18 16:17:29 -03:00
|
|
|
@event_type_distribution_withdrawn = @conference.event_type_distribution(:withdrawn)
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@difficulty_levels_distribution = @conference.difficulty_levels_distribution
|
2017-04-06 23:19:58 -04:00
|
|
|
@difficulty_levels_distribution_confirmed = @conference
|
|
|
|
|
.difficulty_levels_distribution(:confirmed)
|
2018-02-18 16:17:29 -03:00
|
|
|
@difficulty_levels_distribution_withdrawn = @conference
|
|
|
|
|
.difficulty_levels_distribution(:withdrawn)
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@tracks_distribution = @conference.tracks_distribution
|
|
|
|
|
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)
|
2018-02-18 16:17:29 -03:00
|
|
|
@tracks_distribution_withdrawn = @conference.tracks_distribution(:withdrawn)
|
2014-06-16 13:51:43 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
# Recent actions information
|
2015-10-25 13:29:02 +02:00
|
|
|
@recent_events = @conference.program.events.limit(5).order(created_at: :desc)
|
2014-08-06 21:14:00 +03:00
|
|
|
@recent_registrations = @conference.registrations.limit(5).order(created_at: :desc)
|
2014-06-11 09:31:13 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
@top_submitter = @conference.get_top_submitter
|
2014-06-26 09:08:26 +02:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
format.json { render json: @conference.to_json }
|
|
|
|
|
end
|
2014-05-23 13:01:23 +02:00
|
|
|
end
|
|
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def edit
|
|
|
|
|
@conferences = Conference.all
|
2014-08-07 21:33:08 +02:00
|
|
|
@date_string = date_string(@conference.start_date, @conference.end_date)
|
2017-11-11 00:54:31 +05:30
|
|
|
@affected_event_count = @conference.program.events.scheduled(@conference.program.selected_schedule_id).count
|
2014-08-06 21:14:00 +03:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
format.json { render json: @conference.to_json }
|
|
|
|
|
end
|
2013-01-11 15:00:54 +01:00
|
|
|
end
|
2014-08-12 16:06:46 +03:00
|
|
|
|
2015-10-28 18:05:15 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def conference_params
|
2016-03-23 17:18:51 +02:00
|
|
|
params.require(:conference).permit(:title, :short_title, :description, :timezone,
|
2016-08-15 12:39:39 +02:00
|
|
|
:start_date, :end_date, :start_hour, :end_hour,
|
|
|
|
|
:rooms_attributes, :tracks_attributes,
|
2016-03-23 17:18:51 +02:00
|
|
|
:tickets_attributes, :event_types_attributes,
|
2016-04-27 15:17:12 +02:00
|
|
|
:picture, :picture_cache, :questions_attributes,
|
2015-10-28 18:05:15 +02:00
|
|
|
:question_ids, :answers_attributes, :answer_ids, :difficulty_levels_attributes,
|
2016-06-24 22:41:18 +05:30
|
|
|
:use_vpositions, :use_vdays, :vdays_attributes,
|
2015-10-28 18:05:15 +02:00
|
|
|
:vpositions_attributes, :use_volunteers, :color,
|
|
|
|
|
:sponsorship_levels_attributes, :sponsors_attributes,
|
2018-10-08 17:58:41 -07:00
|
|
|
:registration_limit, :organization_id, :ticket_layout,
|
|
|
|
|
:booth_limit)
|
2015-10-28 18:05:15 +02:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
end
|