mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New select options
This commit is contained in:
parent
c0d715c78a
commit
565cb6d79e
@ -27,9 +27,11 @@ use Carbon\Carbon;
|
|||||||
use Eloquent;
|
use Eloquent;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
@ -93,12 +95,51 @@ class ExpandedForm
|
|||||||
return $this->currencyField($name, 'amount-small', $value, $options);
|
return $this->currencyField($name, 'amount-small', $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param $selected
|
||||||
|
* @param null $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function assetAccountCheckList(string $name, $options = null): string
|
||||||
|
{
|
||||||
|
$options = $options ?? [];
|
||||||
|
$label = $this->label($name, $options);
|
||||||
|
$options = $this->expandOptionArray($name, $label, $options);
|
||||||
|
$classes = $this->getHolderClasses($name);
|
||||||
|
$selected = request()->old($name) ?? [];
|
||||||
|
|
||||||
|
// get all asset accounts:
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
$assetAccounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||||
|
$grouped = [];
|
||||||
|
// group accounts:
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($assetAccounts as $account) {
|
||||||
|
$role = $repository->getMetaValue($account, 'accountRole');
|
||||||
|
if (null === $role) {
|
||||||
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
$key = (string)trans('firefly.opt_group_' . $role);
|
||||||
|
$grouped[$key][$account->id] = $account->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($options['class']);
|
||||||
|
$html = view('form.assetAccountCheckList', compact('classes','selected', 'name', 'label', 'options', 'grouped'))->render();
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param null $value
|
* @param null $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public function assetAccountList(string $name, $value = null, array $options = []): string
|
public function assetAccountList(string $name, $value = null, array $options = []): string
|
||||||
{
|
{
|
||||||
@ -193,19 +234,10 @@ class ExpandedForm
|
|||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public function currencyList(string $name, $value = null, array $options = []): string
|
public function currencyList(string $name, $value = null, array $options = []): string
|
||||||
{
|
{
|
||||||
// properties for cache
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty('exp-form-currency-list');
|
|
||||||
$cache->addProperty($name);
|
|
||||||
$cache->addProperty($value);
|
|
||||||
$cache->addProperty($options);
|
|
||||||
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get();
|
|
||||||
}
|
|
||||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
@ -217,7 +249,6 @@ class ExpandedForm
|
|||||||
$array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
|
$array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
|
||||||
}
|
}
|
||||||
$res = $this->select($name, $array, $value, $options);
|
$res = $this->select($name, $array, $value, $options);
|
||||||
$cache->store($res);
|
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
@ -351,28 +382,6 @@ class ExpandedForm
|
|||||||
return $selectList;
|
return $selectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @param array $list
|
|
||||||
* @param null $selected
|
|
||||||
* @param array $options
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @throws \Throwable
|
|
||||||
*/
|
|
||||||
public function multiCheckbox(string $name, array $list = [], $selected = null, array $options = []): string
|
|
||||||
{
|
|
||||||
$label = $this->label($name, $options);
|
|
||||||
$options = $this->expandOptionArray($name, $label, $options);
|
|
||||||
$classes = $this->getHolderClasses($name);
|
|
||||||
$selected = $this->fillFieldValue($name, $selected);
|
|
||||||
|
|
||||||
unset($options['class']);
|
|
||||||
$html = view('form.multiCheckbox', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $list
|
* @param array $list
|
||||||
@ -516,6 +525,31 @@ class ExpandedForm
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param null $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function ruleGroupList(string $name, $value = null, array $options = []): string
|
||||||
|
{
|
||||||
|
/** @var RuleGroupRepositoryInterface $groupRepos */
|
||||||
|
$groupRepos = app(RuleGroupRepositoryInterface::class);
|
||||||
|
|
||||||
|
// get all currencies:
|
||||||
|
$list = $groupRepos->get();
|
||||||
|
$array = [];
|
||||||
|
/** @var RuleGroup $group */
|
||||||
|
foreach ($list as $group) {
|
||||||
|
$array[$group->id] = $group->title;
|
||||||
|
}
|
||||||
|
$res = $this->select($name, $array, $value, $options);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $list
|
* @param array $list
|
||||||
|
@ -188,7 +188,7 @@ return [
|
|||||||
'is_safe' => [
|
'is_safe' => [
|
||||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
||||||
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount',
|
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount',
|
||||||
'number', 'assetAccountList','amountNoCurrency','currencyList'
|
'number', 'assetAccountList','amountNoCurrency','currencyList','ruleGroupList','assetAccountCheckList'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Form' => [
|
'Form' => [
|
||||||
|
@ -2,19 +2,21 @@
|
|||||||
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
||||||
|
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{% for value,description in list %}
|
{% for groupName, accounts in grouped %}
|
||||||
{% set options = options|merge({'id': 'ffInput_'~name~'_'~value}) %}
|
<strong>{{ groupName }}</strong><br />
|
||||||
<div class="checkbox">
|
{% for id, account in accounts %}
|
||||||
|
<div class="checkbox" style="margin-left:2em;">
|
||||||
<label>
|
<label>
|
||||||
{% if value in selected %}
|
{% if account in selected or (selected|length == 0 and options.select_all == true) %}
|
||||||
{{ Form.checkbox(name~'[]', value, true, options) }}
|
{{ Form.checkbox(name~'[]', id, true, options) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ Form.checkbox(name~'[]', value, false, options) }}
|
{{ Form.checkbox(name~'[]', id, false, options) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ description }}
|
{{ account }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
{% include 'form/help' %}
|
{% include 'form/help' %}
|
||||||
{% include 'form/feedback' %}
|
{% include 'form/feedback' %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user