Skip to content

Commit a9ab6d9

Browse files
author
Matt Lewis
committed
feat(month-view): call beforeViewRender with the view period
Closes #418
1 parent 22f14b3 commit a9ab6d9

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/modules/month/calendar-month-view.component.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
CalendarEvent,
1616
WeekDay,
1717
MonthView,
18-
MonthViewDay
18+
MonthViewDay,
19+
ViewPeriod
1920
} from 'calendar-utils';
2021
import { Subject } from 'rxjs/Subject';
2122
import { Subscription } from 'rxjs/Subscription';
@@ -32,6 +33,12 @@ import { CalendarEventTimesChangedEvent } from '../common/calendar-event-times-c
3233
import { CalendarUtils } from '../common/calendar-utils.provider';
3334
import { validateEvents } from '../common/util';
3435

36+
export interface MonthViewBeforeRenderEvent {
37+
header: WeekDay[];
38+
body: MonthViewDay[];
39+
period: ViewPeriod;
40+
}
41+
3542
/**
3643
* Shows all events on a given month. Example usage:
3744
*
@@ -170,10 +177,9 @@ export class CalendarMonthViewComponent
170177
* If you add the `cssClass` property to a day in the body it will add that class to the cell element in the template
171178
*/
172179
@Output()
173-
beforeViewRender: EventEmitter<{
174-
header: WeekDay[];
175-
body: MonthViewDay[];
176-
}> = new EventEmitter();
180+
beforeViewRender: EventEmitter<
181+
MonthViewBeforeRenderEvent
182+
> = new EventEmitter();
177183

178184
/**
179185
* Called when the day cell is clicked
@@ -377,7 +383,8 @@ export class CalendarMonthViewComponent
377383
if (this.columnHeaders && this.view) {
378384
this.beforeViewRender.emit({
379385
header: this.columnHeaders,
380-
body: this.view.days
386+
body: this.view.days,
387+
period: this.view.period
381388
});
382389
}
383390
}

src/modules/month/calendar-month.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { CalendarMonthCellComponent } from './calendar-month-cell.component';
77
import { CalendarOpenDayEventsComponent } from './calendar-open-day-events.component';
88
import { CalendarCommonModule } from '../common/calendar-common.module';
99

10-
export { CalendarMonthViewComponent } from './calendar-month-view.component';
10+
export {
11+
CalendarMonthViewComponent,
12+
MonthViewBeforeRenderEvent
13+
} from './calendar-month-view.component';
1114
export { MonthViewDay as CalendarMonthViewDay } from 'calendar-utils';
1215

1316
@NgModule({

test/calendar-month-view.component.spec.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from './../src';
2525
import { Subject } from 'rxjs/Subject';
2626
import { triggerDomEvent } from './util';
27+
import { take } from 'rxjs/operators';
2728

2829
describe('calendarMonthView component', () => {
2930
beforeEach(() => {
@@ -733,12 +734,14 @@ describe('calendarMonthView component', () => {
733734
fixture.componentInstance.viewDate = new Date('2016-06-27');
734735
fixture.componentInstance.ngOnChanges({ viewDate: {} });
735736
const beforeViewRenderCalled = sinon.spy();
736-
const subscription = fixture.componentInstance.beforeViewRender.subscribe(
737-
beforeViewRenderCalled
738-
);
737+
fixture.componentInstance.beforeViewRender
738+
.pipe(take(1))
739+
.subscribe(beforeViewRenderCalled);
739740
fixture.componentInstance.refresh.next(true);
740741
expect(beforeViewRenderCalled).to.have.callCount(1);
741-
subscription.unsubscribe();
742+
expect(typeof beforeViewRenderCalled.getCall(0).args[0].period).to.equal(
743+
'object'
744+
);
742745
fixture.destroy();
743746
});
744747

0 commit comments

Comments
 (0)