-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor /calendars into it's own controller
Spec it out too
- Loading branch information
1 parent
5e70690
commit 7733622
Showing
7 changed files
with
146 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class CalendarsController < ApplicationController | ||
skip_authorization_check only: :index | ||
|
||
# GET /calendars | ||
def index | ||
calendar = Icalendar::Calendar.new | ||
|
||
Conference.all.each do |conference| | ||
if params[:full] | ||
event_schedules = conference.program.selected_event_schedules( | ||
includes: [{ event: %i[event_type speakers submitter] }] | ||
) | ||
calendar = build_icalendar_from_proposals(calendar, event_schedules.map(&:event), conference) | ||
else | ||
calendar = build_icalender_from_conference(calendar, conference) | ||
end | ||
end | ||
|
||
respond_to do |format| | ||
format.ics do | ||
calendar.publish | ||
render inline: calendar.to_ical | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_icalender_from_conference(calendar, conference) | ||
calendar.event do |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) | ||
|
||
venue = conference.venue | ||
if venue | ||
event.geo = venue.latitude, venue.longitude if venue.latitude && venue.longitude | ||
|
||
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 | ||
event.location = location if location | ||
end | ||
end | ||
calendar | ||
end | ||
|
||
# adds events to icalendar for proposals in a conference | ||
def build_icalendar_from_proposals(calendar, proposals, conference) | ||
proposals.each do |proposal| | ||
calendar.event do |event| | ||
event.dtstart = proposal.time | ||
event.dtend = proposal.time + proposal.event_type.length * 60 | ||
event.duration = "PT#{proposal.event_type.length}M" | ||
event.created = proposal.created_at | ||
event.last_modified = proposal.updated_at | ||
event.summary = proposal.title | ||
event.description = proposal.abstract | ||
event.uid = proposal.guid | ||
event.url = conference_program_proposal_url(conference.short_title, proposal.id) | ||
venue = conference.venue | ||
if venue | ||
event.geo = venue.latitude, venue.longitude if venue.latitude && venue.longitude | ||
|
||
location = '' | ||
location += "#{proposal.room.name} - " if proposal.room.name | ||
location += " - #{venue.street}, " if venue.street | ||
location += "#{venue.postalcode} #{venue.city}, " if venue.postalcode && venue.city | ||
location += "#{venue.country_name}, " if venue.country_name | ||
event.location = location | ||
end | ||
if proposal.difficulty_level && proposal.track | ||
event.categories = proposal.title, "Difficulty: #{proposal.difficulty_level.title}", "Track: #{proposal.track.name}" | ||
end | ||
end | ||
end | ||
calendar | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
.row | ||
.col-md-12 | ||
.well | ||
%h1 | ||
Welcome to your new | ||
= link_to('https://osem.io') do | ||
Open Source Event Manager | ||
installation! | ||
%p | ||
The first user to | ||
- if ENV['OSEM_ICHAIN_ENABLED'] == 'true' | ||
= link_to(new_ichain_registration_path('user')) do | ||
sign up | ||
- else | ||
= link_to(new_registration_path('user')) do | ||
sign up | ||
will the be administrator of it. | ||
%p | ||
We hope you enjoy using OSEM, if you have any question don't hesitate to | ||
= link_to('https://osem.io/#contact') do | ||
contact us! | ||
.container | ||
.row | ||
.col-md-12 | ||
.well | ||
%h1 | ||
Welcome to your new | ||
= link_to('https://osem.io') do | ||
Open Source Event Manager | ||
installation! | ||
%p | ||
The first user to | ||
- if ENV['OSEM_ICHAIN_ENABLED'] == 'true' | ||
= link_to(new_ichain_registration_path('user')) do | ||
sign up | ||
- else | ||
= link_to(new_registration_path('user')) do | ||
sign up | ||
will the be administrator of it. | ||
%p | ||
We hope you enjoy using OSEM, if you have any question don't hesitate to | ||
= link_to('https://osem.io/#contact') do | ||
contact us! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe CalendarsController do | ||
render_views | ||
|
||
let!(:conference) { create(:conference, splashpage: create(:splashpage, public: true), venue: create(:venue)) } | ||
let!(:events) { create_list(:event_scheduled, 2, program: conference.program) } | ||
|
||
describe 'GET #index' do | ||
before :each do | ||
conference.program.update_attributes(schedule_public: true) | ||
get :index, format: :ics | ||
end | ||
|
||
it 'renders a calendar from conference' do | ||
expect(response.body).to match(/#{conference.title}/im) | ||
end | ||
end | ||
|
||
describe 'GET #index with full format' do | ||
before :each do | ||
conference.program.update_attributes(schedule_public: true) | ||
get :index, format: :ics, params: { full: 1 } | ||
end | ||
|
||
it 'renders a calendar from events' do | ||
expect(response.body).to match(/#{events.first.title}/im) | ||
end | ||
end | ||
end |