Simplify autocomplete controller

This commit is contained in:
James Cole
2019-01-27 07:48:29 +01:00
parent 4866b9dabb
commit 156d2fbaa4

View File

@@ -93,60 +93,44 @@ class AutoCompleteController extends Controller
$unfiltered = null; $unfiltered = null;
$filtered = null; $filtered = null;
// search for all accounts. switch ($subject) {
if ('all-accounts' === $subject) { default:
break;
case 'all-accounts':
$unfiltered = $this->getAccounts( $unfiltered = $this->getAccounts(
[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, [AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN,
AccountType::DEBT, AccountType::MORTGAGE] AccountType::DEBT, AccountType::MORTGAGE]
); );
} break;
case 'expense-accounts':
// search for expense accounts.
if ('expense-accounts' === $subject) {
$unfiltered = $this->getAccounts([AccountType::EXPENSE, AccountType::BENEFICIARY]); $unfiltered = $this->getAccounts([AccountType::EXPENSE, AccountType::BENEFICIARY]);
} break;
case 'revenue-accounts':
// search for revenue accounts.
if ('revenue-accounts' === $subject) {
$unfiltered = $this->getAccounts([AccountType::REVENUE]); $unfiltered = $this->getAccounts([AccountType::REVENUE]);
} break;
case 'asset-accounts':
// search for asset accounts.
if ('asset-accounts' === $subject) {
$unfiltered = $this->getAccounts([AccountType::ASSET, AccountType::DEFAULT]); $unfiltered = $this->getAccounts([AccountType::ASSET, AccountType::DEFAULT]);
} break;
case 'categories':
// search for categories.
if ('categories' === $subject) {
$unfiltered = $this->getCategories(); $unfiltered = $this->getCategories();
} break;
case 'budgets':
// search for budgets.
if ('budgets' === $subject) {
$unfiltered = $this->getBudgets(); $unfiltered = $this->getBudgets();
} break;
case 'tags':
// search for tags
if ('tags' === $subject) {
$unfiltered = $this->getTags(); $unfiltered = $this->getTags();
} break;
case 'bills':
// search for bills
if ('bills' === $subject) {
$unfiltered = $this->getBills(); $unfiltered = $this->getBills();
} break;
// search for currency names. case 'currency-names':
if ('currency-names' === $subject) {
$unfiltered = $this->getCurrencyNames(); $unfiltered = $this->getCurrencyNames();
} break;
if ('transaction_types' === $subject) { case 'transaction-types':
case 'transaction_types':
$unfiltered = $this->getTransactionTypes(); $unfiltered = $this->getTransactionTypes();
break;
} }
if ('transaction-types' === $subject) {
$unfiltered = $this->getTransactionTypes();
}
// filter results
$filtered = $this->filterResult($unfiltered, $search); $filtered = $this->filterResult($unfiltered, $search);
if (null === $filtered) { if (null === $filtered) {