Indent.
This commit is contained in:
parent
08a35f0d2c
commit
73485ac1af
@ -1,3 +1,4 @@
|
|||||||
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
||||||
import { Component, Inject, OnInit } from '@angular/core';
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
@ -12,14 +13,15 @@ import { OperationService } from './operation.service';
|
|||||||
import { OperationEditModalComponent } from './operationEditModal.component';
|
import { OperationEditModalComponent } from './operationEditModal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'operation-list',
|
selector: 'operation-list',
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
<balance-chart (onUpdate)="onUpdate($event)"
|
<balance-chart (onUpdate)="onUpdate($event)"
|
||||||
[account]="account"></balance-chart>
|
[account]="account"></balance-chart>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<category-chart
|
<category-chart
|
||||||
[minDate]="minDate"
|
[minDate]="minDate"
|
||||||
@ -63,94 +65,94 @@ import { OperationEditModalComponent } from './operationEditModal.component';
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class OperationListComponent implements OnInit {
|
export class OperationListComponent implements OnInit {
|
||||||
private account: Account;
|
private account: Account;
|
||||||
private minDate: Date;
|
private minDate: Date;
|
||||||
private maxDate: Date;
|
private maxDate: Date;
|
||||||
private operations: Operation[];
|
private operations: Operation[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject("accountIdService") private accountIdService,
|
@Inject("accountIdService") private accountIdService,
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
private operationService: OperationService,
|
private operationService: OperationService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
private ngbModal: NgbModal,
|
private ngbModal: NgbModal,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.accountService.get(this.accountIdService.get()).subscribe(account => {
|
this.accountService.get(this.accountIdService.get()).subscribe(account => {
|
||||||
this.account = account
|
this.account = account
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an empty operation.
|
||||||
|
*/
|
||||||
|
add() {
|
||||||
|
var operation = new Operation();
|
||||||
|
operation.account_id = this.accountIdService.get();
|
||||||
|
|
||||||
|
return this.modify(operation);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load operations.
|
||||||
|
*/
|
||||||
|
load(minDate, maxDate) {
|
||||||
|
this.minDate = minDate;
|
||||||
|
this.maxDate = maxDate;
|
||||||
|
|
||||||
|
return this.operationService.query(
|
||||||
|
this.accountIdService.get(),
|
||||||
|
minDate,
|
||||||
|
maxDate
|
||||||
|
).subscribe((operations: Operation[]) => {
|
||||||
|
this.operations = operations.reverse();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save an operation and return a promise.
|
||||||
|
*/
|
||||||
|
save(operation) {
|
||||||
|
operation.confirmed = true;
|
||||||
|
|
||||||
|
var observable: Observable<Operation>;
|
||||||
|
|
||||||
|
if(operation.id){
|
||||||
|
observable = this.operationService.update(operation);
|
||||||
|
} else {
|
||||||
|
observable = this.operationService.create(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return observable.subscribe((operation) => {
|
||||||
* Add an empty operation.
|
this.toastrService.success('Operation #' + operation.id + ' saved.');
|
||||||
*/
|
|
||||||
add() {
|
|
||||||
var operation = new Operation();
|
|
||||||
operation.account_id = this.accountIdService.get();
|
|
||||||
|
|
||||||
return this.modify(operation);
|
this.load(this.minDate, this.maxDate);
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
return operation;
|
||||||
* Load operations.
|
}, (result) => {
|
||||||
*/
|
this.toastrService.error(
|
||||||
load(minDate, maxDate) {
|
'Error while saving operation: ' + result.message
|
||||||
this.minDate = minDate;
|
);
|
||||||
this.maxDate = maxDate;
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return this.operationService.query(
|
modify(operation) {
|
||||||
this.accountIdService.get(),
|
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||||
minDate,
|
const modal = this.ngbModal.open(OperationEditModalComponent, {
|
||||||
maxDate
|
windowClass: 'in'
|
||||||
).subscribe((operations: Operation[]) => {
|
});
|
||||||
this.operations = operations.reverse();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
modal.componentInstance.operation = operation;
|
||||||
* Save an operation and return a promise.
|
|
||||||
*/
|
|
||||||
save(operation) {
|
|
||||||
operation.confirmed = true;
|
|
||||||
|
|
||||||
var observable: Observable<Operation>;
|
modal.result.then((operation: Operation) => {
|
||||||
|
this.save(operation);
|
||||||
|
}, (reason) => {
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if(operation.id){
|
onUpdate(dateRange) {
|
||||||
observable = this.operationService.update(operation);
|
this.load(dateRange.minDate, dateRange.maxDate);
|
||||||
} else {
|
};
|
||||||
observable = this.operationService.create(operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return observable.subscribe((operation) => {
|
|
||||||
this.toastrService.success('Operation #' + operation.id + ' saved.');
|
|
||||||
|
|
||||||
this.load(this.minDate, this.maxDate);
|
|
||||||
|
|
||||||
return operation;
|
|
||||||
}, (result) => {
|
|
||||||
this.toastrService.error(
|
|
||||||
'Error while saving operation: ' + result.message
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
modify(operation) {
|
|
||||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
|
||||||
const modal = this.ngbModal.open(OperationEditModalComponent, {
|
|
||||||
windowClass: 'in'
|
|
||||||
});
|
|
||||||
|
|
||||||
modal.componentInstance.operation = operation;
|
|
||||||
|
|
||||||
modal.result.then((operation: Operation) => {
|
|
||||||
this.save(operation);
|
|
||||||
}, (reason) => {
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
onUpdate(dateRange) {
|
|
||||||
this.load(dateRange.minDate, dateRange.maxDate);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user