Upgrade routing to Angular2.

This commit is contained in:
Alexis Lahouze
2017-08-01 23:09:21 +02:00
parent 2ae8a9cfad
commit 5726d8bf2e
13 changed files with 81 additions and 59 deletions

View File

@ -4,6 +4,7 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@ -19,20 +20,16 @@ import { OperationListComponent } from './operationList.component';
import { OperationDeleteModalComponent } from './operationDeleteModal.component';
import { OperationFormComponent } from './operationForm.component';
import { OperationEditModalComponent } from './operationEditModal.component'
export function $modalServiceFactory(i: any) {
return i.get('$modal');
}
export function accountIdServiceFactory(i: any) {
return i.get('accountIdService');
}
import { OperationListState } from './operation.states'
@NgModule({
imports: [
HttpClientModule,
CommonModule,
FormsModule,
RouterModule.forChild([
OperationListState
]),
NgLoggerModule,
ToastrModule,
NgbModule,
@ -41,11 +38,6 @@ export function accountIdServiceFactory(i: any) {
providers: [
CategoryService,
OperationService,
{
provide: 'accountIdService',
deps: ['$injector'],
useFactory: accountIdServiceFactory
}
],
declarations: [
BalanceChartComponent,

View File

@ -1,7 +1,8 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
import { OperationListComponent } from './operationList.component';
export const OperationListState = {
name: 'operations',
url: '/account/:accountId/operations',
component: 'operationListComponent'
path: 'account/:accountId/operations',
component: OperationListComponent
}

View File

@ -1,5 +1,7 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
import { Component, Inject, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { Logger } from '@nsalaun/ng-logger';
@ -71,16 +73,18 @@ export class OperationListComponent implements OnInit {
private operations: Operation[];
constructor(
@Inject("accountIdService") private accountIdService,
private toastrService: ToastrService,
private operationService: OperationService,
private accountService: AccountService,
private logger: Logger,
private ngbModal: NgbModal,
private route: ActivatedRoute
) {}
ngOnInit() {
this.accountService.get(this.accountIdService.get()).subscribe(account => {
this.accountService.get(
+this.route.snapshot.paramMap.get('accountId')
).subscribe(account => {
this.account = account
});
}
@ -90,7 +94,7 @@ export class OperationListComponent implements OnInit {
*/
add() {
var operation = new Operation();
operation.account_id = this.accountIdService.get();
operation.account_id = this.account.id;
// FIXME Alexis Lahouze 2017-06-15 i18n
const modal = this.ngbModal.open(OperationEditModalComponent);
@ -111,7 +115,7 @@ export class OperationListComponent implements OnInit {
this.maxDate = maxDate;
return this.operationService.query(
this.accountIdService.get(),
this.account.id,
minDate,
maxDate
).subscribe((operations: Operation[]) => {