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,29 +23,38 @@ 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) {
|
||||||
// Load Operation
|
this.logger.info('Loading operation with id', operationId);
|
||||||
this.operationService.get(
|
|
||||||
+operationId
|
|
||||||
).subscribe((operation: Operation) => {
|
|
||||||
this.operation = operation;
|
|
||||||
|
|
||||||
this.logger.info(operation);
|
// Load Operation
|
||||||
});
|
this.operationService.get(
|
||||||
} else {
|
+operationId
|
||||||
let accountId = this.activatedRoute.snapshot.paramMap.get('accountId');
|
).subscribe((operation: Operation) => {
|
||||||
|
this.operation = operation;
|
||||||
|
|
||||||
this.operation.account_id = +accountId;
|
this.logger.info(operation);
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
this.logger.info('Initialize new operation');
|
||||||
|
|
||||||
|
let accountId = params.get('accountId');
|
||||||
|
|
||||||
|
this.operation = new Operation();
|
||||||
|
this.operation.account_id = +accountId;
|
||||||
|
|
||||||
|
this.logger.info(this.operation);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submit(): void {
|
submit(): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user