From c1674d33b4103af57de7e73e409e3166a339a224 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 20 Apr 2019 15:30:45 +0200 Subject: [PATCH] Make "next X days" configurable (closes #175) --- config-dist.php | 12 ++++++++++++ controllers/BatteriesController.php | 11 ++++++++++- controllers/ChoresController.php | 11 ++++++++++- controllers/StockController.php | 6 +++++- controllers/TasksController.php | 11 ++++++++++- public/viewjs/batteriessettings.js | 1 + public/viewjs/choressettings.js | 1 + public/viewjs/stocksettings.js | 1 + public/viewjs/taskssettings.js | 1 + routes.php | 3 +++ views/batteriessettings.blade.php | 25 +++++++++++++++++++++++++ views/choressettings.blade.php | 25 +++++++++++++++++++++++++ views/layout/default.blade.php | 11 ++++++++++- views/stocksettings.blade.php | 12 +++++++++++- views/taskssettings.blade.php | 24 ++++++++++++++++++++++++ 15 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 public/viewjs/batteriessettings.js create mode 100644 public/viewjs/choressettings.js create mode 100644 public/viewjs/taskssettings.js create mode 100644 views/batteriessettings.blade.php create mode 100644 views/choressettings.blade.php create mode 100644 views/taskssettings.blade.php diff --git a/config-dist.php b/config-dist.php index 2304d0ac..32ca33c6 100644 --- a/config-dist.php +++ b/config-dist.php @@ -55,9 +55,21 @@ DefaultUserSetting('auto_night_mode_time_range_from', "20:00"); // Format HH:mm DefaultUserSetting('auto_night_mode_time_range_to', "07:00"); // Format HH:mm DefaultUserSetting('auto_night_mode_time_range_goes_over_midnight', true); // If the time range above goes over midnight DefaultUserSetting('currently_inside_night_mode_range', false); // If we're currently inside of night mode time range (this is not user configurable, but stored as a user setting because it's evaluated client side to be able to use the client time instead of the maybe different server time) + +# Stock settings DefaultUserSetting('product_presets_location_id', -1); // Default location id for new products (-1 means no location is preset) DefaultUserSetting('product_presets_product_group_id', -1); // Default product group id for new products (-1 means no product group is preset) DefaultUserSetting('product_presets_qu_id', -1); // Default quantity unit id for new products (-1 means no quantity unit is preset) +DefaultUserSetting('stock_expring_soon_days', 5); + +# Chores settings +DefaultUserSetting('chores_due_soon_days', 5); + +# Batteries settings +DefaultUserSetting('batteries_due_soon_days', 5); + +# Tasks settings +DefaultUserSetting('tasks_due_soon_days', 5); # If the page should be automatically reloaded when there was # an external change diff --git a/controllers/BatteriesController.php b/controllers/BatteriesController.php index 9ee3625b..89d77f8b 100644 --- a/controllers/BatteriesController.php +++ b/controllers/BatteriesController.php @@ -3,6 +3,7 @@ namespace Grocy\Controllers; use \Grocy\Services\BatteriesService; +use \Grocy\Services\UsersService; class BatteriesController extends BaseController { @@ -16,10 +17,13 @@ class BatteriesController extends BaseController public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { + $usersService = new UsersService(); + $nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['batteries_due_soon_days']; + return $this->AppContainer->view->render($response, 'batteriesoverview', [ 'batteries' => $this->Database->batteries()->orderBy('name'), 'current' => $this->BatteriesService->GetCurrent(), - 'nextXDays' => 5 + 'nextXDays' => $nextXDays ]); } @@ -61,4 +65,9 @@ class BatteriesController extends BaseController 'batteries' => $this->Database->batteries()->orderBy('name') ]); } + + public function BatteriesSettings(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'batteriessettings'); + } } diff --git a/controllers/ChoresController.php b/controllers/ChoresController.php index 95a55c09..c437290e 100644 --- a/controllers/ChoresController.php +++ b/controllers/ChoresController.php @@ -3,6 +3,7 @@ namespace Grocy\Controllers; use \Grocy\Services\ChoresService; +use \Grocy\Services\UsersService; class ChoresController extends BaseController { @@ -16,10 +17,13 @@ class ChoresController extends BaseController public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { + $usersService = new UsersService(); + $nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['chores_due_soon_days']; + return $this->AppContainer->view->render($response, 'choresoverview', [ 'chores' => $this->Database->chores()->orderBy('name'), 'currentChores' => $this->ChoresService->GetCurrent(), - 'nextXDays' => 5 + 'nextXDays' => $nextXDays ]); } @@ -65,4 +69,9 @@ class ChoresController extends BaseController ]); } } + + public function ChoresSettings(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'choressettings'); + } } diff --git a/controllers/StockController.php b/controllers/StockController.php index a82535e6..7551e2c2 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -3,6 +3,7 @@ namespace Grocy\Controllers; use \Grocy\Services\StockService; +use \Grocy\Services\UsersService; class StockController extends BaseController { @@ -17,6 +18,9 @@ class StockController extends BaseController public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { + $usersService = new UsersService(); + $nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_expring_soon_days']; + return $this->AppContainer->view->render($response, 'stockoverview', [ 'products' => $this->Database->products()->orderBy('name'), 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), @@ -24,7 +28,7 @@ class StockController extends BaseController 'currentStock' => $this->StockService->GetCurrentStock(), 'currentStockLocations' => $this->StockService->GetCurrentStockLocations(), 'missingProducts' => $this->StockService->GetMissingProducts(), - 'nextXDays' => 5, + 'nextXDays' => $nextXDays, 'productGroups' => $this->Database->product_groups()->orderBy('name') ]); } diff --git a/controllers/TasksController.php b/controllers/TasksController.php index e928b118..9150a0b7 100644 --- a/controllers/TasksController.php +++ b/controllers/TasksController.php @@ -3,6 +3,7 @@ namespace Grocy\Controllers; use \Grocy\Services\TasksService; +use \Grocy\Services\UsersService; class TasksController extends BaseController { @@ -25,9 +26,12 @@ class TasksController extends BaseController $tasks = $this->TasksService->GetCurrent(); } + $usersService = new UsersService(); + $nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['tasks_due_soon_days']; + return $this->AppContainer->view->render($response, 'tasks', [ 'tasks' => $tasks, - 'nextXDays' => 5, + 'nextXDays' => $nextXDays, 'taskCategories' => $this->Database->task_categories()->orderBy('name'), 'users' => $this->Database->users() ]); @@ -77,4 +81,9 @@ class TasksController extends BaseController ]); } } + + public function TasksSettings(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'taskssettings'); + } } diff --git a/public/viewjs/batteriessettings.js b/public/viewjs/batteriessettings.js new file mode 100644 index 00000000..2dd30245 --- /dev/null +++ b/public/viewjs/batteriessettings.js @@ -0,0 +1 @@ +$("#batteries_due_soon_days").val(Grocy.UserSettings.batteries_due_soon_days); diff --git a/public/viewjs/choressettings.js b/public/viewjs/choressettings.js new file mode 100644 index 00000000..1b121a35 --- /dev/null +++ b/public/viewjs/choressettings.js @@ -0,0 +1 @@ +$("#chores_due_soon_days").val(Grocy.UserSettings.chores_due_soon_days); diff --git a/public/viewjs/stocksettings.js b/public/viewjs/stocksettings.js index 10bf28d8..f09080c4 100644 --- a/public/viewjs/stocksettings.js +++ b/public/viewjs/stocksettings.js @@ -1,6 +1,7 @@ $("#product_presets_location_id").val(Grocy.UserSettings.product_presets_location_id); $("#product_presets_product_group_id").val(Grocy.UserSettings.product_presets_product_group_id); $("#product_presets_qu_id").val(Grocy.UserSettings.product_presets_qu_id); +$("#stock_expring_soon_days").val(Grocy.UserSettings.stock_expring_soon_days); if (BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled)) { diff --git a/public/viewjs/taskssettings.js b/public/viewjs/taskssettings.js new file mode 100644 index 00000000..0980369a --- /dev/null +++ b/public/viewjs/taskssettings.js @@ -0,0 +1 @@ +$("#tasks_due_soon_days").val(Grocy.UserSettings.tasks_due_soon_days); diff --git a/routes.php b/routes.php index d22b1dd6..feed6b91 100644 --- a/routes.php +++ b/routes.php @@ -59,6 +59,7 @@ $app->group('', function() $this->get('/choresjournal', '\Grocy\Controllers\ChoresController:Journal'); $this->get('/chores', '\Grocy\Controllers\ChoresController:ChoresList'); $this->get('/chore/{choreId}', '\Grocy\Controllers\ChoresController:ChoreEditForm'); + $this->get('/choressettings', '\Grocy\Controllers\ChoresController:ChoresSettings'); } // Battery routes @@ -69,6 +70,7 @@ $app->group('', function() $this->get('/batteriesjournal', '\Grocy\Controllers\BatteriesController:Journal'); $this->get('/batteries', '\Grocy\Controllers\BatteriesController:BatteriesList'); $this->get('/battery/{batteryId}', '\Grocy\Controllers\BatteriesController:BatteryEditForm'); + $this->get('/batteriessettings', '\Grocy\Controllers\BatteriesController:BatteriesSettings'); } // Task routes @@ -78,6 +80,7 @@ $app->group('', function() $this->get('/task/{taskId}', '\Grocy\Controllers\TasksController:TaskEditForm'); $this->get('/taskcategories', '\Grocy\Controllers\TasksController:TaskCategoriesList'); $this->get('/taskcategory/{categoryId}', '\Grocy\Controllers\TasksController:TaskCategoryEditForm'); + $this->get('/taskssettings', '\Grocy\Controllers\TasksController:TasksSettings'); } // Equipment routes diff --git a/views/batteriessettings.blade.php b/views/batteriessettings.blade.php new file mode 100644 index 00000000..133f74d1 --- /dev/null +++ b/views/batteriessettings.blade.php @@ -0,0 +1,25 @@ +@extends('layout.default') + +@section('title', $L('Batteries settings')) + +@section('viewJsName', 'batteriessettings') + +@section('content') +
+
+

@yield('title')

+ +

{{ $L('Batteries overview') }}

+ @include('components.numberpicker', array( + 'id' => 'batteries_due_soon_days', + 'additionalAttributes' => 'data-setting-key="batteries_due_soon_days"', + 'label' => 'Batteries due to be charged soon days', + 'min' => 1, + 'invalidFeedback' => $L('This cannot be lower than #1', '1'), + 'additionalCssClasses' => 'user-setting-control' + )) + + {{ $L('OK') }} +
+
+@stop diff --git a/views/choressettings.blade.php b/views/choressettings.blade.php new file mode 100644 index 00000000..e6e20ed7 --- /dev/null +++ b/views/choressettings.blade.php @@ -0,0 +1,25 @@ +@extends('layout.default') + +@section('title', $L('Chores settings')) + +@section('viewJsName', 'choressettings') + +@section('content') +
+
+

@yield('title')

+ +

{{ $L('Chores overview') }}

+ @include('components.numberpicker', array( + 'id' => 'chores_due_soon_days', + 'additionalAttributes' => 'data-setting-key="chores_due_soon_days"', + 'label' => 'Chores due soon days', + 'min' => 1, + 'invalidFeedback' => $L('This cannot be lower than #1', '1'), + 'additionalCssClasses' => 'user-setting-control' + )) + + {{ $L('OK') }} +
+
+@stop diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 1d3eead7..7881bcb9 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -308,9 +308,18 @@ {{ $L('Settings') }} +

{{ $L('Stock overview') }}

+ @include('components.numberpicker', array( + 'id' => 'stock_expring_soon_days', + 'additionalAttributes' => 'data-setting-key="stock_expring_soon_days"', + 'label' => 'Expiring soon days', + 'min' => 1, + 'invalidFeedback' => $L('This cannot be lower than #1', '1'), + 'additionalCssClasses' => 'user-setting-control' + )) + @if(GROCY_FEATURE_FLAG_SHOPPINGLIST)

{{ $L('Shopping list to stock workflow') }}

@@ -55,7 +65,7 @@ @endif - {{ $L('OK') }} + {{ $L('OK') }} @stop diff --git a/views/taskssettings.blade.php b/views/taskssettings.blade.php new file mode 100644 index 00000000..689961a1 --- /dev/null +++ b/views/taskssettings.blade.php @@ -0,0 +1,24 @@ +@extends('layout.default') + +@section('title', $L('Tasks settings')) + +@section('viewJsName', 'taskssettings') + +@section('content') +
+
+

@yield('title')

+ + @include('components.numberpicker', array( + 'id' => 'tasks_due_soon_days', + 'additionalAttributes' => 'data-setting-key="tasks_due_soon_days"', + 'label' => 'Tasks due soon days', + 'min' => 1, + 'invalidFeedback' => $L('This cannot be lower than #1', '1'), + 'additionalCssClasses' => 'user-setting-control' + )) + + {{ $L('OK') }} +
+
+@stop