From 6aeb55071283dc11d8d9fe93f93a9e99931946ef Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 11 Feb 2018 16:16:27 +0000 Subject: [PATCH] fix(month-view): expose the day the event was dropped on Fixes #443 --- .../month/calendar-month-view.component.ts | 11 ++++++++-- src/modules/month/calendar-month.module.ts | 3 ++- test/calendar-month-view.component.spec.ts | 20 +++++++++---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/modules/month/calendar-month-view.component.ts b/src/modules/month/calendar-month-view.component.ts index 7719db56d..2f342fe4d 100644 --- a/src/modules/month/calendar-month-view.component.ts +++ b/src/modules/month/calendar-month-view.component.ts @@ -39,6 +39,11 @@ export interface CalendarMonthViewBeforeRenderEvent { period: ViewPeriod; } +export interface CalendarMonthViewEventTimesChangedEvent + extends CalendarEventTimesChangedEvent { + day: MonthViewDay; +} + /** * Shows all events on a given month. Example usage: * @@ -199,7 +204,9 @@ export class CalendarMonthViewComponent * Called when an event is dragged and dropped */ @Output() - eventTimesChanged = new EventEmitter(); + eventTimesChanged = new EventEmitter< + CalendarMonthViewEventTimesChangedEvent + >(); /** * @hidden @@ -328,7 +335,7 @@ export class CalendarMonthViewComponent const secondsDiff: number = differenceInSeconds(newStart, event.start); newEnd = addSeconds(event.end, secondsDiff); } - this.eventTimesChanged.emit({ event, newStart, newEnd }); + this.eventTimesChanged.emit({ event, newStart, newEnd, day }); } /** diff --git a/src/modules/month/calendar-month.module.ts b/src/modules/month/calendar-month.module.ts index bb23d0bbc..1a7281a14 100644 --- a/src/modules/month/calendar-month.module.ts +++ b/src/modules/month/calendar-month.module.ts @@ -9,7 +9,8 @@ import { CalendarCommonModule } from '../common/calendar-common.module'; export { CalendarMonthViewComponent, - CalendarMonthViewBeforeRenderEvent + CalendarMonthViewBeforeRenderEvent, + CalendarMonthViewEventTimesChangedEvent } from './calendar-month-view.component'; export { MonthViewDay as CalendarMonthViewDay } from 'calendar-utils'; diff --git a/test/calendar-month-view.component.spec.ts b/test/calendar-month-view.component.spec.ts index 64b60ed49..6d56be53a 100644 --- a/test/calendar-month-view.component.spec.ts +++ b/test/calendar-month-view.component.spec.ts @@ -25,6 +25,7 @@ import { import { Subject } from 'rxjs/Subject'; import { triggerDomEvent } from './util'; import { take } from 'rxjs/operators/take'; +import { CalendarMonthViewEventTimesChangedEvent } from '../src/modules/month'; describe('calendarMonthView component', () => { beforeEach(() => { @@ -517,7 +518,7 @@ describe('calendarMonthView component', () => { } ]; fixture.componentInstance.ngOnChanges({ viewDate: {} }); - let dragEvent: CalendarEventTimesChangedEvent; + let dragEvent: CalendarMonthViewEventTimesChangedEvent; fixture.componentInstance.eventTimesChanged.subscribe(e => { dragEvent = e; }); @@ -560,11 +561,10 @@ describe('calendarMonthView component', () => { fixture.detectChanges(); expect(cells[10].classList.contains('cal-drag-over')).to.equal(false); fixture.destroy(); - expect(dragEvent).to.deep.equal({ - event: fixture.componentInstance.events[0], - newStart: new Date(2016, 11, 7, 10, 39, 14), - newEnd: new Date(2016, 11, 7, 15, 11, 5) - }); + expect(dragEvent.event).to.equal(fixture.componentInstance.events[0]); + expect(dragEvent.newStart).to.deep.equal(new Date(2016, 11, 7, 10, 39, 14)); + expect(dragEvent.newEnd).to.deep.equal(new Date(2016, 11, 7, 15, 11, 5)); + expect(dragEvent.day.date).to.deep.equal(new Date('2016-12-07')); }); it('should apply the year, month and date changes in the correct order when dragging and dropping events', () => { @@ -616,11 +616,9 @@ describe('calendarMonthView component', () => { }); fixture.detectChanges(); fixture.destroy(); - expect(dragEvent).to.deep.equal({ - event: fixture.componentInstance.events[0], - newStart: new Date('2017-01-31'), - newEnd: undefined - }); + expect(dragEvent.event).to.equal(fixture.componentInstance.events[0]); + expect(dragEvent.newStart).to.deep.equal(new Date('2017-01-31')); + expect(dragEvent.newEnd).to.deep.equal(undefined); }); it('should update the event title', () => {