Skip to content

Commit ae1949a

Browse files
committed
docs: cleanup kitchen sink demo
Closes #897
1 parent 41eb4d8 commit ae1949a

File tree

2 files changed

+68
-48
lines changed

2 files changed

+68
-48
lines changed

projects/demos/app/demo-modules/kitchen-sink/component.ts

+35-14
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ export class DemoComponent {
140140
newStart,
141141
newEnd
142142
}: CalendarEventTimesChangedEvent): void {
143-
event.start = newStart;
144-
event.end = newEnd;
143+
this.events = this.events.map(iEvent => {
144+
if (iEvent === event) {
145+
return {
146+
...event,
147+
start: newStart,
148+
end: newEnd
149+
};
150+
}
151+
return iEvent;
152+
});
145153
this.handleEvent('Dropped or resized', event);
146-
this.refresh.next();
147154
}
148155

149156
handleEvent(action: string, event: CalendarEvent): void {
@@ -152,17 +159,31 @@ export class DemoComponent {
152159
}
153160

154161
addEvent(): void {
155-
this.events.push({
156-
title: 'New event',
157-
start: startOfDay(new Date()),
158-
end: endOfDay(new Date()),
159-
color: colors.red,
160-
draggable: true,
161-
resizable: {
162-
beforeStart: true,
163-
afterEnd: true
162+
this.events = [
163+
...this.events,
164+
{
165+
title: 'New event',
166+
start: startOfDay(new Date()),
167+
end: endOfDay(new Date()),
168+
color: colors.red,
169+
draggable: true,
170+
resizable: {
171+
beforeStart: true,
172+
afterEnd: true
173+
}
164174
}
165-
});
166-
this.refresh.next();
175+
];
176+
}
177+
178+
deleteEvent(eventToDelete: CalendarEvent) {
179+
this.events = this.events.filter(event => event !== eventToDelete);
180+
}
181+
182+
setView(view: CalendarView) {
183+
this.view = view;
184+
}
185+
186+
closeOpenMonthViewDay() {
187+
this.activeDayIsOpen = false;
167188
}
168189
}

projects/demos/app/demo-modules/kitchen-sink/template.html

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
<ng-template #modalContent let-close="close">
2-
<div class="modal-header">
3-
<h5 class="modal-title">Event action occurred</h5>
4-
<button type="button" class="close" (click)="close()">
5-
<span aria-hidden="true">&times;</span>
6-
</button>
7-
</div>
8-
<div class="modal-body">
9-
<div>
10-
Action:
11-
<pre>{{ modalData?.action }}</pre>
12-
</div>
13-
<div>
14-
Event:
15-
<pre>{{ modalData?.event | json }}</pre>
16-
</div>
17-
</div>
18-
<div class="modal-footer">
19-
<button type="button" class="btn btn-outline-secondary" (click)="close()">
20-
OK
21-
</button>
22-
</div>
23-
</ng-template>
24-
251
<div class="row text-center">
262
<div class="col-md-4">
273
<div class="btn-group">
@@ -30,7 +6,7 @@ <h5 class="modal-title">Event action occurred</h5>
306
mwlCalendarPreviousView
317
[view]="view"
328
[(viewDate)]="viewDate"
33-
(viewDateChange)="activeDayIsOpen = false"
9+
(viewDateChange)="closeOpenMonthViewDay()"
3410
>
3511
Previous
3612
</div>
@@ -46,7 +22,7 @@ <h5 class="modal-title">Event action occurred</h5>
4622
mwlCalendarNextView
4723
[view]="view"
4824
[(viewDate)]="viewDate"
49-
(viewDateChange)="activeDayIsOpen = false"
25+
(viewDateChange)="closeOpenMonthViewDay()"
5026
>
5127
Next
5228
</div>
@@ -59,21 +35,21 @@ <h3>{{ viewDate | calendarDate:(view + 'ViewTitle'):'en' }}</h3>
5935
<div class="btn-group">
6036
<div
6137
class="btn btn-primary"
62-
(click)="view = CalendarView.Month"
38+
(click)="setView(CalendarView.Month)"
6339
[class.active]="view === CalendarView.Month"
6440
>
6541
Month
6642
</div>
6743
<div
6844
class="btn btn-primary"
69-
(click)="view = CalendarView.Week"
45+
(click)="setView(CalendarView.Week)"
7046
[class.active]="view === CalendarView.Week"
7147
>
7248
Week
7349
</div>
7450
<div
7551
class="btn btn-primary"
76-
(click)="view = CalendarView.Day"
52+
(click)="setView(CalendarView.Day)"
7753
[class.active]="view === CalendarView.Day"
7854
>
7955
Day
@@ -114,6 +90,8 @@ <h3>{{ viewDate | calendarDate:(view + 'ViewTitle'):'en' }}</h3>
11490
</mwl-calendar-day-view>
11591
</div>
11692

93+
<!-- Everything you see below is just for the demo, you don't need to include it in your app -->
94+
11795
<br /><br /><br />
11896

11997
<h3>
@@ -137,7 +115,7 @@ <h3>
137115
</thead>
138116

139117
<tbody>
140-
<tr *ngFor="let event of events; let index = index">
118+
<tr *ngFor="let event of events">
141119
<td>
142120
<input
143121
type="text"
@@ -191,13 +169,34 @@ <h3>
191169
/>
192170
</td>
193171
<td>
194-
<button
195-
class="btn btn-danger"
196-
(click)="events.splice(index, 1); refresh.next()"
197-
>
172+
<button class="btn btn-danger" (click)="deleteEvent(event)">
198173
Delete
199174
</button>
200175
</td>
201176
</tr>
202177
</tbody>
203178
</table>
179+
180+
<ng-template #modalContent let-close="close">
181+
<div class="modal-header">
182+
<h5 class="modal-title">Event action occurred</h5>
183+
<button type="button" class="close" (click)="close()">
184+
<span aria-hidden="true">&times;</span>
185+
</button>
186+
</div>
187+
<div class="modal-body">
188+
<div>
189+
Action:
190+
<pre>{{ modalData?.action }}</pre>
191+
</div>
192+
<div>
193+
Event:
194+
<pre>{{ modalData?.event | json }}</pre>
195+
</div>
196+
</div>
197+
<div class="modal-footer">
198+
<button type="button" class="btn btn-outline-secondary" (click)="close()">
199+
OK
200+
</button>
201+
</div>
202+
</ng-template>

0 commit comments

Comments
 (0)