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.
This commit is contained in:
Zeb Fross 2020-03-29 14:52:49 -07:00
parent 24610af873
commit 9ac2ce3546
6 changed files with 25 additions and 4 deletions

2
migrations/0099.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE products
ADD picture_url TEXT;

View File

@ -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");

View File

@ -226,9 +226,19 @@ var calendar = $("#calendar").fullCalendar({
</h5> \
</div>');
var pictureUrl = null;
if (productDetails.product.picture_file_name && !productDetails.product.picture_file_name.isEmpty())
{
element.html(element.html() + '<div class="mx-auto"><img data-src="' + U("/api/files/productpictures/") + btoa(productDetails.product.picture_file_name) + '?force_serve_as=picture&best_fit_width=400" class="img-fluid lazy"></div>')
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() + '<div class="mx-auto"><img data-src="' + pictureUrl + '" class="img-fluid lazy"></div>')
}
var dayRecipeName = event.start.format("YYYY-MM-DD");

View File

@ -1,4 +1,4 @@
{
"Version": "2.6.1",
"ReleaseDate": "2020-03-06"
"Version": "2.6.2",
"ReleaseDate": "2020-03-29"
}

View File

@ -260,6 +260,10 @@
<input type="file" class="custom-file-input" id="product-picture" accept="image/*">
<label class="custom-file-label" for="product-picture">{{ $__t('No file selected') }}</label>
</div>
@if(!empty($product->picture_url))
<input type="hidden" name="picture_url" value="{{ $product->picture_url }}" />
@endif
</div>
@include('components.userfieldsform', array(

View File

@ -71,7 +71,7 @@
</a>
</td>
<td>
{{ $product->name }}@if(!empty($product->picture_file_name)) <i class="fas fa-image text-muted"></i>@endif
{{ $product->name }}@if(!empty($product->picture_file_name) || !empty($product->picture_url)) <i class="fas fa-image text-muted"></i>@endif
</td>
<td class="@if(!GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) d-none @endif">
{{ FindObjectInArrayByPropertyValue($locations, 'id', $product->location_id)->name }}