diff --git a/src/operations/operationList.component.ts b/src/operations/operationList.component.ts index 1bab72e..243fc4f 100644 --- a/src/operations/operationList.component.ts +++ b/src/operations/operationList.component.ts @@ -1,6 +1,9 @@ // vim: set tw=80 ts=2 sw=2 sts=2 : + +import * as moment from 'moment'; + import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Rx'; @@ -72,21 +75,36 @@ export class OperationListComponent implements OnInit { private accountService: AccountService, private logger: Logger, private ngbModal: NgbModal, - private route: ActivatedRoute + private route: ActivatedRoute, + private router: Router ) {} ngOnInit() { - this.accountService.get( - +this.route.snapshot.paramMap.get('accountId') - ).subscribe(account => { - this.account = account; - }); - this.route.queryParamMap.subscribe(() => { this.loadData(); }); - this.loadData(); + let accountId = this.route.snapshot.paramMap.get('accountId'); + let fromDay = this.route.snapshot.queryParamMap.get('from'); + let toDay = this.route.snapshot.queryParamMap.get('to'); + + if(! fromDay && ! toDay) { + this.router.navigate(['account', accountId, 'operations'], { + queryParams: { + from: moment().startOf('month').format('YYYY-MM-DD'), + to: moment().endOf('month').format('YYYY-MM-DD') + } + }).then(() => { + this.loadData(); + }); + } + + this.accountService.get( + +accountId + ).subscribe(account => { + this.account = account; + }); + //this.loadData(); } /* @@ -137,7 +155,9 @@ export class OperationListComponent implements OnInit { (operation) => { this.toastrService.success('Operation #' + operation.id + ' saved.'); - this.loadData(); + //this.loadData(); + this.logger.info('Reload route', this.router.url); + this.router.navigateByUrl(this.router.url); }, (result) => { this.toastrService.error( 'Error while saving operation: ' + result.message diff --git a/src/operations/operationRow.component.ts b/src/operations/operationRow.component.ts index 0766b21..91bf263 100644 --- a/src/operations/operationRow.component.ts +++ b/src/operations/operationRow.component.ts @@ -1,7 +1,9 @@ // vim: set tw=80 ts=2 sw=2 sts=2 : import { CurrencyPipe } from '@angular/common'; import { Component, Inject, Input, Output, EventEmitter } from '@angular/core'; +import { Router } from '@angular/router'; +import { Logger } from '@nsalaun/ng-logger'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { ToastrService } from 'ngx-toastr'; @@ -80,7 +82,9 @@ export class OperationRowComponent { constructor( private operationService: OperationService, private toastrService: ToastrService, + private logger: Logger, private ngbModal: NgbModal, + private router: Router ) {} togglePointed(operation, rowform) { @@ -102,6 +106,9 @@ export class OperationRowComponent { this.toastrService.success('Operation #' + operation.id + ' saved.'); this.needsReload.emit(); + + this.logger.info('Reload route', this.router.url); + this.router.navigateByUrl(this.router.url); }, (result) => { this.toastrService.error( 'Error while saving operation: ' + result.message @@ -129,6 +136,9 @@ export class OperationRowComponent { this.toastrService.success('Operation #' + id + ' deleted.'); this.needsReload.emit(); + + this.logger.info('Reload route', this.router.url); + this.router.navigateByUrl(this.router.url); }, (result) => { this.toastrService.error( 'An error occurred while trying to delete operation #' +