Skip to content

Commit

Permalink
Make timepickers adjust start and end time limits when picked
Browse files Browse the repository at this point in the history
- Remove crufty javascript that was breaking room removal
- Add presence validation for room and schedule_day to time_slot

Schedule flow UI audit (rubycentral#261)
  • Loading branch information
jonsgreen committed Jan 15, 2018
1 parent 7d4b8ed commit c4e7a6d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
22 changes: 19 additions & 3 deletions app/assets/javascripts/staff/program/time-slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@
}

function initTimePickers() {
$('#time_slot_start_time, #time_slot_end_time').timepicker({
timeFormat: 'HH:mm',
stepMinute: 5
$('#time_slot_start_time').timepicker({
controlType: 'select',
timeFormat: 'h:mm tt',
stepMinute: 5,
maxTime: $('#time_slot_end_time').val(),
onSelect: function(time) {
$('#time_slot_end_time').timepicker('destroy');
initTimePickers();
}
});
$('#time_slot_end_time').timepicker({
controlType: 'select',
timeFormat: 'h:mm tt',
stepMinute: 5,
minTime: $('#time_slot_start_time').val(),
onSelect: function(time) {
$('#time_slot_start_time').timepicker('destroy');
initTimePickers();
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions app/decorators/staff/time_slot_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class Staff::TimeSlotDecorator < Draper::Decorator
delegate_all

def start_time
object.start_time.try(:to_s, :time)
object.start_time.try(:to_s, :time_p)
end

def end_time
object.end_time.try(:to_s, :time)
object.end_time.try(:to_s, :time_p)
end

def session_duration
Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Event < ApplicationRecord

has_many :teammates, dependent: :destroy
has_many :proposals, dependent: :destroy
has_many :speakers
Expand Down
10 changes: 10 additions & 0 deletions app/models/time_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class TimeSlot < ApplicationRecord
end
scope :grid_order, -> { joins(:room).order(:conference_day, :start_time, 'rooms.grid_position') }

validate :end_time_later_than_start_time

validates :room_id, :conference_day, presence: true

def self.import(file)
raw_json = file.read # maybe open as well
parsed_slots = JSON.parse(raw_json)
Expand Down Expand Up @@ -92,6 +96,12 @@ def session_confirmation_notes
def session_duration
(end_time - start_time).to_i/60
end

def end_time_later_than_start_time
if session_duration <= 0
errors.add(:end_time, 'must be later than start time')
end
end
end

# == Schema Information
Expand Down
1 change: 0 additions & 1 deletion app/views/staff/rooms/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$('table#organizer-rooms #room_<%= room.id %>').remove();
window.Schedule.TimeSlots.reloadTable(<%=raw time_slots.rows.to_json %>);

<% if has_missing_requirements?(room.event) %>
$('#time-slot-prereqs').removeClass('hidden');
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/time_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Time::DATE_FORMATS[:month_day] = "%b %d"
Time::DATE_FORMATS[:db_just_date] = "%Y-%m-%d"
Time::DATE_FORMATS[:event_day] = "%A, %b %d"
Time::DATE_FORMATS[:time_p] = "%H:%M%p"
Time::DATE_FORMATS[:time_p] = "%l:%M %P"
7 changes: 4 additions & 3 deletions spec/factories/time_slots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
factory :time_slot do
conference_day 1
start_time "2014-01-31 10:41:58"
end_time "2014-01-31 10:41:58"
end_time "2014-01-31 11:41:58"
title "MyText"
description "MyText"
presenter "MyText"
event
room

factory :time_slot_with_program_session do
conference_day 1
start_time "2014-01-31 10:41:58"
end_time "2014-01-31 10:41:58"
end_time "2014-01-31 11:41:58"
event
program_session { FactoryGirl.create(:program_session_with_proposal)}
end

factory :time_slot_with_empty_program_session do
conference_day 1
start_time "2014-01-31 10:41:58"
end_time "2014-01-31 10:41:58"
end_time "2014-01-31 11:41:58"
event
program_session
end
Expand Down
12 changes: 6 additions & 6 deletions spec/features/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
visit admin_users_path

within("tr#user-#{admin_user.id}") do
expect(page).to have_content admin_teammate.name
expect(page).to have_content admin_teammate.email
expect(page).to have_content admin_user.name
expect(page).to have_content admin_user.email
expect(page).to have_content admin_teammate.role
end

within("tr#user-#{organizer_user.id}") do
expect(page).to have_content organizer_teammate.name
expect(page).to have_content organizer_teammate.email
expect(page).to have_content organizer_user.name
expect(page).to have_content organizer_user.email
expect(page).to have_content organizer_teammate.role
end

within("tr#user-#{reviewer_user.id}") do
expect(page).to have_content reviewer_teammate.name
expect(page).to have_content reviewer_teammate.email
expect(page).to have_content reviewer_user.name
expect(page).to have_content reviewer_user.email
expect(page).to have_content reviewer_teammate.role
end

Expand Down

0 comments on commit c4e7a6d

Please sign in to comment.