@imihai/angular-datetime-picker 21.0.1 → 21.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/style/picker.min.css +1 -0
- package/fesm2022/imihai-angular-datetime-picker.mjs +5845 -0
- package/fesm2022/imihai-angular-datetime-picker.mjs.map +1 -0
- package/imihai-angular-datetime-picker-21.0.2.tgz +0 -0
- package/package.json +33 -77
- package/types/imihai-angular-datetime-picker.d.ts +2193 -0
- package/.browserslistrc +0 -9
- package/.editorconfig +0 -13
- package/.eslintrc.js +0 -208
- package/.github/workflows/ci_test.yml +0 -35
- package/.prettierrc +0 -2
- package/.travis.yml +0 -16
- package/angular.json +0 -221
- package/e2e/protractor.conf.js +0 -28
- package/e2e/src/app.e2e-spec.ts +0 -14
- package/e2e/src/app.po.ts +0 -11
- package/e2e/tsconfig.e2e.json +0 -13
- package/projects/picker/karma.conf.js +0 -62
- package/projects/picker/ng-package.json +0 -7
- package/projects/picker/package.json +0 -23
- package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +0 -313
- package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +0 -18
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +0 -307
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +0 -11
- package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +0 -31
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +0 -356
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +0 -14
- package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +0 -26
- package/projects/picker/src/lib/date-time/calendar-body.component.html +0 -38
- package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +0 -120
- package/projects/picker/src/lib/date-time/calendar-body.component.ts +0 -190
- package/projects/picker/src/lib/date-time/calendar-month-view.component.html +0 -47
- package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +0 -16
- package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +0 -394
- package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +0 -705
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +0 -44
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +0 -343
- package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +0 -465
- package/projects/picker/src/lib/date-time/calendar-year-view.component.html +0 -16
- package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +0 -381
- package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +0 -549
- package/projects/picker/src/lib/date-time/calendar.component.html +0 -169
- package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
- package/projects/picker/src/lib/date-time/calendar.component.spec.ts +0 -592
- package/projects/picker/src/lib/date-time/calendar.component.ts +0 -496
- package/projects/picker/src/lib/date-time/date-time-inline.component.html +0 -1
- package/projects/picker/src/lib/date-time/date-time-inline.component.scss +0 -4
- package/projects/picker/src/lib/date-time/date-time-inline.component.ts +0 -365
- package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +0 -4
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +0 -126
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +0 -631
- package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +0 -851
- package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +0 -76
- package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +0 -88
- package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
- package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +0 -2648
- package/projects/picker/src/lib/date-time/date-time-picker.component.ts +0 -731
- package/projects/picker/src/lib/date-time/date-time.class.ts +0 -256
- package/projects/picker/src/lib/date-time/date-time.module.ts +0 -61
- package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +0 -28
- package/projects/picker/src/lib/date-time/options-provider.ts +0 -44
- package/projects/picker/src/lib/date-time/timer-box.component.html +0 -79
- package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer-box.component.ts +0 -175
- package/projects/picker/src/lib/date-time/timer.component.html +0 -58
- package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
- package/projects/picker/src/lib/date-time/timer.component.spec.ts +0 -399
- package/projects/picker/src/lib/date-time/timer.component.ts +0 -371
- package/projects/picker/src/lib/dialog/dialog-config.class.ts +0 -220
- package/projects/picker/src/lib/dialog/dialog-container.component.html +0 -1
- package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
- package/projects/picker/src/lib/dialog/dialog-container.component.ts +0 -231
- package/projects/picker/src/lib/dialog/dialog-ref.class.ts +0 -178
- package/projects/picker/src/lib/dialog/dialog.module.ts +0 -25
- package/projects/picker/src/lib/dialog/dialog.service.ts +0 -353
- package/projects/picker/src/lib/utils/array.utils.ts +0 -12
- package/projects/picker/src/lib/utils/constants.ts +0 -59
- package/projects/picker/src/lib/utils/date.utils.ts +0 -97
- package/projects/picker/src/lib/utils/index.ts +0 -5
- package/projects/picker/src/lib/utils/object.utils.ts +0 -29
- package/projects/picker/src/public_api.ts +0 -56
- package/projects/picker/src/sass/picker.scss +0 -743
- package/projects/picker/src/test-helpers.ts +0 -125
- package/projects/picker/src/test.ts +0 -52
- package/projects/picker/tsconfig.lib.json +0 -18
- package/projects/picker/tsconfig.lib.prod.json +0 -7
- package/projects/picker/tsconfig.spec.json +0 -17
- package/projects/picker/tslint.json +0 -8
- package/src/app/app.component.html +0 -77
- package/src/app/app.component.scss +0 -32
- package/src/app/app.component.spec.ts +0 -16
- package/src/app/app.component.ts +0 -35
- package/src/assets/.gitkeep +0 -0
- package/src/environments/environment.prod.ts +0 -3
- package/src/environments/environment.ts +0 -16
- package/src/favicon.ico +0 -0
- package/src/index.html +0 -14
- package/src/karma.conf.js +0 -31
- package/src/main.ts +0 -16
- package/src/polyfills.ts +0 -53
- package/src/styles.scss +0 -7
- package/src/test.ts +0 -50
- package/src/tsconfig.app.json +0 -16
- package/src/tsconfig.spec.json +0 -18
- package/src/tslint.json +0 -17
- package/tsconfig.base.json +0 -29
- package/tsconfig.json +0 -30
- package/tslint.json +0 -130
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* calendar-year-view.component
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AfterContentInit,
|
|
7
|
-
ChangeDetectionStrategy,
|
|
8
|
-
ChangeDetectorRef,
|
|
9
|
-
Component,
|
|
10
|
-
EventEmitter,
|
|
11
|
-
Inject,
|
|
12
|
-
Input,
|
|
13
|
-
OnDestroy,
|
|
14
|
-
OnInit,
|
|
15
|
-
Optional,
|
|
16
|
-
Output,
|
|
17
|
-
ViewChild
|
|
18
|
-
} from '@angular/core';
|
|
19
|
-
import {
|
|
20
|
-
CalendarCell,
|
|
21
|
-
OwlCalendarBodyComponent
|
|
22
|
-
} from './calendar-body.component';
|
|
23
|
-
import { DateTimeAdapter } from './adapter/date-time-adapter.class';
|
|
24
|
-
import {
|
|
25
|
-
OWL_DATE_TIME_FORMATS,
|
|
26
|
-
OwlDateTimeFormats
|
|
27
|
-
} from './adapter/date-time-format.class';
|
|
28
|
-
import { Subscription } from 'rxjs';
|
|
29
|
-
import { SelectMode } from './date-time.class';
|
|
30
|
-
import {
|
|
31
|
-
DOWN_ARROW,
|
|
32
|
-
END,
|
|
33
|
-
ENTER,
|
|
34
|
-
HOME,
|
|
35
|
-
LEFT_ARROW,
|
|
36
|
-
PAGE_DOWN,
|
|
37
|
-
PAGE_UP,
|
|
38
|
-
RIGHT_ARROW,
|
|
39
|
-
UP_ARROW
|
|
40
|
-
} from '@angular/cdk/keycodes';
|
|
41
|
-
|
|
42
|
-
const MONTHS_PER_YEAR = 12;
|
|
43
|
-
const MONTHS_PER_ROW = 3;
|
|
44
|
-
|
|
45
|
-
@Component({
|
|
46
|
-
selector: 'owl-date-time-year-view',
|
|
47
|
-
exportAs: 'owlMonthView',
|
|
48
|
-
templateUrl: './calendar-year-view.component.html',
|
|
49
|
-
styleUrls: ['./calendar-year-view.component.scss'],
|
|
50
|
-
host: {
|
|
51
|
-
'[class.owl-dt-calendar-view]': 'owlDTCalendarView'
|
|
52
|
-
},
|
|
53
|
-
standalone: false,
|
|
54
|
-
preserveWhitespaces: false,
|
|
55
|
-
changeDetection: ChangeDetectionStrategy.OnPush
|
|
56
|
-
})
|
|
57
|
-
export class OwlYearViewComponent<T>
|
|
58
|
-
implements OnInit, AfterContentInit, OnDestroy {
|
|
59
|
-
/**
|
|
60
|
-
* The select mode of the picker;
|
|
61
|
-
* */
|
|
62
|
-
private _selectMode: SelectMode = 'single';
|
|
63
|
-
@Input()
|
|
64
|
-
get selectMode(): SelectMode {
|
|
65
|
-
return this._selectMode;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
set selectMode(val: SelectMode) {
|
|
69
|
-
this._selectMode = val;
|
|
70
|
-
if (this.initiated) {
|
|
71
|
-
this.generateMonthList();
|
|
72
|
-
this.cdRef.markForCheck();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** The currently selected date. */
|
|
77
|
-
private _selected: T | null;
|
|
78
|
-
@Input()
|
|
79
|
-
get selected(): T | null {
|
|
80
|
-
return this._selected;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
set selected(value: T | null) {
|
|
84
|
-
value = this.dateTimeAdapter.deserialize(value);
|
|
85
|
-
this._selected = this.getValidDate(value);
|
|
86
|
-
this.setSelectedMonths();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private _selecteds: T[] = [];
|
|
90
|
-
@Input()
|
|
91
|
-
get selecteds(): T[] {
|
|
92
|
-
return this._selecteds;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
set selecteds(values: T[]) {
|
|
96
|
-
this._selecteds = [];
|
|
97
|
-
for (let i = 0; i < values.length; i++) {
|
|
98
|
-
const value = this.dateTimeAdapter.deserialize(values[i]);
|
|
99
|
-
this._selecteds.push(this.getValidDate(value));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.setSelectedMonths();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private _pickerMoment: T | null;
|
|
106
|
-
@Input()
|
|
107
|
-
get pickerMoment() {
|
|
108
|
-
return this._pickerMoment;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
set pickerMoment(value: T) {
|
|
112
|
-
const oldMoment = this._pickerMoment;
|
|
113
|
-
value = this.dateTimeAdapter.deserialize(value);
|
|
114
|
-
this._pickerMoment =
|
|
115
|
-
this.getValidDate(value) || this.dateTimeAdapter.now();
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
!this.hasSameYear(oldMoment, this._pickerMoment) &&
|
|
119
|
-
this.initiated
|
|
120
|
-
) {
|
|
121
|
-
this.generateMonthList();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* A function used to filter which dates are selectable
|
|
127
|
-
* */
|
|
128
|
-
private _dateFilter: (date: T) => boolean;
|
|
129
|
-
@Input()
|
|
130
|
-
get dateFilter() {
|
|
131
|
-
return this._dateFilter;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
set dateFilter(filter: (date: T) => boolean) {
|
|
135
|
-
this._dateFilter = filter;
|
|
136
|
-
if (this.initiated) {
|
|
137
|
-
this.generateMonthList();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** The minimum selectable date. */
|
|
142
|
-
private _minDate: T | null;
|
|
143
|
-
@Input()
|
|
144
|
-
get minDate(): T | null {
|
|
145
|
-
return this._minDate;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
set minDate(value: T | null) {
|
|
149
|
-
value = this.dateTimeAdapter.deserialize(value);
|
|
150
|
-
this._minDate = this.getValidDate(value);
|
|
151
|
-
if (this.initiated) {
|
|
152
|
-
this.generateMonthList();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** The maximum selectable date. */
|
|
157
|
-
private _maxDate: T | null;
|
|
158
|
-
@Input()
|
|
159
|
-
get maxDate(): T | null {
|
|
160
|
-
return this._maxDate;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set maxDate(value: T | null) {
|
|
164
|
-
value = this.dateTimeAdapter.deserialize(value);
|
|
165
|
-
this._maxDate = this.getValidDate(value);
|
|
166
|
-
if (this.initiated) {
|
|
167
|
-
this.generateMonthList();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private readonly monthNames: string[];
|
|
172
|
-
|
|
173
|
-
private _months: CalendarCell[][];
|
|
174
|
-
get months() {
|
|
175
|
-
return this._months;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
get activeCell(): number {
|
|
179
|
-
if (this._pickerMoment) {
|
|
180
|
-
return this.dateTimeAdapter.getMonth(this._pickerMoment);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
get isInSingleMode(): boolean {
|
|
185
|
-
return this.selectMode === 'single';
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
get isInRangeMode(): boolean {
|
|
189
|
-
return (
|
|
190
|
-
this.selectMode === 'range' ||
|
|
191
|
-
this.selectMode === 'rangeFrom' ||
|
|
192
|
-
this.selectMode === 'rangeTo'
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private localeSub: Subscription = Subscription.EMPTY;
|
|
197
|
-
|
|
198
|
-
private initiated = false;
|
|
199
|
-
|
|
200
|
-
public todayMonth: number | null;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* An array to hold all selectedDates' month value
|
|
204
|
-
* the value is the month number in current year
|
|
205
|
-
* */
|
|
206
|
-
public selectedMonths: number[] = [];
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Callback to invoke when a new month is selected
|
|
210
|
-
* */
|
|
211
|
-
@Output()
|
|
212
|
-
readonly change = new EventEmitter<T>();
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Emits the selected year. This doesn't imply a change on the selected date
|
|
216
|
-
* */
|
|
217
|
-
@Output()
|
|
218
|
-
readonly monthSelected = new EventEmitter<T>();
|
|
219
|
-
|
|
220
|
-
/** Emits when any date is activated. */
|
|
221
|
-
@Output()
|
|
222
|
-
readonly pickerMomentChange: EventEmitter<T> = new EventEmitter<T>();
|
|
223
|
-
|
|
224
|
-
/** Emits when use keyboard enter to select a calendar cell */
|
|
225
|
-
@Output()
|
|
226
|
-
readonly keyboardEnter: EventEmitter<any> = new EventEmitter<any>();
|
|
227
|
-
|
|
228
|
-
/** The body of calendar table */
|
|
229
|
-
@ViewChild(OwlCalendarBodyComponent, { static: true })
|
|
230
|
-
calendarBodyElm: OwlCalendarBodyComponent;
|
|
231
|
-
|
|
232
|
-
get owlDTCalendarView(): boolean {
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
constructor(
|
|
237
|
-
private cdRef: ChangeDetectorRef,
|
|
238
|
-
@Optional() private dateTimeAdapter: DateTimeAdapter<T>,
|
|
239
|
-
@Optional()
|
|
240
|
-
@Inject(OWL_DATE_TIME_FORMATS)
|
|
241
|
-
private dateTimeFormats: OwlDateTimeFormats
|
|
242
|
-
) {
|
|
243
|
-
this.monthNames = this.dateTimeAdapter.getMonthNames('short');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public ngOnInit() {
|
|
247
|
-
this.localeSub = this.dateTimeAdapter.localeChanges.subscribe(() => {
|
|
248
|
-
this.generateMonthList();
|
|
249
|
-
this.cdRef.markForCheck();
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
public ngAfterContentInit(): void {
|
|
254
|
-
this.generateMonthList();
|
|
255
|
-
this.initiated = true;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
public ngOnDestroy(): void {
|
|
259
|
-
this.localeSub.unsubscribe();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Handle a calendarCell selected
|
|
264
|
-
*/
|
|
265
|
-
public selectCalendarCell(cell: CalendarCell): void {
|
|
266
|
-
this.selectMonth(cell.value);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Handle a new month selected
|
|
271
|
-
*/
|
|
272
|
-
private selectMonth(month: number): void {
|
|
273
|
-
const firstDateOfMonth = this.dateTimeAdapter.createDate(
|
|
274
|
-
this.dateTimeAdapter.getYear(this.pickerMoment),
|
|
275
|
-
month,
|
|
276
|
-
1
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
this.monthSelected.emit(firstDateOfMonth);
|
|
280
|
-
|
|
281
|
-
const daysInMonth = this.dateTimeAdapter.getNumDaysInMonth(
|
|
282
|
-
firstDateOfMonth
|
|
283
|
-
);
|
|
284
|
-
const result = this.dateTimeAdapter.createDate(
|
|
285
|
-
this.dateTimeAdapter.getYear(this.pickerMoment),
|
|
286
|
-
month,
|
|
287
|
-
Math.min(
|
|
288
|
-
daysInMonth,
|
|
289
|
-
this.dateTimeAdapter.getDate(this.pickerMoment)
|
|
290
|
-
),
|
|
291
|
-
this.dateTimeAdapter.getHours(this.pickerMoment),
|
|
292
|
-
this.dateTimeAdapter.getMinutes(this.pickerMoment),
|
|
293
|
-
this.dateTimeAdapter.getSeconds(this.pickerMoment)
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
this.change.emit(result);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Handle keydown event on calendar body
|
|
301
|
-
*/
|
|
302
|
-
public handleCalendarKeydown(event: KeyboardEvent): void {
|
|
303
|
-
let moment;
|
|
304
|
-
switch (event.keyCode) {
|
|
305
|
-
// minus 1 month
|
|
306
|
-
case LEFT_ARROW:
|
|
307
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
308
|
-
this.pickerMoment,
|
|
309
|
-
-1
|
|
310
|
-
);
|
|
311
|
-
this.pickerMomentChange.emit(moment);
|
|
312
|
-
break;
|
|
313
|
-
|
|
314
|
-
// add 1 month
|
|
315
|
-
case RIGHT_ARROW:
|
|
316
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
317
|
-
this.pickerMoment,
|
|
318
|
-
1
|
|
319
|
-
);
|
|
320
|
-
this.pickerMomentChange.emit(moment);
|
|
321
|
-
break;
|
|
322
|
-
|
|
323
|
-
// minus 3 months
|
|
324
|
-
case UP_ARROW:
|
|
325
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
326
|
-
this.pickerMoment,
|
|
327
|
-
-3
|
|
328
|
-
);
|
|
329
|
-
this.pickerMomentChange.emit(moment);
|
|
330
|
-
break;
|
|
331
|
-
|
|
332
|
-
// add 3 months
|
|
333
|
-
case DOWN_ARROW:
|
|
334
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
335
|
-
this.pickerMoment,
|
|
336
|
-
3
|
|
337
|
-
);
|
|
338
|
-
this.pickerMomentChange.emit(moment);
|
|
339
|
-
break;
|
|
340
|
-
|
|
341
|
-
// move to first month of current year
|
|
342
|
-
case HOME:
|
|
343
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
344
|
-
this.pickerMoment,
|
|
345
|
-
-this.dateTimeAdapter.getMonth(this.pickerMoment)
|
|
346
|
-
);
|
|
347
|
-
this.pickerMomentChange.emit(moment);
|
|
348
|
-
break;
|
|
349
|
-
|
|
350
|
-
// move to last month of current year
|
|
351
|
-
case END:
|
|
352
|
-
moment = this.dateTimeAdapter.addCalendarMonths(
|
|
353
|
-
this.pickerMoment,
|
|
354
|
-
11 - this.dateTimeAdapter.getMonth(this.pickerMoment)
|
|
355
|
-
);
|
|
356
|
-
this.pickerMomentChange.emit(moment);
|
|
357
|
-
break;
|
|
358
|
-
|
|
359
|
-
// minus 1 year (or 10 year)
|
|
360
|
-
case PAGE_UP:
|
|
361
|
-
moment = this.dateTimeAdapter.addCalendarYears(
|
|
362
|
-
this.pickerMoment,
|
|
363
|
-
event.altKey ? -10 : -1
|
|
364
|
-
);
|
|
365
|
-
this.pickerMomentChange.emit(moment);
|
|
366
|
-
break;
|
|
367
|
-
|
|
368
|
-
// add 1 year (or 10 year)
|
|
369
|
-
case PAGE_DOWN:
|
|
370
|
-
moment = this.dateTimeAdapter.addCalendarYears(
|
|
371
|
-
this.pickerMoment,
|
|
372
|
-
event.altKey ? 10 : 1
|
|
373
|
-
);
|
|
374
|
-
this.pickerMomentChange.emit(moment);
|
|
375
|
-
break;
|
|
376
|
-
|
|
377
|
-
// Select current month
|
|
378
|
-
case ENTER:
|
|
379
|
-
this.selectMonth(
|
|
380
|
-
this.dateTimeAdapter.getMonth(this.pickerMoment)
|
|
381
|
-
);
|
|
382
|
-
this.keyboardEnter.emit();
|
|
383
|
-
break;
|
|
384
|
-
default:
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
this.focusActiveCell();
|
|
389
|
-
event.preventDefault();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Generate the calendar month list
|
|
394
|
-
* */
|
|
395
|
-
private generateMonthList(): void {
|
|
396
|
-
if (!this.pickerMoment) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
this.setSelectedMonths();
|
|
401
|
-
this.todayMonth = this.getMonthInCurrentYear(
|
|
402
|
-
this.dateTimeAdapter.now()
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
this._months = [];
|
|
406
|
-
for (let i = 0; i < MONTHS_PER_YEAR / MONTHS_PER_ROW; i++) {
|
|
407
|
-
const row = [];
|
|
408
|
-
|
|
409
|
-
for (let j = 0; j < MONTHS_PER_ROW; j++) {
|
|
410
|
-
const month = j + i * MONTHS_PER_ROW + this.dateTimeAdapter.firstMonthOfTheYear;
|
|
411
|
-
const monthCell = this.createMonthCell(month);
|
|
412
|
-
row.push(monthCell);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
this._months.push(row);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Creates an CalendarCell for the given month.
|
|
423
|
-
*/
|
|
424
|
-
private createMonthCell(month: number): CalendarCell {
|
|
425
|
-
const startDateOfMonth = this.dateTimeAdapter.createDate(
|
|
426
|
-
this.dateTimeAdapter.getYear(this.pickerMoment),
|
|
427
|
-
month,
|
|
428
|
-
1
|
|
429
|
-
);
|
|
430
|
-
const ariaLabel = this.dateTimeAdapter.format(
|
|
431
|
-
startDateOfMonth,
|
|
432
|
-
this.dateTimeFormats.monthYearA11yLabel
|
|
433
|
-
);
|
|
434
|
-
const cellClass = 'owl-dt-month-' + month;
|
|
435
|
-
return new CalendarCell(
|
|
436
|
-
month,
|
|
437
|
-
this.monthNames[month-this.dateTimeAdapter.firstMonthOfTheYear],
|
|
438
|
-
ariaLabel,
|
|
439
|
-
this.isMonthEnabled(month),
|
|
440
|
-
false,
|
|
441
|
-
cellClass
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Check if the given month is enable
|
|
447
|
-
*/
|
|
448
|
-
private isMonthEnabled(month: number): boolean {
|
|
449
|
-
const firstDateOfMonth = this.dateTimeAdapter.createDate(
|
|
450
|
-
this.dateTimeAdapter.getYear(this.pickerMoment),
|
|
451
|
-
month,
|
|
452
|
-
1
|
|
453
|
-
);
|
|
454
|
-
|
|
455
|
-
// If any date in the month is selectable,
|
|
456
|
-
// we count the month as enable
|
|
457
|
-
for (
|
|
458
|
-
let date = firstDateOfMonth;
|
|
459
|
-
this.dateTimeAdapter.getMonth(date) === month;
|
|
460
|
-
date = this.dateTimeAdapter.addCalendarDays(date, 1)
|
|
461
|
-
) {
|
|
462
|
-
if (
|
|
463
|
-
!!date &&
|
|
464
|
-
(!this.dateFilter || this.dateFilter(date)) &&
|
|
465
|
-
(!this.minDate ||
|
|
466
|
-
this.dateTimeAdapter.compare(date, this.minDate) >= 0) &&
|
|
467
|
-
(!this.maxDate ||
|
|
468
|
-
this.dateTimeAdapter.compare(date, this.maxDate) <= 0)
|
|
469
|
-
) {
|
|
470
|
-
return true;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
return false;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Gets the month in this year that the given Date falls on.
|
|
479
|
-
* Returns null if the given Date is in another year.
|
|
480
|
-
*/
|
|
481
|
-
private getMonthInCurrentYear(date: T | null): number {
|
|
482
|
-
if (this.getValidDate(date) && this.getValidDate(this._pickerMoment)) {
|
|
483
|
-
const result = this.dateTimeAdapter.compareYear(
|
|
484
|
-
date,
|
|
485
|
-
this._pickerMoment
|
|
486
|
-
);
|
|
487
|
-
|
|
488
|
-
// < 0 : the given date's year is before pickerMoment's year, we return -1 as selected month value.
|
|
489
|
-
// > 0 : the given date's year is after pickerMoment's year, we return 12 as selected month value.
|
|
490
|
-
// 0 : the give date's year is same as the pickerMoment's year, we return the actual month value.
|
|
491
|
-
if (result < 0) {
|
|
492
|
-
return -1;
|
|
493
|
-
} else if (result > 0) {
|
|
494
|
-
return 12;
|
|
495
|
-
} else {
|
|
496
|
-
return this.dateTimeAdapter.getMonth(date);
|
|
497
|
-
}
|
|
498
|
-
} else {
|
|
499
|
-
return null;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Set the selectedMonths value
|
|
505
|
-
* In single mode, it has only one value which represent the month the selected date in
|
|
506
|
-
* In range mode, it would has two values, one for the month the fromValue in and the other for the month the toValue in
|
|
507
|
-
* */
|
|
508
|
-
private setSelectedMonths(): void {
|
|
509
|
-
this.selectedMonths = [];
|
|
510
|
-
if (this.isInSingleMode && this.selected) {
|
|
511
|
-
this.selectedMonths[0] = this.getMonthInCurrentYear(this.selected);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
if (this.isInRangeMode && this.selecteds) {
|
|
515
|
-
this.selectedMonths[0] = this.getMonthInCurrentYear(
|
|
516
|
-
this.selecteds[0]
|
|
517
|
-
);
|
|
518
|
-
this.selectedMonths[1] = this.getMonthInCurrentYear(
|
|
519
|
-
this.selecteds[1]
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Check the given dates are in the same year
|
|
526
|
-
*/
|
|
527
|
-
private hasSameYear(dateLeft: T, dateRight: T) {
|
|
528
|
-
return !!(
|
|
529
|
-
dateLeft &&
|
|
530
|
-
dateRight &&
|
|
531
|
-
this.dateTimeAdapter.getYear(dateLeft) ===
|
|
532
|
-
this.dateTimeAdapter.getYear(dateRight)
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Get a valid date object
|
|
538
|
-
*/
|
|
539
|
-
private getValidDate(obj: any): T | null {
|
|
540
|
-
return this.dateTimeAdapter.isDateInstance(obj) &&
|
|
541
|
-
this.dateTimeAdapter.isValid(obj)
|
|
542
|
-
? obj
|
|
543
|
-
: null;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
private focusActiveCell() {
|
|
547
|
-
this.calendarBodyElm.focusActiveCell();
|
|
548
|
-
}
|
|
549
|
-
}
|