import { ThyPlacement } from 'ngx-tethys/core' ; import { coerceBooleanProperty , FunctionProp , TinyDate } from 'ngx-tethys/util' ; import { ChangeDetectorRef , Component , EventEmitter , Input , OnChanges , OnInit , Output , TemplateRef } from '@angular/core' ; import { AbstractPickerComponent } from './abstract-picker.component' ; import { CompatibleDate , CompatibleValue , PanelMode } from './standard-types' ; @ Component ( { template : `` } ) export class BasePickerComponent extends AbstractPickerComponent implements OnInit , OnChanges { showWeek = false ; panelMode : PanelMode | PanelMode [ ] ; @ Input ( ) thyDateRender : FunctionProp < TemplateRef < Date > | string > ; @ Output ( ) readonly thyOnPanelChange = new EventEmitter < PanelMode | PanelMode [ ] > ( ) ; @ Output ( ) readonly thyOnCalendarChange = new EventEmitter < Date [ ] > ( ) ; private _showTime : object | boolean ; @ Input ( ) get thyShowTime ( ) : object | boolean { return this . _showTime ; } set thyShowTime ( value ) { this . _showTime = typeof value === 'object' ? value : coerceBooleanProperty ( value ) ; } @ Input ( ) thyMustShowTime = false ; @ Input ( ) thyPlacement : ThyPlacement = 'bottomLeft' ; @ Output ( ) readonly thyOnOk = new EventEmitter < CompatibleDate | null > ( ) ; constructor ( cdr ) { super ( cdr ) ; } ngOnInit ( ) { super . ngOnInit ( ) ; this . setDefaultTimePickerState ( ) ; } onValueChange ( value ) { this . restoreTimePickerState ( value ) ; super . onValueChange ( value ) ; this . closeOverlay ( ) ; } setDefaultTimePickerState ( ) { this . thyMode = this . thyMode || 'date' ; this . withTime = this . thyMustShowTime ; this . panelMode = this . isRange ? [ this . thyMode , this . thyMode ] : this . thyMode ; this . showWeek = this . thyMode === 'week' ; if ( ! this . thyFormat ) { const inputFormats = { year : 'yyyy' , month : 'yyyy-MM' , week : 'yyyy-ww' , date : this . thyShowTime ? 'yyyy-MM-dd HH:mm' : 'yyyy-MM-dd' } ; this . thyFormat = inputFormats [ this . thyMode ] ; } } restoreTimePickerState ( value ) { if ( ! value ) { this . withTime = this . thyMustShowTime || this . originWithTime ; } } onCalendarChange ( value ) { if ( this . isRange ) { const rangeValue = value . map ( x => x . nativeDate ) ; this . thyOnCalendarChange . emit ( rangeValue ) ; } } onShowTimePickerChange ( show ) { this . withTime = show ; } onResultOk ( ) { if ( this . isRange ) { const value = this . thyValue as TinyDate [ ] ; if ( value . length ) { this . thyOnOk . emit ( [ value [ 0 ] . nativeDate , value [ 1 ] . nativeDate ] ) ; } else { this . thyOnOk . emit ( [ ] ) ; } } else { if ( this . thyValue ) { this . thyOnOk . emit ( ( this . thyValue as TinyDate ) . nativeDate ) ; } else { this . thyOnOk . emit ( null ) ; } } this . closeOverlay ( ) ; } onOpenChange ( open ) { this . thyOpenChange . emit ( open ) ; } }