From ea0f5101ecbb52be9c961e5f3d2c83904b72b239 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 15 Jul 2018 09:56:10 +0200 Subject: [PATCH] Finalize recipes feature --- controllers/RecipesController.php | 22 ++++++++++++---- package.json | 4 +-- public/css/grocy.css | 9 +++++++ public/viewjs/recipeform.js | 7 +++++ public/viewjs/recipes.js | 20 ++++++++++++++ views/layout/default.blade.php | 14 +++++----- views/recipeform.blade.php | 16 +++++------ views/recipes.blade.php | 44 ++++++++++++++++++++++++------- yarn.lock | 10 +++---- 9 files changed, 108 insertions(+), 38 deletions(-) diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index 49a2813e..06ec6195 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -16,10 +16,22 @@ class RecipesController extends BaseController public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { + $selectedRecipe = null; + $selectedRecipePositions = null; + if (isset($request->getQueryParams()['recipe'])) + { + $selectedRecipe = $this->Database->recipes($request->getQueryParams()['recipe']); + $selectedRecipePositions = $this->Database->recipes_pos()->where('recipe_id', $request->getQueryParams()['recipe']); + } + return $this->AppContainer->view->render($response, 'recipes', [ 'recipes' => $this->Database->recipes()->orderBy('name'), 'recipesFulfillment' => $this->RecipesService->GetRecipesFulfillment(), - 'recipesSumFulfillment' => $this->RecipesService->GetRecipesSumFulfillment() + 'recipesSumFulfillment' => $this->RecipesService->GetRecipesSumFulfillment(), + 'selectedRecipe' => $selectedRecipe, + 'selectedRecipePositions' => $selectedRecipePositions, + 'products' => $this->Database->products(), + 'quantityunits' => $this->Database->quantity_units() ]); } @@ -40,8 +52,8 @@ class RecipesController extends BaseController 'recipe' => $this->Database->recipes($recipeId), 'recipePositions' => $this->Database->recipes_pos()->where('recipe_id', $recipeId), 'mode' => 'edit', - 'products' => $this->Database->products()->orderBy('name'), - 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), + 'products' => $this->Database->products(), + 'quantityunits' => $this->Database->quantity_units(), 'recipesFulfillment' => $this->RecipesService->GetRecipesFulfillment(), 'recipesSumFulfillment' => $this->RecipesService->GetRecipesSumFulfillment() ]); @@ -54,7 +66,7 @@ class RecipesController extends BaseController return $this->AppContainer->view->render($response, 'recipeposform', [ 'mode' => 'create', 'recipe' => $this->Database->recipes($args['recipeId']), - 'products' => $this->Database->products() + 'products' => $this->Database->products()->orderBy('name') ]); } else @@ -63,7 +75,7 @@ class RecipesController extends BaseController 'mode' => 'edit', 'recipe' => $this->Database->recipes($args['recipeId']), 'recipePos' => $this->Database->recipes_pos($args['recipePosId']), - 'products' => $this->Database->products() + 'products' => $this->Database->products()->orderBy('name') ]); } } diff --git a/package.json b/package.json index 8693082e..078dd4b3 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "bootstrap-side-navbar": "https://github.com/samrayner/bootstrap-side-navbar.git#1.0.1", "datatables.net": "^1.10.19", "datatables.net-bs4": "^1.10.19", - "datatables.net-responsive": "^2.2.3", - "datatables.net-responsive-bs4": "^2.2.3", "datatables.net-colreorder": "^1.5.1", "datatables.net-colreorder-bs4": "^1.5.1", + "datatables.net-responsive": "^2.2.3", + "datatables.net-responsive-bs4": "^2.2.3", "datatables.net-select": "^1.2.7", "datatables.net-select-bs4": "^1.2.7", "jquery": "^3.3.1", diff --git a/public/css/grocy.css b/public/css/grocy.css index 5e55397e..ba67c979 100644 --- a/public/css/grocy.css +++ b/public/css/grocy.css @@ -49,6 +49,15 @@ a.discrete-link:focus { font-size: 95%; } +.fullscreen { + z-index: 9999; + width: 100%; + height: 100%; + position: fixed; + top: 0; + left: 0; + } + /* Navigation style customizations */ #mainNav { background-color: #e5e5e5 !important; diff --git a/public/viewjs/recipeform.js b/public/viewjs/recipeform.js index 433e0fa0..8a8e8cfb 100644 --- a/public/viewjs/recipeform.js +++ b/public/viewjs/recipeform.js @@ -120,3 +120,10 @@ $(document).on('click', '.recipe-pos-order-missing-button', function(e) } ); }); + +$(document).on('click', '.recipe-pos-show-note-button', function(e) +{ + var note = $(e.currentTarget).attr('data-recipe-pos-note'); + + bootbox.alert(note); +}); diff --git a/public/viewjs/recipes.js b/public/viewjs/recipes.js index c96eae2f..80449aae 100644 --- a/public/viewjs/recipes.js +++ b/public/viewjs/recipes.js @@ -11,6 +11,12 @@ 'select': 'single' }); +var rowSelect = GetUriParam("row"); +if (typeof rowSelect !== "undefined") +{ + recipesTables.row(rowSelect).select(); +} + $("#search").on("keyup", function() { var value = $(this).val(); @@ -93,3 +99,17 @@ $(document).on('click', '.recipe-order-missing-button', function(e) } }); }); + +recipesTables.on('select', function(e, dt, type, indexes) +{ + if (type === 'row') + { + var selectedRecipeId = $(recipesTables.row(indexes[0]).node()).data("recipe-id"); + window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString() + "&row=" + indexes[0].toString()); + } +}); + +$("#selectedRecipeToggleFullscreenButton").on('click', function(e) +{ + $("#selectedRecipeCard").toggleClass("fullscreen"); +}); diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 171f83fe..91a2b12d 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -70,9 +70,15 @@ {{ $L('Batteries overview') }} + @@ -89,12 +95,6 @@ {{ $L('Consume') }} -