Skip to content

Firefly III: a personal finances manager

Fix #3246

James Coleb9b8c1168f43
diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php
index bbf72cc08c..75c4052111 100644
--- a/app/Http/Controllers/Transaction/BulkController.php
+++ b/app/Http/Controllers/Transaction/BulkController.php
@@ -55,7 +55,7 @@ class BulkController extends Controller
$this->middleware(
function ($request, $next) {
$this->repository = app(JournalRepositoryInterface::class);
- app('view')->share('title', (string) trans('firefly.transactions'));
+ app('view')->share('title', (string)trans('firefly.transactions'));
app('view')->share('mainTitleIcon', 'fa-exchange');
return $next($request);
@@ -74,7 +74,7 @@ class BulkController extends Controller
*/
public function edit(array $journals)
{
- $subTitle = (string) trans('firefly.mass_bulk_journals');
+ $subTitle = (string)trans('firefly.mass_bulk_journals');
$this->rememberPreviousUri('transactions.bulk-edit.uri');
@@ -100,17 +100,18 @@ class BulkController extends Controller
{
$journalIds = $request->get('journals');
$journalIds = is_array($journalIds) ? $journalIds : [];
- $ignoreCategory = 1 === (int) $request->get('ignore_category');
- $ignoreBudget = 1 === (int) $request->get('ignore_budget');
- $ignoreTags = 1 === (int) $request->get('ignore_tags');
- $count = 0;
+ $ignoreCategory = 1 === (int)$request->get('ignore_category');
+ $ignoreBudget = 1 === (int)$request->get('ignore_budget');
+ $tagsAction = $request->get('tags_action');
+
+ $count = 0;
foreach ($journalIds as $journalId) {
- $journalId = (int) $journalId;
+ $journalId = (int)$journalId;
$journal = $this->repository->findNull($journalId);
if (null !== $journal) {
$resultA = $this->updateJournalBudget($journal, $ignoreBudget, $request->integer('budget_id'));
- $resultB = $this->updateJournalTags($journal, $ignoreTags, explode(',', $request->string('tags')));
+ $resultB = $this->updateJournalTags($journal, $tagsAction, explode(',', $request->string('tags')));
$resultC = $this->updateJournalCategory($journal, $ignoreCategory, $request->string('category'));
if ($resultA || $resultB || $resultC) {
$count++;
@@ -118,7 +119,7 @@ class BulkController extends Controller
}
}
app('preferences')->mark();
- $request->session()->flash('success', (string) trans_choice('firefly.mass_edited_transactions_success', $count));
+ $request->session()->flash('success', (string)trans_choice('firefly.mass_edited_transactions_success', $count));
// redirect to previous URL:
return redirect($this->getPreviousUri('transactions.bulk-edit.uri'));
@@ -162,20 +163,22 @@ class BulkController extends Controller
/**
* @param TransactionJournal $journal
- * @param bool $ignoreUpdate
+ * @param string $action
* @param array $tags
*
* @return bool
*/
- private function updateJournalTags(TransactionJournal $journal, bool $ignoreUpdate, array $tags): bool
+ private function updateJournalTags(TransactionJournal $journal, string $action, array $tags): bool
{
-
- if (true === $ignoreUpdate) {
- return false;
+ if ('do_replace' === $action) {
+ Log::debug(sprintf('Set tags to %s', implode(',', $tags)));
+ $this->repository->updateTags($journal, $tags);
+ }
+ if ('do_append' === $action) {
+ $existing = $journal->tags->pluck('tag')->toArray();
+ $new = array_unique(array_merge($tags, $existing));
+ $this->repository->updateTags($journal, $new);
}
- Log::debug(sprintf('Set tags to %s', implode(',', $tags)));
- $this->repository->updateTags($journal, $tags);
-
return true;
}
}
diff --git a/app/Http/Requests/BulkEditJournalRequest.php b/app/Http/Requests/BulkEditJournalRequest.php
index 6e591e34fe..0c674d49e3 100644
--- a/app/Http/Requests/BulkEditJournalRequest.php
+++ b/app/Http/Requests/BulkEditJournalRequest.php
@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Requests;
+use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
/**
@@ -29,6 +30,7 @@ use Illuminate\Foundation\Http\FormRequest;
*/
class BulkEditJournalRequest extends FormRequest
{
+ use ConvertsDataTypes;
/**
* Verify the request.
*
@@ -50,7 +52,8 @@ class BulkEditJournalRequest extends FormRequest
// fixed
return [
- 'journals.*' => 'required|belongsToUser:transaction_journals,id',
+ 'journals.*' => 'required|belongsToUser:transaction_journals,id',
+ 'tags_action' => 'in:no_nothing,do_replace,do_append',
];
}
}
diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php
index b2f73609f2..00ad50b6ce 100644
--- a/app/Support/Request/ConvertsDataTypes.php
+++ b/app/Support/Request/ConvertsDataTypes.php
@@ -59,9 +59,9 @@ trait ConvertsDataTypes
*
* @return int
*/
- protected function integer(string $field): int
+ public function integer(string $field): int
{
- return (int) $this->get($field);
+ return (int)$this->get($field);
}
@@ -79,7 +79,7 @@ trait ConvertsDataTypes
return null;
}
- return (float) $res;
+ return (float)$res;
}
@@ -122,7 +122,6 @@ trait ConvertsDataTypes
}
-
/**
* @param string|null $string
*
@@ -181,7 +180,7 @@ trait ConvertsDataTypes
return null;
}
- return (int) $string;
+ return (int)$string;
}
/**
@@ -193,7 +192,7 @@ trait ConvertsDataTypes
*/
protected function nlString(string $field): string
{
- return app('steam')->nlCleanString((string) ($this->get($field) ?? ''));
+ return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
}
/**
@@ -209,12 +208,12 @@ trait ConvertsDataTypes
return null;
}
- $value = (string) $this->get($field);
+ $value = (string)$this->get($field);
if ('' === $value) {
return null;
}
- return (int) $value;
+ return (int)$value;
}
/**
@@ -230,7 +229,7 @@ trait ConvertsDataTypes
return null;
}
- return app('steam')->nlCleanString((string) ($this->get($field) ?? ''));
+ return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
}
@@ -275,7 +274,7 @@ trait ConvertsDataTypes
if (!$this->has($field)) {
return null;
}
- $res = trim(app('steam')->cleanString((string) ($this->get($field) ?? '')));
+ $res = trim(app('steam')->cleanString((string)($this->get($field) ?? '')));
if ('' === $res) {
return null;
}
@@ -290,8 +289,8 @@ trait ConvertsDataTypes
*
* @return string
*/
- protected function string(string $field): string
+ public function string(string $field): string
{
- return app('steam')->cleanString((string) ($this->get($field) ?? ''));
+ return app('steam')->cleanString((string)($this->get($field) ?? ''));
}
}
diff --git a/public/v1/js/ff/transactions/mass/edit-bulk.js b/public/v1/js/ff/transactions/mass/edit-bulk.js
index e6a0c71dfd..c1cfa67142 100644
--- a/public/v1/js/ff/transactions/mass/edit-bulk.js
+++ b/public/v1/js/ff/transactions/mass/edit-bulk.js
@@ -36,8 +36,8 @@ $(document).ready(function () {
});
$('input[name="tags"]').on('itemAdded', function(event) {
- $('input[name="ignore_tags"]').attr('checked', false);
-
+ $('#tags_action_do_nothing').attr('checked', false);
+ $('#tags_action_do_replace').attr('checked', true);
});
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 3b4e867d1c..13b8aa5857 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -1088,6 +1088,8 @@ return [
'no_bulk_category' => 'Don\'t update category',
'no_bulk_budget' => 'Don\'t update budget',
'no_bulk_tags' => 'Don\'t update tag(s)',
+ 'replace_with_these_tags' => 'Replace with these tags',
+ 'append_these_tags' => 'Add these tags',
'mass_edit' => 'Edit selected individually',
'bulk_edit' => 'Edit selected in bulk',
'mass_delete' => 'Delete selected',
diff --git a/resources/views/v1/transactions/bulk/edit.twig b/resources/views/v1/transactions/bulk/edit.twig
index d3eecd86ec..9c32011ac9 100644
--- a/resources/views/v1/transactions/bulk/edit.twig
+++ b/resources/views/v1/transactions/bulk/edit.twig
@@ -137,12 +137,24 @@
<input class="form-control" placeholder="" name="tags" autocomplete="off" type="text" value="">
</td>
<td>
- <div class="checkbox">
+ <div class="radio">
<label>
- <input name="ignore_tags" type="checkbox" value="1" checked>
+ <input type="radio" name="tags_action" id="tags_action_do_nothing" value="no_nothing" checked />
{{ 'no_bulk_tags'|_ }}
</label>
</div>
+ <div class="radio">
+ <label>
+ <input type="radio" name="tags_action" id="tags_action_do_replace" value="do_replace" />
+ {{ 'replace_with_these_tags'|_ }}
+ </label>
+ </div>
+ <div class="radio">
+ <label>
+ <input type="radio" name="tags_action" id="tags_action_do_append" value="do_append" />
+ {{ 'append_these_tags'|_ }}
+ </label>
+ </div>
</td>
</tr>
</table>