Improve Operation loading in edit component.
This commit is contained in:
parent
1859efb98c
commit
4071893ed5
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
import { Component, ViewChild } from '@angular/core';
|
import { Component, ViewChild } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router, Params } from '@angular/router';
|
||||||
|
|
||||||
import { Logger } from '@nsalaun/ng-logger';
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
import { ToastrService } from 'ngx-toastr';
|
import { ToastrService } from 'ngx-toastr';
|
||||||
@ -15,7 +15,7 @@ import { OperationService } from './operation.service';
|
|||||||
templateUrl: './operationEdit.component.html'
|
templateUrl: './operationEdit.component.html'
|
||||||
})
|
})
|
||||||
export class OperationEditComponent {
|
export class OperationEditComponent {
|
||||||
public operation = new Operation();
|
public operation: Operation = new Operation();
|
||||||
|
|
||||||
//dateMask = [/\d{4}/, '-', /0[1-9]|1[0-2]/, '-', /[0-2]\d|3[0-1]/];
|
//dateMask = [/\d{4}/, '-', /0[1-9]|1[0-2]/, '-', /[0-2]\d|3[0-1]/];
|
||||||
dateMask = ['2', '0', /\d/, /\d/, '-', /[0-1]/, /\d/, '-', /[0-3]/, /\d/];
|
dateMask = ['2', '0', /\d/, /\d/, '-', /[0-1]/, /\d/, '-', /[0-3]/, /\d/];
|
||||||
@ -23,16 +23,19 @@ export class OperationEditComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
private location: Location,
|
private location: Location,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private activatedRoute: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
private operationService: OperationService
|
private operationService: OperationService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
let operationId = this.activatedRoute.snapshot.paramMap.get('operationId');
|
this.route.paramMap.subscribe((params: Params) => {
|
||||||
|
let operationId = params.get('operationId');
|
||||||
|
|
||||||
if (operationId) {
|
if (operationId) {
|
||||||
|
this.logger.info('Loading operation with id', operationId);
|
||||||
|
|
||||||
// Load Operation
|
// Load Operation
|
||||||
this.operationService.get(
|
this.operationService.get(
|
||||||
+operationId
|
+operationId
|
||||||
@ -42,10 +45,16 @@ export class OperationEditComponent {
|
|||||||
this.logger.info(operation);
|
this.logger.info(operation);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let accountId = this.activatedRoute.snapshot.paramMap.get('accountId');
|
this.logger.info('Initialize new operation');
|
||||||
|
|
||||||
|
let accountId = params.get('accountId');
|
||||||
|
|
||||||
|
this.operation = new Operation();
|
||||||
this.operation.account_id = +accountId;
|
this.operation.account_id = +accountId;
|
||||||
|
|
||||||
|
this.logger.info(this.operation);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submit(): void {
|
submit(): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user