From 9dd57decdfb247c60e69960fe5455b6a005a7e34 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 2 Oct 2018 16:48:39 +0200 Subject: [PATCH] Finish "pictures for products" features (now closes #58) --- localization/de.php | 8 ++++++++ public/viewjs/stockoverview.js | 25 +++++++++++++++++++++++-- services/DemoDataGeneratorService.php | 26 +++++++++++++++++++++----- views/productform.blade.php | 2 +- views/stockoverview.blade.php | 1 + 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/localization/de.php b/localization/de.php index 9cbbe54b..60503791 100644 --- a/localization/de.php +++ b/localization/de.php @@ -257,6 +257,14 @@ return array( 'in format' => 'im Format', 'To' => 'Bis', 'Time range goes over midnight' => 'Zeitraum geht über Mitternacht', + 'Product picture' => 'Produktbild', + 'No file selected' => 'Keine Datei ausgewählt', + 'If you don\'t select a file, the current picture will not be altered' => 'Wenn du keine Datei auswählst, wird das aktuelle Bild nicht verändert', + 'Current picture' => 'Aktuelles Bild', + 'Delete' => 'Löschen', + 'The current picture will be deleted when you save the product' => 'Das aktuelle Bild wird beim Speichern des Produkts gelöscht', + 'Select file' => 'Datei auswählen', + 'Image of product #1' => 'Bild des Produkts #1', //Constants 'manually' => 'Manuell', diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index ad645461..bd0fa982 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -149,10 +149,31 @@ $(document).on("click", ".product-name-cell", function(e) { var pictureUrl = $(e.currentTarget).attr("data-picture-url"); var productName = $(e.currentTarget).attr("data-product-name"); + var productId = $(e.currentTarget).attr("data-product-id"); - bootbox.alert({ + bootbox.dialog({ title: L("Image of product #1", productName), - message: "" + message: "", + backdrop: false, + onEscape: true, + buttons: { + editproduct: { + label: ' ' + L('Edit product'), + className: 'btn-info responsive-button', + callback: function () + { + window.location.href = U('/product/' + productId + '?returnto=' + encodeURIComponent(window.location.pathname) + '#product-picture'); + } + }, + close: { + label: L('Close'), + className: 'btn-default responsive-button', + callback: function() + { + bootbox.hideAll(); + } + } + } }); } }); diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 718affea..6bb97d06 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -39,9 +39,9 @@ class DemoDataGeneratorService extends BaseService INSERT INTO product_groups(name) VALUES ('06 {$localizationService->Localize('Refrigerated products')}'); --6 DELETE FROM sqlite_sequence WHERE name = 'products'; --Just to keep IDs in order as mentioned here... - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->Localize('Cookies')}', 3, 3, 3, 1, 8, 1); --1 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Cookies')}', 3, 3, 3, 1, 8, 1, 'cookies.jpg'); --1 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->Localize('Chocolate')}', 3, 3, 3, 1, 8, 1); --2 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->Localize('Gummy bears')}', 3, 3, 3, 1, 8, 1); --3 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Gummy bears')}', 3, 3, 3, 1, 8, 1, 'gummybears.jpg'); --3 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, min_stock_amount, product_group_id) VALUES ('{$localizationService->Localize('Crisps')}', 3, 3, 3, 1, 10, 1); --4 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Eggs')}', 2, 3, 2, 10, 5); --5 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Noodles')}', 3, 3, 3, 1, 6); --6 @@ -50,10 +50,10 @@ class DemoDataGeneratorService extends BaseService INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Yogurt')}', 2, 6, 6, 1, 6); --9 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Cheese')}', 2, 3, 3, 1, 6); --10 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Cold cuts')}', 2, 3, 3, 1, 6); --11 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Paprika')}', 2, 2, 2, 1, 5); --12 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Cucumber')}', 2, 2, 2, 1, 5); --13 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Paprika')}', 2, 2, 2, 1, 5, 'paprika.jpg'); --12 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Cucumber')}', 2, 2, 2, 1, 5, 'cucumber.jpg'); --13 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Radish')}', 2, 7, 7, 1, 5); --14 - INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Tomato')}', 2, 2, 2, 1, 5); --15 + INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id, picture_file_name) VALUES ('{$localizationService->Localize('Tomato')}', 2, 2, 2, 1, 5, 'tomato.jpg'); --15 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Pizza dough')}', 3, 3, 3, 1, 6); --16 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Sieved tomatoes')}', 4, 5, 5, 1, 3); --17 INSERT INTO products (name, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock, product_group_id) VALUES ('{$localizationService->Localize('Salami')}', 2, 3, 3, 1, 6); --18 @@ -201,6 +201,22 @@ class DemoDataGeneratorService extends BaseService $batteriesService->TrackChargeCycle(2, date('Y-m-d H:i:s', strtotime('-50 days'))); $batteriesService->TrackChargeCycle(3, date('Y-m-d H:i:s', strtotime('-65 days'))); $batteriesService->TrackChargeCycle(4, date('Y-m-d H:i:s', strtotime('-56 days'))); + + // Download demo product pictures + $productPicturesFolder = GROCY_DATAPATH . '/storage/productpictures'; + mkdir(GROCY_DATAPATH . '/storage'); + mkdir(GROCY_DATAPATH . '/storage/productpictures'); + $sslOptions = array( + 'ssl' => array( + 'verify_peer' => false, + 'verify_peer_name' => false, + ), + ); + file_put_contents("$productPicturesFolder/cookies.jpg", file_get_contents('https://releases.grocy.info/demoresources/cookies.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$productPicturesFolder/cucumber.jpg", file_get_contents('https://releases.grocy.info/demoresources/cucumber.jpg', false, stream_context_create($sslOptions))); + file_put_contents("$productPicturesFolder/gummybears.jpg", file_get_contents('https://releases.grocy.info/demoresources/gummybears.jpg', false, stream_context_create($sslOptions))); + 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))); } } diff --git a/views/productform.blade.php b/views/productform.blade.php index 0fd69786..f39e16c3 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -130,7 +130,7 @@ @if(!empty($product->picture_file_name)) - +

{{ $L('The current picture will be deleted when you save the product') }}

@else

{{ $L('No picture') }}

diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 35be88c6..5e33d6c4 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -85,6 +85,7 @@ {{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }}@if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->picture_file_name)) @endif