[feat]Add url, background color, text color to events in vertical schedule
This commit is contained in:
parent
468e170a2e
commit
83aeb5c330
3 changed files with 52 additions and 19 deletions
|
|
@ -4,10 +4,15 @@ class FullCalendarFormatter
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.event_schedules_to_resources(event_schedules)
|
def self.event_schedules_to_resources(event_schedules)
|
||||||
event_schedules.map { |event_schedule| event_schedule_to_resource(event_schedule) }.to_json
|
return '[]' if event_schedules.empty?
|
||||||
|
|
||||||
|
conference = event_schedules.first.schedule.program.conference
|
||||||
|
event_schedules.map { |event_schedule| event_schedule_to_resource(conference, event_schedule) }.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
include FormatHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def room_to_resource(room)
|
def room_to_resource(room)
|
||||||
|
|
@ -17,13 +22,19 @@ class FullCalendarFormatter
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def event_schedule_to_resource(event_schedule)
|
def event_schedule_to_resource(conference, event_schedule)
|
||||||
|
event_type_color = event_schedule.event.event_type.color
|
||||||
|
url = Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event_schedule.event.id)
|
||||||
|
|
||||||
{
|
{
|
||||||
id: event_schedule.event.guid,
|
id: event_schedule.event.guid,
|
||||||
title: event_schedule.event.title,
|
title: event_schedule.event.title,
|
||||||
start: event_schedule.start_time,
|
start: event_schedule.start_time,
|
||||||
end: event_schedule.end_time,
|
end: event_schedule.end_time,
|
||||||
resourceId: event_schedule.room.guid
|
resourceId: event_schedule.room.guid,
|
||||||
|
url: url,
|
||||||
|
backgroundColor: event_type_color,
|
||||||
|
textColor: contrast_color(event_type_color)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,21 @@ describe FullCalendarFormatter do
|
||||||
let!(:room1) { create(:room) }
|
let!(:room1) { create(:room) }
|
||||||
let!(:room2) { create(:room) }
|
let!(:room2) { create(:room) }
|
||||||
let!(:rooms) { [room1, room2] }
|
let!(:rooms) { [room1, room2] }
|
||||||
let!(:event_schedule1) { create(:event_schedule, room: room1) }
|
let!(:conference) { create(:full_conference) }
|
||||||
let!(:event_schedule2) { create(:event_schedule, room: room2) }
|
let!(:program) { conference.program }
|
||||||
|
let!(:selected_schedule) { create(:schedule, program: program) }
|
||||||
|
let!(:event_type1) { create(:event_type, color: '#ffffff') }
|
||||||
|
let!(:event1) do
|
||||||
|
program.update_attributes!(selected_schedule: selected_schedule)
|
||||||
|
create(:event, program: program, event_type: event_type1)
|
||||||
|
end
|
||||||
|
let!(:event_schedule1) { create(:event_schedule, event: event1, schedule: selected_schedule, room: room1) }
|
||||||
|
let!(:event_type2) { create(:event_type, color: '#000000') }
|
||||||
|
let!(:event2) do
|
||||||
|
program.update_attributes!(selected_schedule: selected_schedule)
|
||||||
|
create(:event, program: program, room: room2, event_type: event_type2)
|
||||||
|
end
|
||||||
|
let!(:event_schedule2) { create(:event_schedule, event: event2, schedule: selected_schedule, room: room2) }
|
||||||
let!(:event_schedules) { [event_schedule1, event_schedule2] }
|
let!(:event_schedules) { [event_schedule1, event_schedule2] }
|
||||||
|
|
||||||
describe 'JSON formatting for FullCalendar' do
|
describe 'JSON formatting for FullCalendar' do
|
||||||
|
|
@ -30,18 +43,24 @@ describe FullCalendarFormatter do
|
||||||
resources = described_class.event_schedules_to_resources(event_schedules)
|
resources = described_class.event_schedules_to_resources(event_schedules)
|
||||||
expected_json = [
|
expected_json = [
|
||||||
{
|
{
|
||||||
id: event_schedule1.event.guid,
|
id: event_schedule1.event.guid,
|
||||||
title: event_schedule1.event.title,
|
title: event_schedule1.event.title,
|
||||||
start: event_schedule1.start_time,
|
start: event_schedule1.start_time,
|
||||||
end: event_schedule1.end_time,
|
end: event_schedule1.end_time,
|
||||||
resourceId: room1.guid
|
resourceId: room1.guid,
|
||||||
|
url: conference_program_proposal_path(conference.short_title, event1.id),
|
||||||
|
backgroundColor: event1.event_type.color,
|
||||||
|
textColor: 'black'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: event_schedule2.event.guid,
|
id: event_schedule2.event.guid,
|
||||||
title: event_schedule2.event.title,
|
title: event_schedule2.event.title,
|
||||||
start: event_schedule2.start_time,
|
start: event_schedule2.start_time,
|
||||||
end: event_schedule2.end_time,
|
end: event_schedule2.end_time,
|
||||||
resourceId: room2.guid
|
resourceId: room2.guid,
|
||||||
|
url: conference_program_proposal_path(conference.short_title, event2.id),
|
||||||
|
backgroundColor: event2.event_type.color,
|
||||||
|
textColor: 'white'
|
||||||
}
|
}
|
||||||
].to_json
|
].to_json
|
||||||
expect(resources).to eq(expected_json)
|
expect(resources).to eq(expected_json)
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,9 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
# enable debugging with --only-failures
|
# enable debugging with --only-failures
|
||||||
config.example_status_persistence_file_path = 'tmp/spec_failures.txt'
|
config.example_status_persistence_file_path = 'tmp/spec_failures.txt'
|
||||||
|
|
||||||
|
# include path helpers
|
||||||
|
config.include Rails.application.routes.url_helpers
|
||||||
end
|
end
|
||||||
|
|
||||||
OmniAuth.config.test_mode = true
|
OmniAuth.config.test_mode = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue