Skip to content

Commit 25d6933

Browse files
author
Matt Lewis
committed
feat(weekView): add support for minute level precision on week view events
1 parent 50bd496 commit 25d6933

File tree

8 files changed

+79
-5
lines changed

8 files changed

+79
-5
lines changed

demos/demo-app.module.ts

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import * as refreshingTheView from './demo-modules/refreshing-the-view';
4141
import * as customTemplates from './demo-modules/custom-templates';
4242
import * as groupMonthViewEvents from './demo-modules/group-month-view-events';
4343
import * as contextMenu from './demo-modules/context-menu';
44+
import * as weekViewMinutePrecision from './demo-modules/week-view-minute-precision';
4445

4546
@NgModule({
4647
declarations: [DemoAppComponent],
@@ -78,6 +79,7 @@ import * as contextMenu from './demo-modules/context-menu';
7879
customTemplates.DemoModule,
7980
groupMonthViewEvents.DemoModule,
8081
contextMenu.DemoModule,
82+
weekViewMinutePrecision.DemoModule,
8183
RouterModule.forRoot([{
8284
path: 'kitchen-sink',
8385
component: kitchenSink.DemoComponent,
@@ -252,6 +254,12 @@ import * as contextMenu from './demo-modules/context-menu';
252254
data: {
253255
label: 'Context menu'
254256
}
257+
}, {
258+
path: 'week-view-minute-precision',
259+
component: weekViewMinutePrecision.DemoComponent,
260+
data: {
261+
label: 'Week view minute precision'
262+
}
255263
}, {
256264
path: '**',
257265
redirectTo: 'kitchen-sink'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Component, ChangeDetectionStrategy } from '@angular/core';
2+
import { CalendarEvent } from 'angular-calendar';
3+
import { addDays, addHours, startOfDay } from 'date-fns';
4+
import { colors } from '../demo-utils/colors';
5+
6+
@Component({
7+
selector: 'mwl-demo-component',
8+
changeDetection: ChangeDetectionStrategy.OnPush,
9+
templateUrl: 'template.html',
10+
})
11+
export class DemoComponent {
12+
13+
viewDate: Date = new Date();
14+
15+
events: CalendarEvent[] = [{
16+
start: addHours(startOfDay(new Date()), 5),
17+
end: addHours(startOfDay(new Date()), 17),
18+
title: 'Event 1',
19+
color: colors.red
20+
}, {
21+
start: addHours(startOfDay(addDays(new Date(), 1)), 2),
22+
end: addHours(startOfDay(addDays(new Date(), 1)), 18),
23+
title: 'Event 2',
24+
color: colors.blue
25+
}, {
26+
start: addHours(startOfDay(new Date()), 8),
27+
title: 'Event 3',
28+
color: colors.blue
29+
}];
30+
31+
}
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './module';
2+
export * from './component';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { CalendarModule } from 'angular-calendar';
4+
import { DemoUtilsModule } from '../demo-utils/module';
5+
import { DemoComponent } from './component';
6+
7+
@NgModule({
8+
imports: [
9+
CommonModule,
10+
CalendarModule.forRoot(),
11+
DemoUtilsModule
12+
],
13+
declarations: [
14+
DemoComponent
15+
],
16+
exports: [
17+
DemoComponent
18+
]
19+
})
20+
export class DemoModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<mwl-calendar-week-view
2+
precision="minutes"
3+
[viewDate]="viewDate"
4+
[events]="events">
5+
</mwl-calendar-week-view>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"dependencies": {
143143
"angular-draggable-droppable": "^1.0.1",
144144
"angular-resizable-element": "^1.0.0",
145-
"calendar-utils": "0.0.45",
145+
"calendar-utils": "0.0.46",
146146
"date-fns": "^1.15.1",
147147
"positioning": "^1.0.4"
148148
}

src/components/week/calendarWeekView.component.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
127127
*/
128128
@Input() eventTemplate: TemplateRef<any>;
129129

130+
/**
131+
* The precision to display events.
132+
* `days` will round event start and end dates to the nearest day and `minutes` will not do this rounding
133+
*/
134+
@Input() precision: 'days' | 'minutes' = 'days';
135+
130136
/**
131137
* Called when a header week day is clicked
132138
*/
@@ -320,7 +326,8 @@ export class CalendarWeekViewComponent implements OnChanges, OnInit, OnDestroy {
320326
events: this.events,
321327
viewDate: this.viewDate,
322328
weekStartsOn: this.weekStartsOn,
323-
excluded: this.excludeDays
329+
excluded: this.excludeDays,
330+
precision: this.precision
324331
});
325332
}
326333

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,9 @@ cachedir@^1.1.0:
762762
dependencies:
763763
os-homedir "^1.0.1"
764764

765-
766-
version "0.0.45"
767-
resolved "https://registry.yarnpkg.com/calendar-utils/-/calendar-utils-0.0.45.tgz#ebe2e29250367c5eeb420340c6b1ebbad7a5e078"
765+
766+
version "0.0.46"
767+
resolved "https://registry.yarnpkg.com/calendar-utils/-/calendar-utils-0.0.46.tgz#4d5cc1c6b3dd375b03395556eb6d34ff845bf82e"
768768

769769
770770
version "1.0.0"

0 commit comments

Comments
 (0)