app/helpers/shifts_helper.rb
def shift_style(shift, after = nil)
    @right_overflow = @left_overflow = false

    #necessary for AJAX rerendering
    #we should extract all of this stuff from controllers and here and make a universal shifts helper method -njg
    #(too much duplication -- shifts/dashboard/ajax,etc)
    @dept_start_hour ||= current_department.department_config.schedule_start / 60
    @dept_end_hour ||= current_department.department_config.schedule_end / 60
    @hours_per_day ||= (@dept_end_hour - @dept_start_hour)
    @schedule_width ||= (3600.0 * @hours_per_day)

    if !shift.end
      shift.end = Time.now
    elsif shift.end <= shift.start + current_department.department_config.time_increment.minutes
      shift.end = shift.start + current_department.department_config.time_increment.minutes
    end

    schedule_start_time = shift.start.change(hour: @dept_start_hour)
    draw_start_time = after || shift.start

    left  = 100 * (draw_start_time - schedule_start_time) / @schedule_width
    width = 100 * (shift.end - draw_start_time) / @schedule_width

    if left < 0
      width += left
      left = 0
      @left_overflow = true
    end
    if left + width > 100
      width -= (left+width)-100
      @right_overflow = true
    end
    "width: #{width}%; left: #{left}%;"
  end
#WILL BE CHANGED TO SHIFTS:
WILL BE CHANGED TO SHIFTS.
WILL BE CHANGED TO SHIFTS .
def shift_style(shift, after = nil)
    @right_overflow = @left_overflow = false
    @dept_start_hour ||= current_department.department_config.schedule_start / 60
    @dept_end_hour ||= current_department.department_config.schedule_end / 60
    @hours_per_day ||= (@dept_end_hour - @dept_start_hour)
    @schedule_width ||= (3600.0 * @hours_per_day)
    if !shift.end
      shift.end = Time.now
    elsif shift.end <= shift.start + current_department.department_config.time_increment.minutes
      shift.end = shift.start + current_department.department_config.time_increment.minutes
    end
    schedule_start_time = shift.start.change(hour: @dept_start_hour)
    draw_start_time = after || shift.start
    left  = 100 * (draw_start_time - schedule_start_time) / @schedule_width
    width = 100 * (shift.end - draw_start_time) / @schedule_width
    if left < 0
      width += left
      left = 0
      @left_overflow = true
    end
    if left + width > 100
      width -= (left+width)-100
      @right_overflow = true
    end
    "width: #{width}%; left: #{left}%;"
  end
def shift_style ( shift , after = nil ) @right_overflow = @left_overflow = false @dept_start_hour ||= current_department . department_config . schedule_start / 60 @dept_end_hour ||= current_department . department_config . schedule_end / 60 @hours_per_day ||= ( @dept_end_hour - @dept_start_hour ) @schedule_width ||= ( 3600.0 * @hours_per_day ) if ! shift . end shift . end = Time . now elsif shift . end <= shift . start + current_department . department_config . time_increment . minutes shift . end = shift . start + current_department . department_config . time_increment . minutes end schedule_start_time = shift . start . change ( hour : @dept_start_hour ) draw_start_time = after || shift . start left = 100 * ( draw_start_time - schedule_start_time ) / @schedule_width width = 100 * ( shift . end - draw_start_time ) / @schedule_width if left < 0 width += left left = 0 @left_overflow = true end if left + width > 100 width -= ( left + width ) - 100 @right_overflow = true end "width: #{width}%; left: #{left}%;" end
WILL BE CHANGED TO SHIFTS:
WILL BE CHANGED TO SHIFTS :
#necessary for AJAX rerendering #we should extract all of this stuff from controllers and here and make a universal shifts helper method -njg #(too much duplication -- shifts/dashboard/ajax,etc)
shift
after