Upgrade routing to Angular2.
This commit is contained in:
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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[]) => {
|
||||
|
Reference in New Issue
Block a user