From 8192fb32f4ececead7a9bf986de5129b60f7ae5e Mon Sep 17 00:00:00 2001 From: Leroy Foerster Date: Sun, 1 Sep 2019 23:07:37 +0200 Subject: [PATCH] Add a very simple javascript-only shopping list that works offline The OfflineShoppingList disables auto-reloading by adding the 'fullscreen-card' class to the body. It also requests a confirmation on leaving the page because nothing is saved, not even into the local or session storage. Please consider this feature as a rough draft and foundation for discussion. --- controllers/StockController.php | 19 ++++++++++ routes.php | 7 ++-- views/offlineshoppinglist.blade.php | 59 +++++++++++++++++++++++++++++ views/shoppinglist.blade.php | 3 ++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 views/offlineshoppinglist.blade.php diff --git a/controllers/StockController.php b/controllers/StockController.php index c6f0e82c..869b3427 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -81,6 +81,25 @@ class StockController extends BaseController ]); } + public function OfflineShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + $listId = 1; + if (isset($request->getQueryParams()['list'])) + { + $listId = $request->getQueryParams()['list']; + } + + return $this->AppContainer->view->render($response, 'offlineshoppinglist', [ + 'listItems' => $this->Database->shopping_list()->where('shopping_list_id = :1', $listId), + 'products' => $this->Database->products()->orderBy('name'), + 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), + 'missingProducts' => $this->StockService->GetMissingProducts(), + 'productGroups' => $this->Database->product_groups()->orderBy('name'), + 'shoppingLists' => $this->Database->shopping_lists()->orderBy('name'), + 'selectedShoppingListId' => $listId + ]); + } + public function ProductsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { return $this->AppContainer->view->render($response, 'products', [ diff --git a/routes.php b/routes.php index 577e50e6..8c839fd8 100644 --- a/routes.php +++ b/routes.php @@ -50,6 +50,7 @@ $app->group('', function() $this->get('/shoppinglist', '\Grocy\Controllers\StockController:ShoppingList'); $this->get('/shoppinglistitem/{itemId}', '\Grocy\Controllers\StockController:ShoppingListItemEditForm'); $this->get('/shoppinglist/{listId}', '\Grocy\Controllers\StockController:ShoppingListEditForm'); + $this->get('/offlineshoppinglist', '\Grocy\Controllers\StockController:OfflineShoppingList'); } // Recipe routes @@ -99,7 +100,7 @@ $app->group('', function() $this->get('/equipment', '\Grocy\Controllers\EquipmentController:Overview'); $this->get('/equipment/{equipmentId}', '\Grocy\Controllers\EquipmentController:EditForm'); } - + // Calendar routes if (GROCY_FEATURE_FLAG_CALENDAR) { @@ -119,9 +120,9 @@ $app->group('/api', function() // System $this->get('/system/info', '\Grocy\Controllers\SystemApiController:GetSystemInfo'); - $this->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); + $this->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); $this->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization'); - + // Generic entity interaction $this->get('/objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects'); $this->get('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject'); diff --git a/views/offlineshoppinglist.blade.php b/views/offlineshoppinglist.blade.php new file mode 100644 index 00000000..70f108e3 --- /dev/null +++ b/views/offlineshoppinglist.blade.php @@ -0,0 +1,59 @@ +@extends('layout.default') + +@section('title', $__t('Shopping list')) +@section('activeNav', 'shoppinglist') +@section('viewJsName', 'shoppinglist') + +@push('pageScripts') + + + +@endpush + +@push('pageStyles') + +@endpush + +@section('content') +

Offline {{$__t('Shopping list')}}

+ + + + + + + + + + + + @foreach($listItems as $listItem) + + + + + + + + @endforeach + +
{{ $__t('Product') }} / {{ $__t('Note') }}{{ $__t('Amount') }}Hiden product groupHidden status
+ @if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}
@else{!! nl2br($listItem->note) !!}@endif +
+ {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->qu_id_purchase)->name_plural) }}@endif + + @if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)->name }} @else {{ $__t('Ungrouped') }} @endif + + @if(FindObjectInArrayByPropertyValue($missingProducts, 'id', $listItem->product_id) !== null) belowminstockamount @endif +
+@stop diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php index 8a669370..8331bcbd 100644 --- a/views/shoppinglist.blade.php +++ b/views/shoppinglist.blade.php @@ -23,6 +23,9 @@ {{ $__t('Add item') }} + + Offline {{ $__t('Shopping list') }} + {{ $__t('Clear list') }}