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

188 lines
7.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-08-06 21:14:00 +03:00
module Admin
class ConferencesController < Admin::BaseController
2014-08-12 11:51:59 +03:00
load_and_authorize_resource :conference, find_by: :short_title
load_resource :program, through: :conference, singleton: true, except: :index
load_resource :user, only: [:remove_user]
2014-08-06 21:14:00 +03:00
def index
# Redirect to new form if there is no conference
2025-08-12 16:44:20 +02:00
if Conference.none?
2014-08-06 21:14:00 +03:00
redirect_to new_admin_conference_path
return
end
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-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-08-06 21:14:00 +03:00
@total_submissions = Event.count
@new_submissions = Event.where('created_at > ?', current_user.last_sign_in_at).count
@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-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-08-06 21:14:00 +03:00
@top_submitter = Conference.get_top_submitter
@registrations = []
@submissions = []
@tickets = []
2014-08-06 21:14:00 +03:00
@conferences.each do |c|
# Conference registrations over time chart
@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
}
# Tickets sold over time chart
@tickets << {
name: c.short_title,
data: c.get_tickets_sold_per_week
}
2014-08-06 21:14:00 +03:00
end
2014-08-06 21:14:00 +03:00
@event_distribution = Conference.event_distribution
@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)
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
redirect_to admin_conference_path(id: @conference.short_title),
notice: 'Conference was successfully created.'
2014-08-06 21:14:00 +03:00
else
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
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)
send_mail_on_conf_update = @conference.notify_on_dates_changed?
2014-08-12 16:04:24 +05:30
if @conference.save
ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update
redirect_to edit_admin_conference_path(id: @conference.short_title),
notice: 'Conference was successfully updated.'
2014-08-12 16:04:24 +05:30
else
redirect_to edit_admin_conference_path(id: short_title),
error: 'Updating conference failed. ' \
"#{@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
@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
@total_withdrawn = @all_events.where(state: :withdrawn).count
@new_withdrawn = @all_events.where(state: :withdrawn).where(
'events.created_at > ?',
current_user.last_sign_in_at
).count
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
@registrations = @conference.get_registrations_per_week
@submissions = @conference.get_submissions_data
@tickets = @conference.get_tickets_data
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)
@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)
@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)
@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
@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-08-06 21:14:00 +03:00
@top_submitter = @conference.get_top_submitter
2014-08-06 21:14:00 +03:00
respond_to do |format|
format.html
format.json { render json: @conference.to_json }
end
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)
@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
end
2014-08-12 16:06:46 +03:00
2015-10-28 18:05:15 +02:00
private
def conference_params
params.require(:conference).permit(:title, :short_title, :description, :timezone,
:start_date, :end_date, :start_hour, :end_hour,
:rooms_attributes, :tracks_attributes,
: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,
:use_vpositions, :use_vdays, :vdays_attributes,
2015-10-28 18:05:15 +02:00
:vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes,
2024-06-07 16:19:29 +02:00
:registration_limit, :ticket_layout,
2024-06-07 17:35:41 +02:00
:booth_limit, :code_of_conduct)
2015-10-28 18:05:15 +02:00
end
2013-01-07 09:04:09 +01:00
end
end