[feat]Implement FullCalendar#rooms_to_resources and add tests

This commit is contained in:
Jimmy 2021-04-26 09:48:16 +08:00 committed by CactusPuppy
parent 40916b6a36
commit abe2ea9bb3
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
4 changed files with 59 additions and 29 deletions

View file

@ -80,34 +80,35 @@ class SchedulesController < ApplicationController
end end
def vertical_schedule def vertical_schedule
@event_schedules = @program.selected_event_schedules( @event_schedules = @program.selected_event_schedules(
includes: [{ event: %i[event_id title speaker] }] includes: [{ event: %i[event_id title speaker] }]
) )
respond_to do |format| respond_to do |format|
format.xml do format.xml do
@events_xml = event_schedules.map(&:event).group_by{ |event| event.time.to_date } if event_schedules @events_xml = event_schedules.map(&:event).group_by{ |event| event.time.to_date } if event_schedules
end end
format.ics do format.ics do
cal = Icalendar::Calendar.new cal = Icalendar::Calendar.new
cal = icalendar_proposals(cal, event_schedules.map(&:event), @conference) cal = icalendar_proposals(cal, event_schedules.map(&:event), @conference)
cal.publish cal.publish
render inline: cal.to_ical render inline: cal.to_ical
end end
format.html do format.html do
@rooms = @conference.venue.rooms if @conference.venue @rooms = @conference.venue.rooms if @conference.venue
@dates = @conference.start_date..@conference.end_date @dates = @conference.start_date..@conference.end_date
# Ids of the @event_schedules of confrmed self_organized tracks along with the selected_schedule_id # Ids of the @event_schedules of confrmed self_organized tracks along with the selected_schedule_id
@selected_schedules_ids = [@conference.program.selected_schedule_id] @selected_schedules_ids = [@conference.program.selected_schedule_id]
@conference.program.tracks.self_organized.confirmed.each do |track| @conference.program.tracks.self_organized.confirmed.each do |track|
@selected_schedules_ids << track.selected_schedule_id @selected_schedules_ids << track.selected_schedule_id
end
@selected_schedules_ids.compact!
@event_schedules_by_room_id = event_schedules.select { |s| @selected_schedules_ids.include?(s.schedule_id) }.group_by(&:room_id)
end end
@selected_schedules_ids.compact!
@event_schedules_by_room_id = event_schedules.select { |s| @selected_schedules_ids.include?(s.schedule_id) }.group_by(&:room_id)
end
end
end end
def app def app

View file

@ -1,3 +1,16 @@
class FullCalendarFormatter class FullCalendarFormatter
def rooms_to_resources(rooms); end def self.rooms_to_resources(rooms)
rooms.map { |room| room_to_resource(room) }.to_json
end
def self.event_schedules_to_resources(event_schedules); end
private_class_method
def self.room_to_resource(room)
{
id: room.guid,
title: room.name
}
end
end end

View file

@ -9,6 +9,10 @@ feature Schedule do
before(:each) do before(:each) do
visit vertical_schedule_conference_schedule_path visit vertical_schedule_conference_schedule_path
end end
it 'returns a successful response' do
expect(response.status).to eq(200)
end
end end
end end
end end

View file

@ -3,12 +3,24 @@
require 'spec_helper' require 'spec_helper'
describe FullCalendarFormatter do describe FullCalendarFormatter do
let!(:room0) { create(:room) }
let!(:room1) { create(:room) } let!(:room1) { create(:room) }
let!(:room2) { create(:room) }
describe 'JSON formatting for FullCalendar' do describe 'JSON formatting for FullCalendar' do
it 'translates rooms to resources' do it 'translates rooms to resources' do
room_list = [room1, room2] # TODO rooms = [room1, room2]
resources = described_class.rooms_to_resources(rooms)
expected_json = [
{
id: room1.guid,
title: room1.name
},
{
id: room2.guid,
title: room2.name
}
].to_json
expect(resources).to eq(expected_json)
end end
end end
end end