Added convenience constructors for bank and bank accounts; settings now selected accounts so that we can use presenter.searchSelectedAccountTransactions()

This commit is contained in:
dankito 2020-07-27 12:12:41 +02:00
parent d7c904a677
commit 6b3e4b65c3
3 changed files with 16 additions and 4 deletions

View File

@ -28,9 +28,21 @@ struct AccountTransactionsDialog: View {
@Inject private var presenter: BankingPresenterSwift
init(bank: Customer) {
self.init(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions }, balance: bank.balance)
presenter.selectedAccount(customer: bank)
}
init(title: String, transactions: [AccountTransaction], balance: CommonBigDecimal) {
init(account: BankAccount) {
self.init(title: account.displayName, transactions: account.bookedTransactions, balance: account.balance)
presenter.selectedBankAccount(bankAccount: account)
}
fileprivate init(title: String, transactions: [AccountTransaction], balance: CommonBigDecimal) {
self.title = title
self.allTransactions = transactions
@ -66,7 +78,7 @@ struct AccountTransactionsDialog: View {
private func filterTransactions(_ query: String) {
self.filteredTransactions = presenter.searchAccountTransactions(query: query, transactions: allTransactions)
self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query)
self.balanceOfFilteredTransactions = query.isEmpty ? balanceOfAllTransactions : filteredTransactions.sumAmounts()
}

View File

@ -14,7 +14,7 @@ struct BankAccountListItem : View {
Spacer()
}.frame(height: 35)
NavigationLink(destination: AccountTransactionsDialog(title: account.displayName, transactions: account.bookedTransactions, balance: account.balance)) {
NavigationLink(destination: AccountTransactionsDialog(account: account)) {
EmptyView()
}
}

View File

@ -17,7 +17,7 @@ struct BankListItem : View {
Spacer()
}.frame(height: 35)
NavigationLink(destination: AccountTransactionsDialog(title: bank.displayName, transactions: bank.accounts.flatMap { $0.bookedTransactions }, balance: bank.balance)) {
NavigationLink(destination: AccountTransactionsDialog(bank: bank)) {
EmptyView()
}
}