Skip to content

Commit

Permalink
feat(month-view): add columnHeaderClicked output
Browse files Browse the repository at this point in the history
Closes #722
  • Loading branch information
agilob authored and mattlewis92 committed Oct 13, 2018
1 parent 481eb02 commit 2bd5e2b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, TemplateRef } from '@angular/core';
import { Component, Input, TemplateRef, EventEmitter, Output } from '@angular/core';
import { WeekDay } from 'calendar-utils';
import { trackByWeekDayHeaderDate } from '../common/util';

Expand All @@ -17,6 +17,7 @@ import { trackByWeekDayHeaderDate } from '../common/util';
[class.cal-today]="day.isToday"
[class.cal-future]="day.isFuture"
[class.cal-weekend]="day.isWeekend"
(click)="handleCellClicked(day)"
[ngClass]="day.cssClass">
{{ day.date | calendarDate:'monthViewColumnHeader':locale }}
</div>
Expand All @@ -38,5 +39,12 @@ export class CalendarMonthViewHeaderComponent {
@Input()
customTemplate: TemplateRef<any>;

@Output()
columnHeaderClicked: EventEmitter<number> = new EventEmitter<number>();

trackByWeekDayHeaderDate = trackByWeekDayHeaderDate;

public handleCellClicked(event: WeekDay) {
this.columnHeaderClicked.emit(event.date.getDay());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface CalendarMonthViewEventTimesChangedEvent<
<mwl-calendar-month-view-header
[days]="columnHeaders"
[locale]="locale"
(columnHeaderClicked)="columnHeaderClicked.emit($event)"
[customTemplate]="headerTemplate">
</mwl-calendar-month-view-header>
<div class="cal-days">
Expand Down Expand Up @@ -220,6 +221,13 @@ export class CalendarMonthViewComponent
event: CalendarEvent;
}>();


/**
* Called when a header week day is clicked. Returns ISO day number.
*/
@Output()
columnHeaderClicked = new EventEmitter<number>();

/**
* Called when an event is dragged and dropped
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ describe('calendarMonthView component', () => {
fixture.destroy();
});

it('should emit on the columnHeaderClicked output', (done) => {
const fixture: ComponentFixture<
CalendarMonthViewComponent
> = TestBed.createComponent(CalendarMonthViewComponent);
fixture.componentInstance.viewDate = new Date('2016-06-29');
fixture.componentInstance.ngOnChanges({ viewDate: {} });
fixture.detectChanges();
fixture.componentInstance.columnHeaderClicked.subscribe(val => {
expect(val).to.equal(0);
done();
});
fixture.nativeElement.querySelector('.cal-header .cal-cell').click();
fixture.detectChanges();
});

it('should generate the week view with default colors for events', () => {
const fixture: ComponentFixture<
CalendarMonthViewComponent
Expand Down
2 changes: 2 additions & 0 deletions src/app/demo-modules/clickable-days/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export class DemoComponent {
events: CalendarEvent[] = [];

clickedDate: Date;

clickedColumn: number;
}
4 changes: 3 additions & 1 deletion src/app/demo-modules/clickable-days/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<div class="alert alert-info">
Click on a day on the view.
<strong *ngIf="clickedDate">You clicked on this day: {{ clickedDate | date:'medium' }}</strong>
<strong *ngIf="clickedColumn != null">You clicked on this column: {{ clickedColumn }}</strong>
</div>

<div [ngSwitch]="view">
<mwl-calendar-month-view
*ngSwitchCase="'month'"
[viewDate]="viewDate"
[events]="events"
(columnHeaderClicked)="clickedColumn = $event"
(dayClicked)="clickedDate = $event.day.date">
</mwl-calendar-month-view>
<mwl-calendar-week-view
Expand All @@ -26,4 +28,4 @@
[viewDate]="viewDate"
[events]="events">
</mwl-calendar-day-view>
</div>
</div>

0 comments on commit 2bd5e2b

Please sign in to comment.