Module: EmployeeEventsHelper

Defined in:
app/helpers/employee_events_helper.rb

Overview

== Schema Information

Table name: employee_events

id :integer not null, primary key
employee_id :integer
date :date
status :integer default(0)
description :string(255)
from_hour :time
to_hour :time
created_at :datetime
updated_at :datetime
backup :string
backup_employee_id :integer
authorized :boolean default(FALSE)
sub_status :integer
time_to_add :integer
event_time :integer
broken_down :boolean default(FALSE)
broken_down_time :integer
accumulated :integer

Instance Method Summary collapse

Instance Method Details

#fullcalendar_event_data(event) ⇒ Object

Build a FullCalendar event hash from an EmployeeEvent record.
Used by turbo_stream templates to pass structured data to sync_fullcalendar_event.

rubocop:disable Style/RescueModifier



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/employee_events_helper.rb', line 34

def fullcalendar_event_data(event)
  title_parts = [event.status.titleize]
  title_parts << "(#{humanize(event.event_time)})" rescue nil # append nil on failure; compact_blank strips it

  {
    allDay:  (event.from_hour == event.to_hour rescue false),
    title:   title_parts.compact_blank.join(' '),
    start:   DateTime.new(
               event.date.year, event.date.month, event.date.day,
               (event.from_hour.hour rescue 0),
               (event.from_hour.min  rescue 0)
             ).strftime('%FT%T'),
    end:     DateTime.new(
               event.date.year, event.date.month, event.date.day,
               (event.to_hour.hour rescue 23),
               (event.to_hour.min  rescue 59)
             ).strftime('%FT%T'),
    color:   event.is_partial? ? EmployeeEvent::STATUS_COLOR[:partial_timeoff] : EmployeeEvent::STATUS_COLOR[event.status.to_sym],
    id:      event.id.to_s,
    extendedProps: {
      employee_id:          event.employee.id.to_s,
      pto_date:             event.date.to_s,
      pto_type:             event.status.to_s,
      pto_from_hour:        (event.from_hour.strftime('%I:%M %p') rescue ''),
      pto_to_hour:          (event.to_hour.strftime('%I:%M %p')   rescue ''),
      pto_description:      event.description&.squish || '',
      employee:             event.employee.full_name,
      block_day_departments: event.day_block_departments || ''
    }
  }
end

#fullcalendar_multi_employee_event_data(event) ⇒ Object

Build a FullCalendar event hash for the multi-employee calendar view.
Title includes employee abbreviation, duration, and status initials
(e.g. "JDOE • 4 hrs • V").

rubocop:disable Style/RescueModifier



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/employee_events_helper.rb', line 72

def fullcalendar_multi_employee_event_data(event)
  title_parts = [
    event.employee.show_name_4,
    humanize_short(event.event_time),
    event.status.humanize.split.map(&:first).join.upcase
  ]

  {
    allDay:  (event.from_hour == event.to_hour rescue false),
    title:   title_parts.map(&:presence).compact.join(" \u2022 "),
    start:   DateTime.new(
               event.date.year, event.date.month, event.date.day,
               (event.from_hour.hour rescue 0),
               (event.from_hour.min  rescue 0)
             ).strftime('%FT%T'),
    end:     DateTime.new(
               event.date.year, event.date.month, event.date.day,
               (event.to_hour.hour rescue 23),
               (event.to_hour.min  rescue 59)
             ).strftime('%FT%T'),
    color:   event.is_partial? ? EmployeeEvent::STATUS_COLOR[:partial_timeoff] : EmployeeEvent::STATUS_COLOR[event.status.to_sym],
    id:      event.id.to_s,
    extendedProps: {
      employee_id:     event.employee.id.to_s,
      pto_date:        event.date.to_s,
      pto_type:        event.status.to_s,
      pto_from_hour:   (event.from_hour.strftime('%I:%M %p') rescue ''),
      pto_to_hour:     (event.to_hour.strftime('%I:%M %p')   rescue ''),
      pto_description: event.description&.squish || '',
      employee:        event.employee.full_name
    }
  }
end