2020-03-26 13:18:18 +01:00
|
|
|
import {Component, Input} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-03-26 13:18:18 +01:00
|
|
|
import {DateValue} from './searchHelperClasses.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {FormControl} from "@angular/forms";
|
2021-07-14 13:19:57 +02:00
|
|
|
import { MatDatepickerInputEvent } from "@angular/material/datepicker";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'date-filter',
|
|
|
|
template: `
|
2022-08-02 14:42:32 +02:00
|
|
|
<div>
|
|
|
|
<mat-select *ngIf="dateValue && dateValue.type!='range' " name="{{'select_date_type'+filterId}}" class=" matSelection uk-input" [(ngModel)]=dateValue.type [disableOptionCentering]="true" panelClass="matSelectionPanel">
|
|
|
|
<mat-option *ngFor="let type of dateValue.types let i = index" [value]="type" (click)="typeChanged(type)">{{dateValue.typesTitle[i]}}</mat-option>
|
|
|
|
</mat-select>
|
|
|
|
<div *ngIf="dateValue && dateValue.type=='range' ">
|
|
|
|
<div class=" uk-grid uk-margin-remove-left" >
|
|
|
|
<div class="uk-padding-remove uk-margin-small-bottom uk-width-1-1">
|
|
|
|
<mat-select name="{{'select_date_type'+filterId}}" [(ngModel)]=dateValue.type [disableOptionCentering]="true" class="matSelection uk-input" panelClass="matSelectionPanel">
|
|
|
|
<mat-option *ngFor="let type of dateValue.types let i = index" [value]="type" (click)="typeChanged(type)">{{dateValue.typesTitle[i]}}</mat-option>
|
|
|
|
</mat-select>
|
|
|
|
</div>
|
|
|
|
<div class="uk-padding-remove uk-margin-small-left uk-width-1-1">
|
|
|
|
<mat-form-field class="uk-width-1-1">
|
|
|
|
<input matInput [matDatepicker]="pickerFrom" placeholder="Choose from date"
|
|
|
|
[formControl]="fromDate" (click)="pickerFrom.open()" (dateChange)="fromDateChanged($event)">
|
|
|
|
<mat-datepicker-toggle matSuffix [for]="pickerFrom"></mat-datepicker-toggle>
|
|
|
|
<mat-datepicker #pickerFrom></mat-datepicker>
|
|
|
|
</mat-form-field>
|
|
|
|
</div>
|
|
|
|
<div class="uk-padding-remove uk-margin-small-left uk-width-1-1">
|
|
|
|
<mat-form-field class="uk-width-1-1">
|
|
|
|
<input matInput [matDatepicker]="pickerTo" placeholder="Choose to date"
|
|
|
|
[formControl]="toDate" (click)="pickerTo.open()" (dateChange)="toDateChanged($event)">
|
|
|
|
<mat-datepicker-toggle matSuffix [for]="pickerTo"></mat-datepicker-toggle>
|
|
|
|
<mat-datepicker #pickerTo></mat-datepicker>
|
|
|
|
</mat-form-field>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
export class DateFilterComponent {
|
|
|
|
|
|
|
|
@Input() dateValue = new DateValue("any");
|
|
|
|
@Input() filterId;
|
2019-05-22 12:50:32 +02:00
|
|
|
@Input() validDateFrom: boolean = true;
|
|
|
|
@Input() validDateTo: boolean = true;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
// 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 } };
|
2019-06-03 15:20:36 +02:00
|
|
|
public fromDate;
|
|
|
|
public toDate;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
constructor() {
|
2019-06-03 15:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to);
|
|
|
|
}
|
|
|
|
updateDefaultRangeDates(df:Date,dt:Date){
|
2019-06-03 15:20:36 +02:00
|
|
|
this.fromDate = new FormControl(df);
|
|
|
|
this.toDate = new FormControl(dt);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
typeChanged(type:string){
|
|
|
|
this.dateValue.setDatesByType(type);
|
|
|
|
this.updateDefaultRangeDates(this.dateValue.from, this.dateValue.to);
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
|
|
|
|
fromDateChanged(event: MatDatepickerInputEvent<Date>) {
|
|
|
|
this.dateValue.from = event.value;
|
|
|
|
//console.info("FROM: "+Dates.getDateToString(this.dateValue.from));
|
|
|
|
}
|
|
|
|
|
|
|
|
toDateChanged(event: MatDatepickerInputEvent<Date>) {
|
|
|
|
this.dateValue.to = event.value;
|
|
|
|
//console.info("TO: "+Dates.getDateToString(this.dateValue.to));
|
|
|
|
}
|
|
|
|
}
|