Skip to content

Commit

Permalink
fix(month-view): expose the day the event was dropped on
Browse files Browse the repository at this point in the history
Fixes #443
  • Loading branch information
Matt Lewis committed Feb 11, 2018
1 parent 669017a commit 6aeb550
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/modules/month/calendar-month-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -199,7 +204,9 @@ export class CalendarMonthViewComponent
* Called when an event is dragged and dropped
*/
@Output()
eventTimesChanged = new EventEmitter<CalendarEventTimesChangedEvent>();
eventTimesChanged = new EventEmitter<
CalendarMonthViewEventTimesChangedEvent
>();

/**
* @hidden
Expand Down Expand Up @@ -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 });
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/modules/month/calendar-month.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
20 changes: 9 additions & 11 deletions test/calendar-month-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -517,7 +518,7 @@ describe('calendarMonthView component', () => {
}
];
fixture.componentInstance.ngOnChanges({ viewDate: {} });
let dragEvent: CalendarEventTimesChangedEvent;
let dragEvent: CalendarMonthViewEventTimesChangedEvent;
fixture.componentInstance.eventTimesChanged.subscribe(e => {
dragEvent = e;
});
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 6aeb550

Please sign in to comment.