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 'open' from event status change options and explain with notes
when not openable
- Remove crufty javascript that was breaking room removal

Schedule flow UI audit (rubycentral#261)
  • Loading branch information
jonsgreen committed Jan 9, 2018
1 parent 7d4b8ed commit 4acabb3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 10 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: 4 additions & 0 deletions app/controllers/staff/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def update_status
redirect_to event_staff_info_path(@event), notice: "Event status was successfully updated."
else
flash[:danger] = "There was a problem updating the event status. Please try again."
flash[:danger] += @event.errors.messages.values.flatten.map do |m|
" <br>#{m}"
end.join if @event.errors.present?
@event.reload
render :info
end
end
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
16 changes: 16 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module EventsHelper
def event_status_options(event)
statuses = Event::STATUSES.values
if event.public_session_formats.empty? || event.guidelines.blank?
statuses.delete(Event::STATUSES[:open])
end
options_for_select(statuses, event.status)
end

def event_status_messages(event)
messages = []
messages << Event::SESSION_FORMAT_MESSAGE if event.public_session_formats.empty?
messages << Event::GUIDELINE_MESSAGE if event.guidelines.blank?
messages
end
end
8 changes: 6 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Event < ApplicationRecord

GUIDELINE_MESSAGE = 'Guidelines must be defined before event can be opened.'
SESSION_FORMAT_MESSAGE = 'At least one public session format must be defined before event can be opened.'

has_many :teammates, dependent: :destroy
has_many :proposals, dependent: :destroy
has_many :speakers
Expand Down Expand Up @@ -46,8 +50,8 @@ def to_param
end

with_options on: :update, if: :open? do
validates :public_session_formats, presence: { message: 'A least one public session format must be defined before event can be opened.' }
validates :guidelines, presence: { message: 'Guidelines must be defined before event can be opened.' }
validates :public_session_formats, presence: { message: SESSION_FORMAT_MESSAGE }
validates :guidelines, presence: { message: GUIDELINE_MESSAGE }
end

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

validate :end_time_later_than_start_time

def self.import(file)
raw_json = file.read # maybe open as well
parsed_slots = JSON.parse(raw_json)
Expand Down Expand Up @@ -92,6 +94,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
4 changes: 3 additions & 1 deletion app/views/staff/events/info.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
= link_to "Edit Info", event_staff_edit_path(event), class: "btn btn-primary"
= link_to "Change Status", '#', class: "btn btn-primary status-button"
.status-dropdown.pull-right
- event_status_messages(event).each do |message|
.message= "Note: #{message}"
= form_for(event, url: event_staff_update_status_path(event)) do |f|
= f.select(:state, options_for_select(Event::STATUSES.values, f.object.state))
= f.select(:state, event_status_options(event))
= link_to "Cancel", '#', {:class=>"cancel-status-change btn btn-danger"}
= f.submit "Update Status", class: "btn btn-success"
%h1 Event Info
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"

0 comments on commit 4acabb3

Please sign in to comment.