mirror of https://github.com/kcal-app/kcal.git
Add option to group or not group journal entries
This commit is contained in:
parent
4a754643ec
commit
73022ac167
|
@ -131,16 +131,25 @@ class JournalEntryController extends Controller
|
|||
'ingredients.id.*' => 'required_with:ingredients.amount.*|nullable',
|
||||
'ingredients.type' => ['required', 'array', new ArrayNotEmpty],
|
||||
'ingredients.type.*' => ['required_with:ingredients.id.*', 'nullable', new UsesIngredientTrait()],
|
||||
'group_entries' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$ingredients = ArrayFormat::flipTwoDimensionalKeys($input['ingredients']);
|
||||
|
||||
/** @var \App\Models\JournalEntry[] $entries */
|
||||
$entries = [];
|
||||
// TODO: Improve efficiency? Potential for lots of queries here...
|
||||
$entry_key = 0;
|
||||
// TODO: Improve efficiency. Potential for lots of queries here...
|
||||
foreach ($ingredients as $ingredient) {
|
||||
// Set entry key (combined date and meal or individual entries).
|
||||
if (isset($input['group_entries']) && (bool) $input['group_entries']) {
|
||||
$entry_key = "{$ingredient['date']}{$ingredient['meal']}";
|
||||
}
|
||||
else {
|
||||
$entry_key++;
|
||||
}
|
||||
|
||||
// Prepare entry values.
|
||||
$entry_key = "{$ingredient['date']}{$ingredient['meal']}";
|
||||
$entries[$entry_key] = $entries[$entry_key] ?? JournalEntry::make([
|
||||
'date' => $ingredient['date'],
|
||||
'meal' => $ingredient['meal'],
|
||||
|
|
|
@ -26,8 +26,12 @@
|
|||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</x-inputs.icon-button>
|
||||
<div class="flex items-center justify-end mt-4">
|
||||
<x-inputs.button class="ml-3" x-on:click="removeTemplate($el);">Add entries</x-inputs.button>
|
||||
<div class="flex items-center justify-end mt-4 space-x-4">
|
||||
<fieldset class="flex space-x-2">
|
||||
<x-inputs.label for="groupEntries" value="Group entries by day and meal" />
|
||||
<x-inputs.input type="checkbox" name="group_entries" value="1" checked />
|
||||
</fieldset>
|
||||
<x-inputs.button x-on:click="removeTemplate($el);">Add entries</x-inputs.button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue