2017-07-21 00:45:04 +02:00
|
|
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
2017-07-21 21:50:19 +02:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2017-07-14 10:24:46 +02:00
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
|
2017-07-16 22:25:50 +02:00
|
|
|
import { Logger } from '@nsalaun/ng-logger';
|
2017-07-20 10:32:05 +02:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
2017-07-21 00:29:03 +02:00
|
|
|
import { ToastrService } from 'ngx-toastr';
|
2017-07-08 09:19:02 +02:00
|
|
|
|
2017-07-14 10:24:46 +02:00
|
|
|
import { Account } from './account';
|
2017-07-16 17:03:37 +02:00
|
|
|
import { AccountBalances } from './accountBalances';
|
|
|
|
import { AccountService } from './account.service';
|
2017-07-20 10:32:05 +02:00
|
|
|
import { AccountEditModalComponent } from './accountEditModal.component';
|
2017-07-21 00:39:15 +02:00
|
|
|
|
|
|
|
@Component({
|
2017-07-21 00:45:04 +02:00
|
|
|
selector: 'account-list',
|
|
|
|
template: `
|
2017-07-21 00:39:15 +02:00
|
|
|
<div class="row">
|
|
|
|
<table class="table table-striped table-condensed table-hover">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Nom du compte</th>
|
|
|
|
<th class="col-md-1">Solde courant</th>
|
|
|
|
<th class="col-md-1">Solde pointé</th>
|
|
|
|
<th class="col-md-1">Découvert autorisé</th>
|
|
|
|
<th class="col-md-1">Actions</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td colspan="5">
|
|
|
|
<button class="btn btn-success" (click)="add()">
|
|
|
|
Ajouter
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
2017-07-21 21:50:19 +02:00
|
|
|
<tr *ngFor="let account of accounts"
|
|
|
|
[account-row]="account" (needsReload)="load()">
|
2017-07-21 00:39:15 +02:00
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
})
|
2017-07-21 21:50:19 +02:00
|
|
|
export class AccountListComponent implements OnInit {
|
2017-07-21 00:45:04 +02:00
|
|
|
accounts: Account[];
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private AccountService: AccountService,
|
|
|
|
private ToastrService: ToastrService,
|
|
|
|
private Logger: Logger,
|
|
|
|
private NgbModal: NgbModal
|
|
|
|
) {
|
2017-07-21 21:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-07-21 00:45:04 +02:00
|
|
|
// Load accounts.
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
load() {
|
|
|
|
this.AccountService.query().subscribe(accounts => {
|
2017-07-21 21:50:19 +02:00
|
|
|
this.accounts = accounts;
|
2017-07-21 00:45:04 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an empty account.
|
|
|
|
*/
|
|
|
|
add() {
|
|
|
|
const modal = this.NgbModal.open(AccountEditModalComponent, {
|
|
|
|
windowClass: 'in'
|
|
|
|
});
|
|
|
|
|
|
|
|
modal.componentInstance.account = new Account();
|
|
|
|
|
|
|
|
modal.result.then((account: Account) => {
|
|
|
|
this.Logger.log("Modal closed => save account", account);
|
|
|
|
this.save(account);
|
|
|
|
}, (reason) => function(reason) {
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save account.
|
|
|
|
*/
|
|
|
|
save(account) {
|
2017-07-21 21:50:19 +02:00
|
|
|
this.AccountService.create(account).subscribe(account => {
|
2017-07-21 00:45:04 +02:00
|
|
|
this.ToastrService.success('Account #' + account.id + ' saved.');
|
|
|
|
|
|
|
|
this.load();
|
|
|
|
}, result => {
|
|
|
|
this.Logger.error('Error while saving account', account, result);
|
|
|
|
|
|
|
|
this.ToastrService.error(
|
|
|
|
'Error while saving account: ' + result.message
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2017-07-08 09:19:02 +02:00
|
|
|
};
|