From b57fd83cb83286ab632577261c8dee790fbc7714 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 21 Sep 2019 13:08:42 +0200 Subject: [PATCH] Fixed various smaller problems after some testing --- controllers/RecipesController.php | 1 + public/viewjs/components/productamountpicker.js | 8 +++++++- views/components/productpicker.blade.php | 1 + views/components/recipepicker.blade.php | 2 ++ views/productform.blade.php | 2 +- views/recipeform.blade.php | 2 +- views/recipes.blade.php | 2 ++ views/stockoverview.blade.php | 2 ++ 8 files changed, 17 insertions(+), 3 deletions(-) diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index 8f6cd3da..93b20cd3 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -110,6 +110,7 @@ class RecipesController extends BaseController return $this->AppContainer->view->render($response, 'recipeposform', [ 'mode' => 'create', 'recipe' => $this->Database->recipes($args['recipeId']), + 'recipePos' => new \stdClass(), 'products' => $this->Database->products()->orderBy('name'), 'quantityUnits' => $this->Database->quantity_units()->orderBy('name'), 'quantityUnitConversionsResolved' => $this->Database->quantity_unit_conversions_resolved() diff --git a/public/viewjs/components/productamountpicker.js b/public/viewjs/components/productamountpicker.js index 7e60c5b2..ced3987c 100644 --- a/public/viewjs/components/productamountpicker.js +++ b/public/viewjs/components/productamountpicker.js @@ -3,9 +3,10 @@ Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = false; Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuId, forceInitialDisplayQu = false) { + var conversionsForProduct = FindAllObjectsInArrayByPropertyValue(Grocy.QuantityUnitConversionsResolved, 'product_id', productId); + if (!Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled) { - var conversionsForProduct = FindAllObjectsInArrayByPropertyValue(Grocy.QuantityUnitConversionsResolved, 'product_id', productId); $("#qu_id").find("option").remove().end(); $("#qu_id").attr("data-destination-qu-name", FindObjectInArrayByPropertyValue(Grocy.QuantityUnits, 'id', destinationQuId).name); conversionsForProduct.forEach(conversion => @@ -27,6 +28,11 @@ Grocy.Components.ProductAmountPicker.Reload = function(productId, destinationQuI Grocy.Components.ProductAmountPicker.InitalValueSet = true; } + if (conversionsForProduct.length === 1) + { + $("#qu_id").val($("#qu_id option:first").val()); + } + $(".input-group-productamountpicker").trigger("change"); } diff --git a/views/components/productpicker.blade.php b/views/components/productpicker.blade.php index 5352d7ad..ecef52c9 100644 --- a/views/components/productpicker.blade.php +++ b/views/components/productpicker.blade.php @@ -10,6 +10,7 @@ @php if(!isset($label)) { $label = 'Product'; } @endphp @php if(!isset($disabled)) { $disabled = false; } @endphp @php if(empty($hint)) { $hint = ''; } @endphp +@php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp
diff --git a/views/components/recipepicker.blade.php b/views/components/recipepicker.blade.php index 52430ffa..1a1237cf 100644 --- a/views/components/recipepicker.blade.php +++ b/views/components/recipepicker.blade.php @@ -6,6 +6,8 @@ @php if(empty($prefillById)) { $prefillById = ''; } @endphp @php if(!isset($isRequired)) { $isRequired = true; } @endphp @php if(empty($hint)) { $hint = ''; } @endphp +@php if(empty($hintId)) { $hintId = ''; } @endphp +@php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp
diff --git a/views/productform.blade.php b/views/productform.blade.php index 1a20faf6..f6ccda39 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -203,7 +203,7 @@
- @php if($mode == 'edit') { $value = $product->calories; } else { $value = ''; } @endphp + @php if($mode == 'edit') { $value = $product->calories; } else { $value = 0; } @endphp @include('components.numberpicker', array( 'id' => 'calories', 'label' => 'Energy (kcal)', diff --git a/views/recipeform.blade.php b/views/recipeform.blade.php index bd1aabca..9b1d2f14 100644 --- a/views/recipeform.blade.php +++ b/views/recipeform.blade.php @@ -24,7 +24,7 @@ diff --git a/views/recipes.blade.php b/views/recipes.blade.php index 306f2870..14cf1ab7 100644 --- a/views/recipes.blade.php +++ b/views/recipes.blade.php @@ -161,12 +161,14 @@ 'additionalAttributes' => 'data-recipe-id="' . $selectedRecipe->id . '"' )) + @if(!empty($selectedRecipeTotalCalories) && intval($selectedRecipeTotalCalories) > 0)

{{ $selectedRecipeTotalCalories }}

+ @endif @if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)