mirror of https://github.com/kcal-app/kcal.git
Use mg base unit for cholesterol and sodium
This commit is contained in:
parent
0829b69e14
commit
3c5d1c1f00
|
|
@ -62,7 +62,6 @@ class FoodController extends Controller
|
||||||
return view('foods.edit')
|
return view('foods.edit')
|
||||||
->with('food', $food)
|
->with('food', $food)
|
||||||
->with('food_tags', $food_tags)
|
->with('food_tags', $food_tags)
|
||||||
->with('nutrients', Nutrients::$all)
|
|
||||||
->with('serving_units', new Collection([
|
->with('serving_units', new Collection([
|
||||||
['value' => 'tsp', 'label' => 'tsp.'],
|
['value' => 'tsp', 'label' => 'tsp.'],
|
||||||
['value' => 'tbsp', 'label' => 'tbsp.'],
|
['value' => 'tbsp', 'label' => 'tbsp.'],
|
||||||
|
|
|
||||||
|
|
@ -128,14 +128,14 @@ class JournalEntryController extends Controller
|
||||||
$ingredient['unit']
|
$ingredient['unit']
|
||||||
);
|
);
|
||||||
foreach (Nutrients::$all as $nutrient) {
|
foreach (Nutrients::$all as $nutrient) {
|
||||||
$entries[$entry_key]->{$nutrient} += $item->{$nutrient} * $nutrient_multiplier;
|
$entries[$entry_key]->{$nutrient['value']} += $item->{$nutrient['value']} * $nutrient_multiplier;
|
||||||
}
|
}
|
||||||
$entries[$entry_key]->foods->add($item);
|
$entries[$entry_key]->foods->add($item);
|
||||||
}
|
}
|
||||||
elseif ($ingredient['type'] == Recipe::class) {
|
elseif ($ingredient['type'] == Recipe::class) {
|
||||||
$item = Recipe::whereId($ingredient['id'])->first();
|
$item = Recipe::whereId($ingredient['id'])->first();
|
||||||
foreach (Nutrients::$all as $nutrient) {
|
foreach (Nutrients::$all as $nutrient) {
|
||||||
$entries[$entry_key]->{$nutrient} += $item->{"{$nutrient}PerServing"}() * Number::floatFromString($ingredient['amount']);
|
$entries[$entry_key]->{$nutrient['value']} += $item->{"{$nutrient['value']}PerServing"}() * Number::floatFromString($ingredient['amount']);
|
||||||
}
|
}
|
||||||
$entries[$entry_key]->recipes->add($item);
|
$entries[$entry_key]->recipes->add($item);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ use App\Models\Food;
|
||||||
class Nutrients
|
class Nutrients
|
||||||
{
|
{
|
||||||
public static array $all = [
|
public static array $all = [
|
||||||
'calories',
|
['value' => 'calories', 'unit' => null],
|
||||||
'fat',
|
['value' => 'fat', 'unit' => 'g'],
|
||||||
'cholesterol',
|
['value' => 'cholesterol', 'unit' => 'mg'],
|
||||||
'sodium',
|
['value' => 'sodium', 'unit' => 'mg'],
|
||||||
'carbohydrates',
|
['value' => 'carbohydrates', 'unit' => 'g'],
|
||||||
'protein',
|
['value' => 'protein', 'unit' => 'g'],
|
||||||
];
|
];
|
||||||
|
|
||||||
public static array $units = [
|
public static array $units = [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class ConvertCholesterolAndSodiumToMg extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
DB::update("UPDATE `foods` SET `cholesterol` = `cholesterol` * 1000;");
|
||||||
|
DB::update("UPDATE `foods` SET `sodium` = `sodium` * 1000;");
|
||||||
|
DB::update("UPDATE `journal_entries` SET `cholesterol` = `cholesterol` * 1000;");
|
||||||
|
DB::update("UPDATE `journal_entries` SET `sodium` = `sodium` * 1000;");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
DB::update("UPDATE `foods` SET `cholesterol` = `cholesterol`/1000;");
|
||||||
|
DB::update("UPDATE `foods` SET `sodium` = `sodium`/1000;");
|
||||||
|
DB::update("UPDATE `journal_entries` SET `cholesterol` = `cholesterol`/1000;");
|
||||||
|
DB::update("UPDATE `journal_entries` SET `sodium` = `sodium`/1000;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -110,18 +110,17 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col space-y-4 md:flex-row md:space-y-0">
|
<div class="flex flex-col space-y-4 md:flex-row md:space-y-0">
|
||||||
@foreach ($nutrients as $nutrient)
|
@foreach (\App\Support\Nutrients::$all as $nutrient)
|
||||||
<!-- {{ ucfirst($nutrient) }} -->
|
<!-- {{ ucfirst($nutrient['value']) }} -->
|
||||||
<div class="flex-auto">
|
<div class="flex-auto">
|
||||||
<x-inputs.label for="{{ $nutrient }}"
|
<x-inputs.label for="{{ $nutrient['value'] }}"
|
||||||
:value="ucfirst($nutrient) . ' (g)'"/>
|
:value="ucfirst($nutrient['value']) . ($nutrient['unit'] ? ' (' . $nutrient['unit'] . ')' : '')"/>
|
||||||
|
|
||||||
<x-inputs.input id="{{ $nutrient }}"
|
<x-inputs.input name="{{ $nutrient['value'] }}"
|
||||||
class="block w-full mt-1 md:w-5/6"
|
|
||||||
type="number"
|
type="number"
|
||||||
|
class="block w-full mt-1 md:w-5/6"
|
||||||
step="any"
|
step="any"
|
||||||
name="{{ $nutrient }}"
|
:value="old($nutrient['value'], $food->{$nutrient['value']})"/>
|
||||||
:value="old($nutrient, $food->{$nutrient})"/>
|
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,12 @@
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Cholesterol</div>
|
<div class="font-bold">Cholesterol</div>
|
||||||
<div x-text="`${Math.round(food.cholesterol*1000)}mg`"></div>
|
<div x-text="`${food.cholesterol}mg`"></div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Sodium</div>
|
<div class="font-bold">Sodium</div>
|
||||||
<div x-text="`${Math.round(food.sodium*1000)}mg`"></div>
|
<div x-text="`${food.sodium}mg`"></div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,12 @@
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Cholesterol</div>
|
<div class="font-bold">Cholesterol</div>
|
||||||
<div>{{ $food->cholesterol }}g</div>
|
<div>{{ $food->cholesterol }}mg</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Sodium</div>
|
<div class="font-bold">Sodium</div>
|
||||||
<div>{{ $food->sodium }}g</div>
|
<div>{{ $food->sodium }}mg</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,16 @@
|
||||||
|
|
||||||
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0 w-full">
|
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0 w-full">
|
||||||
@foreach (\App\Support\Nutrients::$all as $nutrient)
|
@foreach (\App\Support\Nutrients::$all as $nutrient)
|
||||||
<!-- {{ ucfirst($nutrient) }} -->
|
<!-- {{ ucfirst($nutrient['value']) }} -->
|
||||||
<div class="flex-auto">
|
<div class="flex-auto">
|
||||||
<x-inputs.label for="{{ $nutrient }}"
|
<x-inputs.label for="{{ $nutrient['value'] }}"
|
||||||
:value="ucfirst($nutrient) . ' (g)'"/>
|
:value="ucfirst($nutrient) . ' (g)'"/>
|
||||||
|
|
||||||
<x-inputs.input id="{{ $nutrient }}"
|
<x-inputs.input id="{{ $nutrient['value'] }}"
|
||||||
class="block w-full"
|
class="block w-full"
|
||||||
type="number"
|
type="number"
|
||||||
step="any"
|
step="any"
|
||||||
name="{{ $nutrient }}"
|
name="{{ $nutrient['value'] }}"
|
||||||
:value="old($nutrient)"/>
|
:value="old($nutrient)"/>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@
|
||||||
<div class="font-bold border-b border-gray-300">Fat</div>
|
<div class="font-bold border-b border-gray-300">Fat</div>
|
||||||
<div class="text-right border-b border-gray-300">{{ round($entries->sum('fat'), 2) }}g</div>
|
<div class="text-right border-b border-gray-300">{{ round($entries->sum('fat'), 2) }}g</div>
|
||||||
<div class="font-bold border-b border-gray-300">Cholesterol</div>
|
<div class="font-bold border-b border-gray-300">Cholesterol</div>
|
||||||
<div class="text-right border-b border-gray-300">{{ round($entries->sum('cholesterol'), 2) }}g</div>
|
<div class="text-right border-b border-gray-300">{{ round($entries->sum('cholesterol'), 2) }}mg</div>
|
||||||
<div class="font-bold border-b border-gray-300">Sodium</div>
|
<div class="font-bold border-b border-gray-300">Sodium</div>
|
||||||
<div class="text-right border-b border-gray-300">{{ round($entries->sum('sodium'), 2) }}g</div>
|
<div class="text-right border-b border-gray-300">{{ round($entries->sum('sodium'), 2) }}mg</div>
|
||||||
<div class="font-bold border-b border-gray-300">Carbohydrates</div>
|
<div class="font-bold border-b border-gray-300">Carbohydrates</div>
|
||||||
<div class="text-right border-b border-gray-300">{{ round($entries->sum('carbohydrates'), 2) }}g</div>
|
<div class="text-right border-b border-gray-300">{{ round($entries->sum('carbohydrates'), 2) }}g</div>
|
||||||
<div class="font-bold">Protein</div>
|
<div class="font-bold">Protein</div>
|
||||||
|
|
@ -65,8 +65,8 @@
|
||||||
</div>
|
</div>
|
||||||
<span class="text-sm text-gray-500">
|
<span class="text-sm text-gray-500">
|
||||||
@foreach(\App\Support\Nutrients::$all as $nutrient)
|
@foreach(\App\Support\Nutrients::$all as $nutrient)
|
||||||
{{ round($entries->where('meal', $meal)->sum($nutrient), 2) }}g
|
{{ round($entries->where('meal', $meal)->sum($nutrient['value']), 2) }}{{ $nutrient['unit'] }}
|
||||||
{{ $nutrient }}@if(!$loop->last), @endif
|
{{ $nutrient['value'] }}@if(!$loop->last), @endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
@ -85,8 +85,8 @@
|
||||||
<div>
|
<div>
|
||||||
<span class="font-bold">nutrients:</span>
|
<span class="font-bold">nutrients:</span>
|
||||||
@foreach(\App\Support\Nutrients::$all as $nutrient)
|
@foreach(\App\Support\Nutrients::$all as $nutrient)
|
||||||
{{ round($entry->{$nutrient}, 2) }}g
|
{{ round($entry->{$nutrient['value']}, 2) }}{{ $nutrient['unit'] }}
|
||||||
{{ $nutrient }}@if(!$loop->last), @endif
|
{{ $nutrient['value'] }}@if(!$loop->last), @endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@if($entry->foods()->exists())
|
@if($entry->foods()->exists())
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,12 @@
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Cholesterol</div>
|
<div class="font-bold">Cholesterol</div>
|
||||||
<div x-text="`${recipe.cholesterolPerServing}g`"></div>
|
<div x-text="`${recipe.cholesterolPerServing}mg`"></div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Sodium</div>
|
<div class="font-bold">Sodium</div>
|
||||||
<div x-text="`${recipe.sodiumPerServing}g`"></div>
|
<div x-text="`${recipe.sodiumPerServing}mg`"></div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,12 @@
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Cholesterol</div>
|
<div class="font-bold">Cholesterol</div>
|
||||||
<div>{{ $recipe->cholesterolPerServing() }}g</div>
|
<div>{{ $recipe->cholesterolPerServing() }}mg</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div class="font-bold">Sodium</div>
|
<div class="font-bold">Sodium</div>
|
||||||
<div>{{ $recipe->sodiumPerServing() }}g</div>
|
<div>{{ $recipe->sodiumPerServing() }}mg</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-gray-500"/>
|
<hr class="border-gray-500"/>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue