From 738a311f49b5c84e3db4336fc98405462193ebea Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 21 Jan 2017 09:07:10 +0100 Subject: [PATCH] Various code cleanup. --- app/Http/Controllers/AccountController.php | 14 ++++- app/Http/Requests/Request.php | 63 +++++++++++++------ app/Support/Twig/General.php | 14 ----- config/firefly.php | 7 +-- resources/lang/en_US/firefly.php | 5 +- resources/views/accounts/create.twig | 2 +- resources/views/accounts/edit.twig | 2 +- resources/views/list/accounts.twig | 2 +- resources/views/search/partials/accounts.twig | 2 +- 9 files changed, 65 insertions(+), 46 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 42eec4e59b..b3b007cb9e 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -75,6 +75,11 @@ class AccountController extends Controller $defaultCurrency = Amount::getDefaultCurrency(); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); $subTitle = trans('firefly.make_new_' . $what . '_account'); + $roles = []; + foreach (config('firefly.accountRoles') as $role) { + $roles[$role] = strval(trans('firefly.account_role_' . $role)); + } + // pre fill some data Session::flash('preFilled', ['currency_id' => $defaultCurrency->id,]); @@ -87,7 +92,7 @@ class AccountController extends Controller Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventAction', 'create-' . $what); - return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies')); + return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies', 'roles')); } @@ -155,6 +160,11 @@ class AccountController extends Controller /** @var CurrencyRepositoryInterface $repository */ $repository = app(CurrencyRepositoryInterface::class); $currencies = ExpandedForm::makeSelectList($repository->get()); + $roles = []; + foreach (config('firefly.accountRoles') as $role) { + $roles[$role] = strval(trans('firefly.account_role_' . $role)); + } + // put previous url in session if not redirect from store (not "return_to_edit"). if (session('accounts.edit.fromUpdate') !== true) { @@ -185,7 +195,7 @@ class AccountController extends Controller Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventAction', 'edit-' . $what); - return view('accounts.edit', compact('currencies', 'account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what')); + return view('accounts.edit', compact('currencies', 'account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what', 'roles')); } /** diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 78a741cb1e..e73b17ac60 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -88,27 +88,52 @@ class Request extends FormRequest protected function string(string $field): string { $string = $this->get($field) ?? ''; - $search = [ + "\u{0001}", // start of heading + "\u{0002}", // start of text + "\u{0003}", // end of text + "\u{0004}", // end of transmission + "\u{0005}", // enquiry + "\u{0006}", // ACK + "\u{0007}", // BEL + "\u{0008}", // backspace + "\u{000E}", // shift out + "\u{000F}", // shift in + "\u{0010}", // data link escape + "\u{0011}", // DC1 + "\u{0012}", // DC2 + "\u{0013}", // DC3 + "\u{0014}", // DC4 + "\u{0015}", // NAK + "\u{0016}", // SYN + "\u{0017}", // ETB + "\u{0018}", // CAN + "\u{0019}", // EM + "\u{001A}", // SUB + "\u{001B}", // escape + "\u{001C}", // file separator + "\u{001D}", // group separator + "\u{001E}", // record separator + "\u{001F}", // unit separator + "\u{007F}", // DEL "\u{00A0}", // non-breaking space - "\u{1680}", // OGHAM SPACE MARK - "\u{180E}", // MONGOLIAN VOWEL SEPARATOR - "\u{2000}", // EN QUAD - "\u{2001}", // EM QUAD - "\u{2002}", // EN SPACE - "\u{2003}", // EM SPACE - "\u{2004}", // THREE-PER-EM SPACE - "\u{2005}", // FOUR-PER-EM SPACE - "\u{2006}", // SIX-PER-EM SPACE - "\u{2007}", // FIGURE SPACE - "\u{2008}", // PUNCTUATION SPACE - "\u{2009}", // THIN SPACE - "\u{200A}", // HAIR SPACE - "\u{200B}", // ZERO WIDTH SPACE - "\u{202F}", // NARROW NO-BREAK SPACE - "\u{205F}", // MEDIUM MATHEMATICAL SPACE - "\u{3000}", // IDEOGRAPHIC SPACE - "\u{FEFF}", // ZERO WIDTH NO -BREAK SPACE + "\u{1680}", // ogham space mark + "\u{180E}", // mongolian vowel separator + "\u{2000}", // en quad + "\u{2001}", // em quad + "\u{2002}", // en space + "\u{2003}", // em space + "\u{2004}", // three-per-em space + "\u{2005}", // four-per-em space + "\u{2006}", // six-per-em space + "\u{2007}", // figure space + "\u{2008}", // punctuation space + "\u{2009}", // thin space + "\u{200A}", // hair space + "\u{200B}", // zero width space + "\u{202F}", // narrow no-break space + "\u{3000}", // ideographic space + "\u{FEFF}", // zero width no -break space ]; $replace = "\x20"; // plain old normal space $string = str_replace($search, $replace, $string); diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 04336c3163..cfd98fcafc 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -14,7 +14,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Twig; use Carbon\Carbon; -use Config; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; use Route; @@ -42,7 +41,6 @@ class General extends Twig_Extension $this->formatAmountPlain(), $this->formatJournal(), $this->balance(), - $this->getAccountRole(), $this->formatFilesize(), $this->mimeIcon(), ]; @@ -234,18 +232,6 @@ class General extends Twig_Extension ); } - /** - * @return Twig_SimpleFilter - */ - protected function getAccountRole(): Twig_SimpleFilter - { - return new Twig_SimpleFilter( - 'getAccountRole', function (string $name): string { - return Config::get('firefly.accountRoles.' . $name); - } - ); - } - /** * @return Twig_SimpleFunction */ diff --git a/config/firefly.php b/config/firefly.php index 67f9ccdd15..8c4f2a4085 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -41,12 +41,7 @@ return [ 'default_export_format' => 'csv', 'default_import_format' => 'csv', 'bill_periods' => ['weekly', 'monthly', 'quarterly', 'half-year', 'yearly'], - 'accountRoles' => [ - 'defaultAsset' => 'Default asset account', - 'sharedAsset' => 'Shared asset account', - 'savingAsset' => 'Savings account', - 'ccAsset' => 'Credit card', - ], + 'accountRoles' => ['defaultAsset', 'sharedAsset', 'savingAsset', 'ccAsset',], 'ccTypes' => [ 'monthlyFull' => 'Full payment every month', ], diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 06c60e8258..8e9ed4d568 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -745,7 +745,10 @@ return [ 'description' => 'Description', 'sum_of_period' => 'Sum of period', 'average_in_period' => 'Average in period', - + 'account_role_defaultAsset' => 'Default asset account', + 'account_role_sharedAsset' => 'Shared asset account', + 'account_role_savingAsset' => 'Savings account', + 'account_role_ccAsset' => 'Credit card', // charts: 'chart' => 'Chart', diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig index 0c6d28238c..07e55d4f55 100644 --- a/resources/views/accounts/create.twig +++ b/resources/views/accounts/create.twig @@ -41,7 +41,7 @@ {{ ExpandedForm.balance('openingBalance') }} {{ ExpandedForm.date('openingBalanceDate', phpdate('Y-m-d')) }} - {{ ExpandedForm.select('accountRole', Config.get('firefly.accountRoles'),null,{'helpText' : 'asset_account_role_help'|_}) }} + {{ ExpandedForm.select('accountRole', roles,null,{'helpText' : 'asset_account_role_help'|_}) }} {{ ExpandedForm.balance('virtualBalance') }} {% endif %} diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig index 53784429a1..29cd807ac2 100644 --- a/resources/views/accounts/edit.twig +++ b/resources/views/accounts/edit.twig @@ -38,7 +38,7 @@ {% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %} {{ ExpandedForm.balance('openingBalance',null, {'currency' : openingBalance ? openingBalance.transactionCurrency : null}) }} {{ ExpandedForm.date('openingBalanceDate') }} - {{ ExpandedForm.select('accountRole',Config.get('firefly.accountRoles')) }} + {{ ExpandedForm.select('accountRole', roles) }} {{ ExpandedForm.balance('virtualBalance',null) }} {% endif %} diff --git a/resources/views/list/accounts.twig b/resources/views/list/accounts.twig index dbf3d7436c..baa896e1b7 100644 --- a/resources/views/list/accounts.twig +++ b/resources/views/list/accounts.twig @@ -28,7 +28,7 @@ {% for entry in account.accountmeta %} {% if entry.name == 'accountRole' %} - {{ entry.data|getAccountRole }} + {{ ('account_role_'~entry.data)|_ }} {% endif %} {% endfor %} diff --git a/resources/views/search/partials/accounts.twig b/resources/views/search/partials/accounts.twig index 45c4a2466a..c86b89c345 100644 --- a/resources/views/search/partials/accounts.twig +++ b/resources/views/search/partials/accounts.twig @@ -24,7 +24,7 @@ {% for entry in account.accountmeta %} {% if entry.name == 'accountRole' %} - {{ trans('firefly.'~entry.data|getAccountRole) }} + {{ ('account_role_'~entry.data)|_ }} {% endif %} {% endfor %}