From 58c6ec8a8c6846e2b9507ca65de03d33c7cb8f4e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 28 Dec 2019 09:59:41 +0100 Subject: [PATCH] Option to mass delete tags #2064 --- app/Http/Controllers/TagController.php | 25 ++++++++ config/twigbridge.php | 18 +++--- resources/lang/en_US/firefly.php | 81 +++++++++++++------------- resources/views/v1/tags/index.twig | 59 ++++++++++--------- routes/web.php | 1 + 5 files changed, 110 insertions(+), 74 deletions(-) diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index a86db88a30..ec7404f7cb 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -62,6 +62,31 @@ class TagController extends Controller ); } + /** + * + */ + public function massDestroy(Request $request) + { + $tags = $request->get('tags'); + if (null === $tags || !is_array($tags)) { + session()->flash('info', (string)trans('firefly.select_tags_to_delete')); + + return redirect(route('tags.index')); + } + $count = 0; + foreach ($tags as $tagId) { + $tagId = (int)$tagId; + $tag = $this->repository->findNull($tagId); + if (null !== $tag) { + $this->repository->destroy($tag); + $count++; + } + } + session()->flash('success', (string)trans('firefly.deleted_x_tags', ['count' => $count])); + + return redirect(route('tags.index')); + } + /** * Create a new tag. * diff --git a/config/twigbridge.php b/config/twigbridge.php index c629dd6cf8..56dee25508 100644 --- a/config/twigbridge.php +++ b/config/twigbridge.php @@ -38,7 +38,7 @@ return [ | File extension for Twig view files. | */ - 'extension' => 'twig', + 'extension' => 'twig', /* |-------------------------------------------------------------------------- @@ -53,11 +53,11 @@ return [ // When set to true, the generated templates have a __toString() method // that you can use to display the generated nodes. // default: false - 'debug' => env('APP_DEBUG', false), + 'debug' => env('APP_DEBUG', false), // The charset used by the templates. // default: utf-8 - 'charset' => 'utf-8', + 'charset' => 'utf-8', // The base template class to use for generated templates. // default: TwigBridge\Twig\Template @@ -66,26 +66,26 @@ return [ // An absolute path where to store the compiled templates, or false to disable caching. If null // then the cache file path is used. // default: cache file storage path - 'cache' => null, + 'cache' => null, // When developing with Twig, it's useful to recompile the template // whenever the source code changes. If you don't provide a value // for the auto_reload option, it will be determined automatically based on the debug value. - 'auto_reload' => true, + 'auto_reload' => true, // If set to false, Twig will silently ignore invalid variables // (variables and or attributes/methods that do not exist) and // replace them with a null value. When set to true, Twig throws an exception instead. // default: false - 'strict_variables' => false, + 'strict_variables' => false, // If set to true, auto-escaping will be enabled by default for all templates. // default: 'html' - 'autoescape' => 'html', + 'autoescape' => 'html', // A flag that indicates which optimizations to apply // (default to -1 -- all optimizations are enabled; set it to 0 to disable) - 'optimizations' => -1, + 'optimizations' => -1, ], /* @@ -97,7 +97,7 @@ return [ | NOTE: these will be overwritten if you pass data into the view with the same key. | */ - 'globals' => [], + 'globals' => [], ], 'extensions' => [ diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 19bc826309..698c6cebab 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -482,49 +482,52 @@ return [ 'rule_action_convert_transfer_choice' => 'Convert the transaction to a transfer', 'rule_action_convert_transfer' => 'Convert the transaction to a transfer with ":action_value"', - 'rules_have_read_warning' => 'Have you read the warning?', - 'apply_rule_warning' => 'Warning: running a rule(group) on a large selection of transactions could take ages, and it could time-out. If it does, the rule(group) will only be applied to an unknown subset of your transactions. This might leave your financial administration in tatters. Please be careful.', - 'rulegroup_for_bills_title' => 'Rule group for bills', - 'rulegroup_for_bills_description' => 'A special rule group for all the rules that involve bills.', - 'rule_for_bill_title' => 'Auto-generated rule for bill ":name"', - 'rule_for_bill_description' => 'This rule is auto-generated to try to match bill ":name".', - 'create_rule_for_bill' => 'Create a new rule for bill ":name"', - 'create_rule_for_bill_txt' => 'You have just created a new bill called ":name", congratulations! Firefly III can automagically match new withdrawals to this bill. For example, whenever you pay your rent, the bill "rent" will be linked to the expense. This way, Firefly III can accurately show you which bills are due and which ones aren\'t. In order to do so, a new rule must be created. Firefly III has filled in some sensible defaults for you. Please make sure these are correct. If these values are correct, Firefly III will automatically link the correct withdrawal to the correct bill. Please check out the triggers to see if they are correct, and add some if they\'re wrong.', - 'new_rule_for_bill_title' => 'Rule for bill ":name"', - 'new_rule_for_bill_description' => 'This rule marks transactions for bill ":name".', + 'rules_have_read_warning' => 'Have you read the warning?', + 'apply_rule_warning' => 'Warning: running a rule(group) on a large selection of transactions could take ages, and it could time-out. If it does, the rule(group) will only be applied to an unknown subset of your transactions. This might leave your financial administration in tatters. Please be careful.', + 'rulegroup_for_bills_title' => 'Rule group for bills', + 'rulegroup_for_bills_description' => 'A special rule group for all the rules that involve bills.', + 'rule_for_bill_title' => 'Auto-generated rule for bill ":name"', + 'rule_for_bill_description' => 'This rule is auto-generated to try to match bill ":name".', + 'create_rule_for_bill' => 'Create a new rule for bill ":name"', + 'create_rule_for_bill_txt' => 'You have just created a new bill called ":name", congratulations! Firefly III can automagically match new withdrawals to this bill. For example, whenever you pay your rent, the bill "rent" will be linked to the expense. This way, Firefly III can accurately show you which bills are due and which ones aren\'t. In order to do so, a new rule must be created. Firefly III has filled in some sensible defaults for you. Please make sure these are correct. If these values are correct, Firefly III will automatically link the correct withdrawal to the correct bill. Please check out the triggers to see if they are correct, and add some if they\'re wrong.', + 'new_rule_for_bill_title' => 'Rule for bill ":name"', + 'new_rule_for_bill_description' => 'This rule marks transactions for bill ":name".', // tags - 'store_new_tag' => 'Store new tag', - 'update_tag' => 'Update tag', - 'no_location_set' => 'No location set.', - 'meta_data' => 'Meta data', - 'location' => 'Location', - 'without_date' => 'Without date', - 'result' => 'Result', - 'sums_apply_to_range' => 'All sums apply to the selected range', - 'mapbox_api_key' => 'To use map, get an API key from Mapbox. Open your .env file and enter this code after MAPBOX_API_KEY=.', - 'press_tag_location' => 'Right click or long press to set the tag\'s location.', - 'clear_location' => 'Clear location', + 'store_new_tag' => 'Store new tag', + 'update_tag' => 'Update tag', + 'no_location_set' => 'No location set.', + 'meta_data' => 'Meta data', + 'location' => 'Location', + 'without_date' => 'Without date', + 'result' => 'Result', + 'sums_apply_to_range' => 'All sums apply to the selected range', + 'mapbox_api_key' => 'To use map, get an API key from Mapbox. Open your .env file and enter this code after MAPBOX_API_KEY=.', + 'press_tag_location' => 'Right click or long press to set the tag\'s location.', + 'clear_location' => 'Clear location', + 'delete_all_selected_tags' => 'Delete all selected tags', + 'select_tags_to_delete' => 'Don\'t forget to select some tags.', + 'deleted_x_tags' => 'Deleted :count tag(s).', // preferences - 'pref_home_screen_accounts' => 'Home screen accounts', - 'pref_home_screen_accounts_help' => 'Which accounts should be displayed on the home page?', - 'pref_view_range' => 'View range', - 'pref_view_range_help' => 'Some charts are automatically grouped in periods. Your budgets will also be grouped in periods. What period would you prefer?', - 'pref_1D' => 'One day', - 'pref_1W' => 'One week', - 'pref_1M' => 'One month', - 'pref_3M' => 'Three months (quarter)', - 'pref_6M' => 'Six months', - 'pref_1Y' => 'One year', - 'pref_languages' => 'Languages', - 'pref_languages_help' => 'Firefly III supports several languages. Which one do you prefer?', - 'pref_custom_fiscal_year' => 'Fiscal year settings', - 'pref_custom_fiscal_year_label' => 'Enabled', - 'pref_custom_fiscal_year_help' => 'In countries that use a financial year other than January 1 to December 31, you can switch this on and specify start / end days of the fiscal year', - 'pref_fiscal_year_start_label' => 'Fiscal year start date', - 'pref_two_factor_auth' => '2-step verification', - 'pref_two_factor_auth_help' => 'When you enable 2-step verification (also known as two-factor authentication), you add an extra layer of security to your account. You sign in with something you know (your password) and something you have (a verification code). Verification codes are generated by an application on your phone, such as Authy or Google Authenticator.', + 'pref_home_screen_accounts' => 'Home screen accounts', + 'pref_home_screen_accounts_help' => 'Which accounts should be displayed on the home page?', + 'pref_view_range' => 'View range', + 'pref_view_range_help' => 'Some charts are automatically grouped in periods. Your budgets will also be grouped in periods. What period would you prefer?', + 'pref_1D' => 'One day', + 'pref_1W' => 'One week', + 'pref_1M' => 'One month', + 'pref_3M' => 'Three months (quarter)', + 'pref_6M' => 'Six months', + 'pref_1Y' => 'One year', + 'pref_languages' => 'Languages', + 'pref_languages_help' => 'Firefly III supports several languages. Which one do you prefer?', + 'pref_custom_fiscal_year' => 'Fiscal year settings', + 'pref_custom_fiscal_year_label' => 'Enabled', + 'pref_custom_fiscal_year_help' => 'In countries that use a financial year other than January 1 to December 31, you can switch this on and specify start / end days of the fiscal year', + 'pref_fiscal_year_start_label' => 'Fiscal year start date', + 'pref_two_factor_auth' => '2-step verification', + 'pref_two_factor_auth_help' => 'When you enable 2-step verification (also known as two-factor authentication), you add an extra layer of security to your account. You sign in with something you know (your password) and something you have (a verification code). Verification codes are generated by an application on your phone, such as Authy or Google Authenticator.', 'pref_enable_two_factor_auth' => 'Enable 2-step verification', 'pref_two_factor_auth_disabled' => '2-step verification code removed and disabled', 'pref_two_factor_auth_remove_it' => 'Don\'t forget to remove the account from your authentication app!', diff --git a/resources/views/v1/tags/index.twig b/resources/views/v1/tags/index.twig index 9fbd31f6d6..a03ca214e0 100644 --- a/resources/views/v1/tags/index.twig +++ b/resources/views/v1/tags/index.twig @@ -15,37 +15,44 @@

- {% for period,entries in clouds %} - {% if entries|length > 0 %} -
-
-
-
-

- {% if period == 'no-date' %}{{ 'without_date'|_ }}{% else %}{{ period }}{% endif %} -

-
-
-

- {% for tagInfo in entries %} - {{ tagInfo.tag }} - {% endfor %} -

+
+ + {% for period,entries in clouds %} + {% if entries|length > 0 %} +
+
+
+
+

+ {% if period == 'no-date' %}{{ 'without_date'|_ }}{% else %}{{ period }}{% endif %} +

+
+
+

+ {% for tagInfo in entries %} + + {{ tagInfo.tag }} + {% endfor %} +

+
+ {% endif %} + {% endfor %} +
+
+

+ {{ ('no_tags_create_default')|_ }} + +

- {% endif %} - {% endfor %} - + {% endif %} {% endblock %} diff --git a/routes/web.php b/routes/web.php index eaf9e60f3d..5ff616394b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -937,6 +937,7 @@ Route::group( Route::post('store', ['uses' => 'TagController@store', 'as' => 'store']); Route::post('update/{tag}', ['uses' => 'TagController@update', 'as' => 'update']); Route::post('destroy/{tag}', ['uses' => 'TagController@destroy', 'as' => 'destroy']); + Route::post('mass-destroy', ['uses' => 'TagController@massDestroy', 'as' => 'mass-destroy']); } );