mirror of https://github.com/kcal-app/kcal.git
Supper gram-based data entry
This commit is contained in:
parent
7f3ed5b704
commit
87311b9ec4
|
@ -70,14 +70,7 @@ class JournalEntryController extends Controller
|
|||
return view('journal-entries.create')
|
||||
->with('ingredients', $ingredients)
|
||||
->with('meals', JournalEntry::$meals)
|
||||
->with('units', [
|
||||
['value' => 'tsp', 'label' => 'tsp.'],
|
||||
['value' => 'tbsp', 'label' => 'tbsp.'],
|
||||
['value' => 'cup', 'label' => 'cup'],
|
||||
['value' => 'oz', 'label' => 'oz'],
|
||||
['value' => 'g', 'label' => 'grams'],
|
||||
['value' => 'serving', 'label' => 'servings'],
|
||||
])
|
||||
->with('units', Nutrients::$units)
|
||||
->with('default_date', Carbon::createFromFormat('Y-m-d', $date));
|
||||
}
|
||||
|
||||
|
@ -88,14 +81,7 @@ class JournalEntryController extends Controller
|
|||
{
|
||||
return view('journal-entries.create-from-nutrients')
|
||||
->with('meals', JournalEntry::$meals)
|
||||
->with('units', [
|
||||
['value' => 'tsp', 'label' => 'tsp.'],
|
||||
['value' => 'tbsp', 'label' => 'tbsp.'],
|
||||
['value' => 'cup', 'label' => 'cup'],
|
||||
['value' => 'oz', 'label' => 'oz'],
|
||||
['value' => 'g', 'label' => 'grams'],
|
||||
['value' => 'serving', 'label' => 'servings'],
|
||||
]);
|
||||
->with('units', Nutrients::$units);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Rules\ArrayNotEmpty;
|
|||
use App\Rules\StringIsDecimalOrFraction;
|
||||
use App\Rules\UsesIngredientTrait;
|
||||
use App\Support\Number;
|
||||
use App\Support\Nutrients;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
@ -128,14 +129,7 @@ class RecipeController extends Controller
|
|||
->with('recipe', $recipe)
|
||||
->with('ingredients', $ingredients)
|
||||
->with('steps', $steps)
|
||||
->with('ingredients_units', new Collection([
|
||||
['value' => 'tsp', 'label' => 'tsp.'],
|
||||
['value' => 'tbsp', 'label' => 'tbsp.'],
|
||||
['value' => 'cup', 'label' => 'cup'],
|
||||
['value' => 'oz', 'label' => 'oz'],
|
||||
['value' => 'g', 'label' => 'grams'],
|
||||
['value' => 'serving', 'label' => 'servings'],
|
||||
]));
|
||||
->with('ingredients_units', Nutrients::$units);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,15 @@ class Nutrients
|
|||
'protein',
|
||||
];
|
||||
|
||||
public static array $units = [
|
||||
['value' => 'tsp', 'label' => 'tsp.'],
|
||||
['value' => 'tbsp', 'label' => 'tbsp.'],
|
||||
['value' => 'cup', 'label' => 'cup'],
|
||||
['value' => 'oz', 'label' => 'oz'],
|
||||
['value' => 'gram', 'label' => 'grams'],
|
||||
['value' => 'serving', 'label' => 'servings'],
|
||||
];
|
||||
|
||||
public static function calculateFoodNutrientMultiplier(
|
||||
Food $food,
|
||||
float $amount,
|
||||
|
@ -29,6 +38,9 @@ class Nutrients
|
|||
elseif ($fromUnit === 'serving') {
|
||||
return $amount;
|
||||
}
|
||||
elseif ($fromUnit === 'gram') {
|
||||
return $amount / $food->serving_weight;
|
||||
}
|
||||
|
||||
if (
|
||||
empty($fromUnit)
|
||||
|
|
Loading…
Reference in New Issue