mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Fix #3246
This commit is contained in:
@@ -102,7 +102,8 @@ class BulkController extends Controller
|
||||
$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');
|
||||
$tagsAction = $request->get('tags_action');
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($journalIds as $journalId) {
|
||||
@@ -110,7 +111,7 @@ class BulkController extends Controller
|
||||
$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++;
|
||||
@@ -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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*
|
||||
@@ -51,6 +53,7 @@ class BulkEditJournalRequest extends FormRequest
|
||||
// fixed
|
||||
return [
|
||||
'journals.*' => 'required|belongsToUser:transaction_journals,id',
|
||||
'tags_action' => 'in:no_nothing,do_replace,do_append',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ trait ConvertsDataTypes
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function integer(string $field): int
|
||||
public function integer(string $field): int
|
||||
{
|
||||
return (int)$this->get($field);
|
||||
}
|
||||
@@ -122,7 +122,6 @@ trait ConvertsDataTypes
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string|null $string
|
||||
*
|
||||
@@ -290,7 +289,7 @@ trait ConvertsDataTypes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function string(string $field): string
|
||||
public function string(string $field): string
|
||||
{
|
||||
return app('steam')->cleanString((string)($this->get($field) ?? ''));
|
||||
}
|
||||
|
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
@@ -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',
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user