From c3d4be352d843fb823be70d28a834a9abbd2a431 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Wed, 25 Mar 2020 19:49:10 +0100 Subject: [PATCH] Fix product card chart rendering error when there is no shopping location (references #658) --- grocy.openapi.json | 2 +- localization/strings.pot | 3 +++ public/viewjs/components/productcard.js | 7 ++++++- services/StockService.php | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/grocy.openapi.json b/grocy.openapi.json index 5c758213..70fb445f 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -3767,7 +3767,7 @@ "format": "number" }, "shopping_location": { - "type": "string" + "$ref": "#/components/schemas/ShoppingLocation" } } }, diff --git a/localization/strings.pot b/localization/strings.pot index 52cc834a..f3881af5 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1762,3 +1762,6 @@ msgstr "" msgid "Group ingredients by their product group" msgstr "" + +msgid "Unknown shopping location" +msgstr "" diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js index 878480fc..73a1fefc 100644 --- a/public/viewjs/components/productcard.js +++ b/public/viewjs/components/productcard.js @@ -122,7 +122,12 @@ Grocy.Components.ProductCard.Refresh = function(productId) var chart = Grocy.Components.ProductCard.PriceHistoryChart.data; priceHistoryDataPoints.forEach((dataPoint) => { - var key = dataPoint.shopping_location || "empty"; + var key = __t("Unknown shopping location"); + if (dataPoint.shopping_location) + { + key = dataPoint.shopping_location.name + } + if (!datasets[key]) { datasets[key] = [] } diff --git a/services/StockService.php b/services/StockService.php index 6c2e7016..02c1e0a1 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -178,7 +178,7 @@ class StockService extends BaseService $returnData[] = array( 'date' => $row->purchased_date, 'price' => $row->price, - 'shopping_location' => FindObjectInArrayByPropertyValue($shoppingLocations, 'id', $row->shopping_location_id)->name, + 'shopping_location' => FindObjectInArrayByPropertyValue($shoppingLocations, 'id', $row->shopping_location_id), ); } return $returnData;