mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 20:38:57 +00:00
Optimize queries for statistics.
This commit is contained in:
@@ -36,7 +36,7 @@ trait FormSupport
|
||||
{
|
||||
public function multiSelect(string $name, ?array $list = null, mixed $selected = null, ?array $options = null): string
|
||||
{
|
||||
$list ??= [];
|
||||
$list ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
@@ -54,15 +54,26 @@ trait FormSupport
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function label(string $name, ?array $options = null): string
|
||||
/**
|
||||
* @param mixed $selected
|
||||
*/
|
||||
public function select(string $name, ?array $list = null, $selected = null, ?array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
if (array_key_exists('label', $options)) {
|
||||
return $options['label'];
|
||||
}
|
||||
$name = str_replace('[]', '', $name);
|
||||
$list ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$selected = $this->fillFieldValue($name, $selected);
|
||||
unset($options['autocomplete'], $options['placeholder']);
|
||||
|
||||
return (string)trans('form.'.$name);
|
||||
try {
|
||||
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
||||
} catch (Throwable $e) {
|
||||
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
||||
$html = 'Could not render select.';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,29 +81,16 @@ trait FormSupport
|
||||
*/
|
||||
protected function expandOptionArray(string $name, $label, ?array $options = null): array
|
||||
{
|
||||
$options ??= [];
|
||||
$options ??= [];
|
||||
$name = str_replace('[]', '', $name);
|
||||
$options['class'] = 'form-control';
|
||||
$options['id'] = 'ffInput_'.$name;
|
||||
$options['id'] = 'ffInput_' . $name;
|
||||
$options['autocomplete'] = 'off';
|
||||
$options['placeholder'] = ucfirst((string)$label);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
protected function getHolderClasses(string $name): string
|
||||
{
|
||||
// Get errors from session:
|
||||
/** @var null|MessageBag $errors */
|
||||
$errors = session('errors');
|
||||
|
||||
if (null !== $errors && $errors->has($name)) {
|
||||
return 'form-group has-error has-feedback';
|
||||
}
|
||||
|
||||
return 'form-group';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|mixed $value
|
||||
*
|
||||
@@ -116,28 +114,6 @@ trait FormSupport
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $selected
|
||||
*/
|
||||
public function select(string $name, ?array $list = null, $selected = null, ?array $options = null): string
|
||||
{
|
||||
$list ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$selected = $this->fillFieldValue($name, $selected);
|
||||
unset($options['autocomplete'], $options['placeholder']);
|
||||
|
||||
try {
|
||||
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
||||
} catch (Throwable $e) {
|
||||
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
|
||||
$html = 'Could not render select.';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function getAccountRepository(): AccountRepositoryInterface
|
||||
{
|
||||
return app(AccountRepositoryInterface::class);
|
||||
@@ -147,4 +123,28 @@ trait FormSupport
|
||||
{
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
protected function getHolderClasses(string $name): string
|
||||
{
|
||||
// Get errors from session:
|
||||
/** @var null|MessageBag $errors */
|
||||
$errors = session('errors');
|
||||
|
||||
if (null !== $errors && $errors->has($name)) {
|
||||
return 'form-group has-error has-feedback';
|
||||
}
|
||||
|
||||
return 'form-group';
|
||||
}
|
||||
|
||||
protected function label(string $name, ?array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
if (array_key_exists('label', $options)) {
|
||||
return $options['label'];
|
||||
}
|
||||
$name = str_replace('[]', '', $name);
|
||||
|
||||
return (string)trans('form.' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user