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
2017-08-03 11:15:19 +05:30
def custom_domain ; end
2017-08-03 00:07:38 +05:30
2017-08-05 01:53:59 +05:30
def attach_custom_domain ; end
def update_domain
@conference . assign_attributes ( conference_params )
if @conference . save
redirect_to custom_domain_admin_conference_path ( id : @conference . short_title ) ,
notice : 'Added new domain name to conference. This does not mean that the new domain should work. Please make sure you follow step 2 to point your domain to this hosted version'
else
redirect_to custom_domain_admin_conference_path ( id : @conference . short_title ) ,
notice : 'Failed to add the new domain as custom domain to the conference'
end
end
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
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
2014-08-06 21:14:00 +03:00
@submissions = { }
@cfp_weeks = [ 0 ]
2014-05-30 10:10:47 +02:00
2014-08-06 21:14:00 +03:00
@registrations = { }
@registration_weeks = [ 0 ]
2014-06-02 12:37:57 +02:00
2017-04-20 09:47:19 +03:00
@tickets = { }
@ticket_weeks = [ 0 ]
2014-08-06 21:14:00 +03:00
@conferences . each do | c |
# Event submissions over time chart
@submissions [ c . short_title ] = c . get_submissions_per_week
@cfp_weeks . push ( @submissions [ c . short_title ] . length )
2014-05-30 10:10:47 +02:00
2014-08-06 21:14:00 +03:00
# Conference registrations over time chart
@registrations [ c . short_title ] = c . get_registrations_per_week
@registration_weeks . push ( @registrations [ c . short_title ] . length )
2017-04-20 09:47:19 +03:00
# Tickets sold over time chart
@tickets [ c . short_title ] = c . get_tickets_sold_per_week
@ticket_weeks . push ( @tickets [ c . short_title ] . length )
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
@cfp_weeks = @cfp_weeks . max
@submissions = normalize_array_length ( @submissions , @cfp_weeks )
@cfp_weeks = @cfp_weeks > 0 ? ( 1 .. @cfp_weeks ) . to_a : 1
2014-05-30 10:10:47 +02:00
2014-08-06 21:14:00 +03:00
@registration_weeks = @registration_weeks . max
@registrations = normalize_array_length ( @registrations , @registration_weeks )
@registration_weeks = @registration_weeks > 0 ? ( 1 .. @registration_weeks ) . to_a : 1
2013-01-07 09:04:09 +01:00
2017-04-20 09:47:19 +03:00
@ticket_weeks = @ticket_weeks . max
@tickets = normalize_array_length ( @tickets , @ticket_weeks )
@ticket_weeks = @ticket_weeks > 0 ? ( 1 .. @ticket_weeks ) . to_a : 1
2014-08-06 21:14:00 +03:00
@event_distribution = Conference . event_distribution
@user_distribution = Conference . user_distribution
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-06-10 19:36:50 +05:30
@conference . organization = Organization . find_or_create_by ( name : 'organization' )
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
2015-10-28 18:05:15 +02:00
if @conference . update_attributes ( 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
2015-10-25 13:29:02 +02:00
@program = @conference . program
unless @conference . program
@program = Program . new ( conference_id : @conference . id )
end
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
2015-10-25 13:29:02 +02:00
@total_submissions = @program . events . count
2017-04-06 23:19:58 -04:00
@new_submissions = @program . events
. 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
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
2014-08-07 21:33:08 +02:00
@registrations = { @conference . short_title = > @conference . get_registrations_per_week }
2014-08-06 21:14:00 +03:00
@registration_weeks = [ 0 ]
@registration_weeks . push ( @registrations [ @conference . short_title ] . length )
2014-06-16 13:51:43 +02:00
2014-08-06 21:14:00 +03:00
@registration_weeks = @registration_weeks . max
@registrations = normalize_array_length ( @registrations , @registration_weeks )
@registration_weeks = @registration_weeks > 0 ? ( 1 .. @registration_weeks ) . to_a : 1
2014-06-16 13:51:43 +02:00
2014-08-06 21:14:00 +03:00
@submissions = Conference . get_event_state_line_colors
2014-06-16 13:51:43 +02:00
2014-08-06 21:14:00 +03:00
@submissions_data = { }
@submissions_data = @conference . get_submissions_data
@cfp_weeks = 0
if @submissions_data [ 'Weeks' ]
@cfp_weeks = @submissions_data [ 'Weeks' ]
@submissions_data = @submissions_data . except ( 'Weeks' )
end
2014-06-16 13:51:43 +02:00
2017-04-20 09:47:19 +03:00
@tickets_data = { }
@tickets_data = @conference . get_tickets_data
@ticket_weeks = 0
if @tickets_data [ 'Weeks' ]
@ticket_weeks = @tickets_data [ 'Weeks' ]
@tickets_data = @tickets_data . except ( 'Weeks' )
end
# Set line color using a hash function
@tickets = [ ]
@tickets_data . keys . each do | title |
@tickets . append ( short_title : title , color : " \# #{ Digest :: MD5 . hexdigest ( title ) [ 0 .. 5 ] } " )
end
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 )
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 )
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 )
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
# get targets
@registration_targets = @conference . get_targets ( Target . units [ :registrations ] )
@submission_targets = @conference . get_targets ( Target . units [ :submissions ] )
@program_minutes_targets = @conference . get_targets ( Target . units [ :program_minutes ] )
2014-06-26 09:08:26 +02:00
2014-08-06 21:14:00 +03:00
# get campaigns
@campaigns = @conference . get_campaigns
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 )
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 ,
2016-04-27 12:36:38 +02:00
:targets , :targets_attributes ,
2017-08-05 01:53:59 +05:30
:campaigns , :campaigns_attributes , :registration_limit , :organization_id , :ticket_layout , :custom_domain )
2015-10-28 18:05:15 +02:00
end
2013-01-07 09:04:09 +01:00
end
end