Make "next X days" configurable (closes #175)

This commit is contained in:
Bernd Bestel 2019-04-20 15:30:45 +02:00
parent 41988aa1ee
commit c1674d33b4
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
15 changed files with 149 additions and 6 deletions

View File

@ -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

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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')
]);
}

View File

@ -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');
}
}

View File

@ -0,0 +1 @@
$("#batteries_due_soon_days").val(Grocy.UserSettings.batteries_due_soon_days);

View File

@ -0,0 +1 @@
$("#chores_due_soon_days").val(Grocy.UserSettings.chores_due_soon_days);

View File

@ -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))
{

View File

@ -0,0 +1 @@
$("#tasks_due_soon_days").val(Grocy.UserSettings.tasks_due_soon_days);

View File

@ -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

View File

@ -0,0 +1,25 @@
@extends('layout.default')
@section('title', $L('Batteries settings'))
@section('viewJsName', 'batteriessettings')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<h4 class="mt-2">{{ $L('Batteries overview') }}</h4>
@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'
))
<a href="{{ $U('/batteriesoverview') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop

View File

@ -0,0 +1,25 @@
@extends('layout.default')
@section('title', $L('Chores settings'))
@section('viewJsName', 'choressettings')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<h4 class="mt-2">{{ $L('Chores overview') }}</h4>
@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'
))
<a href="{{ $U('/choresoverview') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop

View File

@ -308,9 +308,18 @@
<a class="nav-link dropdown-toggle discrete-link" href="#" data-toggle="dropdown"><i class="fas fa-wrench"></i> <span class="d-inline d-lg-none">{{ $L('Settings') }}</span></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item discrete-link" href="{{ $U('/users') }}"><i class="fas fa-users"></i>&nbsp;{{ $L('Manage users') }}</a>
<a class="dropdown-item discrete-link" href="{{ $U('/stocksettings') }}"><i class="fas fa-box"></i>&nbsp;{{ $L('Stock settings') }}</a>
@if(GROCY_FEATURE_FLAG_CHORES)
<a class="dropdown-item discrete-link" href="{{ $U('/choressettings') }}"><i class="fas fa-home"></i>&nbsp;{{ $L('Chores settings') }}</a>
@endif
@if(GROCY_FEATURE_FLAG_BATTERIES)
<a class="dropdown-item discrete-link" href="{{ $U('/batteriessettings') }}"><i class="fas fa-battery-half"></i>&nbsp;{{ $L('Batteries settings') }}</a>
@endif
@if(GROCY_FEATURE_FLAG_TASKS)
<a class="dropdown-item discrete-link" href="{{ $U('/taskssettings') }}"><i class="fas fa-tasks"></i>&nbsp;{{ $L('Tasks settings') }}</a>
@endif
<div class="dropdown-divider"></div>
<a class="dropdown-item discrete-link" href="{{ $U('/users') }}"><i class="fas fa-users"></i>&nbsp;{{ $L('Manage users') }}</a>
<a class="dropdown-item discrete-link" href="{{ $U('/manageapikeys') }}"><i class="fas fa-handshake"></i>&nbsp;{{ $L('Manage API keys') }}</a>
<a class="dropdown-item discrete-link" target="_blank" href="{{ $U('/api') }}"><i class="fas fa-book"></i>&nbsp;{{ $L('REST API & data model documentation') }}</a>
<div class="dropdown-divider"></div>

View File

@ -43,6 +43,16 @@
</div>
</div>
<h4 class="mt-2">{{ $L('Stock overview') }}</h4>
@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)
<h4 class="mt-2">{{ $L('Shopping list to stock workflow') }}</h4>
@ -55,7 +65,7 @@
</div>
@endif
<a href="{{ $U('/products') }}" class="btn btn-success">{{ $L('OK') }}</a>
<a href="{{ $U('/stockoverview') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop

View File

@ -0,0 +1,24 @@
@extends('layout.default')
@section('title', $L('Tasks settings'))
@section('viewJsName', 'taskssettings')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
@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'
))
<a href="{{ $U('/tasks') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop