8
8
Input ,
9
9
ViewChild ,
10
10
ElementRef ,
11
- AfterViewInit
11
+ AfterViewInit ,
12
+ ViewChildren ,
13
+ QueryList
12
14
} from '@angular/core' ;
13
15
import { NG_VALUE_ACCESSOR } from '@angular/forms' ;
14
16
import { fadeIn , scaleInCenter } from '../animations/main' ;
@@ -21,26 +23,16 @@ import { ICalendarDate, monthRange } from './calendar';
21
23
import { CalendarView , IgxMonthPickerBase } from './month-picker-base' ;
22
24
import { IgxMonthsViewComponent } from './months-view/months-view.component' ;
23
25
import { IgxYearsViewComponent } from './years-view/years-view.component' ;
24
- import { IgxDaysViewComponent } from './days-view/days-view.component' ;
25
- import { DateRangeDescriptor } from '../core/dates' ;
26
+ import { IgxDaysViewComponent , IViewChangedArgs } from './days-view/days-view.component' ;
26
27
import { interval } from 'rxjs' ;
27
28
import { takeUntil , debounce , skipLast , switchMap } from 'rxjs/operators' ;
28
29
import { ScrollMonth } from './calendar-base' ;
29
30
30
31
let NEXT_ID = 0 ;
31
32
32
- export interface IDayView {
33
- changeDaysView : boolean ;
34
- animationAction : string ;
35
- locale : string ;
33
+ export interface IMonthView {
36
34
value : Date | Date [ ] ;
37
35
viewDate : Date ;
38
- weekStart : number ;
39
- formatOptions : object ;
40
- formatViews : object ;
41
- selection : string ;
42
- disabledDates : DateRangeDescriptor [ ] ;
43
- specialDates : DateRangeDescriptor [ ] ;
44
36
}
45
37
46
38
/**
@@ -110,30 +102,31 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
110
102
public vertical = false ;
111
103
112
104
/**
113
- * Sets/gets the number of dayViews duisplayed .
105
+ * Sets/gets the number of month views displayed .
114
106
* Default value is `1`.
115
107
* ```html
116
- * <igx-calendar [vertical] = "true" [daysViewNumber ]="2"></igx-calendar>
108
+ * <igx-calendar [vertical] = "true" [monthsViewNumber ]="2"></igx-calendar>
117
109
* ```
118
110
* ```typescript
119
- * let daysViewsDisplayed = this.calendar.daysViewNumber ;
111
+ * let monthViewsDisplayed = this.calendar.monthsViewNumber ;
120
112
* ```
121
113
*/
122
114
@Input ( )
123
- get daysViewNumber ( ) {
124
- return this . _daysViewNumber ;
115
+ get monthsViewNumber ( ) {
116
+ return this . _monthsViewNumber ;
125
117
}
126
118
127
- set daysViewNumber ( val : number ) {
128
- this . _daysViewNumber = val ;
119
+ set monthsViewNumber ( val : number ) {
120
+ this . _monthsViewNumber = val ;
129
121
130
- for ( let i = 1 ; i < val ; i ++ ) {
131
- const dayView = Object . assign ( { } , this . defaultDayView ) ;
132
- dayView . value = null ;
133
- const nextMonthDate = new Date ( dayView . viewDate ) ;
122
+ for ( let i = 0 ; i < val ; i ++ ) {
123
+ const nextMonthDate = new Date ( this . viewDate ) ;
134
124
nextMonthDate . setMonth ( nextMonthDate . getMonth ( ) + i ) ;
135
- dayView . viewDate = nextMonthDate ;
136
- this . dayViews . push ( dayView ) ;
125
+ const monthView : IMonthView = {
126
+ value : null ,
127
+ viewDate : nextMonthDate
128
+ } ;
129
+ this . dayViews . push ( monthView ) ;
137
130
}
138
131
}
139
132
@@ -201,7 +194,10 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
201
194
* @hidden
202
195
*/
203
196
@ViewChild ( 'days' , { read : IgxDaysViewComponent , static : false } )
204
- public daysView : IgxDaysViewComponent ;
197
+ public daysView = new IgxDaysViewComponent ;
198
+
199
+ @ViewChildren ( 'days' , { read : IgxDaysViewComponent } )
200
+ public monthViews : QueryList < IgxDaysViewComponent > ;
205
201
206
202
/**
207
203
* @hidden
@@ -335,32 +331,22 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
335
331
/**
336
332
*@hidden
337
333
*/
338
- private _daysViewNumber = 1 ;
339
-
340
- /**
341
- *@hidden
342
- */
343
- private defaultDayView : IDayView = {
344
- changeDaysView : true ,
345
- animationAction : this . _monthAction ,
346
- locale : this . locale ,
347
- value : this . value ,
348
- viewDate : this . viewDate ,
349
- weekStart : this . weekStart ,
350
- formatOptions : this . formatOptions ,
351
- formatViews : this . formatViews ,
352
- selection : this . selection ,
353
- disabledDates : this . disabledDates ,
354
- specialDates : this . specialDates
355
- } ;
334
+ private _monthsViewNumber = 1 ;
356
335
357
336
/**
358
337
*@hidden
359
338
*/
360
- private dayViews : Array < IDayView > = [ this . defaultDayView ] ;
339
+ private dayViews = [ ] ;
361
340
362
341
public ngAfterViewInit ( ) {
363
342
343
+ this . monthViews . forEach ( ( item , index ) => {
344
+ const prevMonthView = this . getMonthView ( index - 1 ) ;
345
+ const nextMonthView = this . getMonthView ( index + 1 ) ;
346
+ item . nextMonthView = nextMonthView ;
347
+ item . prevMonthView = prevMonthView ;
348
+ } ) ;
349
+
364
350
this . startMonthScroll$ . pipe (
365
351
takeUntil ( this . stopMonthScroll$ ) ,
366
352
switchMap ( ( ) => this . daysView . scrollMonth$ . pipe (
@@ -400,7 +386,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
400
386
*/
401
387
public previousMonth ( isKeydownTrigger = false ) {
402
388
this . viewDate = this . calendarModel . timedelta ( this . viewDate , 'month' , - 1 ) ;
403
- this . dayViews . forEach ( ( val , index ) => {
389
+ this . dayViews . forEach ( ( val ) => {
404
390
val . viewDate = this . calendarModel . timedelta ( val . viewDate , 'month' , - 1 ) ;
405
391
} ) ;
406
392
this . _monthAction = 'prev' ;
@@ -415,6 +401,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
415
401
*/
416
402
public nextMonth ( isKeydownTrigger = false ) {
417
403
this . viewDate = this . calendarModel . timedelta ( this . viewDate , 'month' , 1 ) ;
404
+ this . dayViews . forEach ( ( val ) => {
405
+ val . viewDate = this . calendarModel . timedelta ( val . viewDate , 'month' , 1 ) ;
406
+ } ) ;
418
407
this . _monthAction = 'next' ;
419
408
420
409
if ( this . daysView ) {
@@ -518,8 +507,14 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
518
507
/**
519
508
* @hidden
520
509
*/
521
- public viewChanged ( event ) {
522
- this . viewDate = this . calendarModel . timedelta ( event , 'month' , 0 ) ;
510
+ public viewChanged ( event : IViewChangedArgs ) {
511
+ let date = this . viewDate ,
512
+ delta = event . delta ;
513
+ if ( event . moveToFirst ) {
514
+ delta = 0 ;
515
+ date = event . date ;
516
+ }
517
+ this . viewDate = this . calendarModel . timedelta ( date , 'month' , delta ) ;
523
518
}
524
519
525
520
/**
@@ -570,6 +565,15 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
570
565
this . _onChangeCallback ( this . selectedDates ) ;
571
566
}
572
567
568
+ /**
569
+ * @hidden
570
+ */
571
+ public getViewDate ( i : number ) : Date {
572
+ const nextMonthDate = new Date ( this . viewDate ) ;
573
+ nextMonthDate . setMonth ( nextMonthDate . getMonth ( ) + i ) ;
574
+ return nextMonthDate ;
575
+ }
576
+
573
577
/**
574
578
* @hidden
575
579
*/
@@ -746,4 +750,16 @@ export class IgxCalendarComponent extends IgxMonthPickerBase implements AfterVie
746
750
} ;
747
751
return { $implicit : formatObject } ;
748
752
}
753
+
754
+ /**
755
+ * Helper method returning previous/next day views
756
+ * @hidden
757
+ */
758
+ private getMonthView ( index ) : IgxDaysViewComponent {
759
+ if ( index === - 1 || index === this . monthViews . length ) {
760
+ return null ;
761
+ } else {
762
+ return this . monthViews . toArray ( ) [ index ] ;
763
+ }
764
+ }
749
765
}
0 commit comments