mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 03:42:54 +00:00
Can edit category notes
This commit is contained in:
@@ -41,11 +41,8 @@ use Illuminate\View\View;
|
|||||||
class EditController extends Controller
|
class EditController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var CategoryRepositoryInterface The category repository */
|
private CategoryRepositoryInterface $repository;
|
||||||
private $repository;
|
private AttachmentHelperInterface $attachments;
|
||||||
|
|
||||||
/** @var AttachmentHelperInterface Helper for attachments. */
|
|
||||||
private $attachments;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CategoryController constructor.
|
* CategoryController constructor.
|
||||||
@@ -87,7 +84,11 @@ class EditController extends Controller
|
|||||||
}
|
}
|
||||||
$request->session()->forget('categories.edit.fromUpdate');
|
$request->session()->forget('categories.edit.fromUpdate');
|
||||||
|
|
||||||
return view('categories.edit', compact('category', 'subTitle'));
|
$preFilled = [
|
||||||
|
'notes' => $request->old('notes') ?? $this->repository->getNoteText($category),
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('categories.edit', compact('category', 'subTitle', 'preFilled'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Services\Internal\Update;
|
namespace FireflyIII\Services\Internal\Update;
|
||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\RuleTrigger;
|
use FireflyIII\Models\RuleTrigger;
|
||||||
@@ -68,6 +69,7 @@ class CategoryUpdateService
|
|||||||
$this->updateRuleTriggers($oldName, $data['name']);
|
$this->updateRuleTriggers($oldName, $data['name']);
|
||||||
$this->updateRuleActions($oldName, $data['name']);
|
$this->updateRuleActions($oldName, $data['name']);
|
||||||
$this->updateRecurrences($oldName, $data['name']);
|
$this->updateRecurrences($oldName, $data['name']);
|
||||||
|
$this->updateNotes($category, $data);
|
||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
@@ -137,4 +139,40 @@ class CategoryUpdateService
|
|||||||
->update(['rt_meta.value' => $newName]);
|
->update(['rt_meta.value' => $newName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Category $category
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function updateNotes(Category $category, array $data): void
|
||||||
|
{
|
||||||
|
$note = array_key_exists('notes', $data) ? $data['notes'] : null;
|
||||||
|
if (null === $note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ('' === $note) {
|
||||||
|
$dbNote = $category->notes()->first();
|
||||||
|
if (null !== $dbNote) {
|
||||||
|
try {
|
||||||
|
$dbNote->delete();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::debug($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$dbNote = $category->notes()->first();
|
||||||
|
if (null === $dbNote) {
|
||||||
|
$dbNote = new Note;
|
||||||
|
$dbNote->noteable()->associate($category);
|
||||||
|
}
|
||||||
|
$dbNote->text = trim($note);
|
||||||
|
$dbNote->save();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
|
{{ ExpandedForm.textarea('notes', preFilled.notes, {helpText: trans('firefly.field_supports_markdown')} ) }}
|
||||||
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user