Added a new config option for energy unit display (closes #2109)

This commit is contained in:
Bernd Bestel 2023-02-05 15:55:45 +01:00
parent 0bd698c968
commit b64d726c42
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
8 changed files with 17 additions and 11 deletions

View File

@ -47,7 +47,7 @@
### Meal plan
- Added a new sub feature flag `FEATURE_FLAG_RECIPES_MEALPLAN` to only disable the meal plan if not needed (thanks @webysther)
- Added a new sub feature flag `FEATURE_FLAG_RECIPES_MEALPLAN` (in `config.php`) to only disable the meal plan if not needed (thanks @webysther)
### Chores
@ -75,6 +75,7 @@
### General
- Added a new `config.php` setting `ENERGY_UNIT` to customize the label to display energy values (was fixed `kcal` before and defaults to that, so no changed behavior when not configured)
- New translations: (thanks all the translators)
- Romanian (demo available at <https://ro.demo.grocy.info>)

View File

@ -41,6 +41,10 @@ Setting('MEAL_PLAN_FIRST_DAY_OF_WEEK', '');
// ISO 4217 code of the currency ("USD", "EUR", "GBP", etc.)
Setting('CURRENCY', 'USD');
// Your preferred unit for energy
// E.g. "kcal" or "kJ" or something else (doesn't really matter, it's only used to display energy values)
Setting('ENERGY_UNIT', 'kcal');
// When running grocy in a subdirectory, this should be set to the relative path, otherwise empty
// It needs to be set to the part (of the URL) AFTER the document root,
// if URL rewriting is disabled, including index.php

View File

@ -1356,7 +1356,7 @@ msgstr ""
msgid "Output"
msgstr ""
msgid "Energy (kcal)"
msgid "Energy"
msgstr ""
msgid "Per stock quantity unit"

View File

@ -168,11 +168,11 @@ $(".calendar").each(function()
var costsAndCaloriesPerServing = ""
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-currency">' + resolvedRecipe.costs + '</span> / <span class="locale-number locale-number-generic">' + resolvedRecipe.calories / mealPlanEntry.recipe_servings + '</span> kcal ' + __t('per serving') + '</h5>';
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-currency">' + resolvedRecipe.costs + '</span> / <span class="locale-number locale-number-generic">' + resolvedRecipe.calories / mealPlanEntry.recipe_servings + '</span> ' + Grocy.EnergyUnit + ' ' + __t('per serving') + '</h5>';
}
else
{
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-generic">' + resolvedRecipe.calories / mealPlanEntry.recipe_servings + '</span> kcal ' + __t('per serving') + '</h5>';
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-generic">' + resolvedRecipe.calories / mealPlanEntry.recipe_servings + '</span> ' + Grocy.EnergyUnit + ' ' + __t('per serving') + '</h5>';
}
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK)
@ -245,11 +245,11 @@ $(".calendar").each(function()
var costsAndCaloriesPerServing = ""
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-currency">' + productDetails.last_price * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories + '</span> kcal ' + '</h5>';
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-currency">' + productDetails.last_price * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories + '</span> ' + Grocy.EnergyUnit + ' </h5>';
}
else
{
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-generic">' + productDetails.product.calories + '</span> kcal ' + '</h5>';
costsAndCaloriesPerServing = '<h5 class="small text-truncate mb-1"><span class="locale-number locale-number-generic">' + productDetails.product.calories + '</span> ' + Grocy.EnergyUnit + ' </h5>';
}
var shoppingListButtonHtml = "";
@ -302,11 +302,11 @@ $(".calendar").each(function()
var costsAndCaloriesPerDay = ""
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
costsAndCaloriesPerDay = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + dayRecipeResolved.costs + '</span> / <span class="locale-number locale-number-generic">' + dayRecipeResolved.calories + '</span> kcal ' + __t('per day') + '</h5>';
costsAndCaloriesPerDay = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + dayRecipeResolved.costs + '</span> / <span class="locale-number locale-number-generic">' + dayRecipeResolved.calories + '</span> ' + Grocy.EnergyUnit + ' ' + __t('per day') + '</h5>';
}
else
{
costsAndCaloriesPerDay = '<h5 class="small text-truncate"><span class="locale-number locale-number-generic">' + dayRecipeResolved.calories + '</span> kcal ' + __t('per day') + '</h5>';
costsAndCaloriesPerDay = '<h5 class="small text-truncate"><span class="locale-number locale-number-generic">' + dayRecipeResolved.calories + '</span> ' + Grocy.EnergyUnit + ' ' + __t('per day') + '</h5>';
}
$(".calendar[data-primary-section='true'] .fc-day-header[data-date='" + dayRecipeName + "']").append('<h5 id="day-summary-' + dayRecipeName + '" class="small text-truncate border-top pt-1 pb-0">' + costsAndCaloriesPerDay + '</h5>');

View File

@ -161,7 +161,7 @@ $('.input-group-qu').on('change', function(e)
{
$("#tare_weight_qu_info").text($("#qu_id_stock option:selected").text());
$("#quick_consume_qu_info").text($("#qu_id_stock option:selected").text());
$("#energy_qu_info").text($("#qu_id_stock option:selected").text());
$("#energy_qu_info").text(Grocy.EnergyUnit + " / " + $("#qu_id_stock option:selected").text());
Grocy.FrontendHelpers.ValidateForm('product-form');
});

View File

@ -95,6 +95,7 @@
Grocy.CurrentUrlRelative = "/" + window.location.href.split('?')[0].replace(Grocy.BaseUrl, "");
Grocy.ActiveNav = '@yield('activeNav', '')';
Grocy.Currency = '{{ GROCY_CURRENCY }}';
Grocy.EnergyUnit = '{{ GROCY_ENERGY_UNIT }}';
Grocy.CalendarFirstDayOfWeek = '{{ GROCY_CALENDAR_FIRST_DAY_OF_WEEK }}';
Grocy.CalendarShowWeekNumbers = {{ BoolToString(GROCY_CALENDAR_SHOW_WEEK_OF_YEAR) }};
Grocy.LocalizationStrings = {!! $LocalizationStrings !!};

View File

@ -478,7 +478,7 @@
@php if($mode == 'edit') { $value = $product->calories; } else { $value = 0; } @endphp
@include('components.numberpicker', array(
'id' => 'calories',
'label' => 'Energy (kcal)',
'label' => 'Energy',
'min' => '0.' . str_repeat('0', $userSettings['stock_decimal_places_amounts']),
'decimals' => $userSettings['stock_decimal_places_amounts'],
'value' => $value,

View File

@ -388,7 +388,7 @@
<div class="row ml-1">
@if(!empty($calories) && intval($calories) > 0)
<div class="col-4">
<label>{{ $__t('Energy (kcal)') }}</label>&nbsp;
<label>{{ GROCY_ENERGY_UNIT }}</label>&nbsp;
<i class="fa-solid fa-question-circle text-muted d-print-none"
data-toggle="tooltip"
data-trigger="hover click"