Use queryParameter for dates.

This commit is contained in:
Alexis Lahouze 2018-06-10 18:06:04 +02:00
parent 89c1c4f64c
commit 8d6465de71

View File

@ -20,8 +20,7 @@ import { OperationEditModalComponent } from './operationEditModal.component';
<div> <div>
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<balance-chart (onUpdate)="onUpdate($event)" <balance-chart [account]="account"></balance-chart>
[account]="account"></balance-chart>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@ -65,8 +64,6 @@ import { OperationEditModalComponent } from './operationEditModal.component';
}) })
export class OperationListComponent implements OnInit { export class OperationListComponent implements OnInit {
private account: Account; private account: Account;
private minDate: Date;
private maxDate: Date;
public operations: Operation[]; public operations: Operation[];
constructor( constructor(
@ -84,6 +81,12 @@ export class OperationListComponent implements OnInit {
).subscribe(account => { ).subscribe(account => {
this.account = account this.account = account
}); });
this.route.queryParamMap.subscribe(() => {
this.loadData();
});
this.loadData();
} }
/* /*
@ -91,7 +94,8 @@ export class OperationListComponent implements OnInit {
*/ */
add() { add() {
var operation = new Operation(); var operation = new Operation();
operation.account_id = this.account.id; let accountId = this.route.snapshot.paramMap.get('accountId');
operation.account_id = +accountId;
// FIXME Alexis Lahouze 2017-06-15 i18n // FIXME Alexis Lahouze 2017-06-15 i18n
const modal = this.ngbModal.open(OperationEditModalComponent, { const modal = this.ngbModal.open(OperationEditModalComponent, {
@ -109,14 +113,15 @@ export class OperationListComponent implements OnInit {
/* /*
* Load operations. * Load operations.
*/ */
load(minDate, maxDate) { loadData() {
this.minDate = minDate; let accountId = this.route.snapshot.paramMap.get('accountId');
this.maxDate = maxDate; let fromDay = this.route.snapshot.queryParamMap.get('from');
let toDay = this.route.snapshot.queryParamMap.get('to');
return this.operationService.query( return this.operationService.query(
this.account.id, +accountId,
minDate, fromDay,
maxDate toDay
).subscribe((operations: Operation[]) => { ).subscribe((operations: Operation[]) => {
this.operations = operations.reverse(); this.operations = operations.reverse();
}); });
@ -132,7 +137,7 @@ export class OperationListComponent implements OnInit {
(operation) => { (operation) => {
this.toastrService.success('Operation #' + operation.id + ' saved.'); this.toastrService.success('Operation #' + operation.id + ' saved.');
this.load(this.minDate, this.maxDate); this.loadData();
}, (result) => { }, (result) => {
this.toastrService.error( this.toastrService.error(
'Error while saving operation: ' + result.message 'Error while saving operation: ' + result.message
@ -140,8 +145,4 @@ export class OperationListComponent implements OnInit {
} }
); );
}; };
onUpdate(dateRange) {
this.load(dateRange.minDate, dateRange.maxDate);
};
}; };