From 9ac2ce35463008b373bd8dc0fe234f80b3e10cbc Mon Sep 17 00:00:00 2001 From: Zeb Fross Date: Sun, 29 Mar 2020 14:52:49 -0700 Subject: [PATCH] Add picture_url to products table When importing data from grocery stores, they provide product images, so I thought it would be better to just save the url rather than trying to download them. --- migrations/0099.sql | 2 ++ public/viewjs/components/productcard.js | 5 +++++ public/viewjs/mealplan.js | 12 +++++++++++- version.json | 4 ++-- views/productform.blade.php | 4 ++++ views/products.blade.php | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 migrations/0099.sql diff --git a/migrations/0099.sql b/migrations/0099.sql new file mode 100644 index 00000000..d9a923c2 --- /dev/null +++ b/migrations/0099.sql @@ -0,0 +1,2 @@ +ALTER TABLE products +ADD picture_url TEXT; \ No newline at end of file diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js index 76117d83..3fd4ff44 100644 --- a/public/viewjs/components/productcard.js +++ b/public/viewjs/components/productcard.js @@ -92,6 +92,11 @@ Grocy.Components.ProductCard.Refresh = function(productId) $("#productcard-product-picture").removeClass("d-none"); $("#productcard-product-picture").attr("src", U('/api/files/productpictures/' + btoa(productDetails.product.picture_file_name) + '?force_serve_as=picture&best_fit_width=400')); } + else if (productDetails.product.picture_url !== null && !productDetails.product.picture_url.isEmpty()) + { + $("#productcard-product-picture").removeClass("d-none"); + $("#productcard-product-picture").attr("src", productDetails.product.picture_url); + } else { $("#productcard-product-picture").addClass("d-none"); diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js index b1dedbc7..25daeaba 100644 --- a/public/viewjs/mealplan.js +++ b/public/viewjs/mealplan.js @@ -226,9 +226,19 @@ var calendar = $("#calendar").fullCalendar({ \ '); + var pictureUrl = null; if (productDetails.product.picture_file_name && !productDetails.product.picture_file_name.isEmpty()) { - element.html(element.html() + '
') + pictureUrl = U("/api/files/productpictures/") + btoa(productDetails.product.picture_file_name) + '?force_serve_as=picture&best_fit_width=400'; + } + else if (productDetails.product.picture_url && !productDetails.product.picture_url.isEmpty()) + { + pictureUrl = productDetails.product.picture_url; + } + + if (pictureUrl) + { + element.html(element.html() + '
') } var dayRecipeName = event.start.format("YYYY-MM-DD"); diff --git a/version.json b/version.json index 0ddad53f..1286133c 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "Version": "2.6.1", - "ReleaseDate": "2020-03-06" + "Version": "2.6.2", + "ReleaseDate": "2020-03-29" } diff --git a/views/productform.blade.php b/views/productform.blade.php index 8b74dd29..9a6276df 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -260,6 +260,10 @@ + + @if(!empty($product->picture_url)) + + @endif @include('components.userfieldsform', array( diff --git a/views/products.blade.php b/views/products.blade.php index 10f6823f..1f1b4563 100644 --- a/views/products.blade.php +++ b/views/products.blade.php @@ -71,7 +71,7 @@ - {{ $product->name }}@if(!empty($product->picture_file_name)) @endif + {{ $product->name }}@if(!empty($product->picture_file_name) || !empty($product->picture_url)) @endif {{ FindObjectInArrayByPropertyValue($locations, 'id', $product->location_id)->name }}