From 816eb031477d176e2e3f9637dd5c36c5d52833bb Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 5 Mar 2019 17:59:33 +0100 Subject: [PATCH] Added a "recipe gallery" view (closes #147) --- localization/en/strings.php | 4 +- public/viewjs/recipes.js | 32 +++++++-- services/DemoDataGeneratorService.php | 24 ++++--- views/recipes.blade.php | 100 ++++++++++++++++++-------- 4 files changed, 116 insertions(+), 44 deletions(-) diff --git a/localization/en/strings.php b/localization/en/strings.php index 79aee3d6..94f4e579 100644 --- a/localization/en/strings.php +++ b/localization/en/strings.php @@ -341,5 +341,7 @@ return array( 'This is useful e.g. for flour in jars - on purchase/consume/inventory you always weigh the whole jar, the amount to be posted is then automatically calculated based on what is in stock and the tare weight defined below' => 'This is useful e.g. for flour in jars - on purchase/consume/inventory you always weigh the whole jar, the amount to be posted is then automatically calculated based on what is in stock and the tare weight defined below', 'Tare weight' => 'Tare weight', 'Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated' => 'Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated', - 'You have to select a location' => 'You have to select a location' + 'You have to select a location' => 'You have to select a location', + 'List' => 'List', + 'Gallery' => 'Gallery' ); diff --git a/public/viewjs/recipes.js b/public/viewjs/recipes.js index ec3643b6..6383412c 100644 --- a/public/viewjs/recipes.js +++ b/public/viewjs/recipes.js @@ -26,12 +26,29 @@ $('#recipes-table tbody').removeClass("d-none"); recipesTables.columns.adjust().draw(); -var rowSelect = GetUriParam("row"); -if (typeof rowSelect !== "undefined") +if ((typeof tab !== "undefined" && tab === "gallery") || window.localStorage.getItem("recipes_last_tab_id") == "gallery-tab") { - recipesTables.row(rowSelect).select(); + $(".nav-tabs a[href='#gallery']").tab("show"); } +var recipe = GetUriParam("recipe"); +if (typeof recipe !== "undefined") +{ + $("#recipes-table tr").removeClass("selected"); + var rowId = "#recipe-row-" + recipe; + $(rowId).addClass("selected") + + var cardId = "#recipe-card-" + recipe; + $(cardId).addClass("bg-primary").addClass("text-white"); + $(cardId)[0].scrollIntoView(); +} + +$("a[data-toggle='tab']").on("shown.bs.tab", function(e) +{ + var tabId = $(e.target).attr("id"); + window.localStorage.setItem("recipes_last_tab_id", tabId); +}); + $("#search").on("keyup", function() { var value = $(this).val(); @@ -169,10 +186,17 @@ recipesTables.on('select', function(e, dt, type, indexes) if (type === 'row') { var selectedRecipeId = $(recipesTables.row(indexes[0]).node()).data("recipe-id"); - window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString() + "&row=" + indexes[0].toString()); + window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString()); } }); +$(".recipe-gallery-item").on("click", function(e) +{ + e.preventDefault(); + + window.location.href = U('/recipes?tab=gallery&recipe=' + $(this).data("recipe-id")); +}); + $("#selectedRecipeToggleFullscreenButton").on('click', function(e) { e.preventDefault(); diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 52907578..26808914 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -71,12 +71,12 @@ class DemoDataGeneratorService extends BaseService INSERT INTO shopping_list (product_id, amount) VALUES (20, 1); INSERT INTO shopping_list (product_id, amount) VALUES (17, 1); - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Pizza')}', '{$loremIpsumWithHtmlFormattings}'); --1 - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Spaghetti bolognese')}', '{$loremIpsumWithHtmlFormattings}'); --2 - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Sandwiches')}', '{$loremIpsumWithHtmlFormattings}'); --3 - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')}', '{$loremIpsumWithHtmlFormattings}'); --4 - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}'); --5 - INSERT INTO recipes (name, description) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')} / {$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}'); --6 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pizza')}', '{$loremIpsumWithHtmlFormattings}', 'pizza.jpg'); --1 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Spaghetti bolognese')}', '{$loremIpsumWithHtmlFormattings}', 'spaghetti.jpg'); --2 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Sandwiches')}', '{$loremIpsumWithHtmlFormattings}', 'sandwiches.jpg'); --3 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes.jpg'); --4 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'chocolate_sauce.jpg'); --5 + INSERT INTO recipes (name, description, picture_file_name) VALUES ('{$localizationService->LocalizeForSqlString('Pancakes')} / {$localizationService->LocalizeForSqlString('Chocolate sauce')}', '{$loremIpsumWithHtmlFormattings}', 'pancakes_chocolate_sauce.jpg'); --6 INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 16, 1, '{$localizationService->LocalizeForSqlString('Bottom')}'); INSERT INTO recipes_pos (recipe_id, product_id, amount, ingredient_group) VALUES (1, 17, 1, '{$localizationService->LocalizeForSqlString('Topping')}'); @@ -225,9 +225,11 @@ class DemoDataGeneratorService extends BaseService // Download demo storage data $productPicturesFolder = GROCY_DATAPATH . '/storage/productpictures'; $equipmentManualsFolder = GROCY_DATAPATH . '/storage/equipmentmanuals'; + $recipePicturesFolder = GROCY_DATAPATH . '/storage/recipepictures'; mkdir(GROCY_DATAPATH . '/storage'); - mkdir(GROCY_DATAPATH . '/storage/productpictures'); - mkdir(GROCY_DATAPATH . '/storage/equipmentmanuals'); + mkdir($productPicturesFolder); + mkdir($equipmentManualsFolder); + mkdir($recipePicturesFolder); $sslOptions = array( 'ssl' => array( 'verify_peer' => false, @@ -240,6 +242,12 @@ class DemoDataGeneratorService extends BaseService file_put_contents("$productPicturesFolder/paprika.jpg", file_get_contents('https://releases.grocy.info/demoresources/paprika.jpg', false, stream_context_create($sslOptions))); file_put_contents("$productPicturesFolder/tomato.jpg", file_get_contents('https://releases.grocy.info/demoresources/tomato.jpg', false, stream_context_create($sslOptions))); file_put_contents("$equipmentManualsFolder/loremipsum.pdf", file_get_contents('https://releases.grocy.info/demoresources/loremipsum.pdf', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/pizza.jpg", file_get_contents('https://releases.grocy.info/demoresources/pizza.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/sandwiches.jpg", file_get_contents('https://releases.grocy.info/demoresources/sandwiches.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/pancakes.jpg", file_get_contents('https://releases.grocy.info/demoresources/pancakes.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/spaghetti.jpg", file_get_contents('https://releases.grocy.info/demoresources/spaghetti.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/chocolate_sauce.jpg", file_get_contents('https://releases.grocy.info/demoresources/chocolate_sauce.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$recipePicturesFolder/pancakes_chocolate_sauce.jpg", file_get_contents('https://releases.grocy.info/demoresources/pancakes_chocolate_sauce.jpg', false, stream_context_create($sslOptions))); } } diff --git a/views/recipes.blade.php b/views/recipes.blade.php index f0beedc8..3c2b00c3 100644 --- a/views/recipes.blade.php +++ b/views/recipes.blade.php @@ -18,35 +18,73 @@ - - - - - - - - - - - @foreach($recipes as $recipe) - - - - - - + + +
+ +
+
{{ $L('Name') }}{{ $L('Servings') }}{{ $L('Requirements fulfilled') }}Hidden status for sorting of "Requirements fulfilled" column
- {{ $recipe->name }} - - {{ $recipe->desired_servings }} - - @if(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled == 1)@elseif(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1)@else@endif - @if(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled == 1){{ $L('Enough in stock') }}@elseif(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1){{ $L('Not enough in stock, #1 ingredients missing but already on the shopping list', FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count) }}@else{{ $L('Not enough in stock, #1 ingredients missing', FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count) }}@endif - - {{ FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count }} -
+ + + + + + + + + + @foreach($recipes as $recipe) + + + + + + + @endforeach + +
{{ $L('Name') }}{{ $L('Servings') }}{{ $L('Requirements fulfilled') }}Hidden status for sorting of "Requirements fulfilled" column
+ {{ $recipe->name }} + + {{ $recipe->desired_servings }} + + @if(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled == 1)@elseif(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1)@else@endif + @if(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled == 1){{ $L('Enough in stock') }}@elseif(FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1){{ $L('Not enough in stock, #1 ingredients missing but already on the shopping list', FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count) }}@else{{ $L('Not enough in stock, #1 ingredients missing', FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count) }}@endif + + {{ FindObjectInArrayByPropertyValue($recipesSumFulfillment, 'recipe_id', $recipe->id)->missing_products_count }} +
+ + + + + @if($selectedRecipe !== null) @@ -88,7 +126,7 @@ {{ $L('Based on the prices of the last purchase per product') }}

- {{ $totalRecipeCosts }} {{ GROCY_CURRENCY }} + {{ $totalRecipeCosts }}

@@ -101,7 +139,7 @@ @if(!empty($selectedRecipeSubRecipe->picture_file_name)) -

+

@endif @php $selectedRecipeSubRecipePositionsFiltered = FindAllObjectsInArrayByPropertyValue($selectedRecipeSubRecipesPositions, 'recipe_id', $selectedRecipeSubRecipe->id); @endphp @@ -137,7 +175,7 @@ @if(!empty($selectedRecipe->picture_file_name)) -

+

@endif @if($selectedRecipePositions->count() > 0)