mirror of
https://github.com/chuot/rdio-scanner.git
synced 2026-08-13 16:33:01 -06:00
Improved date selection filter to reflect database content
This commit is contained in:
parent
d6571f17e2
commit
fbb40f501c
|
|
@ -81,7 +81,7 @@
|
||||||
<mat-label>
|
<mat-label>
|
||||||
Date
|
Date
|
||||||
</mat-label>
|
</mat-label>
|
||||||
<input formControlName="date" [matDatepicker]="date" matInput placeholder="Choose a date">
|
<input (focus)="date.open()" formControlName="date" [matDatepicker]="date" matInput [max]="dateMax" [min]="dateMin" placeholder="Choose a date">
|
||||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||||
<mat-datepicker #date></mat-datepicker>
|
<mat-datepicker #date></mat-datepicker>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
@ -115,7 +115,7 @@
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button (click)="resetFilters()" mat-raised-button>
|
<button (click)="resetFilters()" mat-raised-button type="button">
|
||||||
Reset
|
Reset
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
|
dateMax: Date;
|
||||||
|
dateMin: Date;
|
||||||
|
|
||||||
form: FormGroup = this.ngFormBuilder.group({
|
form: FormGroup = this.ngFormBuilder.group({
|
||||||
date: [],
|
date: [],
|
||||||
sort: [],
|
sort: [],
|
||||||
|
|
@ -58,10 +61,12 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
private _subscriptions: {
|
private _subscriptions: {
|
||||||
calls: Subscription[];
|
calls: Subscription[];
|
||||||
|
dateLimits: Subscription[];
|
||||||
form: Subscription[];
|
form: Subscription[];
|
||||||
radio: Subscription[];
|
radio: Subscription[];
|
||||||
} = {
|
} = {
|
||||||
calls: [],
|
calls: [],
|
||||||
|
dateLimits: [],
|
||||||
form: [],
|
form: [],
|
||||||
radio: [],
|
radio: [],
|
||||||
};
|
};
|
||||||
|
|
@ -111,8 +116,10 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
if (this._active) {
|
if (this._active) {
|
||||||
this._subscribeCalls();
|
this._subscribeCalls();
|
||||||
|
this._subscribeDateLimits();
|
||||||
} else {
|
} else {
|
||||||
this._unsubscribeCalls();
|
this._unsubscribeCalls();
|
||||||
|
this._unsubscribeDateLimits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -212,6 +219,40 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _subscribeDateLimits(): void {
|
||||||
|
this._subscriptions.dateLimits.push(
|
||||||
|
|
||||||
|
MeteorObservable.subscribe('calls', {}, {
|
||||||
|
fields: { audio: 0 },
|
||||||
|
limit: 1,
|
||||||
|
sort: { startTime: -1 },
|
||||||
|
}).subscribe(() => {
|
||||||
|
const call = RadioCalls.findOne({}, {
|
||||||
|
sort: { startTime: -1 },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (call) {
|
||||||
|
this.dateMax = call.startTime;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
MeteorObservable.subscribe('calls', {}, {
|
||||||
|
fields: { audio: 0 },
|
||||||
|
limit: 1,
|
||||||
|
sort: { startTime: 1 },
|
||||||
|
}).subscribe(() => {
|
||||||
|
const call = RadioCalls.findOne({}, {
|
||||||
|
sort: { startTime: 1 },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (call) {
|
||||||
|
this.dateMin = call.startTime;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private _subscribeFormChanges(): void {
|
private _subscribeFormChanges(): void {
|
||||||
const dateForm = this.form.get('date');
|
const dateForm = this.form.get('date');
|
||||||
const sortForm = this.form.get('sort');
|
const sortForm = this.form.get('sort');
|
||||||
|
|
@ -268,6 +309,7 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
private _unsubscribe(subscriptions: Subscription[] = [
|
private _unsubscribe(subscriptions: Subscription[] = [
|
||||||
...this._subscriptions.calls,
|
...this._subscriptions.calls,
|
||||||
|
...this._subscriptions.dateLimits,
|
||||||
...this._subscriptions.form,
|
...this._subscriptions.form,
|
||||||
...this._subscriptions.radio,
|
...this._subscriptions.radio,
|
||||||
]): void {
|
]): void {
|
||||||
|
|
@ -279,4 +321,8 @@ export class AppRadioSearchComponent implements OnDestroy, OnInit {
|
||||||
private _unsubscribeCalls(): void {
|
private _unsubscribeCalls(): void {
|
||||||
this._unsubscribe(this._subscriptions.calls);
|
this._unsubscribe(this._subscriptions.calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _unsubscribeDateLimits(): void {
|
||||||
|
this._unsubscribe(this._subscriptions.dateLimits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue