Able to scroll between months accuratly
// Generate days in a month
generateDays(date) {
// account for year rollover
this.lastMonth = date.getMonth() === 0 ? 11 : date.getMonth() - 1
this.lastMonthYear = date.getMonth() === 0 ? (date.getFullYear - 1) : date.getFullYear()
this.nextMonth = date.getMonth() === 11 ? 0 : date.getMonth() + 1
this.nextMonthYear = date.getMonth() === 11 ? (date.getFullYear + 1) : date.getFullYear()
this.days = []
// Get previous month lapover days
for (let index = 0; index < this.startofMonth.getDay(); index++) {
let current = false
this.days.unshift(new Day(this.lastMonthYear, this.lastMonth, this.daysInMonths[this.lastMonth] - index, current))
}
// Get current months days
for (let index = 1; index < (this.daysInMonths[date.getMonth()] + 1); index++) {
this.days.push(new Day(date.getFullYear(), date.getMonth(), index, true))
}
// Get next month lapover days
for (let index = 0; index < 6 - (this.endofMonth.getDay()); index++) {
this.days.push(new Day(this.nextMonthYear, this.nextMonth, index + 1, false))
}
}
### Appointment Scheduling
* Users choose which provider they would like to schedule an appointment with
* Users choose which dates they would like to schedule appointments on
* Users choose which available time slots on selected days they would
* Users able to cancel appointments
* Custom validations to see if both user and provider is available for requested timeslot
```javascript
def available_timeslot_provider
self.provider.appointments.each do |appointment|
if (self.start > appointment.start && self.start < appointment.end)
errors.add(:start, "appointment time is unavailable, #{self.provider.fname} #{self.provider.lname} has a conflicting appointment")
end
if (self.end > appointment.start && self.end < appointment.end)
errors.add(:end, "appointment time is unavailable, #{self.provider.fname} #{self.provider.lname} has a conflicting appointment")
end
end
end
def available_timeslot_user
self.user.appointments.each do |appointment|
if (self.start > appointment.start && self.start < appointment.end)
errors.add(:start, 'another already scheduled appointment conflicts with the start of this appointment')
end
if (self.end > appointment.start && self.end < appointment.end)
errors.add(:end, 'another already scheduled appointment conflicts with the end of this appointment')
end
end
end