refatored conferences_controller
This commit is contained in:
parent
616615a749
commit
50bce629d8
3 changed files with 200 additions and 73 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
class ConferencesController < ApplicationController
|
class ConferencesController < ApplicationController
|
||||||
protect_from_forgery with: :null_session
|
protect_from_forgery with: :null_session
|
||||||
before_action :respond_to_options
|
before_action :respond_to_options
|
||||||
|
before_action :conference, only: [:show]
|
||||||
|
before_action :set_conferences_service, only: [:show]
|
||||||
load_and_authorize_resource find_by: :short_title, except: :show
|
load_and_authorize_resource find_by: :short_title, except: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
@ -14,14 +16,6 @@ class ConferencesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
# load conference with header content
|
|
||||||
@conference = Conference.unscoped.eager_load(
|
|
||||||
:splashpage,
|
|
||||||
:program,
|
|
||||||
:registration_period,
|
|
||||||
:contact,
|
|
||||||
venue: :commercial
|
|
||||||
).find_by!(conference_finder_conditions)
|
|
||||||
authorize! :show, @conference # TODO: reduce the 10 queries performed here
|
authorize! :show, @conference # TODO: reduce the 10 queries performed here
|
||||||
|
|
||||||
splashpage = @conference.splashpage
|
splashpage = @conference.splashpage
|
||||||
|
|
@ -29,42 +23,7 @@ class ConferencesController < ApplicationController
|
||||||
unless splashpage.present?
|
unless splashpage.present?
|
||||||
redirect_to admin_conference_splashpage_path(@conference.short_title) && return
|
redirect_to admin_conference_splashpage_path(@conference.short_title) && return
|
||||||
end
|
end
|
||||||
|
handle_present_splash_page(splashpage)
|
||||||
@image_url = "#{request.protocol}#{request.host}#{@conference.picture}"
|
|
||||||
|
|
||||||
if splashpage.include_cfp
|
|
||||||
cfps = @conference.program.cfps
|
|
||||||
@call_for_events = cfps.find { |call| call.cfp_type == 'events' }
|
|
||||||
if @call_for_events.try(:open?)
|
|
||||||
@event_types = @conference.event_types.pluck(:title)
|
|
||||||
@track_names = @conference.confirmed_tracks.pluck(:name).sort
|
|
||||||
end
|
|
||||||
@call_for_tracks = cfps.find { |call| call.cfp_type == 'tracks' }
|
|
||||||
@call_for_booths = cfps.find { |call| call.cfp_type == 'booths' }
|
|
||||||
end
|
|
||||||
if splashpage.include_program
|
|
||||||
@highlights = @conference.highlighted_events.eager_load(:speakers)
|
|
||||||
if splashpage.include_tracks
|
|
||||||
@tracks = @conference.confirmed_tracks.eager_load(
|
|
||||||
:room
|
|
||||||
).order('tracks.name')
|
|
||||||
end
|
|
||||||
if splashpage.include_booths
|
|
||||||
@booths = @conference.confirmed_booths.order('title')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if splashpage.include_registrations || splashpage.include_tickets
|
|
||||||
@tickets = @conference.tickets.order('price_cents')
|
|
||||||
end
|
|
||||||
if splashpage.include_lodgings
|
|
||||||
@lodgings = @conference.lodgings.order('name')
|
|
||||||
end
|
|
||||||
if splashpage.include_sponsors
|
|
||||||
@sponsorship_levels = @conference.sponsorship_levels.eager_load(
|
|
||||||
:sponsors
|
|
||||||
).order('sponsorship_levels.position ASC', 'sponsors.name')
|
|
||||||
@sponsors = @conference.sponsors
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def calendar
|
def calendar
|
||||||
|
|
@ -72,34 +31,11 @@ class ConferencesController < ApplicationController
|
||||||
format.ics do
|
format.ics do
|
||||||
calendar = Icalendar::Calendar.new
|
calendar = Icalendar::Calendar.new
|
||||||
Conference.all.each do |conf|
|
Conference.all.each do |conf|
|
||||||
if params[:full]
|
service = ConferenceCalendarService.new(calendar, conf)
|
||||||
event_schedules = conf.program.selected_event_schedules(
|
calendar = if params[:full]
|
||||||
includes: [{ event: %i[event_type speakers submitter] }]
|
service.full_calendar
|
||||||
)
|
|
||||||
calendar = icalendar_proposals(calendar, event_schedules.map(&:event), conf)
|
|
||||||
else
|
else
|
||||||
calendar.event do |e|
|
service.not_full_calendar
|
||||||
e.dtstart = conf.start_date
|
|
||||||
e.dtstart.ical_params = { 'VALUE'=>'DATE' }
|
|
||||||
e.dtend = conf.end_date
|
|
||||||
e.dtend.ical_params = { 'VALUE'=>'DATE' }
|
|
||||||
e.duration = "P#{(conf.end_date - conf.start_date + 1).floor}D"
|
|
||||||
e.created = conf.created_at
|
|
||||||
e.last_modified = conf.updated_at
|
|
||||||
e.summary = conf.title
|
|
||||||
e.description = conf.description
|
|
||||||
e.uid = conf.guid
|
|
||||||
e.url = conference_url(conf.short_title)
|
|
||||||
v = conf.venue
|
|
||||||
if v
|
|
||||||
e.geo = v.latitude, v.longitude if v.latitude && v.longitude
|
|
||||||
location = ''
|
|
||||||
location += "#{v.street}, " if v.street
|
|
||||||
location += "#{v.postalcode} #{v.city}, " if v.postalcode && v.city
|
|
||||||
location += v.country_name if v.country_name
|
|
||||||
e.location = location if location
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
calendar.publish
|
calendar.publish
|
||||||
|
|
@ -110,6 +46,51 @@ class ConferencesController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def handle_present_splash_page(splashpage)
|
||||||
|
@image_url = @service.conference_image_url(request)
|
||||||
|
|
||||||
|
if splashpage.include_cfp
|
||||||
|
cfp_variables
|
||||||
|
end
|
||||||
|
|
||||||
|
if splashpage.include_program
|
||||||
|
program_variables
|
||||||
|
end
|
||||||
|
|
||||||
|
@tickets = @service.if_include_registrations_or_tickets
|
||||||
|
@lodgings = @service.if_include_lodgings
|
||||||
|
|
||||||
|
if splashpage.include_sponsors
|
||||||
|
sponsor_variables
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def program_variables
|
||||||
|
@highlights = @conference.highlighted_events.eager_load(:speakers)
|
||||||
|
@tracks = @service.if_include_tracks
|
||||||
|
@booths = @service.if_include_booths
|
||||||
|
end
|
||||||
|
|
||||||
|
def cfp_variables
|
||||||
|
@call_for_events = @service.cfp_call_by_type('events')
|
||||||
|
@event_types, @track_names = @service.cfp_variables_if_event_open(@call_for_events)
|
||||||
|
@call_for_tracks = @service.cfp_call_by_type('tracks')
|
||||||
|
@call_for_booths = @service.cfp_call_by_type('booths')
|
||||||
|
end
|
||||||
|
|
||||||
|
def sponsor_variables
|
||||||
|
@sponsorship_levels = @service.sponsorship_levels
|
||||||
|
@sponsors = @conference.sponsors
|
||||||
|
end
|
||||||
|
|
||||||
|
def conference
|
||||||
|
@conference = ConferencesService.conference_by_filter(conference_finder_conditions)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_conferences_service
|
||||||
|
@service = ConferencesService.new(@conference)
|
||||||
|
end
|
||||||
|
|
||||||
def conference_finder_conditions
|
def conference_finder_conditions
|
||||||
if params[:id]
|
if params[:id]
|
||||||
{ short_title: params[:id] }
|
{ short_title: params[:id] }
|
||||||
|
|
|
||||||
57
app/services/conferences_calendar_service.rb
Normal file
57
app/services/conferences_calendar_service.rb
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
class ConferencesCalendarService
|
||||||
|
def initialize(calendar, conference)
|
||||||
|
@calendar = calendar
|
||||||
|
@conference = conference
|
||||||
|
end
|
||||||
|
|
||||||
|
def not_full_calendar
|
||||||
|
calendar.event do |e|
|
||||||
|
default_calendar_params(e)
|
||||||
|
if @conference.venue
|
||||||
|
venue_calendar_params(e)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
calendar
|
||||||
|
end
|
||||||
|
|
||||||
|
def full_calendar
|
||||||
|
icalendar_proposals(@calendar, event_schedules.map(&:event), @conference)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def default_calendar_params(event)
|
||||||
|
event.dtstart = @conference.start_date
|
||||||
|
event.dtstart.ical_params = { 'VALUE'=>'DATE' }
|
||||||
|
event.dtend = @conference.end_date
|
||||||
|
event.dtend.ical_params = { 'VALUE'=>'DATE' }
|
||||||
|
event.duration = "P#{(@conference.end_date - @conference.start_date + 1).floor}D"
|
||||||
|
event.created = @conference.created_at
|
||||||
|
event.last_modified = @conference.updated_at
|
||||||
|
event.summary = @conference.title
|
||||||
|
event.description = @conference.description
|
||||||
|
event.uid = @conference.guid
|
||||||
|
event.url = conference_url(@conference.short_title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def venue_calendar_params(event)
|
||||||
|
venue = @conference.venue
|
||||||
|
event.geo = venue.latitude, venue.longitude if venue.latitude && venue.longitude
|
||||||
|
location = location(venue)
|
||||||
|
event.location = location if location
|
||||||
|
end
|
||||||
|
|
||||||
|
def location(venue)
|
||||||
|
location = ''
|
||||||
|
location += "#{venue.street}, " if venue.street
|
||||||
|
location += "#{venue.postalcode} #{venue.city}, " if venue.postalcode && venue.city
|
||||||
|
location += venue.country_name if venue.country_name
|
||||||
|
location
|
||||||
|
end
|
||||||
|
|
||||||
|
def event_schedules
|
||||||
|
@conference.program.selected_event_schedules(
|
||||||
|
includes: [{ event: %i[event_type speakers submitter] }]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
89
app/services/conferences_service.rb
Normal file
89
app/services/conferences_service.rb
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
class ConferencesService
|
||||||
|
def initialize(conference = nil)
|
||||||
|
@conference = conference
|
||||||
|
@cfps = @conference&.program&.cfps
|
||||||
|
@splashpage = @conference&.splashpage
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.conference_by_filter(conference_finder_conditions)
|
||||||
|
Conference.unscoped.eager_load(
|
||||||
|
:splashpage,
|
||||||
|
:program,
|
||||||
|
:registration_period,
|
||||||
|
:contact,
|
||||||
|
venue: :commercial
|
||||||
|
).find_by!(conference_finder_conditions)
|
||||||
|
end
|
||||||
|
|
||||||
|
def conference_image_url(request)
|
||||||
|
"#{request.protocol}#{request.host}#{@conference.picture}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def cfp_variables_if_event_open(call_for_events)
|
||||||
|
if call_for_events.try(:open?)
|
||||||
|
[event_types, track_names]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cfp_call_by_type(type)
|
||||||
|
@cfps.find { |call| call.cfp_type == type }
|
||||||
|
end
|
||||||
|
|
||||||
|
def if_include_tracks
|
||||||
|
if @splashpage.include_tracks
|
||||||
|
tracks
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def if_include_booths
|
||||||
|
if @splashpage.include_booths
|
||||||
|
booths
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def if_include_registrations_or_tickets
|
||||||
|
if @splashpage.include_registrations || @splashpage.include_tickets
|
||||||
|
tickets
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def if_include_lodgings
|
||||||
|
if @splashpage.include_lodgings
|
||||||
|
lodgings
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sponsorship_levels
|
||||||
|
@conference.sponsorship_levels.eager_load(
|
||||||
|
:sponsors
|
||||||
|
).order('sponsorship_levels.position ASC', 'sponsors.name')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def lodgings
|
||||||
|
@conference.lodgings.order('name')
|
||||||
|
end
|
||||||
|
|
||||||
|
def track_names
|
||||||
|
@conference.confirmed_tracks.pluck(:name).sort
|
||||||
|
end
|
||||||
|
|
||||||
|
def event_types
|
||||||
|
@conference.event_types.pluck(:title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def tracks
|
||||||
|
@conference.confirmed_tracks.eager_load(
|
||||||
|
:room
|
||||||
|
).order('tracks.name')
|
||||||
|
end
|
||||||
|
|
||||||
|
def booths
|
||||||
|
@conference.confirmed_booths.order('title')
|
||||||
|
end
|
||||||
|
|
||||||
|
def tickets
|
||||||
|
@conference.tickets.order('price_cents')
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue