@@ -9,22 +9,198 @@ import {GaService} from './common/services/ga/ga.service';
99import { ECalendarValue } from '../../../projects/ng2-date-picker/src/lib/common/types/calendar-value-enum' ;
1010import { INavEvent } from '../../../projects/ng2-date-picker/src/lib/common/models/navigation-event.model' ;
1111import { ISelectionEvent } from '../../../projects/ng2-date-picker/src/lib/common/types/selection-event.model' ;
12- import { IDayTimeCalendarConfig } from '../../../projects/ng2-date-picker/src/public-api' ;
1312
1413@Component ( {
1514 selector : 'dp-demo' ,
1615 templateUrl : './demo.component.html' ,
1716 styleUrls : [ './demo.component.less' ]
1817} )
19- export class DemoComponent {
20- date = dayjs ( ) . format ( 'YYYY-MM-DDTHH:mm:ss' ) ;
21- format = 'YYYY-MM-DDTHH:mm:ss' ;
22- config = {
23- format : this . format ,
24- max : dayjs ( ) . format ( this . format ) ,
25- } as IDayTimeCalendarConfig ;
26-
27- onChange ( theDate : any ) {
28- this . date = theDate ;
18+ export class DemoComponent implements OnInit {
19+ @ViewChild ( 'dateComponent' ) dateComponent : DatePickerComponent ;
20+ @ViewChild ( 'donateForm' ) donateForm : any ;
21+ @ViewChild ( 'dateDirectivePicker' ) datePickerDirective : DatePickerDirective ;
22+ demoFormat = 'DD-MM-YYYY' ;
23+ pickerMode = 'daytimePicker' ;
24+
25+ date : Dayjs ;
26+ dates : Dayjs [ ] = [ ] ;
27+ material : boolean = true ;
28+ required : boolean = false ;
29+ disabled : boolean = false ;
30+ validationMinDate : Dayjs ;
31+ validationMaxDate : Dayjs ;
32+ validationMinTime : Dayjs ;
33+ validationMaxTime : Dayjs ;
34+ placeholder : string = 'Choose a date...' ;
35+ displayDate : Dayjs | string ;
36+ dateTypes : { name : string , value : ECalendarValue } [ ] = [
37+ {
38+ name : 'Guess' ,
39+ value : null
40+ } ,
41+ {
42+ name : ECalendarValue [ ECalendarValue . Dayjs ] ,
43+ value : ECalendarValue . Dayjs
44+ } ,
45+ {
46+ name : ECalendarValue [ ECalendarValue . DayjsArr ] ,
47+ value : ECalendarValue . DayjsArr
48+ } ,
49+ {
50+ name : ECalendarValue [ ECalendarValue . String ] ,
51+ value : ECalendarValue . String
52+ } ,
53+ {
54+ name : ECalendarValue [ ECalendarValue . StringArr ] ,
55+ value : ECalendarValue . StringArr
56+ }
57+ ] ;
58+ config : IDatePickerConfig = {
59+ firstDayOfWeek : 'su' ,
60+ monthFormat : 'MMM, YYYY' ,
61+ disableKeypress : false ,
62+ allowMultiSelect : false ,
63+ closeOnSelect : undefined ,
64+ closeOnSelectDelay : 100 ,
65+ openOnFocus : true ,
66+ openOnClick : true ,
67+ onOpenDelay : 0 ,
68+ weekDayFormat : 'ddd' ,
69+ showNearMonthDays : true ,
70+ showWeekNumbers : false ,
71+ enableMonthSelector : true ,
72+ yearFormat : 'YYYY' ,
73+ showGoToCurrent : true ,
74+ dayBtnFormat : 'DD' ,
75+ monthBtnFormat : 'MMM' ,
76+ hours12Format : 'hh' ,
77+ hours24Format : 'HH' ,
78+ meridiemFormat : 'A' ,
79+ minutesFormat : 'mm' ,
80+ minutesInterval : 1 ,
81+ secondsFormat : 'ss' ,
82+ secondsInterval : 1 ,
83+ showSeconds : false ,
84+ showTwentyFourHours : false ,
85+ timeSeparator : ':' ,
86+ multipleYearsNavigateBy : 10 ,
87+ showMultipleYearsNavigation : false ,
88+ hideInputContainer : false ,
89+ returnedValueType : ECalendarValue . String ,
90+ unSelectOnClick : true ,
91+ hideOnOutsideClick : true
92+ } ;
93+
94+ formGroup : UntypedFormGroup ;
95+ isAtTop : boolean = true ;
96+
97+ constructor ( private readonly gaService : GaService ) {
98+ }
99+
100+ ngOnInit ( ) : void {
101+ this . formGroup = this . buildForm ( ) ;
102+ }
103+
104+ @HostListener ( 'document:scroll' )
105+ @debounce ( 100 )
106+ updateIsAtTop ( ) {
107+ this . isAtTop = document . body . scrollTop === 0 ;
108+ }
109+
110+ validatorsChanged ( ) {
111+ this . formGroup . get ( 'datePicker' ) . updateValueAndValidity ( ) ;
112+ }
113+
114+ openCalendar ( ) {
115+ if ( this . dateComponent ) {
116+ this . dateComponent . api . open ( ) ;
117+ } else if ( this . datePickerDirective ) {
118+ this . datePickerDirective . api . open ( ) ;
119+ }
120+ }
121+
122+ closeCalendar ( ) {
123+ if ( this . dateComponent ) {
124+ this . dateComponent . api . close ( ) ;
125+ } else if ( this . datePickerDirective ) {
126+ this . datePickerDirective . api . close ( ) ;
127+ }
128+ }
129+
130+ opened ( ) {
131+ console . info ( 'opened' ) ;
132+ }
133+
134+ closed ( ) {
135+ console . info ( 'closed' ) ;
136+ }
137+
138+ log ( _ ) {
139+ // console.info(item);
140+ }
141+
142+ onLeftNav ( change : INavEvent ) {
143+ console . info ( 'left nav' , change ) ;
144+ }
145+
146+ onRightNav ( change : INavEvent ) {
147+ console . info ( 'right nav' , change ) ;
148+ }
149+
150+ moveCalendarTo ( ) {
151+ this . dateComponent . api . moveCalendarTo ( dayjs ( '14-01-1987' , this . demoFormat ) ) ;
152+ }
153+
154+ donateClicked ( ) {
155+ this . gaService . emitEvent ( 'donate' , 'clicked' ) ;
156+ this . donateForm . nativeElement . submit ( ) ;
157+ }
158+
159+ becomeABackerClicked ( ) {
160+ this . gaService . emitEvent ( 'becomeABacker' , 'clicked' ) ;
161+ }
162+
163+ onSelect ( data : ISelectionEvent ) {
164+ console . info ( data ) ;
165+ }
166+
167+ private buildForm ( ) : UntypedFormGroup {
168+ return new UntypedFormGroup ( {
169+ datePicker : new UntypedFormControl ( { value : this . date , disabled : this . disabled } , [
170+ this . required ? Validators . required : ( ) => undefined ,
171+ ( control ) => {
172+ return this . validationMinDate && this . config &&
173+ dayjs ( control . value , this . config . format || DemoComponent . getDefaultFormatByMode ( this . pickerMode ) )
174+ . isBefore ( this . validationMinDate )
175+ ? { minDate : 'minDate Invalid' } : undefined
176+ } ,
177+ control => this . validationMaxDate && this . config &&
178+ dayjs ( control . value , this . config . format || DemoComponent . getDefaultFormatByMode ( this . pickerMode ) )
179+ . isAfter ( this . validationMaxDate )
180+ ? { maxDate : 'maxDate Invalid' } : undefined
181+ ] )
182+ } ) ;
183+ }
184+
185+ private static getDefaultFormatByMode ( mode : string ) : string {
186+ switch ( mode ) {
187+ case 'daytimePicker' :
188+ case 'daytimeInline' :
189+ case 'daytimeDirective' :
190+ return 'DD-MM-YYYY HH:mm:ss' ;
191+ case 'dayPicker' :
192+ case 'dayInline' :
193+ case 'dayDirective' :
194+ case 'dayDirectiveReactiveMenu' :
195+ return 'DD-MM-YYYY' ;
196+ case 'monthPicker' :
197+ case 'monthInline' :
198+ case 'monthDirective' :
199+ return 'MMM, YYYY' ;
200+ case 'timePicker' :
201+ case 'timeInline' :
202+ case 'timeDirective' :
203+ return 'HH:mm:ss' ;
204+ }
29205 }
30206}
0 commit comments