import {Component, Input, Output, EventEmitter} from '@angular/core'; import {Observable} from 'rxjs'; import { Filter, Value, DateValue} from './searchHelperClasses.class'; import {IMyOptions, IMyDateModel} from '../../utils/my-date-picker/interfaces/index'; // import {IMyDateModel} from '../../../utils/my-date-picker/interfaces/my-date-model.interface'; import {Dates} from '../../utils/string-utils.class'; import {FormControl} from "@angular/forms"; import {MatDatepickerInputEvent} from "@angular/material"; @Component({ selector: 'date-filter', template: `
` }) export class DateFilterComponent { @Input() dateValue = new DateValue("any"); @Input() filterId; @Input() validDateFrom: boolean = true; @Input() validDateTo: boolean = true; private myDatePickerOptions: IMyOptions = { // other options... dateFormat: 'yyyy-mm-dd', selectionTxtFontSize: '15px', height:'28px', width: '100%', editableDateField: false, showClearDateBtn: false }; // Initialized to specific date (09.10.2018). public from;//: Object = { date: { year: 2018, month: 10, day: 9 } }; public to;//: Object = { date: { year: 2018, month: 10, day: 9 } }; public fromDate; public toDate; constructor() { //this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to); } ngOnInit() { this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to); } updateDefaultRangeDates(df:Date,dt:Date){ //df.setMonth(df.getMonth()-1); this.fromDate = new FormControl(df); this.toDate = new FormControl(dt); //this.from = { date: { year: df.getFullYear(), month: (df.getMonth()+1), day: df.getDate() } }; //this.to = { date: { year: dt.getFullYear(), month: (dt.getMonth()+1), day: dt.getDate() } }; } typeChanged(type:string){ this.dateValue.setDatesByType(type); this.updateDefaultRangeDates(this.dateValue.from, this.dateValue.to); } /* onFromDateChanged(event: IMyDateModel) { this.dateValue.from = Dates.getDateFromString(event.formatted); this.validDateFrom = true; } onToDateChanged(event: IMyDateModel) { this.dateValue.to = Dates.getDateFromString(event.formatted); this.validDateTo = true; } */ fromDateChanged(event: MatDatepickerInputEvent) { this.dateValue.from = event.value; //console.info("FROM: "+Dates.getDateToString(this.dateValue.from)); } toDateChanged(event: MatDatepickerInputEvent) { this.dateValue.to = event.value; //console.info("TO: "+Dates.getDateToString(this.dateValue.to)); } }