import { SchedulerViewPeriod , SchedulerViewEvent , SchedulerViewDay , CalendarSchedulerEvent , SchedulerViewHour , SchedulerViewHourSegment } from '../scheduler/models' ; import { WeekViewHour } from 'calendar-utils' ; import { CalendarView , DateAdapter } from 'angular-calendar' ; import { MINUTES_IN_HOUR } from '../scheduler/utils/calendar-scheduler-utils' ; export function addPeriod ( dateAdapter , period , date , amount ) { return { day : dateAdapter . addDays , week : dateAdapter . addWeeks , month : dateAdapter . addMonths } [ period ] ( date , amount ) ; } export function subPeriod ( dateAdapter , period , date , amount ) { return { day : dateAdapter . subDays , week : dateAdapter . subWeeks , month : dateAdapter . subMonths } [ period ] ( date , amount ) ; } export function startOfPeriod ( dateAdapter , period , date ) { return { day : dateAdapter . startOfDay , week : dateAdapter . startOfWeek , month : dateAdapter . startOfMonth } [ period ] ( date ) ; } export function endOfPeriod ( dateAdapter , period , date ) { return { day : dateAdapter . endOfDay , week : dateAdapter . endOfWeek , month : dateAdapter . endOfMonth } [ period ] ( date ) ; } export const trackByDayOrEvent = ( index , event ) => ( event . event . id ? event . event . id : event . event ) ; export const trackByHourColumn = ( index , day ) => day . hours [ 0 ] ? day . hours [ 0 ] . segments [ 0 ] . date . toISOString ( ) : day ; export const trackByHour = ( index , hour ) => hour . segments [ 0 ] . date . toISOString ( ) ; export const trackByHourSegment = ( index , segment ) => segment . date . toISOString ( ) ; export function getMinimumEventHeightInMinutes ( hourSegments , hourSegmentHeight ) { return ( MINUTES_IN_HOUR / ( hourSegments * hourSegmentHeight ) ) * hourSegmentHeight ; } export function getDefaultEventEnd ( dateAdapter , event , minimumMinutes ) { return event . end ? event . end : dateAdapter . addMinutes ( event . start , minimumMinutes ) ; } export function roundToNearest ( amount , precision ) { return Math . round ( amount / precision ) * precision ; } export function getMinutesMoved ( movedY , hourSegments , hourSegmentHeight , eventSnapSize ) { const draggedInPixelsSnapSize = roundToNearest ( movedY , eventSnapSize || hourSegmentHeight ) ; const pixelAmountInMinutes = MINUTES_IN_HOUR / ( hourSegments * hourSegmentHeight ) ; return draggedInPixelsSnapSize * pixelAmountInMinutes ; } export function isDraggedWithinPeriod ( newStart , newEnd , period ) { const end = newEnd || newStart ; return ( ( period . start <= newStart && newStart <= period . end ) || ( period . start <= end && end <= period . end ) ) ; } export function shouldFireDroppedEvent ( dropEvent , date , calendarId ) { return ( dropEvent . dropData && dropEvent . dropData . event && dropEvent . dropData . calendarId !== calendarId ) ; }