Skip to content

Commit 28c35ab

Browse files
committed
Merge branch 'master' into 0.28
2 parents 9e5f0bc + 45d548f commit 28c35ab

File tree

7 files changed

+241
-131
lines changed

7 files changed

+241
-131
lines changed

projects/demos/app/demo-app.module.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ import { ClipboardModule } from 'ngx-clipboard';
303303
}
304304
},
305305
{
306-
path: 'group-month-view-events',
306+
path: 'group-similar-events',
307307
loadChildren: () =>
308-
import('./demo-modules/group-month-view-events/module').then(
308+
import('./demo-modules/group-similar-events/module').then(
309309
m => m.DemoModule
310310
),
311311
data: {
312-
label: 'Group month view events'
312+
label: 'Group similar events'
313313
}
314314
},
315315
{

projects/demos/app/demo-modules/group-month-view-events/component.ts

-83
This file was deleted.

projects/demos/app/demo-modules/group-month-view-events/template.html

-45
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
2+
import {
3+
CalendarEvent,
4+
CalendarMonthViewDay,
5+
CalendarView
6+
} from 'angular-calendar';
7+
import { colors } from '../demo-utils/colors';
8+
import { isSameMinute, startOfDay } from 'date-fns';
9+
10+
interface EventGroupMeta {
11+
type: string;
12+
}
13+
14+
@Component({
15+
selector: 'mwl-demo-component',
16+
changeDetection: ChangeDetectionStrategy.OnPush,
17+
templateUrl: './template.html',
18+
styles: [
19+
`
20+
.cell-totals {
21+
margin: 5px;
22+
text-align: center;
23+
}
24+
.badge {
25+
margin-right: 5px;
26+
}
27+
`
28+
]
29+
})
30+
export class DemoComponent implements OnInit {
31+
view: CalendarView = CalendarView.Month;
32+
33+
viewDate: Date = new Date();
34+
35+
events: CalendarEvent[] = [
36+
{
37+
title: 'Event 1',
38+
color: colors.yellow,
39+
start: startOfDay(new Date()),
40+
meta: {
41+
type: 'warning'
42+
}
43+
},
44+
{
45+
title: 'Event 2',
46+
color: colors.yellow,
47+
start: startOfDay(new Date()),
48+
meta: {
49+
type: 'warning'
50+
}
51+
},
52+
{
53+
title: 'Event 3',
54+
color: colors.blue,
55+
start: startOfDay(new Date()),
56+
meta: {
57+
type: 'info'
58+
}
59+
},
60+
{
61+
title: 'Event 4',
62+
color: colors.red,
63+
start: startOfDay(new Date()),
64+
meta: {
65+
type: 'danger'
66+
}
67+
},
68+
{
69+
title: 'Event 5',
70+
color: colors.red,
71+
start: startOfDay(new Date()),
72+
meta: {
73+
type: 'danger'
74+
}
75+
}
76+
];
77+
78+
groupedSimilarEvents: CalendarEvent[] = [];
79+
80+
ngOnInit() {
81+
// group any events together that have the same type and dates
82+
// use for when you have a lot of events on the week or day view at the same time
83+
this.groupedSimilarEvents = [];
84+
const processedEvents = new Set();
85+
this.events.forEach(event => {
86+
if (processedEvents.has(event)) {
87+
return;
88+
}
89+
const similarEvents = this.events.filter(otherEvent => {
90+
return (
91+
otherEvent !== event &&
92+
!processedEvents.has(otherEvent) &&
93+
isSameMinute(otherEvent.start, event.start) &&
94+
(isSameMinute(otherEvent.end, event.end) ||
95+
(!otherEvent.end && !event.end)) &&
96+
otherEvent.color.primary === event.color.primary &&
97+
otherEvent.color.secondary === event.color.secondary
98+
);
99+
});
100+
processedEvents.add(event);
101+
similarEvents.forEach(otherEvent => {
102+
processedEvents.add(otherEvent);
103+
});
104+
if (similarEvents.length > 0) {
105+
this.groupedSimilarEvents.push({
106+
title: `${similarEvents.length + 1} events`,
107+
color: event.color,
108+
start: event.start,
109+
end: event.end,
110+
meta: {
111+
groupedEvents: [event, ...similarEvents]
112+
}
113+
});
114+
} else {
115+
this.groupedSimilarEvents.push(event);
116+
}
117+
});
118+
}
119+
120+
beforeMonthViewRender({
121+
body
122+
}: {
123+
body: Array<CalendarMonthViewDay<EventGroupMeta>>;
124+
}): void {
125+
// month view has a different UX from the week and day view so we only really need to group by the type
126+
body.forEach(cell => {
127+
const groups = {};
128+
cell.events.forEach((event: CalendarEvent<EventGroupMeta>) => {
129+
groups[event.meta.type] = groups[event.meta.type] || [];
130+
groups[event.meta.type].push(event);
131+
});
132+
cell['eventGroups'] = Object.entries(groups);
133+
});
134+
}
135+
}

projects/demos/app/demo-modules/group-month-view-events/module.ts projects/demos/app/demo-modules/group-similar-events/module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CalendarModule, DateAdapter } from 'angular-calendar';
55
import { DemoUtilsModule } from '../demo-utils/module';
66
import { DemoComponent } from './component';
77
import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
8+
import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
89

910
@NgModule({
1011
imports: [
@@ -13,6 +14,7 @@ import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
1314
provide: DateAdapter,
1415
useFactory: adapterFactory
1516
}),
17+
NgbPopoverModule,
1618
DemoUtilsModule,
1719
RouterModule.forChild([{ path: '', component: DemoComponent }])
1820
],

0 commit comments

Comments
 (0)