This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #1360 - Add Calendarable controller concern to generate HTML, JSON, and iCalendar representations of all the reservations for a given resource - Add calendarable routing concern and clean up config/routes.rb - Add Reservation#end_date to find the last day for a reservation, status-dependent (with model specs) - Add the associated controller specs as a shared example as well as feature specs for equipment models - Add calendars for categories, equipment models, equipment items, and users - Fix routing issue with jQuery-UI-Bootstrap assets
- Loading branch information
Showing
34 changed files
with
644 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
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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module Calendarable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# before filters and such | ||
end | ||
|
||
def calendar # rubocop:disable AbcSize, MethodLength | ||
prepare_calendar_vars | ||
|
||
# extract calendar data | ||
respond_to do |format| | ||
format.html | ||
format.json { @calendar_res = generate_calendar_reservations } | ||
# generate iCal version | ||
# see https://gorails.com/forum/multi-event-ics-file-generation | ||
format.ics do | ||
@calendar_res = generate_calendar_reservations | ||
cal = Icalendar::Calendar.new | ||
|
||
@calendar_res.each do |r| | ||
event = Icalendar::Event.new | ||
event.dtstart = Icalendar::Values::Date.new(r.start_date) | ||
event.dtend = Icalendar::Values::Date.new(r.end_date + 1.day) | ||
event.summary = r.reserver.name | ||
event.location = r.equipment_item.name unless r.equipment_item.nil? | ||
event.url = reservation_url(r, format: :html) | ||
cal.add_event(event) | ||
end | ||
cal.publish | ||
|
||
response.headers['Content-Type'] = 'text/calendar' | ||
response.headers['Content-Disposition'] = | ||
'attachment; filename=reservations.ics' | ||
render text: cal.to_ical | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def prepare_calendar_vars | ||
@start_date = calendar_start_date | ||
@end_date = calendar_end_date | ||
@resource = generate_calendar_resource | ||
@src_path = generate_source_path | ||
end | ||
|
||
def calendar_start_date | ||
if params[:start] | ||
Time.zone.parse(params[:start]).to_date | ||
elsif params[:calendar] && params[:calendar][:start_date] | ||
Time.zone.parse(params[:calendar][:start_date]).to_date | ||
else | ||
Time.zone.today - 6.months | ||
end | ||
end | ||
|
||
def calendar_end_date | ||
if params[:end] | ||
Time.zone.parse(params[:end]).to_date | ||
elsif params[:calendar] && params[:calendar][:end_date] | ||
Time.zone.parse(params[:calendar][:end_date]).to_date | ||
else | ||
Time.zone.today + 6.months | ||
end | ||
end | ||
|
||
def generate_calendar_reservations | ||
fail NotImplementedError | ||
end | ||
|
||
def generate_calendar_resource | ||
fail NotImplementedError | ||
end | ||
|
||
def generate_source_path | ||
"calendar_#{@resource.class.to_s.underscore}_path".to_sym | ||
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
Oops, something went wrong.