diff --git a/src/accounts/accountList.component.ts b/src/accounts/accountList.component.ts index 5522195..a2cc67c 100644 --- a/src/accounts/accountList.component.ts +++ b/src/accounts/accountList.component.ts @@ -1,3 +1,4 @@ +// vim: set tw=80 ts=2 sw=2 sts=2 : import { CurrencyPipe } from '@angular/common'; import { Component, Inject } from '@angular/core'; import { Observable } from 'rxjs/Rx'; @@ -14,8 +15,8 @@ import { AccountDeleteModalComponent } from './accountDeleteModal.component'; import { AccountEditModalComponent } from './accountEditModal.component'; @Component({ - selector: 'account-list', - template: ` + selector: 'account-list', + template: `
@@ -87,164 +88,164 @@ import { AccountEditModalComponent } from './accountEditModal.component'; `, }) export class AccountListComponent { - static $inject = [ - 'AccountService', - 'AccountBalancesService', - 'ToastrService', - 'Logger', - 'NgbModal' - ]; + static $inject = [ + 'AccountService', + 'AccountBalancesService', + 'ToastrService', + 'Logger', + 'NgbModal' + ]; - accounts: Account[]; + accounts: Account[]; - constructor( - private AccountService: AccountService, - private AccountBalancesService: AccountBalancesService, - private ToastrService: ToastrService, - private Logger: Logger, - private NgbModal: NgbModal - ) { - // Load accounts. - this.load(); + constructor( + private AccountService: AccountService, + private AccountBalancesService: AccountBalancesService, + private ToastrService: ToastrService, + private Logger: Logger, + private NgbModal: NgbModal + ) { + // Load accounts. + this.load(); + } + + /* + * Return the class for an account current value compared to authorized + * overdraft. + */ + rowClass(account) { + // eslint-disable-next-line camelcase + if (!account || !account.authorized_overdraft || !account.current) { + return; } - /* - * Return the class for an account current value compared to authorized - * overdraft. - */ - rowClass(account) { - // eslint-disable-next-line camelcase - if (!account || !account.authorized_overdraft || !account.current) { - return; - } + // eslint-disable-next-line camelcase + if (account.current < account.authorized_overdraft) { + return 'danger'; + } else if (account.current < 0) { + return 'warning'; + } + }; - // eslint-disable-next-line camelcase - if (account.current < account.authorized_overdraft) { - return 'danger'; - } else if (account.current < 0) { - return 'warning'; - } - }; + /* + * Return the class for a value compared to account authorized overdraft. + */ + valueClass(account, value) { + if (!account || !value) { + return; + } - /* - * Return the class for a value compared to account authorized overdraft. - */ - valueClass(account, value) { - if (!account || !value) { - return; - } + // eslint-disable-next-line camelcase + if (value < account.authorized_overdraft) { + return 'text-danger'; + } else if (value < 0) { + return 'text-warning'; + } + }; - // eslint-disable-next-line camelcase - if (value < account.authorized_overdraft) { - return 'text-danger'; - } else if (value < 0) { - return 'text-warning'; - } - }; + load() { + this.AccountService.query().subscribe(accounts => { + this.accounts = accounts.map((account: Account) => { + this.Logger.log(account); + this.AccountBalancesService + .get(account.id) + .subscribe((accountBalances: AccountBalances) => { + account.balances = accountBalances; + }) + return account; + }) + }); + }; - load() { - this.AccountService.query().subscribe(accounts => { - this.accounts = accounts.map((account: Account) => { - this.Logger.log(account); - this.AccountBalancesService - .get(account.id) - .subscribe((accountBalances: AccountBalances) => { - account.balances = accountBalances; - }) - return account; - }) - }); - }; + /* + * Add an empty account. + */ + add() { + const modal = this.NgbModal.open(AccountEditModalComponent, { + windowClass: 'in' + }); - /* - * Add an empty account. - */ - add() { - const modal = this.NgbModal.open(AccountEditModalComponent, { - windowClass: 'in' - }); + modal.componentInstance.account = new Account(); - modal.componentInstance.account = new Account(); + modal.result.then((account: Account) => { + this.Logger.log("Modal closed => save account", account); + this.save(account); + }, (reason) => function(reason) { + }); + }; - modal.result.then((account: Account) => { - this.Logger.log("Modal closed => save account", account); - this.save(account); - }, (reason) => function(reason) { - }); - }; + /* + * Save account. + */ + save(account) { + var observable: Observable; - /* - * Save account. - */ - save(account) { - var observable: Observable; + if(account.id) { + observable = this.AccountService.update(account); + } else { + observable = this.AccountService.create(account); + } - if(account.id) { - observable = this.AccountService.update(account); - } else { - observable = this.AccountService.create(account); - } + observable.subscribe(account => { + this.ToastrService.success('Account #' + account.id + ' saved.'); - observable.subscribe(account => { - this.ToastrService.success('Account #' + account.id + ' saved.'); + this.load(); + }, result => { + this.Logger.error('Error while saving account', account, result); - this.load(); - }, result => { - this.Logger.error('Error while saving account', account, result); + this.ToastrService.error( + 'Error while saving account: ' + result.message + ); + }); + }; - this.ToastrService.error( - 'Error while saving account: ' + result.message - ); - }); - }; + confirmDelete(account) { + const modal = this.NgbModal.open(AccountDeleteModalComponent, { + windowClass: 'in' + }); - confirmDelete(account) { - const modal = this.NgbModal.open(AccountDeleteModalComponent, { - windowClass: 'in' - }); + modal.componentInstance.account = account; - modal.componentInstance.account = account; + modal.result.then((account: Account) => { + this.delete(account); + }, (reason) => function(reason) { + }); + }; - modal.result.then((account: Account) => { - this.delete(account); - }, (reason) => function(reason) { - }); - }; + /* + * Delete an account. + */ + delete(account) { + var id = account.id; - /* - * Delete an account. - */ - delete(account) { - var id = account.id; + this.AccountService.delete(account).subscribe(account => { + this.ToastrService.success('account #' + id + ' deleted.'); - this.AccountService.delete(account).subscribe(account => { - this.ToastrService.success('account #' + id + ' deleted.'); + this.load(); - this.load(); + return account; + }, function(result) { + this.ToastrService.error( + 'An error occurred while trying to delete account #' + + id + ':
' + result + ); + }); + }; - return account; - }, function(result) { - this.ToastrService.error( - 'An error occurred while trying to delete account #' + - id + ':
' + result - ); - }); - }; + /* + * Open the popup to modify the account, save it on confirm. + */ + modify(account) { + const modal = this.NgbModal.open(AccountEditModalComponent, { + windowClass: 'in' + }); - /* - * Open the popup to modify the account, save it on confirm. - */ - modify(account) { - const modal = this.NgbModal.open(AccountEditModalComponent, { - windowClass: 'in' - }); + modal.componentInstance.account = account; - modal.componentInstance.account = account; - - modal.result.then((account: Account) => { - this.Logger.log("Modal closed => save account", account); - this.save(account); - }, (reason) => function(reason) { - }); - }; + modal.result.then((account: Account) => { + this.Logger.log("Modal closed => save account", account); + this.save(account); + }, (reason) => function(reason) { + }); + }; };