Compare commits

...

103 Commits

Author SHA1 Message Date
Bernd Bestel
5833364e51 Add pluralization of demo and default quantity units 2018-08-04 17:37:43 +02:00
Bernd Bestel
525f1705d1 Update dependencies for next release 2018-08-04 17:22:15 +02:00
Bernd Bestel
5a13cb5ffe Fix jquery timeago update did not really work 2018-08-04 16:54:46 +02:00
Bernd Bestel
e830805443 Refresh also habit/battery statistics on changes on overview pages (references #26) 2018-08-04 15:44:58 +02:00
Bernd Bestel
ca3f28b615 Refresh stock statistics on consume on stock overview page (references #26) 2018-08-04 14:25:32 +02:00
Bernd Bestel
6081b8ee67 Fix some form validation problems (closes #36) 2018-08-04 07:45:24 +02:00
Bernd Bestel
7eef4acd81 Use the same info-bar to explain table colors in shopping list as in stock overview (fixes #27) 2018-08-03 09:06:11 +02:00
Bernd Bestel
678579e933 Don't use ORDER BY in VIEWS (as this is invalid SQL, why does this even work sometimes in SQLite) (fixes #33) 2018-08-03 08:26:59 +02:00
Bernd Bestel
4cc2d39063 Merge remote-tracking branch 'remotes/origin/fix-issue-33' 2018-08-03 08:18:59 +02:00
Bernd Bestel
14cc153422 Removed unused dependency 2018-08-03 08:16:33 +02:00
Bernd Bestel
f5b5c4c7e1 Add default quantity units and locations to reduce confusion (only for new installations) (references #38) 2018-08-03 08:14:23 +02:00
Bernd Bestel
88b76a52a5 Merge pull request #37 from BlizzWave/patch-9
Update no.php
2018-08-02 07:48:33 +02:00
Marius Boro
a4a25af460 Update no.php
typos
2018-08-01 22:44:23 +02:00
Bernd Bestel
41a72d11da Remove unneeded ORDER BY as this maybe lead to problems like in #33 2018-07-31 17:42:07 +02:00
Bernd Bestel
c8236b101b Fix redefine of constant GROCY_DATAPATH when it's not an embedded AND not a demo installation 2018-07-31 17:31:03 +02:00
Bernd Bestel
ef1df0a446 Unify path references and only use relative ones 2018-07-30 19:16:36 +02:00
Bernd Bestel
5c4953b9b2 Merge pull request #28 from BlizzWave/patch-5
Update README.md
2018-07-30 19:12:06 +02:00
Bernd Bestel
ccaf2411fe Merge pull request #30 from BlizzWave/patch-7
Update de.php
2018-07-30 19:03:41 +02:00
Bernd Bestel
bce8bd6b35 Merge pull request #31 from BlizzWave/patch-8
Update batteriesoverview.blade.php
2018-07-30 19:03:28 +02:00
Marius Boro
66c07887cb Update no.php (#29)
* Update no.php

Keeping it updated

* Update no.php
2018-07-30 19:02:02 +02:00
Marius Boro
be99880ce4 Update batteriesoverview.blade.php
Some german slipped in there too.
2018-07-29 23:49:35 +02:00
Marius Boro
e026609972 Update de.php 2018-07-29 23:46:16 +02:00
Marius Boro
3474f55866 Update README.md
added useful information for new users
2018-07-29 23:26:34 +02:00
Bernd Bestel
f583810d5c Properly pluralize everything (closes #19) 2018-07-27 19:39:34 +02:00
Bernd Bestel
419445f5ae Don't add a dummy data point on chart initialization (not needed, will lead to that the current price is always 0 - references #22) 2018-07-26 21:23:37 +02:00
Bernd Bestel
c64eb27ca1 Add something for product price tracking (references #22) 2018-07-26 20:27:38 +02:00
Bernd Bestel
f4eb5196f7 Merge pull request #24 from BlizzWave/patch-4
Updated for Version 1.16.0
2018-07-26 17:30:51 +02:00
Bernd Bestel
9e493430d8 Battery charge interval was not editable and not shown anywhere 2018-07-26 17:28:30 +02:00
Marius Boro
7690eedd70 Update no.php
Updated for Version 1.16.0
2018-07-25 23:40:57 +02:00
Bernd Bestel
aaa270a52f Hotfix for old user to database migration (this will be included in the v1.16.0 release) 2018-07-25 20:26:23 +02:00
Bernd Bestel
6f47a5415c Added a rudimentary habit analysis possibility 2018-07-25 20:01:58 +02:00
Bernd Bestel
42c1709633 Optimize and refactor latest changes 2018-07-25 19:28:15 +02:00
Bernd Bestel
4685ff4145 Add an update script for Linux 2018-07-25 08:22:27 +02:00
Bernd Bestel
249b01d7a8 Added possibility to track who did a habit (this implements and closes #21) 2018-07-24 20:45:14 +02:00
Bernd Bestel
bcbdf58376 Prefix all global vars 2018-07-24 19:41:35 +02:00
Bernd Bestel
7f8540ff4e Replace the single user (defined in /data/config.php) with a multi user management thing 2018-07-24 19:31:43 +02:00
Marius Boro
b52ab91606 Update no.php (#23)
* Update no.php

Better translation and minor typos

* Update no.php
2018-07-23 21:23:55 +02:00
Bernd Bestel
7246ac55b6 Hide scrollbar in sidebar for now (workaround for #15, found no better solution, this closes #15)
This also references BlackrockDigital/startbootstrap-sb-admin#73
2018-07-23 21:21:27 +02:00
Bernd Bestel
848931da21 Mention grocy-desktop in README 2018-07-22 13:59:53 +02:00
Bernd Bestel
bf4092e746 Changed latest release download link 2018-07-22 13:26:46 +02:00
Bernd Bestel
7cee18c926 This is version 1.15.0 2018-07-22 13:10:12 +02:00
Bernd Bestel
e9a4b43268 Improve date picker MMDD shorthand 2018-07-22 13:09:23 +02:00
Bernd Bestel
b1522742cc Add new date input shorthand 2018-07-22 13:03:08 +02:00
Bernd Bestel
ecdaaab789 Update README.md 2018-07-22 12:41:11 +02:00
Bernd Bestel
3379942086 Document settingoverrides for embedded mode 2018-07-22 11:06:01 +02:00
Bernd Bestel
12eaa8c074 Fixed barcode lookup disabled hint was not localized 2018-07-22 10:18:03 +02:00
Bernd Bestel
c6310d636d Always save the recipe edit form when adding, editing or deleting ingredients (fixes #17) 2018-07-22 10:14:06 +02:00
Bernd Bestel
9bedc6a138 Fixed habit- and batterytracking dropdowns - selection did not work 2018-07-22 09:54:06 +02:00
Bernd Bestel
70dbc6018f Fix selected product in productpicker was not highlighted 2018-07-22 09:33:01 +02:00
Bernd Bestel
3afeb44b1d Prepare for embedded mode 2018-07-18 19:07:00 +02:00
Bernd Bestel
3131b8965e Prepare for embedded mode 2018-07-16 21:23:13 +02:00
Bernd Bestel
bbc2fc9e42 Merge pull request #18 from BlizzWave/patch-2
Update no.php
2018-07-16 21:18:23 +02:00
Bernd Bestel
3b4141eb4d Prepare for embedded mode 2018-07-16 21:17:32 +02:00
BlizzWave
5f826be82c Update no.php
typos
2018-07-16 19:17:47 +02:00
BlizzWave
db9ee93d2b Norwegian localization (#16)
* Create no.php

* Update no.php
2018-07-15 21:46:16 +02:00
Bernd Bestel
1eabd29105 Describe new API function 2018-07-15 13:57:27 +02:00
Bernd Bestel
dc05c56440 Do not expand card body automatically 2018-07-15 13:39:48 +02:00
Bernd Bestel
cb88ab2080 Changed file extension of custom CSS and JS files to clarify that the content is HTML and not directly CSS/JS 2018-07-15 13:35:54 +02:00
Bernd Bestel
254e1a9bc1 Fix all the little things for the next release 2018-07-15 13:33:59 +02:00
Bernd Bestel
0fc7c297bf Fixed a problem about recipe fulfillment wrong when there is no stock of a given product 2018-07-15 11:25:12 +02:00
Bernd Bestel
82bfb6a3c3 Improve demo data 2018-07-15 11:24:36 +02:00
Bernd Bestel
277c622475 Add missing German translations 2018-07-15 10:40:21 +02:00
Bernd Bestel
091a0f3efe Removed not needed Italian technical translation item 2018-07-15 10:32:50 +02:00
Bernd Bestel
823c76aa08 Add missing German translations 2018-07-15 10:30:27 +02:00
Bernd Bestel
37dee2a50b Display first recipe by default on recipes page 2018-07-15 10:16:36 +02:00
Bernd Bestel
ea0f5101ec Finalize recipes feature 2018-07-15 09:56:10 +02:00
Bernd Bestel
be650d093d Add a button to clear the whole shopping list 2018-07-15 08:29:26 +02:00
Bernd Bestel
734814d96b More or less finalize recipes feature 2018-07-14 22:49:42 +02:00
Bernd Bestel
d9246b9b42 Start working on recipes feature 2018-07-14 18:23:41 +02:00
Bernd Bestel
70e7e630c3 Refresh screenshots 2018-07-14 14:52:18 +02:00
Bernd Bestel
71fc49252f Modularize product picker 2018-07-14 14:43:57 +02:00
Bernd Bestel
aa0771877f Remember sidebar collapsed state 2018-07-14 11:25:19 +02:00
Bernd Bestel
e5a4d11c0b Remove arrows on tooltips (only needed for sidebar, but found now way to limit this now) 2018-07-14 11:08:10 +02:00
Bernd Bestel
909949a9e1 Expand and highlight parent menu item when active page sidebar navigation item is a sub menu 2018-07-14 10:28:33 +02:00
Bernd Bestel
f018696219 Save data tables state (client side for now) 2018-07-14 10:17:12 +02:00
Bernd Bestel
347a47d0d2 Add info about how to maintain own localizations 2018-07-14 08:51:48 +02:00
Bernd Bestel
c3de4b86b0 Enable column reordering for all data tables 2018-07-14 08:48:14 +02:00
Bernd Bestel
594e77ca41 Only changed default width of datetimepicker for date-only inputs, as this does not work for side-by-side with time picker (references #14) 2018-07-14 08:38:03 +02:00
Bernd Bestel
31ce7a13ea Show a calendar on the shopping list page (just for info purposes) 2018-07-13 22:38:31 +02:00
Bernd Bestel
5d762001c8 Fix too small border in datetime picker (references #14) 2018-07-13 21:37:49 +02:00
Bernd Bestel
bc3d339d9c Small UI adjustments 2018-07-13 21:10:58 +02:00
Bernd Bestel
33e5ed9ddc Fix non-string settings were not correctly recognized 2018-07-12 22:23:00 +02:00
Bernd Bestel
2d712b0ef7 Update comment to reflect changed config "style" 2018-07-12 21:24:37 +02:00
Bernd Bestel
13d81a4e4b Fixed wrong icon 2018-07-12 21:23:47 +02:00
Bernd Bestel
8d917aee12 Corrected typo 2018-07-12 21:21:51 +02:00
Bernd Bestel
09b2cfc46a Fixed loading of a JS when the webserver is case sensitive 2018-07-12 19:48:59 +02:00
Bernd Bestel
789e475207 Fix missing comma 2018-07-12 19:30:33 +02:00
Bernd Bestel
eec5105e5b Merge pull request #13 from davidoskky/master
Italian localization
2018-07-12 19:27:38 +02:00
Bernd Bestel
82f7b2109c Changed how custom JS/CSS can be added 2018-07-12 19:25:45 +02:00
Bernd Bestel
840dd58c03 Add some more info 2018-07-12 19:22:05 +02:00
Bernd Bestel
37d1377f99 Fixed the rest of the broken stuff after the dependency upgrade party 2018-07-12 19:12:31 +02:00
davidoskky
882a3545e5 Add files via upload 2018-07-12 01:04:42 +02:00
Bernd Bestel
778191fd11 Fixed all (or most of) the broken stuff after the dependency upgrade party 2018-07-11 19:43:05 +02:00
Bernd Bestel
71701804ea (More or less) finish upgrading to Bootstrap 4 2018-07-10 20:37:13 +02:00
Bernd Bestel
306c404362 Continue upgrading to Bootstrap 4 2018-07-10 00:07:38 +02:00
Bernd Bestel
4fab4f87d3 Start upgrading top Bootstrap 4 2018-07-09 21:33:23 +02:00
Bernd Bestel
54717a81b1 Streamline data tables 2018-07-09 19:27:22 +02:00
Bernd Bestel
eca299454b Migrate to use Yarn instead of Bower for frontend dependencies 2018-07-08 21:36:07 +02:00
Bernd Bestel
c58083f84a Better approach for stock overview filtering by location (references #11) 2018-07-08 16:54:37 +02:00
Bernd Bestel
ecf96252b9 Add possibility to filter products by location (references #10) 2018-07-08 15:16:24 +02:00
Bernd Bestel
92e648490a Sort all dropdowns 2018-07-08 13:59:42 +02:00
Bernd Bestel
6dd3c26ddd Fix Bower (for now, need to switch to Yarn soon) 2018-07-08 13:51:29 +02:00
Bernd Bestel
02ea26b090 Disable pagination for data tables 2018-07-08 13:50:52 +02:00
150 changed files with 6227 additions and 2332 deletions

View File

@@ -1,3 +0,0 @@
{
"directory": "public/bower_components"
}

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/public/bower_components
/public/node_modules
/vendor
/.release
embedded.txt

4
.yarnrc Normal file
View File

@@ -0,0 +1,4 @@
--modules-folder public/node_modules
--install.production true
--install.ignore-scripts true
--install.ignore-optional true

View File

@@ -5,22 +5,33 @@ ERP beyond your fridge
Public demo of the latest version → [https://demo.grocy.info](https://demo.grocy.info)
## Motivation
A household needs to be managed. I did this so far (almost 10 years) with my first self written software (a C# windows forms application) and with a bunch of Excel sheets. The software is a pain to use and Excel is Excel. So I searched for and tried different things for a (very) long time, nothing 100 % fitted, so this is my aim for a "complete houshold management"-thing.
## What it is about
For now my main focus is on stock management, ERP your fridge!
A household needs to be managed. I did this so far (almost 10 years) with my first self written software (a C# windows forms application) and with a bunch of Excel sheets. The software is a pain to use and Excel is Excel. So I searched for and tried different things for a (very) long time, nothing 100 % fitted, so this is my aim for a "complete houshold management"-thing. ERP your fridge!
## How to install
Just unpack the [latest release](https://github.com/berrnd/grocy/releases/latest) on your PHP (currently only tested with PHP 7.2) enabled webserver (webservers root should point to the `/public` directory), copy `config-dist.php` to `data/config.php`, edit it to your needs, ensure that the `data` directory is writable and you're ready to go.
> **NEW**
>
> There is now grocy-desktop if you want to run grocy without a webserver just like a normal (windows) desktop application.
>
> See https://github.com/berrnd/grocy-desktop or directly download the [latest release](https://releases.grocy.info/latest-desktop) - the installation is nothing more than just clicking 2 times "next"...
Default login is user `admin` with password `admin` - see the `data/config.php` file. Alternatively clone this repository and install Composer and Bower dependencies manually.
Just unpack the [latest release](https://releases.grocy.info/latest) on your PHP (SQLite extension required, currently only tested with PHP 7.2) enabled webserver (webservers root should point to the `public` directory), copy `config-dist.php` to `data/config.php`, edit it to your needs, ensure that the `data` directory is writable and you're ready to go, (to make writable `chown -R www-data:www-data data/`). Default login is user `admin` with password `admin`, please change the password immediately (see user menu).
Alternatively clone this repository and install Composer and Yarn dependencies manually.
If you use nginx as your webserver, please include `try_files $uri /index.php;` in your location block.
If, however, your webserver does not support URL rewriting, set `DISABLE_URL_REWRITING` in `data/config.php`.
If, however, your webserver does not support URL rewriting, set `DISABLE_URL_REWRITING` in `data/config.php` (`Setting('DISABLE_URL_REWRITING', true);`).
## How to update
Just overwrite everything with the latest release while keeping the `/data` directory, check `config-dist.php` for new configuration options and add them to your `data/config.php` (it will show up as an error if something is missing there).
Just overwrite everything with the latest release while keeping the `data` directory, check `config-dist.php` for new configuration options and add them to your `data/config.php` (the default from values `config-dist.php` will be used for not in `data/config.php` defined settings). Just to be sure, please empty `data/viewcache`.
If you run grocy on Linux, there is also `update.sh` (remember to make the script executable, `chmod +x update.sh` and ensure that you have `unzip` installed) which does exactly this and additionally creates a backup (`.tgz` archive) of the current installation in `data/backups` (backups older than 60 days will be deleted during the update).
## Localization
grocy is fully localizable - the default language is English (integrated into code), a German localization is always maintained by me. There is one file per language in the `localization` directory, if you want to create a translation, it's best to copy `localization/de.php` to a new one (e. g. `localization/it.php`) and translating all strings there. (Language can be changed in `data/config.php`, e. g. `Setting('CULTURE', 'it');`)
### Maintaining your own localization
As the German translation will always be the most complete one, for maintaining your localization it would be easiest when you compare your localization with the German one with a diff tool of your choice.
## Things worth to know
@@ -33,10 +44,12 @@ Some fields also allow to select a value by scanning a barcode. It works best wh
### Input shorthands for date fields
For (productivity) reasons all date (and time) input fields use the ISO-8601 format regardless of localization.
The following shorthands are available:
- `MMDD` gets expanded to the given day on the current year in proper notation
- `MMDD` gets expanded to the given day on the current year, if > today, or to the given day next year, if < today, in proper notation
- Example: `0517` will be converted to `2018-05-17`
- `YYYYMMDD` gets expanded to the proper ISO-8601 notation
- Example: `20190417` will be converted to `2019-04-17`
- `YYYYMMe` or `YYYYMM+` gets expanded to the end of the given month in the given year in proper notation
- Example: `201807e` will be converted to `2018-07-31`
- `x` gets expanded to `2999-12-31` (which I use for products which never expire)
- Down/up arrow keys will increase/decrease the date by one day
- Right/left arrow keys will increase/decrease the date by 1 week
@@ -53,11 +66,17 @@ There is no plugin included for any service, see the reference implementation in
### Database migrations
Database schema migration is automatically done when visiting the root (`/`) route (click on the logo in the left upper edge).
### Adding your own CSS or JS without to have to modify the application itself
- When the file `data/custom_js.html` exists, the contents of the file will be added just before `</body>` (end of body) on every page
- When the file `data/custom_css.html` exists, the contents of the file will be added just before `</head>` (end of head) on every page
### Demo mode
When the file `data/demo.txt` exists, the application will work in a demo mode which means authentication is disabled and some demo data will be generated during the database schema migration.
### Other things
When the file `data/add_before_end_body.html` exists, the contents of the file be added just before `</body>` on every page, useful for your own JS/CSS without to have to modify the application itself.
### Embedded mode
When the file `embedded.txt` exists, it must contain a valid and writable path which will be used as the data directory instead of `data` and authentication will be disabled (used in [grocy-desktop](https://github.com/berrnd/grocy-desktop)).
In embedded mode, settings can be overridden by text files in `data/settingoverrides`, the file name must be `<SettingName>.txt` (e. g. `BASE_URL.txt`) and the content must be the setting value (normally one single line).
## Screenshots
#### Dashboard

43
app.php
View File

@@ -6,8 +6,39 @@ use \Psr\Http\Message\ResponseInterface as Response;
use \Grocy\Helpers\UrlManager;
use \Grocy\Controllers\LoginController;
// Definitions for embedded mode
if (file_exists(__DIR__ . '/embedded.txt'))
{
define('GROCY_IS_EMBEDDED_INSTALL', true);
define('GROCY_DATAPATH', file_get_contents(__DIR__ . '/embedded.txt'));
define('GROCY_USER_ID', 1);
}
else
{
define('GROCY_IS_EMBEDDED_INSTALL', false);
define('GROCY_DATAPATH', __DIR__ . '/data');
}
// Definitions for demo mode
if (file_exists(GROCY_DATAPATH . '/demo.txt'))
{
define('GROCY_IS_DEMO_INSTALL', true);
if (!defined('GROCY_USER_ID'))
{
define('GROCY_USER_ID', 1);
}
}
else
{
define('GROCY_IS_DEMO_INSTALL', false);
}
// Load composer dependencies
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/data/config.php';
// Load config files
require_once GROCY_DATAPATH . '/config.php';
require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones
// Setup base application
$appContainer = new \Slim\Container([
@@ -17,7 +48,7 @@ $appContainer = new \Slim\Container([
],
'view' => function($container)
{
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
},
'LoginControllerInstance' => function($container)
{
@@ -25,7 +56,7 @@ $appContainer = new \Slim\Container([
},
'UrlManager' => function($container)
{
return new UrlManager(BASE_URL);
return new UrlManager(GROCY_BASE_URL);
},
'ApiKeyHeaderName' => function($container)
{
@@ -34,11 +65,7 @@ $appContainer = new \Slim\Container([
]);
$app = new \Slim\App($appContainer);
if (PHP_SAPI === 'cli')
{
$app->add(\pavlakis\cli\CliRequest::class);
}
// Load routes from separate file
require_once __DIR__ . '/routes.php';
$app->run();

View File

@@ -1,25 +0,0 @@
{
"name": "grocy",
"private": true,
"dependencies": {
"bootstrap": "^3.3.7",
"font-awesome": "^4.7.0",
"bootbox": "^4.4.0",
"jquery.serializeJSON": "^2.8.1",
"bootstrap-validator": "^0.11.9",
"bootstrap-datepicker": "^1.7.1",
"moment": "^2.18.1",
"bootstrap-combobox": "^1.1.8",
"datatables.net": "^1.10.15",
"datatables.net-bs": "^2.1.1",
"datatables.net-responsive": "^2.1.1",
"datatables.net-responsive-bs": "^2.1.1",
"jquery-timeago": "^1.6.1",
"toastr": "^2.1.3",
"tagmanager": "^3.0.2",
"eonasdan-bootstrap-datetimepicker": "^4.17.47",
"swagger-ui": "^3.13.4",
"jquery-ui": "^1.12.1",
"bootstrap-side-navbar": "^1.0.1"
}
}

View File

@@ -4,10 +4,10 @@ if %projectPath:~-1%==\ set projectPath=%projectPath:~0,-1%
set releasePath=%projectPath%\.release
mkdir "%releasePath%"
for /f "tokens=*" %%a in ('type version.txt') do set version=%%a
for /f "tokens=*" %%a in ('build_tools\jq.exe .Version version.json --raw-output') do set version=%%a
del "%releasePath%\grocy_%version%.zip"
"build_tools\7za.exe" a -r "%releasePath%\grocy_%version%.zip" "%projectPath%\*" -xr!.* -xr!build_tools -xr!build.bat -xr!composer.json -xr!composer.lock -xr!bower.json -xr!publication_assets
"build_tools\7za.exe" a -r "%releasePath%\grocy_%version%.zip" "%projectPath%\*" -xr!.* -xr!build_tools -xr!build.bat -xr!composer.json -xr!composer.lock -xr!package.json -xr!yarn.lock -xr!publication_assets
"build_tools\7za.exe" a "%releasePath%\grocy_%version%.zip" "%projectPath%\public\.htaccess"
"build_tools\7za.exe" rn "%releasePath%\grocy_%version%.zip" .htaccess public\.htaccess
"build_tools\7za.exe" d "%releasePath%\grocy_%version%.zip" data\*.* data\sessions data\viewcache\*

BIN
build_tools/jq.exe Normal file

Binary file not shown.

View File

@@ -3,7 +3,6 @@
"php": ">=7.2",
"slim/slim": "^3.8",
"morris/lessql": "^0.3.4",
"pavlakis/slim-cli": "^1.0",
"rubellum/slim-blade-view": "^0.1.1",
"tuupola/cors-middleware": "^0.7.0"
},

195
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "42031c0b205b7ce7efb4b6eb95a0096a",
"content-hash": "c1bc4c17739e9d0ee8b33628f6d4b9a4",
"packages": [
{
"name": "container-interop/container-interop",
@@ -154,20 +154,21 @@
"request",
"response"
],
"abandoned": "psr/http-factory",
"time": "2017-03-24T14:48:51+00:00"
},
{
"name": "illuminate/container",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
"reference": "4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a"
"reference": "1f0757cae8749400aeda730f6438a081fc3c082d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/container/zipball/4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a",
"reference": "4a42d667a05ec6d31f05b532cdac7e8e68e5ea2a",
"url": "https://api.github.com/repos/illuminate/container/zipball/1f0757cae8749400aeda730f6438a081fc3c082d",
"reference": "1f0757cae8749400aeda730f6438a081fc3c082d",
"shasum": ""
},
"require": {
@@ -198,20 +199,20 @@
],
"description": "The Illuminate Container package.",
"homepage": "https://laravel.com",
"time": "2018-01-21T02:13:38+00:00"
"time": "2018-05-24T13:16:56+00:00"
},
{
"name": "illuminate/contracts",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
"reference": "322ec80498b3bf85bc4025d028e130a9b50242b9"
"reference": "3dc639feabe0f302f574157a782ede323881a944"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/322ec80498b3bf85bc4025d028e130a9b50242b9",
"reference": "322ec80498b3bf85bc4025d028e130a9b50242b9",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/3dc639feabe0f302f574157a782ede323881a944",
"reference": "3dc639feabe0f302f574157a782ede323881a944",
"shasum": ""
},
"require": {
@@ -242,20 +243,20 @@
],
"description": "The Illuminate Contracts package.",
"homepage": "https://laravel.com",
"time": "2018-04-07T17:05:26+00:00"
"time": "2018-05-11T23:38:58+00:00"
},
{
"name": "illuminate/events",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/events.git",
"reference": "b6e73ed40478cef2ef98d5ddb27f333291606cea"
"reference": "5bdd8e84c0528970961289da088306c632eca8f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/events/zipball/b6e73ed40478cef2ef98d5ddb27f333291606cea",
"reference": "b6e73ed40478cef2ef98d5ddb27f333291606cea",
"url": "https://api.github.com/repos/illuminate/events/zipball/5bdd8e84c0528970961289da088306c632eca8f7",
"reference": "5bdd8e84c0528970961289da088306c632eca8f7",
"shasum": ""
},
"require": {
@@ -287,20 +288,20 @@
],
"description": "The Illuminate Events package.",
"homepage": "https://laravel.com",
"time": "2018-02-26T19:00:55+00:00"
"time": "2018-07-23T01:01:28+00:00"
},
{
"name": "illuminate/filesystem",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/filesystem.git",
"reference": "c9ab9376076cedd88a374d7281d62b619634d578"
"reference": "2677365f61c66fad13ff12a37cd4fa8aaeb048d2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/filesystem/zipball/c9ab9376076cedd88a374d7281d62b619634d578",
"reference": "c9ab9376076cedd88a374d7281d62b619634d578",
"url": "https://api.github.com/repos/illuminate/filesystem/zipball/2677365f61c66fad13ff12a37cd4fa8aaeb048d2",
"reference": "2677365f61c66fad13ff12a37cd4fa8aaeb048d2",
"shasum": ""
},
"require": {
@@ -339,20 +340,20 @@
],
"description": "The Illuminate Filesystem package.",
"homepage": "https://laravel.com",
"time": "2018-04-06T13:15:37+00:00"
"time": "2018-07-07T14:54:27+00:00"
},
{
"name": "illuminate/support",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
"reference": "cc8d6f5cef3a901de6bb7d1b362102a6db001085"
"reference": "c684cb5e77e213020f7a4ed213d94b2b384c2951"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/cc8d6f5cef3a901de6bb7d1b362102a6db001085",
"reference": "cc8d6f5cef3a901de6bb7d1b362102a6db001085",
"url": "https://api.github.com/repos/illuminate/support/zipball/c684cb5e77e213020f7a4ed213d94b2b384c2951",
"reference": "c684cb5e77e213020f7a4ed213d94b2b384c2951",
"shasum": ""
},
"require": {
@@ -367,6 +368,7 @@
},
"suggest": {
"illuminate/filesystem": "Required to use the composer class (5.6.*).",
"ramsey/uuid": "Required to use Str::uuid() (^3.7).",
"symfony/process": "Required to use the composer class (~4.0).",
"symfony/var-dumper": "Required to use the dd function (~4.0)."
},
@@ -396,20 +398,20 @@
],
"description": "The Illuminate Support package.",
"homepage": "https://laravel.com",
"time": "2018-04-17T12:26:47+00:00"
"time": "2018-07-26T15:32:11+00:00"
},
{
"name": "illuminate/view",
"version": "v5.6.17",
"version": "v5.6.29",
"source": {
"type": "git",
"url": "https://github.com/illuminate/view.git",
"reference": "54eaf45ee7946d8f8cde13d5e89c5ea2e997040d"
"reference": "8d4e1c4d8c133eaca33c94ee35b7c0d2ef1dc66f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/view/zipball/54eaf45ee7946d8f8cde13d5e89c5ea2e997040d",
"reference": "54eaf45ee7946d8f8cde13d5e89c5ea2e997040d",
"url": "https://api.github.com/repos/illuminate/view/zipball/8d4e1c4d8c133eaca33c94ee35b7c0d2ef1dc66f",
"reference": "8d4e1c4d8c133eaca33c94ee35b7c0d2ef1dc66f",
"shasum": ""
},
"require": {
@@ -444,7 +446,7 @@
],
"description": "The Illuminate View package.",
"homepage": "https://laravel.com",
"time": "2018-04-03T12:56:35+00:00"
"time": "2018-07-19T23:06:53+00:00"
},
{
"name": "morris/lessql",
@@ -496,16 +498,16 @@
},
{
"name": "neomerx/cors-psr7",
"version": "v1.0.12",
"version": "v1.0.13",
"source": {
"type": "git",
"url": "https://github.com/neomerx/cors-psr7.git",
"reference": "24944f39483d1a89f66ae9d58cca9f82b8815b35"
"reference": "2556e2013f16a55532c95928455257d5b6bbc6e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/neomerx/cors-psr7/zipball/24944f39483d1a89f66ae9d58cca9f82b8815b35",
"reference": "24944f39483d1a89f66ae9d58cca9f82b8815b35",
"url": "https://api.github.com/repos/neomerx/cors-psr7/zipball/2556e2013f16a55532c95928455257d5b6bbc6e2",
"reference": "2556e2013f16a55532c95928455257d5b6bbc6e2",
"shasum": ""
},
"require": {
@@ -514,7 +516,7 @@
"psr/log": "^1.0"
},
"require-dev": {
"mockery/mockery": "^0.9.9",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^5.7",
"scrutinizer/ocular": "^1.1",
"squizlabs/php_codesniffer": "^3.0"
@@ -547,20 +549,20 @@
"w3.org",
"www.w3.org"
],
"time": "2017-09-03T22:31:57+00:00"
"time": "2018-05-23T16:10:11+00:00"
},
{
"name": "nesbot/carbon",
"version": "1.26.4",
"version": "1.32.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "e3d9014279133a3cccc01f6a691322a2d5a6a87b"
"reference": "64563e2b9f69e4db1b82a60e81efa327a30ff343"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e3d9014279133a3cccc01f6a691322a2d5a6a87b",
"reference": "e3d9014279133a3cccc01f6a691322a2d5a6a87b",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/64563e2b9f69e4db1b82a60e81efa327a30ff343",
"reference": "64563e2b9f69e4db1b82a60e81efa327a30ff343",
"shasum": ""
},
"require": {
@@ -572,6 +574,13 @@
"phpunit/phpunit": "^4.8.35 || ^5.7"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Carbon\\Laravel\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"": "src/"
@@ -595,7 +604,7 @@
"datetime",
"time"
],
"time": "2018-04-17T15:35:42+00:00"
"time": "2018-07-05T06:59:26+00:00"
},
{
"name": "nikic/fast-route",
@@ -643,55 +652,6 @@
],
"time": "2018-02-13T20:26:39+00:00"
},
{
"name": "pavlakis/slim-cli",
"version": "1.0.4",
"source": {
"type": "git",
"url": "https://github.com/pavlakis/slim-cli.git",
"reference": "603933a54e391b3c70c573206cce543b75d8b1db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pavlakis/slim-cli/zipball/603933a54e391b3c70c573206cce543b75d8b1db",
"reference": "603933a54e391b3c70c573206cce543b75d8b1db",
"shasum": ""
},
"require": {
"php": "^5.5|^5.6|^7.0|^7.1"
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"slim/slim": "^3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"pavlakis\\cli\\tests\\": "tests/phpunit",
"pavlakis\\cli\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Antonis Pavlakis",
"email": "adoni@pavlakis.info",
"homepage": "http://pavlakis.info"
}
],
"description": "Making a mock GET request through the CLI and enabling the same application entry point on CLI scripts.",
"homepage": "http://github.com/pavlakis/slim-cli",
"keywords": [
"cli",
"framework",
"middleware",
"slim"
],
"time": "2017-01-30T22:50:06+00:00"
},
{
"name": "philo/laravel-blade",
"version": "v3.1",
@@ -1206,16 +1166,16 @@
},
{
"name": "symfony/debug",
"version": "v4.0.8",
"version": "v4.1.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "5961d02d48828671f5d8a7805e06579d692f6ede"
"reference": "9316545571f079c4dd183e674721d9dc783ce196"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/5961d02d48828671f5d8a7805e06579d692f6ede",
"reference": "5961d02d48828671f5d8a7805e06579d692f6ede",
"url": "https://api.github.com/repos/symfony/debug/zipball/9316545571f079c4dd183e674721d9dc783ce196",
"reference": "9316545571f079c4dd183e674721d9dc783ce196",
"shasum": ""
},
"require": {
@@ -1231,7 +1191,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.1-dev"
}
},
"autoload": {
@@ -1258,20 +1218,20 @@
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2018-04-03T05:24:00+00:00"
"time": "2018-07-26T11:24:31+00:00"
},
{
"name": "symfony/finder",
"version": "v4.0.8",
"version": "v4.1.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "ca27c02b7a3fef4828c998c2ff9ba7aae1641c49"
"reference": "e162f1df3102d0b7472805a5a9d5db9fcf0a8068"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/ca27c02b7a3fef4828c998c2ff9ba7aae1641c49",
"reference": "ca27c02b7a3fef4828c998c2ff9ba7aae1641c49",
"url": "https://api.github.com/repos/symfony/finder/zipball/e162f1df3102d0b7472805a5a9d5db9fcf0a8068",
"reference": "e162f1df3102d0b7472805a5a9d5db9fcf0a8068",
"shasum": ""
},
"require": {
@@ -1280,7 +1240,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.1-dev"
}
},
"autoload": {
@@ -1307,20 +1267,20 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2018-04-04T05:10:37+00:00"
"time": "2018-07-26T11:24:31+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.7.0",
"version": "v1.8.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b"
"reference": "3296adf6a6454a050679cde90f95350ad604b171"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b",
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171",
"reference": "3296adf6a6454a050679cde90f95350ad604b171",
"shasum": ""
},
"require": {
@@ -1332,7 +1292,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
"dev-master": "1.8-dev"
}
},
"autoload": {
@@ -1366,20 +1326,20 @@
"portable",
"shim"
],
"time": "2018-01-30T19:27:44+00:00"
"time": "2018-04-26T10:06:28+00:00"
},
{
"name": "symfony/translation",
"version": "v4.0.8",
"version": "v4.1.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "e20a9b7f9f62cb33a11638b345c248e7d510c938"
"reference": "6fcd1bd44fd6d7181e6ea57a6f4e08a09b29ef65"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/e20a9b7f9f62cb33a11638b345c248e7d510c938",
"reference": "e20a9b7f9f62cb33a11638b345c248e7d510c938",
"url": "https://api.github.com/repos/symfony/translation/zipball/6fcd1bd44fd6d7181e6ea57a6f4e08a09b29ef65",
"reference": "6fcd1bd44fd6d7181e6ea57a6f4e08a09b29ef65",
"shasum": ""
},
"require": {
@@ -1394,20 +1354,21 @@
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.4|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/finder": "~2.8|~3.0|~4.0",
"symfony/intl": "~3.4|~4.0",
"symfony/yaml": "~3.4|~4.0"
},
"suggest": {
"psr/log": "To use logging capability in translator",
"psr/log-implementation": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.1-dev"
}
},
"autoload": {
@@ -1434,7 +1395,7 @@
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
"time": "2018-02-22T10:50:29+00:00"
"time": "2018-07-26T11:24:31+00:00"
},
{
"name": "tuupola/callable-handler",
@@ -1604,7 +1565,7 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=7.0"
"php": ">=7.2"
},
"platform-dev": []
}

View File

@@ -1,26 +1,27 @@
<?php
# Login credentials
define('HTTP_USER', 'admin');
define('HTTP_PASSWORD', 'admin');
# Either "production" or "dev"
define('MODE', 'production');
Setting('MODE', 'production');
# Either "en" or "de" or the filename (without extension) of
# one of the other available localization files in the "/localization" directory
define('CULTURE', 'en');
Setting('CULTURE', 'en');
# To keep it simpel, grocy does not handle any currency conversions,
# this here is used to format all money values,
# so can be anything (e. g. "USD" OR "$", doesn't matter...)
Setting('CURRENCY', '$');
# The base url of your installation,
# should be just "/" when running directly under the root of a (sub)domain
# or for example "https:/example.com/grocy" when using a subdirectory
define('BASE_URL', '/');
Setting('BASE_URL', '/');
# The plugin to use for external barcode lookups,
# must be the filename without .php extension and must be located in /data/plugins,
# see /data/plugins/DemoBarcodeLookupPlugin.php for an example implementation
define('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin');
Setting('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin');
# If, however, your webserver does not support URL rewriting,
# set this to true
define('DISABLE_URL_REWRITING', false);
Setting('DISABLE_URL_REWRITING', false);

View File

@@ -11,13 +11,15 @@ class BaseController
public function __construct(\Slim\Container $container) {
$databaseService = new DatabaseService();
$this->Database = $databaseService->GetDbConnection();
$localizationService = new LocalizationService(GROCY_CULTURE);
$this->LocalizationService = $localizationService;
$applicationService = new ApplicationService();
$versionInfo = $applicationService->GetInstalledVersion();
$container->view->set('version', $versionInfo->Version);
$container->view->set('releaseDate', $versionInfo->ReleaseDate);
$localizationService = new LocalizationService(CULTURE);
$container->view->set('localizationStrings', $localizationService->GetCurrentCultureLocalizations());
$container->view->set('L', function($text, ...$placeholderValues) use($localizationService)
{
@@ -33,4 +35,5 @@ class BaseController
protected $AppContainer;
protected $Database;
protected $LocalizationService;
}

View File

@@ -17,7 +17,7 @@ class BatteriesApiController extends BaseApiController
public function TrackChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$trackedTime = date('Y-m-d H:i:s');
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']))
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
{
$trackedTime = $request->getQueryParams()['tracked_time'];
}
@@ -44,4 +44,9 @@ class BatteriesApiController extends BaseApiController
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->ApiResponse($this->BatteriesService->GetCurrent());
}
}

View File

@@ -16,36 +16,24 @@ class BatteriesController extends BaseController
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$nextChargeTimes = array();
foreach($this->Database->batteries() as $battery)
{
$nextChargeTimes[$battery->id] = $this->BatteriesService->GetNextChargeTime($battery->id);
}
$nextXDays = 5;
$countDueNextXDays = count(FindAllItemsInArrayByValue($nextChargeTimes, date('Y-m-d', strtotime("+$nextXDays days")), '<'));
$countOverdue = count(FindAllItemsInArrayByValue($nextChargeTimes, date('Y-m-d', strtotime('-1 days')), '<'));
return $this->AppContainer->view->render($response, 'batteriesoverview', [
'batteries' => $this->Database->batteries(),
'batteries' => $this->Database->batteries()->orderBy('name'),
'current' => $this->BatteriesService->GetCurrent(),
'nextChargeTimes' => $nextChargeTimes,
'nextXDays' => $nextXDays,
'countDueNextXDays' => $countDueNextXDays - $countOverdue,
'countOverdue' => $countOverdue
'nextXDays' => 5
]);
}
public function TrackChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'batterytracking', [
'batteries' => $this->Database->batteries()
'batteries' => $this->Database->batteries()->orderBy('name')
]);
}
public function BatteriesList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'batteries', [
'batteries' => $this->Database->batteries()
'batteries' => $this->Database->batteries()->orderBy('name')
]);
}

View File

@@ -1,19 +0,0 @@
<?php
namespace Grocy\Controllers;
use \Grocy\Services\ApplicationService;
use \Grocy\Services\DatabaseMigrationService;
class CliController extends BaseController
{
public function RecreateDemo(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$applicationService = new ApplicationService();
if ($applicationService->IsDemoInstallation())
{
$databaseMigrationService = new DatabaseMigrationService();
$databaseMigrationService->RecreateDemo();
}
}
}

View File

@@ -17,14 +17,20 @@ class HabitsApiController extends BaseApiController
public function TrackHabitExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$trackedTime = date('Y-m-d H:i:s');
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']))
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
{
$trackedTime = $request->getQueryParams()['tracked_time'];
}
$doneBy = GROCY_USER_ID;
if (isset($request->getQueryParams()['done_by']) && !empty($request->getQueryParams()['done_by']))
{
$doneBy = $request->getQueryParams()['done_by'];
}
try
{
$this->HabitsService->TrackHabit($args['habitId'], $trackedTime);
$this->HabitsService->TrackHabit($args['habitId'], $trackedTime, $doneBy);
return $this->VoidApiActionResponse($response);
}
catch (\Exception $ex)
@@ -44,4 +50,9 @@ class HabitsApiController extends BaseApiController
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->ApiResponse($this->HabitsService->GetCurrent());
}
}

View File

@@ -16,36 +16,34 @@ class HabitsController extends BaseController
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$nextHabitTimes = array();
foreach($this->Database->habits() as $habit)
{
$nextHabitTimes[$habit->id] = $this->HabitsService->GetNextHabitTime($habit->id);
}
$nextXDays = 5;
$countDueNextXDays = count(FindAllItemsInArrayByValue($nextHabitTimes, date('Y-m-d', strtotime("+$nextXDays days")), '<'));
$countOverdue = count(FindAllItemsInArrayByValue($nextHabitTimes, date('Y-m-d', strtotime('-1 days')), '<'));
return $this->AppContainer->view->render($response, 'habitsoverview', [
'habits' => $this->Database->habits(),
'currentHabits' => $this->HabitsService->GetCurrentHabits(),
'nextHabitTimes' => $nextHabitTimes,
'nextXDays' => $nextXDays,
'countDueNextXDays' => $countDueNextXDays - $countOverdue,
'countOverdue' => $countOverdue
'habits' => $this->Database->habits()->orderBy('name'),
'currentHabits' => $this->HabitsService->GetCurrent(),
'nextXDays' => 5
]);
}
public function TrackHabitExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'habittracking', [
'habits' => $this->Database->habits()
'habits' => $this->Database->habits()->orderBy('name'),
'users' => $this->Database->users()->orderBy('username')
]);
}
public function HabitsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'habits', [
'habits' => $this->Database->habits()
'habits' => $this->Database->habits()->orderBy('name')
]);
}
public function Analysis(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'habitsanalysis', [
'habitsLog' => $this->Database->habits_log()->orderBy('tracked_time', 'DESC'),
'habits' => $this->Database->habits()->orderBy('name'),
'users' => $this->Database->users()->orderBy('username')
]);
}

View File

@@ -3,7 +3,6 @@
namespace Grocy\Controllers;
use \Grocy\Services\SessionService;
use \Grocy\Services\ApplicationService;
use \Grocy\Services\DatabaseMigrationService;
use \Grocy\Services\DemoDataGeneratorService;
@@ -24,11 +23,21 @@ class LoginController extends BaseController
$postParams = $request->getParsedBody();
if (isset($postParams['username']) && isset($postParams['password']))
{
if ($postParams['username'] === HTTP_USER && $postParams['password'] === HTTP_PASSWORD)
$user = $this->Database->users()->where('username', $postParams['username'])->fetch();
$inputPassword = $postParams['password'];
if ($user !== null && password_verify($inputPassword, $user->password))
{
$sessionKey = $this->SessionService->CreateSession();
$sessionKey = $this->SessionService->CreateSession($user->id);
setcookie($this->SessionCookieName, $sessionKey, time() + 31536000); // Cookie expires in 1 year, but session validity is up to SessionService
if (password_needs_rehash($user->password, PASSWORD_DEFAULT))
{
$user->update(array(
'password' => password_hash($inputPassword, PASSWORD_DEFAULT)
));
}
return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/'));
}
else
@@ -59,8 +68,7 @@ class LoginController extends BaseController
$databaseMigrationService = new DatabaseMigrationService();
$databaseMigrationService->MigrateDatabase();
$applicationService = new ApplicationService();
if ($applicationService->IsDemoInstallation())
if (GROCY_IS_DEMO_INSTALL)
{
$demoDataGeneratorService = new DemoDataGeneratorService();
$demoDataGeneratorService->PopulateDemoData();

View File

@@ -35,7 +35,8 @@ class OpenApiController extends BaseApiController
public function ApiKeysList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'manageapikeys', [
'apiKeys' => $this->Database->api_keys()
'apiKeys' => $this->Database->api_keys(),
'users' => $this->Database->users()
]);
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Grocy\Controllers;
use \Grocy\Services\RecipesService;
class RecipesApiController extends BaseApiController
{
public function __construct(\Slim\Container $container)
{
parent::__construct($container);
$this->RecipesService = new RecipesService();
}
protected $RecipesService;
public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId']);
return $this->VoidApiActionResponse($response);
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Grocy\Controllers;
use \Grocy\Services\RecipesService;
class RecipesController extends BaseController
{
public function __construct(\Slim\Container $container)
{
parent::__construct($container);
$this->RecipesService = new RecipesService();
}
protected $RecipesService;
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$recipes = $this->Database->recipes()->orderBy('name');
$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']);
}
else
{
foreach ($recipes as $recipe)
{
$selectedRecipe = $recipe;
$selectedRecipePositions = $this->Database->recipes_pos()->where('recipe_id', $recipe->id);
break;
}
}
return $this->AppContainer->view->render($response, 'recipes', [
'recipes' => $recipes,
'recipesFulfillment' => $this->RecipesService->GetRecipesFulfillment(),
'recipesSumFulfillment' => $this->RecipesService->GetRecipesSumFulfillment(),
'selectedRecipe' => $selectedRecipe,
'selectedRecipePositions' => $selectedRecipePositions,
'products' => $this->Database->products(),
'quantityunits' => $this->Database->quantity_units()
]);
}
public function RecipeEditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$recipeId = $args['recipeId'];
if ($recipeId == 'new')
{
$newRecipe = $this->Database->recipes()->createRow(array(
'name' => $this->LocalizationService->Localize('New recipe')
));
$newRecipe->save();
$recipeId = $this->Database->lastInsertId();
}
return $this->AppContainer->view->render($response, 'recipeform', [
'recipe' => $this->Database->recipes($recipeId),
'recipePositions' => $this->Database->recipes_pos()->where('recipe_id', $recipeId),
'mode' => 'edit',
'products' => $this->Database->products(),
'quantityunits' => $this->Database->quantity_units(),
'recipesFulfillment' => $this->RecipesService->GetRecipesFulfillment(),
'recipesSumFulfillment' => $this->RecipesService->GetRecipesSumFulfillment()
]);
}
public function RecipePosEditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
if ($args['recipePosId'] == 'new')
{
return $this->AppContainer->view->render($response, 'recipeposform', [
'mode' => 'create',
'recipe' => $this->Database->recipes($args['recipeId']),
'products' => $this->Database->products()->orderBy('name')
]);
}
else
{
return $this->AppContainer->view->render($response, 'recipeposform', [
'mode' => 'edit',
'recipe' => $this->Database->recipes($args['recipeId']),
'recipePos' => $this->Database->recipes_pos($args['recipePosId']),
'products' => $this->Database->products()->orderBy('name')
]);
}
}
}

View File

@@ -26,14 +26,32 @@ class StockApiController extends BaseApiController
}
}
public function ProductPriceHistory(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
try
{
return $this->ApiResponse($this->StockService->GetProductPriceHistory($args['productId']));
}
catch (\Exception $ex)
{
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function AddProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$bestBeforeDate = date('Y-m-d');
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']))
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']) && IsIsoDate($request->getQueryParams()['bestbeforedate']))
{
$bestBeforeDate = $request->getQueryParams()['bestbeforedate'];
}
$price = null;
if (isset($request->getQueryParams()['price']) && !empty($request->getQueryParams()['price']) && is_numeric($request->getQueryParams()['price']))
{
$price = $request->getQueryParams()['price'];
}
$transactionType = StockService::TRANSACTION_TYPE_PURCHASE;
if (isset($request->getQueryParams()['transactiontype']) && !empty($request->getQueryParams()['transactiontype']))
{
@@ -42,7 +60,7 @@ class StockApiController extends BaseApiController
try
{
$this->StockService->AddProduct($args['productId'], $args['amount'], $bestBeforeDate, $transactionType);
$this->StockService->AddProduct($args['productId'], $args['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price);
return $this->VoidApiActionResponse($response);
}
catch (\Exception $ex)
@@ -79,7 +97,7 @@ class StockApiController extends BaseApiController
public function InventoryProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$bestBeforeDate = date('Y-m-d');
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']))
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']) && IsIsoDate($request->getQueryParams()['bestbeforedate']))
{
$bestBeforeDate = $request->getQueryParams()['bestbeforedate'];
}
@@ -100,12 +118,36 @@ class StockApiController extends BaseApiController
return $this->ApiResponse($this->StockService->GetCurrentStock());
}
public function CurrentVolatilStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$nextXDays = 5;
if (isset($request->getQueryParams()['expiring_days']) && !empty($request->getQueryParams()['expiring_days']) && is_numeric($request->getQueryParams()['expiring_days']))
{
$nextXDays = $request->getQueryParams()['expiring_days'];
}
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays);
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
$missingProducts = $this->StockService->GetMissingProducts();
return $this->ApiResponse(array(
'expiring_products' => $expiringProducts,
'expired_products' => $expiredProducts,
'missing_products' => $missingProducts
));
}
public function AddMissingProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$this->StockService->AddMissingProductsToShoppingList();
return $this->VoidApiActionResponse($response);
}
public function ClearShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$this->StockService->ClearShoppingList();
return $this->VoidApiActionResponse($response);
}
public function ExternalBarcodeLookup(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
try

View File

@@ -17,39 +17,34 @@ class StockController extends BaseController
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$currentStock = $this->StockService->GetCurrentStock();
$nextXDays = 5;
$countExpiringNextXDays = count(FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime('+5 days')), '<'));
$countAlreadyExpired = count(FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime('-1 days')), '<'));
return $this->AppContainer->view->render($response, 'stockoverview', [
'products' => $this->Database->products(),
'quantityunits' => $this->Database->quantity_units(),
'currentStock' => $currentStock,
'products' => $this->Database->products()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name'),
'locations' => $this->Database->locations()->orderBy('name'),
'currentStock' => $this->StockService->GetCurrentStock(),
'missingProducts' => $this->StockService->GetMissingProducts(),
'nextXDays' => $nextXDays,
'countExpiringNextXDays' => $countExpiringNextXDays,
'countAlreadyExpired' => $countAlreadyExpired
'nextXDays' => 5
]);
}
public function Purchase(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'purchase', [
'products' => $this->Database->products()
'products' => $this->Database->products()->orderBy('name')
]);
}
public function Consume(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'consume', [
'products' => $this->Database->products()
'products' => $this->Database->products()->orderBy('name')
]);
}
public function Inventory(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'inventory', [
'products' => $this->Database->products()
'products' => $this->Database->products()->orderBy('name')
]);
}
@@ -57,8 +52,8 @@ class StockController extends BaseController
{
return $this->AppContainer->view->render($response, 'shoppinglist', [
'listItems' => $this->Database->shopping_list(),
'products' => $this->Database->products(),
'quantityunits' => $this->Database->quantity_units(),
'products' => $this->Database->products()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name'),
'missingProducts' => $this->StockService->GetMissingProducts()
]);
}
@@ -66,23 +61,23 @@ class StockController extends BaseController
public function ProductsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'products', [
'products' => $this->Database->products(),
'locations' => $this->Database->locations(),
'quantityunits' => $this->Database->quantity_units()
'products' => $this->Database->products()->orderBy('name'),
'locations' => $this->Database->locations()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name')
]);
}
public function LocationsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'locations', [
'locations' => $this->Database->locations()
'locations' => $this->Database->locations()->orderBy('name')
]);
}
public function QuantityUnitsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'quantityunits', [
'quantityunits' => $this->Database->quantity_units()
'quantityunits' => $this->Database->quantity_units()->orderBy('name')
]);
}
@@ -91,8 +86,8 @@ class StockController extends BaseController
if ($args['productId'] == 'new')
{
return $this->AppContainer->view->render($response, 'productform', [
'locations' => $this->Database->locations(),
'quantityunits' => $this->Database->quantity_units(),
'locations' => $this->Database->locations()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name'),
'mode' => 'create'
]);
}
@@ -100,8 +95,8 @@ class StockController extends BaseController
{
return $this->AppContainer->view->render($response, 'productform', [
'product' => $this->Database->products($args['productId']),
'locations' => $this->Database->locations(),
'quantityunits' => $this->Database->quantity_units(),
'locations' => $this->Database->locations()->orderBy('name'),
'quantityunits' => $this->Database->quantity_units()->orderBy('name'),
'mode' => 'edit'
]);
}
@@ -146,7 +141,7 @@ class StockController extends BaseController
if ($args['itemId'] == 'new')
{
return $this->AppContainer->view->render($response, 'shoppinglistform', [
'products' => $this->Database->products(),
'products' => $this->Database->products()->orderBy('name'),
'mode' => 'create'
]);
}
@@ -154,7 +149,7 @@ class StockController extends BaseController
{
return $this->AppContainer->view->render($response, 'shoppinglistform', [
'listItem' => $this->Database->shopping_list($args['itemId']),
'products' => $this->Database->products(),
'products' => $this->Database->products()->orderBy('name'),
'mode' => 'edit'
]);
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Grocy\Controllers;
use \Grocy\Services\UsersService;
class UsersApiController extends BaseApiController
{
public function __construct(\Slim\Container $container)
{
parent::__construct($container);
$this->UsersService = new UsersService();
}
protected $UsersService;
public function GetUsers(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
try
{
return $this->ApiResponse($this->UsersService->GetUsersAsDto());
}
catch (\Exception $ex)
{
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function CreateUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$requestBody = $request->getParsedBody();
try
{
$this->UsersService->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->ApiResponse(array('success' => true));
}
catch (\Exception $ex)
{
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function DeleteUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
try
{
$this->UsersService->DeleteUser($args['userId']);
return $this->ApiResponse(array('success' => true));
}
catch (\Exception $ex)
{
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
public function EditUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$requestBody = $request->getParsedBody();
try
{
$this->UsersService->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->ApiResponse(array('success' => true));
}
catch (\Exception $ex)
{
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Grocy\Controllers;
class UsersController extends BaseController
{
public function UsersList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->AppContainer->view->render($response, 'users', [
'users' => $this->Database->users()->orderBy('username')
]);
}
public function UserEditForm(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
if ($args['userId'] == 'new')
{
return $this->AppContainer->view->render($response, 'userform', [
'mode' => 'create'
]);
}
else
{
return $this->AppContainer->view->render($response, 'userform', [
'user' => $this->Database->users($args['userId']),
'mode' => 'edit'
]);
}
}
}

View File

@@ -9,7 +9,7 @@ class DemoBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
{
/*
To use this plugin, configure it in data/config.php like this:
define('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin');
Setting('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin');
*/
/*

View File

@@ -370,6 +370,173 @@
}
}
},
"/users/get": {
"get": {
"description": "Returns all users",
"tags": [
"User management"
],
"responses": {
"200": {
"description": "A list of user objects",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserDto"
}
}
}
}
},
"400": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse"
}
}
}
}
}
}
},
"/users/create": {
"post": {
"description": "Creates a new user",
"tags": [
"User management"
],
"requestBody": {
"description": "A valid user object",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"responses": {
"200": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VoidApiActionResponse"
}
}
}
},
"400": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse"
}
}
}
}
}
}
},
"/users/edit/{userId}": {
"post": {
"description": "Edits the given user",
"tags": [
"User management"
],
"parameters": [
{
"in": "path",
"name": "userId",
"required": true,
"description": "A valid user id",
"schema": {
"type": "integer"
}
}
],
"requestBody": {
"description": "A valid user object",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"responses": {
"200": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VoidApiActionResponse"
}
}
}
},
"400": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse"
}
}
}
}
}
}
},
"/users/delete/{userId}": {
"get": {
"description": "Deletes the given user",
"tags": [
"User management"
],
"parameters": [
{
"in": "path",
"name": "userId",
"required": true,
"description": "A valid user id",
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VoidApiActionResponse"
}
}
}
},
"400": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse"
}
}
}
}
}
}
},
"/stock/add-product/{productId}/{amount}": {
"get": {
"description": "Adds the the given amount of the given product to stock",
@@ -401,7 +568,18 @@
"required": false,
"description": "The best before date of the product to add, when omitted, the current date is used",
"schema": {
"type": "date"
"type": "string",
"format": "date"
}
},
{
"in": "query",
"name": "price",
"required": false,
"description": "The price per purchase quantity unit in configured currency",
"schema": {
"type": "number",
"format": "double"
}
},
{
@@ -538,7 +716,8 @@
"required": false,
"description": "The best before date which applies to added products",
"schema": {
"type": "date"
"type": "string",
"format": "date"
}
}
],
@@ -607,6 +786,50 @@
}
}
},
"/stock/get-product-price-history/{productId}": {
"get": {
"description": "Returns the price history of the given product",
"tags": [
"Stock"
],
"parameters": [
{
"in": "path",
"name": "productId",
"required": true,
"description": "A valid product id",
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "An array of ProductPriceHistory objects",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ProductPriceHistory"
}
}
}
}
},
"400": {
"description": "A VoidApiActionResponse object (possible errors are: Not existing product)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse"
}
}
}
}
}
}
},
"/stock/get-current-stock": {
"get": {
"description": "Returns all products which are currently in stock incl. the next expiring date per product",
@@ -621,7 +844,42 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Product"
"$ref": "#/components/schemas/CurrentStockResponse"
}
}
}
}
}
}
}
},
"/stock/get-current-volatil-stock": {
"get": {
"description": "Returns all products which are expiring soon, are already expired or currently missing",
"tags": [
"Stock"
],
"parameters": [
{
"in": "path",
"name": "expiring_days",
"required": false,
"description": "The number of days in which products are considered expiring soon",
"schema": {
"type": "integer",
"default": 5
}
}
],
"responses": {
"200": {
"description": "A CurrentVolatilStockResponse object",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CurrentVolatilStockResponse"
}
}
}
@@ -650,6 +908,26 @@
}
}
},
"/stock/clear-shopping-list": {
"get": {
"description": "Removes all items from the shopping list",
"tags": [
"Stock"
],
"responses": {
"200": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VoidApiActionResponse"
}
}
}
}
}
}
},
"/stock/external-barcode-lookup/{barcode}": {
"get": {
"description": "Executes an external barcode lookoup via the configured plugin with the given barcode",
@@ -701,6 +979,37 @@
}
}
},
"/recipes/add-not-fulfilled-products-to-shopping-list/{recipeId}": {
"get": {
"description": "Adds all missing products for the given recipe to the shopping list",
"tags": [
"Recipes"
],
"parameters": [
{
"in": "path",
"name": "recipeId",
"required": true,
"description": "A valid recipe id",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "A VoidApiActionResponse object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VoidApiActionResponse"
}
}
}
}
}
}
},
"/habits/track-habit-execution/{habitId}": {
"get": {
"description": "Tracks an execution of the given habit",
@@ -725,6 +1034,15 @@
"schema": {
"type": "date-time"
}
},
{
"in": "query",
"name": "done_by",
"required": false,
"description": "A valid user id of who executed this habit, when omitted, the currently authenticated user will be used",
"schema": {
"type": "integer"
}
}
],
"responses": {
@@ -792,6 +1110,29 @@
}
}
},
"/habits/get-current": {
"get": {
"description": "Returns all habits incl. the next estimated execution time per habit",
"tags": [
"Habits"
],
"responses": {
"200": {
"description": "An array of CurrentHabitResponse objects",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CurrentHabitResponse"
}
}
}
}
}
}
}
},
"/batteries/track-charge-cycle/{batteryId}": {
"get": {
"description": "Tracks a charge cycle of the given battery",
@@ -814,7 +1155,8 @@
"required": false,
"description": "The time of when the battery was charged, when omitted, the current time is used",
"schema": {
"type": "date-time"
"type": "string",
"format": "date-time"
}
}
],
@@ -882,6 +1224,29 @@
}
}
}
},
"/batteries/get-current": {
"get": {
"description": "Returns all batteries incl. the next estimated charge time per battery",
"tags": [
"Batteries"
],
"responses": {
"200": {
"description": "An array of CurrentBatteryResponse objects",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CurrentBatteryResponse"
}
}
}
}
}
}
}
}
},
"components": {
@@ -894,7 +1259,9 @@
"batteries",
"locations",
"quantity_units",
"shopping_list"
"shopping_list",
"recipes",
"recipes_pos"
]
},
"StockTransactionType": {
@@ -961,6 +1328,9 @@
"name": {
"type": "string"
},
"name_plural": {
"type": "string"
},
"description": {
"type": "string"
},
@@ -1043,6 +1413,19 @@
}
}
},
"ProductPriceHistory": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date-time"
},
"price": {
"type": "number",
"format": "double"
}
}
},
"ExternalBarcodeLookupResponse": {
"type": "object",
"properties": {
@@ -1086,6 +1469,9 @@
"track_count": {
"type": "integer",
"description": "How often this habit was tracked so far"
},
"last_done_by": {
"$ref": "#/components/schemas/UserDto"
}
}
},
@@ -1129,6 +1515,55 @@
}
}
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"password": {
"type": "string"
},
"row_created_timestamp": {
"type": "string",
"format": "date-time"
}
}
},
"UserDto": {
"type": "object",
"description": "A user object without the *password* and with an additional *display_name* property",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"display_name": {
"type": "string"
},
"row_created_timestamp": {
"type": "string",
"format": "date-time"
}
}
},
"ApiKey": {
"type": "object",
"properties": {
@@ -1354,10 +1789,68 @@
"type": "integer"
},
"best_before_date": {
"type": "date",
"type": "string",
"format": "date",
"description": "The next best before date for this product"
}
}
},
"CurrentHabitResponse": {
"type": "object",
"properties": {
"habit_id": {
"type": "integer"
},
"last_tracked_time": {
"type": "string",
"format": "date-time"
},
"next_estimated_execution_time": {
"type": "string",
"format": "date-time",
"description": "The next estimated execution time of this habit, 2999-12-31 23:59:59 when the given habit has a period_type of manually"
}
}
},
"CurrentBatteryResponse": {
"type": "object",
"properties": {
"battery_id": {
"type": "integer"
},
"last_tracked_time": {
"type": "string",
"format": "date-time"
},
"next_estimated_charge_time": {
"type": "string",
"format": "date-time",
"description": "The next estimated charge time of this battery, 2999-12-31 23:59:59 when the given battery has no charge_interval_days defined"
}
}
},
"CurrentVolatilStockResponse": {
"type": "object",
"properties": {
"expiring_products": {
"type": "array",
"items":{
"$ref": "#/components/schemas/Product"
}
},
"expired_products": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Product"
}
},
"missing_products": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Product"
}
}
}
}
},
"examples": {

View File

@@ -20,7 +20,7 @@ class UrlManager
public function ConstructUrl($relativePath, $isResource = false)
{
if (DISABLE_URL_REWRITING === false || $isResource === true)
if (GROCY_DISABLE_URL_REWRITING === false || $isResource === true)
{
return rtrim($this->BasePath, '/') . $relativePath;
}

View File

@@ -110,3 +110,71 @@ function IsAssociativeArray(array $array)
$keys = array_keys($array);
return array_keys($keys) !== $keys;
}
function IsIsoDate($dateString)
{
$d = DateTime::createFromFormat('Y-m-d', $dateString);
return $d && $d->format('Y-m-d') === $dateString;
}
function IsIsoDateTime($dateTimeString)
{
$d = DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeString);
return $d && $d->format('Y-m-d H:i:s') === $dateTimeString;
}
function BoolToString(bool $bool)
{
return $bool ? 'true' : 'false';
}
function Setting(string $name, $value)
{
if (!defined('GROCY_' . $name))
{
// The content of a $name.txt file in /data/settingoverrides can overwrite the given setting (for embedded mode)
$settingOverrideFile = GROCY_DATAPATH . '/settingoverrides/' . $name . '.txt';
if (file_exists($settingOverrideFile))
{
define('GROCY_' . $name, file_get_contents($settingOverrideFile));
}
else
{
define('GROCY_' . $name, $value);
}
}
}
function GetUserDisplayName($user)
{
$displayName = '';
if (empty($user->first_name) && !empty($user->last_name))
{
$displayName = $user->last_name;
}
elseif (empty($user->last_name) && !empty($user->first_name))
{
$displayName = $user->first_name;
}
elseif (!empty($user->last_name) && !empty($user->first_name))
{
$displayName = $user->first_name . ' ' . $user->last_name;
}
else
{
$displayName = $user->username;
}
return $displayName;
}
function Pluralize($number, $singularForm, $pluralForm)
{
$text = $singularForm;
if ($number != 1 && $pluralForm !== null && !empty($pluralForm))
{
$text = $pluralForm;
}
return $text;
}

View File

@@ -2,7 +2,6 @@
return array(
'Stock overview' => 'Bestand',
'#1 products with #2 units in stock' => '#1 Produkte (#2 Einheiten) vorrätig',
'#1 products expiring within the next #2 days' => '#1 Produkte laufen innerhalb der nächsten #2 Tage ab',
'#1 products are already expired' => '#1 Produkte sind bereits abgelaufen',
'#1 products are below defined min. stock amount' => '#1 Produkte sind unter Mindestbestand',
@@ -129,6 +128,83 @@ return array(
'All' => 'Alle',
'Track charge cycle of battery #1' => 'Erfasse einen Ladezyklus für Batterie #1',
'Track execution of habit #1' => 'Erfasse eine Ausführung von #1',
'Filter by location' => 'Nach Standort filtern',
'Search' => 'Suche',
'Not logged in' => 'Nicht angemeldet',
'You have to select a product' => 'Ein Produkt muss ausgewählt werden',
'You have to select a habit' => 'Eine Gewohnheit muss ausgewählt werden',
'You have to select a battery' => 'Eine Batterie muss ausgewählt werden',
'A name is required' => 'Ein Name ist erforderlich',
'A location is required' => 'Ein Standort ist erforderlich',
'The amount cannot be lower than #1' => 'Die Menge darf nicht kleiner als #1 sein',
'This cannot be negative' => 'Dies darf nicht negativ sein',
'A quantity unit is required' => 'Eine Mengeneinheit muss ausgewählt werden',
'A period type is required' => 'Eine Periodentyp muss ausgewählt werden',
'A best before date is required and must be later than today' => 'Ein Mindesthaltbarkeitsdatum ist erforderlich und muss später als heute sein',
'Settings' => 'Einstellungen',
'This can only be before now' => 'Dies kann nur vor jetzt sein',
'Calendar' => 'Kalender',
'Recipes' => 'Rezepte',
'Edit recipe' => 'Rezept bearbeiten',
'New recipe' => 'Neues Rezept',
'Ingredients list' => 'Zutatenliste',
'Add recipe ingredient' => 'Rezeptzutat hinzufügen',
'Edit recipe ingredient' => 'Rezeptzutat bearbeiten',
'Are you sure to delete recipe "#1"?' => 'Rezept "#1" wirklich löschen?',
'Are you sure to delete recipe ingredient "#1"?' => 'Rezeptzutat "#1" wirklich löschen?',
'Are you sure to empty the shopping list?' => 'Sicher, dass den Einkaufszettel geleert werden soll?',
'Clear list' => 'Liste leeren',
'Requirements fulfilled' => 'Bedarf im Bestand',
'Put missing products on shopping list' => 'Fehlende Produkte auf den Einkaufszettel setzen',
'Not enough in stock, #1 ingredients missing' => 'Nicht ausreichend im Bestand, #1 Zutaten fehlen',
'Enough in stock' => 'Bestand reicht aus',
'Not enough in stock, #1 ingredients missing but already on the shopping list' => 'Bestand nicht ausreichend, #1 Zutaten fehlen, stehen aber bereits auf dem Einkaufszettel',
'Expand to fullscreen' => 'Auf ganzen Bildschirm vergrößern',
'Ingredients' => 'Zutaten',
'Preparation' => 'Zubereitung',
'Recipe' => 'Rezept',
'Not enough in stock, #1 missing, #2 already on shopping list' => 'Nicht ausreichend im Bestand, #1 fehlen, #2 stehen bereits auf dem Einkaufszettel',
'Show notes' => 'Notizen anzeigen',
'Put missing amount on shopping list' => 'Fehlende Menge auf den Einkaufszettel setzen',
'Are you sure to put all missing ingredients for recipe "#1" on the shopping list?' => 'Sicher alle fehlenden Zutaten für Rezept "#1" auf die Einkaufsliste zu setzen?',
'Added for recipe #1' => 'Hinzugefügt für Rezept #1',
'Manage users' => 'Benutzer verwalten',
'User' => 'Benutzer',
'Users' => 'Benutzer',
'Are you sure to delete user "#1"?' => 'Benutzer "#1" wirklich löschen?',
'Create user' => 'Benutzer erstellen',
'Edit user' => 'Benutzer bearbeiten',
'First name' => 'Vorname',
'Last name' => 'Nachname',
'A username is required' => 'Ein Benutzername ist erforderlich',
'Confirm password' => 'Passwort bestätigen',
'Passwords do not match' => 'Passwörter stimmen nicht überein',
'Change password' => 'Passwort ändern',
'Done by' => 'Ausgeführt von',
'Last done by' => 'Zuletzt ausgeführt von',
'Unknown' => 'Unbekannt',
'Filter by habit' => 'Nach Gewohnheit filtern',
'Habits analysis' => 'Gewohnheiten Analyse',
'0 means suggestions for the next charge cycle are disabled' => '0 bedeutet dass Vorschläge für den nächsten Ladezyklus deaktiviert sind',
'Charge cycle interval (days)' => 'Ladezyklusintervall (Tage)',
'Last price' => 'Letzter Preis',
'Price history' => 'Preisentwicklung',
'No price history available' => 'Keine Preisdaten verfügbar',
'Price' => 'Preis',
'in #1 per purchase quantity unit' => 'in #1 pro Einkaufsmengeneinheit',
'The price cannot be lower than #1' => 'Der Preis darf nicht niedriger als #1 sein',
'#1 product expires within the next #2 days' => '#1 Produkt läuft innerhalb der nächsten #2 Tage ab',
'#1 product is already expired' => '#1 Produkt ist bereits abgelaufen',
'#1 product is below defined min. stock amount' => '#1 Produkt ist unter Mindestbestand',
'Unit' => 'Einheit',
'Units' => 'Einheiten',
'#1 habit is due to be done within the next #2 days' => '#1 Gewohnheit steht in den nächsten #2 Tagen an',
'#1 habit is overdue to be done' => '#1 Gewohnheit ist überfällig',
'#1 battery is due to be charged within the next #2 days' => '#1 Batterie muss in den nächsten #2 Tagen geladen werden',
'#1 battery is overdue to be charged' => '#1 Batterie ist überfällig',
'#1 unit was automatically added and will apply in addition to the amount entered here' => '#1 Einheit wurde automatisch hinzugefügt und gilt zusätzlich der hier eingegebenen Menge',
'in singular form' => 'in der Einzahl',
'in plural form' => 'in der Mehrzahl',
//Constants
'manually' => 'Manuell',
@@ -138,7 +214,6 @@ return array(
'timeago_locale' => 'de',
'timeago_nan' => 'vor NaN Jahren',
'moment_locale' => 'de',
'bootstrap_datepicker_locale' => 'de',
'datatables_localization' => '{"sEmptyTable":"Keine Daten in der Tabelle vorhanden","sInfo":"_START_ bis _END_ von _TOTAL_ Einträgen","sInfoEmpty":"Keine Daten vorhanden","sInfoFiltered":"(gefiltert von _MAX_ Einträgen)","sInfoPostFix":"","sInfoThousands":".","sLengthMenu":"_MENU_ Einträge anzeigen","sLoadingRecords":"Wird geladen ..","sProcessing":"Bitte warten ..","sSearch":"Suchen","sZeroRecords":"Keine Einträge vorhanden","oPaginate":{"sFirst":"Erste","sPrevious":"Zurück","sNext":"Nächste","sLast":"Letzte"},"oAria":{"sSortAscending":": aktivieren, um Spalte aufsteigend zu sortieren","sSortDescending":": aktivieren, um Spalte absteigend zu sortieren"},"select":{"rows":{"0":"Zum Auswählen auf eine Zeile klicken","1":"1 Zeile ausgewählt","_":"%d Zeilen ausgewählt"}},"buttons":{"print":"Drucken","colvis":"Spalten","copy":"Kopieren","copyTitle":"In Zwischenablage kopieren","copyKeys":"Taste <i>ctrl</i> oder <i>⌘</i> + <i>C</i> um Tabelle<br>in Zwischenspeicher zu kopieren.<br><br>Um abzubrechen die Nachricht anklicken oder Escape drücken.","copySuccess":{"1":"1 Spalte kopiert","_":"%d Spalten kopiert"}}}',
//Demo data
@@ -149,11 +224,17 @@ return array(
'Tinned food cupboard' => 'Konservenschrank',
'Fridge' => 'Kühlschrank',
'Piece' => 'Stück',
'Pieces' => 'Stücke',
'Pack' => 'Packung',
'Packs' => 'Packungen',
'Glass' => 'Glas',
'Glasses' => 'Gläser',
'Tin' => 'Dose',
'Tins' => 'Dosen',
'Can' => 'Becher',
'Cans' => 'Becher',
'Bunch' => 'Bund',
'Bunches' => 'Bunde',
'Gummy bears' => 'Gummibärchen',
'Crisps' => 'Chips',
'Eggs' => 'Eier',
@@ -172,5 +253,21 @@ return array(
'Warranty ends' => 'Garantie endet',
'TV remote control' => 'TV Fernbedienung',
'Alarm clock' => 'Wecker',
'Heat remote control' => 'Fernbedienung Heizung'
'Heat remote control' => 'Fernbedienung Heizung',
'Lawn mowed in the garden' => 'Rasen im Garten gemäht',
'Some good snacks' => 'Paar gute Snacks',
'Pizza dough' => 'Pizzateig',
'Sieved tomatoes' => 'Passierte Tomaten',
'Salami' => 'Salami',
'Toast' => 'Toast',
'Minced meat' => 'Hackfleisch',
'Pizza' => 'Pizza',
'Spaghetti bolognese' => 'Spaghetti Bolognese',
'Sandwiches' => 'Belegte Toasts',
'English' => 'Englisch',
'German' => 'Deutsch',
'Italian' => 'Italienisch',
'Demo in different language' => 'Demo in anderer Sprache',
'This is the note content of the recipe ingredient' => 'Dies ist der Inhalt der Notiz der Zutat',
'Demo User' => 'Demo Benutzer'
);

View File

@@ -9,6 +9,5 @@ return array(
'timeago_locale' => 'en',
'timeago_nan' => 'NaN years ago',
'moment_locale' => '',
'bootstrap_datepicker_locale' => '',
'datatables_localization' => '{"sEmptyTable":"No data available in table","sInfo":"Showing _START_ to _END_ of _TOTAL_ entries","sInfoEmpty":"Showing 0 to 0 of 0 entries","sInfoFiltered":"(filtered from _MAX_ total entries)","sInfoPostFix":"","sInfoThousands":",","sLengthMenu":"Show _MENU_ entries","sLoadingRecords":"Loading...","sProcessing":"Processing...","sSearch":"Search:","sZeroRecords":"No matching records found","oPaginate":{"sFirst":"First","sLast":"Last","sNext":"Next","sPrevious":"Previous"},"oAria":{"sSortAscending":": activate to sort column ascending","sSortDescending":": activate to sort column descending"}}'
);

192
localization/it.php Normal file
View File

@@ -0,0 +1,192 @@
<?php
return array(
'Stock overview' => 'Dispensa',
'#1 products expiring within the next #2 days' => '#1 prodotti scadranno tra #2 giorni',
'#1 products are already expired' => '#1 prodotti scaduti',
'#1 products are below defined min. stock amount' => '#1 prodotti sotto il limite minimo',
'Product' => 'prodotto',
'Amount' => 'quantità',
'Next best before date' => 'Prossima data di scadenza',
'Logout' => 'Logout',
'Habits overview' => 'Riepilogo delle abitudini',
'Batteries overview' => 'Riepilogo delle batterie',
'Purchase' => 'Acquisti',
'Consume' => 'Consumi',
'Inventory' => 'Inventario',
'Shopping list' => 'Lista della spesa',
'Habit tracking' => 'Dati abitudini',
'Battery tracking' => 'Dati batterie',
'Products' => 'Prodotti',
'Locations' => 'Posizioni',
'Quantity units' => 'Unità di misura',
'Habits' => 'Abitudini',
'Batteries' => 'Batterie',
'Habit' => 'Abitudine',
'Next estimated tracking' => 'Prossima esecuzione',
'Last tracked' => 'Ultima esecuzione',
'Battery' => 'Batterie',
'Last charged' => 'Ultima ricarica',
'Next planned charge cycle' => 'Prossima ricarica',
'Best before' => 'Data di scadenza',
'OK' => 'OK',
'Product overview' => 'Riepilogo dei prodotti',
'Stock quantity unit' => 'Unità di misura',
'Stock amount' => 'Quantità',
'Last purchased' => 'Ultimo acquisto',
'Last used' => 'Ultimo utilizzo',
'Spoiled' => 'Scaduto',
'Barcode lookup is disabled' => 'I codici a barre sono disabilitati',
'will be added to the list of barcodes for the selected product on submit' => 'sarà aggiunto alla lista dei codici a barre per questo prodotto',
'New amount' => 'Nuova quantità',
'Note' => 'Nota',
'Tracked time' => 'Ora di esecuzione',
'Habit overview' => 'Riepilogo dell\'abitudine',
'Tracked count' => 'Numero di esecuzioni',
'Battery overview' => 'Riepilogo della batteria',
'Charge cycles count' => 'Numero di ricariche',
'Create shopping list item' => 'Aggiungi un prodotto alla lista della spesa',
'Edit shopping list item' => 'Modifica un\'entrata della lista della spesa',
'#1 units were automatically added and will apply in addition to the amount entered here' => '#1 sono state aggiunte automaticamente',
'Save' => 'Salva',
'Add' => 'Aggiungi',
'Name' => 'Nome',
'Location' => 'Posizione',
'Min. stock amount' => 'Quantità minima',
'QU purchase' => 'Unità di acquisto',
'QU stock' => 'Unità di dispensa',
'QU factor' => 'Fattore di conversione',
'Description' => 'Descrizione',
'Create product' => 'Aggiungi prodotto',
'Barcode(s)' => 'Codice a barre',
'Minimum stock amount' => 'Quantità minima',
'Default best before days' => 'Data di scadenza standard in giorni',
'Quantity unit purchase' => 'Unità di acquisto',
'Quantity unit stock' => 'Unità di dispensa',
'Factor purchase to stock quantity unit' => 'Fattore di conversione tra quantità di acquisto e di dispensa',
'Create location' => 'Aggiungi posizione',
'Create quantity unit' => 'Aggiungi unità di misura',
'Period type' => 'Tipo di ripetizione',
'Period days' => 'Periodo in giorni',
'Create habit' => 'Aggiungi abitudine',
'Used in' => 'Usato in',
'Create battery' => 'Aggiungi batteria',
'Edit battery' => 'Modifica batteria',
'Edit habit' => 'Modifica abitudine',
'Edit quantity unit' => 'Modifica unità di misura',
'Edit product' => 'Modifica prodotto',
'Edit location' => 'Modifica posizione',
'Record data' => 'Registra dati',
'Manage master data' => 'Gestisci dati',
'This will apply to added products' => 'Verrà applicato ai prodotti aggiunti',
'never' => 'mai',
'Add products that are below defined min. stock amount' => 'Aggiungi prodotti sotti il limite minimo',
'For purchases this amount of days will be added to today for the best before date suggestion' => 'Questo numero di giorni verrà aggiunto alla data di acquisto per la data di scadenza',
'This means 1 #1 purchased will be converted into #2 #3 in stock' => 'Questo significa che 1 #1 acquistato diventerà #2 #3 in dispensa',
'Login' => 'Login',
'Username' => 'Username',
'Password' => 'Password',
'Invalid credentials, please try again' => 'Credenziali non valide, per favore riprova',
'Are you sure to delete battery "#1"?' => 'Sei sicuro di voler eliminare la batteria "#1"?',
'Yes' => 'Si',
'No' => 'No',
'Are you sure to delete habit "#1"?' => 'Sei sicuro di voler eliminare l\'abitudine "#1"?',
'"#1" could not be resolved to a product, how do you want to proceed?' => '"#1" non è stato associato a nessun prodotto, vuoi procedere?',
'Create or assign product' => 'Aggiungi o assegna prodotto',
'Cancel' => 'Annulla',
'Add as new product' => 'Aggiungi come nuovo prodotto',
'Add as barcode to existing product' => 'Assegna il codice a barre ad un prodotto',
'Add as new product and prefill barcode' => 'Aggiungi come nuovo prodotto ed assegna il codice a barre',
'Are you sure to delete quantity unit "#1"?' => 'Sei sicuro di voler eliminare l\'unità di misura "#1"?',
'Are you sure to delete product "#1"?' => 'Sei sicuro di voler eliminare il prodotto "#1"?',
'Are you sure to delete location "#1"?' => 'Sei sicuro di voler eliminare la posizione "#1"?',
'Manage API keys' => 'Gestisci le chiavi API',
'REST API & data model documentation' => 'REST API & Documentazione del modello di dati',
'API keys' => 'Chiavi API',
'Create new API key' => 'Crea nuova chiave API',
'API key' => 'Chiave API',
'Expires' => 'Scade il',
'Created' => 'Creata il',
'This product is not in stock' => 'Questo prodotto non è in dispensa',
'This means #1 will be added to stock' => '#1 sarà aggiunto alla dispensa',
'This means #1 will be removed from stock' => '#1 sarà rimosso dalla dispensa',
'This means it is estimated that a new execution of this habit is tracked #1 days after the last was tracked' => 'L\'esecuzione dell\'abitudine è #1 giorni dopo la precedente',
'Removed #1 #2 of #3 from stock' => '#1 #2 su #3 rimossi dalla dispensa',
'About grocy' => 'Riguardo grocy',
'Close' => 'Chiudi',
'#1 batteries are due to be charged within the next #2 days' => '#1 batterie da ricaricare entro #2 giorni',
'#1 batteries are overdue to be charged' => '#1 batterie devono essere ricaricate',
'#1 habits are due to be done within the next #2 days' => '#1 abitudini da eseguire entro #2 giorni',
'#1 habits are overdue to be done' => '#1 abitudini da eseguire',
'Released on' => 'Rilasciato il',
'Consume #3 #1 of #2' => 'Consumati #3 #1 di #2',
'Added #1 #2 of #3 to stock' => 'Aggiunti #1 #2 di #3',
'Stock amount of #1 is now #2 #3' => 'La quantità in dispensa di #1 è ora #2 #3',
'Tracked execution of habit #1 on #2' => 'Esecuzione dell\'abitudine #1 registrata il #2',
'Tracked charge cylce of battery #1 on #2' => 'Ricarica della batteria #1 effettuata il #2',
'Consume all #1 which are currently in stock' => 'Consuma tutto #1 in dispensa',
'All' => 'Tutto',
'Track charge cycle of battery #1' => 'Registra la ricarica della batteria #1',
'Track execution of habit #1' => 'Registra l\'esecuzione dell\'abitudine #1',
'Filter by location' => 'Filtra per posizione',
'Search' => 'Cerca',
'Not logged in' => 'Non autenticato',
'You have to select a product' => 'Devi selezionare un prodotto',
'You have to select a habit' => 'Devi selezionare un\'abitudine',
'You have to select a battery' => 'Devi selezionare una batteria',
'A name is required' => 'Inserisci un nome',
'A location is required' => 'Inserisci la posizione',
'The amount cannot be lower than #1' => 'La quantità non può essere minore di #1',
'This cannot be negative' => 'Il numero non può essere negativo',
'A quantity unit is required' => 'Inserisci un\'unità di misura',
'A period type is required' => 'Seleziona un tipo di ripetizione',
//Constants
'manually' => 'Manualmente',
'dynamic-regular' => 'Regolatore dinamico',
//Technical component translations
'timeago_locale' => 'it',
'timeago_nan' => 'NaN anni fa',
'moment_locale' => 'it',
'datatables_localization' => '{"sEmptyTable":"Nessun dato disponibile","sInfo":"Mostrando da _START_ a _END_ di _TOTAL_ voci","sInfoEmpty":"Mostrando da 0 a 0 di 0 voci","sInfoFiltered":"(Filtrato da _MAX_ voci totali)","sInfoPostFix":"","sInfoThousands":",","sLengthMenu":"Mostra _MENU_ voci","sLoadingRecords":"Caricando...","sProcessing":"Calcolando...","sSearch":"Cerca:","sZeroRecords":"Nessun risultato trovato","oPaginate":{"sFirst":"Prima","sLast":"Ultima","sNext":"Prossima","sPrevious":"Precedente"},"oAria":{"sSortAscending":": ordine crescente","sSortDescending":": ordine decrescente"}}',
//Demo data
'Cookies' => 'Biscotti',
'Chocolate' => 'Cioccolato',
'Pantry' => 'Vorratskammer',
'Candy cupboard' => 'Süßigkeitenschrank',
'Tinned food cupboard' => 'Konservenschrank',
'Fridge' => 'Kühlschrank',
'Piece' => 'Pezzo',
'Pieces' => 'Pezzi',
'Pack' => 'Pacco',
'Packs' => 'Pacchi',
'Glass' => 'Bicchiere',
'Glasses' => 'Bicchieri',
'Tin' => 'Scatola',
'Tins' => 'Scatole',
'Can' => 'Lattina',
'Cans' => 'Lattine',
'Bunch' => 'Cespo',
'Bunches' => 'Cespi',
'Gummy bears' => 'Caramelle',
'Crisps' => 'Patatine',
'Eggs' => 'Uova',
'Noodles' => 'Spaghetti',
'Pickles' => 'Marmellata',
'Gulash soup' => 'Dado',
'Yogurt' => 'Yogurt',
'Cheese' => 'Parmigiano',
'Cold cuts' => 'Pancetta',
'Paprika' => 'Pepe',
'Cucumber' => 'Zucchine',
'Radish' => 'Radicchio',
'Tomato' => 'Pomodori',
'Changed towels in the bathroom' => 'Cambiare asciugamani in bagno',
'Cleaned the kitchen floor' => 'Pulire la cucina',
'Warranty ends' => 'Scadenza dalla garanzia',
'TV remote control' => 'Telecomando',
'Alarm clock' => 'Sveglia',
'Heat remote control' => 'Termostato'
);

267
localization/no.php Normal file
View File

@@ -0,0 +1,267 @@
<?php
return array(
'Stock overview' => 'Husholdning',
'#1 products expiring within the next #2 days' => '#1 Produkter som går ut på dato innen de neste #2 dagene',
'#1 products are already expired' => '#1 Produkt som har gått ut på dato',
'#1 products are below defined min. stock amount' => '#1 Produkt under minimum husholdningsnivå',
'Product' => 'Produkt',
'Amount' => 'Antall',
'Next best before date' => 'Kommende best før dato',
'Logout' => 'Logg ut',
'Habits overview' => 'Oversikt Husoppgaver',
'Batteries overview' => 'Oversikt Batteri',
'Purchase' => 'Innkjøp',
'Consume' => 'Forbrukt',
'Inventory' => 'Endre Husholdning',
'Shopping list' => 'Handleliste',
'Habit tracking' => 'Logge Husoppgaver',
'Battery tracking' => 'Batteri Ladesyklus',
'Products' => 'Produkter',
'Locations' => 'Lokasjoner',
'Quantity units' => 'Forpakning',
'Habits' => 'Husoppgaver',
'Batteries' => 'Batterier',
'Habit' => 'Husoppgave',
'Next estimated tracking' => 'Neste handling',
'Last tracked' => 'Sist logget',
'Battery' => 'Batteri',
'Last charged' => 'Sist ladet',
'Next planned charge cycle' => 'Neste planlagte ladesyklus',
'Best before' => 'Best før',
'OK' => 'OK',
'Product overview' => 'Oversikt Produkt',
'Stock quantity unit' => 'Forpakningstype i husholdningen',
'Stock amount' => 'Husholdning',
'Last purchased' => 'Sist kjøpt',
'Last used' => 'Sist brukt',
'Spoiled' => 'Produkt har gått ut på dato',
'Barcode lookup is disabled' => 'Strekkodesøk deaktivert',
'will be added to the list of barcodes for the selected product on submit' => 'Blir lagt til liste over strekkoder når produkt blir lagt inn.',
'New amount' => 'Nytt antall',
'Note' => 'Info',
'Tracked time' => 'Tid logget',
'Habit overview' => 'Oversikt Husoppgave',
'Tracked count' => 'Logget',
'Battery overview' => 'Batteri Oversikt',
'Charge cycles count' => 'Antall ladesykluser',
'Create shopping list item' => 'Opprett handelisteoppføring',
'Edit shopping list item' => 'Endre på handlelistoppføring',
'#1 units were automatically added and will apply in addition to the amount entered here' => '#1 enheter ble automatisk lagt til i tillegg til hva som blir skrevet inn her',
'Save' => 'Lagre',
'Add' => 'Legg til',
'Name' => 'Navn',
'Location' => 'Lokasjon',
'Min. stock amount' => 'Minimums antall for husholdingen',
'QU purchase' => 'FPK innkjøp',
'QU stock' => 'FPK husholdning',
'QU factor' => 'FPK faktor',
'Description' => 'Beskrivelse',
'Create product' => 'Opprett produkt',
'Barcode(s)' => 'Strekkode(r)',
'Minimum stock amount' => 'Minimums antall for husholdningen',
'Default best before days' => 'Standard antall dager best før',
'Quantity unit purchase' => 'Forpakning kjøpt',
'Quantity unit stock' => 'Forpakning husholdning',
'Factor purchase to stock quantity unit' => 'Innkjøpsfaktor for forpakning',
'Create location' => 'Opprett lokasjon',
'Create quantity unit' => 'Opprett forpakning',
'Period type' => 'Gjentakelse',
'Period days' => 'Dager for gjentakelse',
'Create habit' => 'Opprett husoppgave',
'Used in' => 'Brukt',
'Create battery' => 'Opprett batteri',
'Edit battery' => 'Endre batteri',
'Edit habit' => 'Endre husoppgave',
'Edit quantity unit' => 'Endre forpakning',
'Edit product' => 'Endre produkt',
'Edit location' => 'Endre lokasjon',
'Record data' => 'Logg handlinger',
'Manage master data' => 'Administrer masterdata',
'This will apply to added products' => 'Dette vil gjelde for produkt som blir lagt til',
'never' => 'aldri',
'Add products that are below defined min. stock amount' => 'Legg til produkt som er under definert minimums antall for husholdningen',
'For purchases this amount of days will be added to today for the best before date suggestion' => 'For innkjøp vil dette antallet dager legges til bestfør forslaget',
'This means 1 #1 purchased will be converted into #2 #3 in stock' => 'Dette betyr at 1 #1 innkjøp vil bli omgjort til #2 #3 husholdning',
'Login' => 'Logg inn',
'Username' => 'Brukernavn',
'Password' => 'Passord',
'Invalid credentials, please try again' => 'Feil brukernavn og/eller passord, prøv igjen',
'Are you sure to delete battery "#1"?' => 'Er du sikker du ønsker å slette Batteri "#1"?',
'Yes' => 'Ja',
'No' => 'Nei',
'Are you sure to delete habit "#1"?' => 'Er du sikker på du ønsker å slette husoppgave "#1"?',
'"#1" could not be resolved to a product, how do you want to proceed?' => '"#1" kunne ikke bli tildelt et produkt, hvordan ønsker du å fortsette?',
'Create or assign product' => 'Opprett eller tildel til produkt',
'Cancel' => 'Avbryt',
'Add as new product' => 'Legg til som nytt produkt',
'Add as barcode to existing product' => 'Legg til strekkode til allerede eksisterende produkt',
'Add as new product and prefill barcode' => 'Legg til som nytt produkt med forhåndsutfylt strekkode',
'Are you sure to delete quantity unit "#1"?' => 'Er du sikker du ønsker å slette forpakning "#1"?',
'Are you sure to delete product "#1"?' => 'Er du sikker du ønsker å slette produkt "#1"?',
'Are you sure to delete location "#1"?' => 'Er du sikker du ønsker å slette lokasjon "#1"?',
'Manage API keys' => 'Administrer API-Keys',
'REST API & data model documentation' => 'REST-API & Datamodell Dokumentasjon',
'API keys' => 'API-Keys',
'Create new API key' => 'Opprett ny API-Key',
'API key' => 'API-Key',
'Expires' => 'Går ut',
'Created' => 'Opprettet',
'This product is not in stock' => 'Dette produktet er ikke i husholdningen',
'This means #1 will be added to stock' => 'Dette betyr at #1 vil bli lagt til i husholdningen',
'This means #1 will be removed from stock' => 'Dette betyr at #1 vil bli fjernet fra husholdningen',
'This means it is estimated that a new execution of this habit is tracked #1 days after the last was tracked' => 'Dette betyr at det er estimert at den nye utførelsen av denne husoppgaven er logget #1 dag etter den sist var logget',
'Removed #1 #2 of #3 from stock' => 'Fjernet #1 #2 av #3 fra husholdningen',
'About grocy' => 'Om Grocy',
'Close' => 'Lukk',
'#1 batteries are due to be charged within the next #2 days' => '#1 Batteri må lades innen de #2 neste dagene',
'#1 batteries are overdue to be charged' => '#1 Batteri har gått over fristen for å bli ladet opp',
'#1 habits are due to be done within the next #2 days' => '#1 husoppgaver skal gjøres inne de #2 neste dagene',
'#1 habits are overdue to be done' => '#1 husoppgaver har gått over fristen for utførelse',
'Released on' => 'Utgitt',
'Consume #3 #1 of #2' => 'Forbruk #3 #1 #2',
'Added #1 #2 of #3 to stock' => '#1 #2 #3 lagt til i husholdningen',
'Stock amount of #1 is now #2 #3' => 'Husholdning antall #1 er nå #2 #3',
'Tracked execution of habit #1 on #2' => 'Logget utførelse av husoppgave "#1" den #2',
'Tracked charge cylce of battery #1 on #2' => 'Logget ladesyklus for batteri #1 og #2',
'Consume all #1 which are currently in stock' => 'Konsumér alle #1 som er i husholdningen',
'All' => 'Alle',
'Track charge cycle of battery #1' => 'Logg ladesyklus for batteri #1',
'Track execution of habit #1' => 'Logg utførelse av husoppgave #1',
'Filter by location' => 'Filtrér etter lokasjon',
'Search' => 'Søk',
'Not logged in' => 'Ikke logget inn',
'You have to select a product' => 'Du må velge et produkt',
'You have to select a habit' => 'Du må velge en husoppgaven',
'You have to select a battery' => 'Du må velge et batteri',
'A name is required' => 'Et navn kreves',
'A location is required' => 'En lokasjon kreves',
'The amount cannot be lower than #1' => 'Antallet kan ikke være lavere enn #1',
'This cannot be negative' => 'Dette kan ikke være negativt',
'A quantity unit is required' => 'Forpakning antall/størrelse kreves',
'A period type is required' => 'En periodetype kreves',
'A best before date is required and must be later than today' => 'En best før dato kreves, denne må være senere enn i dag',
'Settings' => 'Innstillinger',
'This can only be before now' => 'Dette kan kun være før nå',
'Calendar' => 'Kalender',
'Recipes' => 'Oppskrifter',
'Edit recipe' => 'Endre oppskrift',
'New recipe' => 'Ny oppskrift',
'Ingredients list' => 'Liste over ingredienser',
'Add recipe ingredient' => 'Legg ingrediens til oppskrift',
'Edit recipe ingredient' => 'Endre ingrediens i oppskrift',
'Are you sure to delete recipe "#1"?' => 'Er du sikker du ønsker å slette oppskrift "#1"?',
'Are you sure to delete recipe ingredient "#1"?' => 'Er du sikker du ønsker å slette ingrediens "#1" fra oppskriften?',
'Are you sure to empty the shopping list?' => 'Er du sikker du ønsker å slette handlelisten?',
'Clear list' => 'Tøm liste',
'Requirements fulfilled' => 'Krav oppfylt',
'Put missing products on shopping list' => 'Legg manglende produkter til handlelisten',
'Not enough in stock, #1 ingredients missing' => 'Ikke nok i husholdningen, #1 ingredienser mangler',
'Enough in stock' => 'Nok i husholdningen',
'Not enough in stock, #1 ingredients missing but already on the shopping list' => 'Ikke nok i husholdningen, #1 ingrediens mangler, men står allerede på handelisten',
'Expand to fullscreen' => 'Full skjerm',
'Ingredients' => 'Ingredienser',
'Preparation' => 'Forberedelse / Slik gjør du',
'Recipe' => 'Oppskrift',
'Not enough in stock, #1 missing, #2 already on shopping list' => 'Ikke nok i husholdningen, #1 mangler, #2 allerede i handlisten',
'Show notes' => 'Vis notater',
'Put missing amount on shopping list' => 'Legg manglende til handlelisten',
'Are you sure to put all missing ingredients for recipe "#1" on the shopping list?' => 'Er du sikker du ønsker å legge alle manglende ingredienser til oppskrift "#1"?',
'Added for recipe #1' => 'Lagt til oppskrift #1',
'Manage users' => 'Administrer brukere',
'User' => 'Bruker',
'Users' => 'Brukere',
'Are you sure to delete user "#1"?' => 'Er du sikker på du ønsker å slette bruker, "#1"?',
'Create user' => 'Legg til bruker',
'Edit user' => 'Endre på bruker',
'First name' => 'Fornavn',
'Last name' => 'Etternavn',
'A username is required' => 'Et brukernavn er nødvendig',
'Confirm password' => 'Bekreft passord',
'Passwords do not match' => 'Passord er ikke like',
'Change password' => 'Endre passord',
'Done by' => 'Utført av',
'Last done by' => 'Sist utført av',
'Unknown' => 'Ukjent',
'Filter by habit' => 'Filtrér husoppave',
'Habits analysis' => 'Statistikk husoppgaver',
'0 means suggestions for the next charge cycle are disabled' => '0 betyr neste ladesyklus er avslått',
'Charge cycle interval (days)' => 'Ladesyklysintervall (Dager)',
'Last price' => 'Siste pris',
'Price history' => 'Prishistorikk',
'No price history available' => 'Ingen prishistorikk tilgjengelig',
'Price' => 'Pris',
'in #1 per purchase quantity unit' => 'I #1 per kjøpt forpakning ',
'The price cannot be lower than #1' => 'Prisen kan ikke være lavere enn #1',
'#1 product expires within the next #2 days' => '#1 Produkt går ut på dato innen de #2 neste dagene',
'#1 product is already expired' => '#1 Produkt er allerede gått ut på dato',
'#1 product is below defined min. stock amount' => '#1 Produkt er under minimums husholdningsnivå',
'Unit' => 'Enhet',
'Units' => 'Enheter',
'#1 habit is due to be done within the next #2 days' => '#1 husoppgave skal gjøres inne de #2 neste dagene',
'#1 habit is overdue to be done' => '#1 husoppgave har gått over fristen for utførelse',
'#1 battery is due to be charged within the next #2 days' => '#1 Batteri må lades innen #2 dager',
'#1 battery is overdue to be charged' => '#1 Batteri har gått over fristen for å lades',
'#1 unit was automatically added and will apply in addition to the amount entered here' => '#1 enhet ble automatisk lagt til i tillegg til hva som blir skrevet inn her',
'in singular form' => 'I entall',
'in plural form' => 'I flertall',
//Constants
'manually' => 'Manuel',
'dynamic-regular' => 'Automatisk (rullering settes under)',
//Technical component translations
'timeago_locale' => 'no',
'timeago_nan' => 'for NaN År',
'moment_locale' => 'nb',
'datatables_localization' => '{"sEmptyTable":"Det finnes ingen data i tabellen","sInfo":"_START_ fra _END_ til _TOTAL_ skriv","sInfoEmpty":"Ingen data tilgjengelign","sInfoFiltered":"(filtrert fra _MAX_ skriv)","sInfoPostFix":"","sInfoThousands":".","sLengthMenu":"_MENU_ registrer deg","sLoadingRecords":"Laster ..","sProcessing":"Vennligst vent ..","sSearch":"Søk","sZeroRecords":"Ingen oppføringer tilgjengelig","oPaginate":{"sFirst":"Første","sPrevious":"Bakover","sNext":"Neste","sLast":"Siste"},"oAria":{"sSortAscending":": Sortér stigende","sSortDescending":": Sortér synkende"},"select":{"rows":{"0":"klikk på en linje for å velge","1":"1 linje valgt","_":"%d linger valgt"}},"buttons":{"print":"Print","colvis":"Søyle","copy":"Kopi","copyTitle":"Kopier til utklippstavlen","copyKeys":"Trykk <i>ctrl</i> eller <i>⌘</i> + <i>C</i> for å kopiere tabell<br> til utklipptavlen.<br><br>For å avbryte, klikke på meldingen eller trykk på ESC.","copySuccess":{"1":"1 Kolonne kopiert","_":"%d kolonne kopiert"}}}',
//Demo data
'Cookies' => 'Cookies',
'Chocolate' => 'Sjokolade',
'Pantry' => 'Spiskammers',
'Candy cupboard' => 'Godteriskapet',
'Tinned food cupboard' => 'Boksematskapet',
'Fridge' => 'Kjøleskapet',
'Piece' => 'Ett',
'Pack' => 'Pakke',
'Glass' => 'Glass',
'Tin' => 'Hermetikkboks',
'Can' => 'Boks',
'Bunch' => 'Klase',
'Gummy bears' => 'Vingummibjørner',
'Crisps' => 'Chips',
'Eggs' => 'Egg',
'Noodles' => 'Nuddler',
'Pickles' => 'Sur agurk',
'Gulash soup' => 'Gulasj suppe',
'Yogurt' => 'Yoghurt',
'Cheese' => 'Ost',
'Cold cuts' => 'Kjøttpålegg',
'Paprika' => 'Paprika',
'Cucumber' => 'Agurk',
'Radish' => 'Reddik',
'Tomato' => 'Tomat',
'Changed towels in the bathroom' => 'Bytt handklær på badet',
'Cleaned the kitchen floor' => 'Vasket kjøkkengulvet',
'Warranty ends' => 'Garanti utgår',
'TV remote control' => 'Fjernkontroll for TV',
'Alarm clock' => 'Alarmklokke',
'Heat remote control' => 'Fjernkontroll for termostat',
'Lawn mowed in the garden' => 'Kuttet gresse i hagen',
'Some good snacks' => 'Noen gode snacks',
'Pizza dough' => 'Pizzadeig',
'Sieved tomatoes' => 'Tomatpuré',
'Salami' => 'Salami',
'Toast' => 'Ristet brød',
'Minced meat' => 'Kjøttdeig',
'Pizza' => 'Pizza',
'Spaghetti bolognese' => 'Spaghetti Bolognese',
'Sandwiches' => 'Smørbrød',
'English' => 'Engelsk',
'German' => 'Tysk',
'Italian' => 'Italiensk',
'Demo in different language' => 'Demo i annet språk',
'This is the note content of the recipe ingredient' => 'Dette er notisen for ingrediensen i oppskriften'
'Demo User' => 'Demo Bruker'
);

View File

@@ -22,8 +22,9 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
$route = $request->getAttribute('route');
$routeName = $route->getName();
if ($this->ApplicationService->IsDemoInstallation())
if (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL)
{
define('GROCY_AUTHENTICATED', true);
$response = $next($request, $response);
}
else
@@ -45,10 +46,23 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
if (!$validSession && !$validApiKey)
{
define('GROCY_AUTHENTICATED', false);
$response = $response->withStatus(401);
}
else
elseif ($validApiKey)
{
$user = $apiKeyService->GetUserByApiKey($request->getHeaderLine($this->ApiKeyHeaderName));
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
elseif ($validSession)
{
$user = $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
}

View File

@@ -1,20 +0,0 @@
<?php
namespace Grocy\Middleware;
class CliMiddleware extends BaseMiddleware
{
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next)
{
if (PHP_SAPI !== 'cli')
{
$response->write('Please call this only from CLI');
return $response->withHeader('Content-Type', 'text/plain')->withStatus(400);
}
else
{
$response = $next($request, $response);
return $response->withHeader('Content-Type', 'text/plain');
}
}
}

View File

@@ -3,6 +3,7 @@
namespace Grocy\Middleware;
use \Grocy\Services\SessionService;
use \Grocy\Services\LocalizationService;
class SessionAuthMiddleware extends BaseMiddleware
{
@@ -18,23 +19,42 @@ class SessionAuthMiddleware extends BaseMiddleware
{
$route = $request->getAttribute('route');
$routeName = $route->getName();
$sessionService = new SessionService();
if ($routeName === 'root' || $this->ApplicationService->IsDemoInstallation())
if ($routeName === 'root')
{
define('AUTHENTICATED', $this->ApplicationService->IsDemoInstallation());
$response = $next($request, $response);
}
elseif (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL)
{
$user = $sessionService->GetDefaultUser();
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_USERNAME', $user->username);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
else
{
$sessionService = new SessionService();
if ((!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName])) && $routeName !== 'login')
{
define('AUTHENTICATED', false);
define('GROCY_AUTHENTICATED', false);
$response = $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/login'));
}
else
{
define('AUTHENTICATED', $routeName !== 'login');
if ($routeName !== 'login')
{
$user = $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_USERNAME', $user->username);
define('GROCY_USER_ID', $user->id);
}
else
{
define('GROCY_AUTHENTICATED', false);
}
$response = $next($request, $response);
}
}

View File

@@ -3,4 +3,3 @@ AS
SELECT product_id, SUM(amount) AS amount, MIN(best_before_date) AS best_before_date
FROM stock
GROUP BY product_id
ORDER BY MIN(best_before_date) ASC

View File

@@ -3,4 +3,3 @@ AS
SELECT habit_id, MAX(tracked_time) AS last_tracked_time
FROM habits_log
GROUP BY habit_id
ORDER BY MAX(tracked_time) DESC

View File

@@ -3,4 +3,3 @@ AS
SELECT battery_id, MAX(tracked_time) AS last_tracked_time
FROM battery_charge_cycles
GROUP BY battery_id
ORDER BY MAX(tracked_time) DESC

50
migrations/0025.sql Normal file
View File

@@ -0,0 +1,50 @@
CREATE TABLE recipes (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT NOT NULL,
description TEXT,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);
CREATE TABLE recipes_pos (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
recipe_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
amount INTEGER NOT NULL DEFAULT 0,
note TEXT,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);
CREATE VIEW recipes_fulfillment
AS
SELECT
r.id AS recipe_id,
rp.id AS recipe_pos_id,
rp.product_id AS product_id,
rp.amount AS recipe_amount,
IFNULL(sc.amount, 0) AS stock_amount,
CASE WHEN IFNULL(sc.amount, 0) >= rp.amount THEN 1 ELSE 0 END AS need_fulfilled,
CASE WHEN IFNULL(sc.amount, 0) - IFNULL(rp.amount, 0) < 0 THEN ABS(IFNULL(sc.amount, 0) - IFNULL(rp.amount, 0)) ELSE 0 END AS missing_amount,
IFNULL(sl.amount, 0) AS amount_on_shopping_list,
CASE WHEN IFNULL(sc.amount, 0) + IFNULL(sl.amount, 0) >= rp.amount THEN 1 ELSE 0 END AS need_fulfilled_with_shopping_list
FROM recipes r
JOIN recipes_pos rp
ON r.id = rp.recipe_id
LEFT JOIN (
SELECT product_id, SUM(amount + amount_autoadded) AS amount
FROM shopping_list
GROUP BY product_id) sl
ON rp.product_id = sl.product_id
LEFT JOIN stock_current sc
ON rp.product_id = sc.product_id;
CREATE VIEW recipes_fulfillment_sum
AS
SELECT
r.id AS recipe_id,
IFNULL(MIN(rf.need_fulfilled), 1) AS need_fulfilled,
IFNULL(MIN(rf.need_fulfilled_with_shopping_list), 1) AS need_fulfilled_with_shopping_list,
(SELECT COUNT(*) FROM recipes_fulfillment WHERE recipe_id = rf.recipe_id AND need_fulfilled = 0 AND recipe_pos_id IS NOT NULL) AS missing_products_count
FROM recipes r
LEFT JOIN recipes_fulfillment rf
ON rf.recipe_id = r.id
GROUP BY r.id;

20
migrations/0026.sql Normal file
View File

@@ -0,0 +1,20 @@
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
username TEXT NOT NULL UNIQUE,
first_name TEXT,
last_name TEXT,
password TEXT NOT NULL,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);
DROP TABLE sessions;
CREATE TABLE sessions (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
session_key TEXT NOT NULL UNIQUE,
user_id INTEGER NOT NULL,
expires DATETIME,
last_used DATETIME,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
)

24
migrations/0027.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
// This is executed inside DatabaseMigrationService class/context
$db = $this->DatabaseService->GetDbConnection();
if (defined('GROCY_HTTP_USER'))
{
// Migrate old user defined in config file to database
$newUserRow = $db->users()->createRow(array(
'username' => GROCY_HTTP_USER,
'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_DEFAULT)
));
$newUserRow->save();
}
else
{
// Create default user "admin" with password "admin"
$newUserRow = $db->users()->createRow(array(
'username' => 'admin',
'password' => password_hash('admin', PASSWORD_DEFAULT)
));
$newUserRow->save();
}

13
migrations/0028.sql Normal file
View File

@@ -0,0 +1,13 @@
ALTER TABLE habits_log
ADD done_by_user_id;
DROP TABLE api_keys;
CREATE TABLE api_keys (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
api_key TEXT NOT NULL UNIQUE,
user_id INTEGER NOT NULL,
expires DATETIME,
last_used DATETIME,
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
);

5
migrations/0029.sql Normal file
View File

@@ -0,0 +1,5 @@
ALTER TABLE stock
ADD price DECIMAL(15, 2);
ALTER TABLE stock_log
ADD price DECIMAL(15, 2);

2
migrations/0030.sql Normal file
View File

@@ -0,0 +1,2 @@
ALTER TABLE quantity_units
ADD name_plural TEXT;

32
migrations/0031.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
// This is executed inside DatabaseMigrationService class/context
use \Grocy\Services\LocalizationService;
$localizationService = new LocalizationService(GROCY_CULTURE);
$db = $this->DatabaseService->GetDbConnection();
if ($db->quantity_units()->count() === 0)
{
// Create 2 default quantity units
$newRow = $db->quantity_units()->createRow(array(
'name' => $localizationService->Localize('Piece'),
'name_plural' => $localizationService->Localize('Pieces')
));
$newRow->save();
$newRow = $db->quantity_units()->createRow(array(
'name' => $localizationService->Localize('Pack'),
'name_plural' => $localizationService->Localize('Packs')
));
$newRow->save();
}
if ($db->locations()->count() === 0)
{
// Create a default location
$newRow = $db->locations()->createRow(array(
'name' => $localizationService->Localize('Fridge')
));
$newRow->save();
}

20
migrations/0032.sql Normal file
View File

@@ -0,0 +1,20 @@
DROP VIEW stock_current;
CREATE VIEW stock_current
AS
SELECT product_id, SUM(amount) AS amount, MIN(best_before_date) AS best_before_date
FROM stock
GROUP BY product_id;
DROP VIEW habits_current;
CREATE VIEW habits_current
AS
SELECT habit_id, MAX(tracked_time) AS last_tracked_time
FROM habits_log
GROUP BY habit_id;
DROP VIEW batteries_current;
CREATE VIEW batteries_current
AS
SELECT battery_id, MAX(tracked_time) AS last_tracked_time
FROM battery_charge_cycles
GROUP BY battery_id;

29
migrations/0033.sql Normal file
View File

@@ -0,0 +1,29 @@
DROP VIEW habits_current;
CREATE VIEW habits_current
AS
SELECT
h.id AS habit_id,
MAX(l.tracked_time) AS last_tracked_time,
CASE h.period_type
WHEN 'manually' THEN '2999-12-31 23:59:59'
WHEN 'dynamic-regular' THEN datetime(MAX(l.tracked_time), '+' || CAST(h.period_days AS TEXT) || ' day')
END AS next_estimated_execution_time
FROM habits h
LEFT JOIN habits_log l
ON h.id = l.habit_id
GROUP BY h.id, h.period_days;
DROP VIEW batteries_current;
CREATE VIEW batteries_current
AS
SELECT
b.id AS battery_id,
MAX(l.tracked_time) AS last_tracked_time,
CASE WHEN b.charge_interval_days = 0
THEN '2999-12-31 23:59:59'
ELSE datetime(MAX(l.tracked_time), '+' || CAST(b.charge_interval_days AS TEXT) || ' day')
END AS next_estimated_charge_time
FROM batteries b
LEFT JOIN battery_charge_cycles l
ON b.id = l.battery_id
GROUP BY b.id, b.charge_interval_days;

30
package.json Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "grocy",
"private": true,
"dependencies": {
"@danielfarrell/bootstrap-combobox": "https://github.com/pallidus-fintech/bootstrap-combobox.git#enhance/boostrap_4",
"@fortawesome/fontawesome-free": "^5.1.0",
"TagManager": "https://github.com/max-favilli/tagmanager.git#3.0.2",
"bootbox": "https://github.com/makeusabrew/bootbox.git#v5.x",
"bootstrap": "^4.1.1",
"chart.js": "^2.7.2",
"datatables.net": "^1.10.19",
"datatables.net-bs4": "^1.10.19",
"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",
"jquery-serializejson": "^2.8.1",
"jquery-ui-dist": "^1.12.1",
"moment": "^2.22.2",
"startbootstrap-sb-admin": "^4.0.0",
"swagger-ui-dist": "^3.17.3",
"tagmanager": "https://github.com/max-favilli/tagmanager.git#3.0.2",
"tempusdominus-bootstrap-4": "^5.0.1",
"timeago": "^1.6.3",
"toastr": "^2.1.4"
}
}

View File

@@ -1,118 +1,26 @@
body {
padding-top: 50px;
/* Main style customizations */
body {
font-family: 'Noto Sans', sans-serif;
}
.navbar-fixed-top {
background-color: #e5e5e5;
border-bottom: 2px solid;
border-color: #d6d6d6;
}
.navbar-brand {
font-weight: bold;
letter-spacing: -5px;
font-size: 2.2em;
color: #0b024c !important;
margin-left: 0 !important;
padding-left: 5px !important;
}
.navbar-fixed-side {
top: 51px;
padding-top: 20px;
margin-bottom: 20px;
background-color: #e5e5e5;
border-right: 2px solid #d6d6d6;
max-width: 260px;
border-left: 0;
}
#sidebar {
overflow-y: auto;
}
@media (min-width: 768px) {
#navbar-mobile {
display: none !important;
}
.nav-copyright {
padding-bottom: 100px;
}
}
@media (max-width: 768px) {
.navbar-brand {
margin-left: 25px !important;
}
}
.sidebar-nav > li > a {
padding-right: 20px;
padding-left: 20px;
transition: all 0.3s;
}
.sidebar-nav > li > a:hover {
box-shadow: inset 5px 0 0 #337ab7;
transition: all 0.3s;
}
.sidebar-nav > li > a:focus {
box-shadow: inset 5px 0 0 #ab2230;
transition: all 0.3s;
}
.sidebar-nav > .active > a,
.sidebar-nav > .active > a:hover,
.sidebar-nav > .active > a:focus {
background-color: #d6d6d6;
box-shadow: inset 5px 0 0 #ab2230;
transition: all 0.3s;
}
.nav > li.disabled > a,
.navbar-default .navbar-nav > .disabled > a {
color: #a7a7a7;
}
.nav-copyright {
color: #a7a7a7;
font-size: 11px;
text-align: center;
}
.nav-copyright > li > a {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
.navbar-default .navbar-nav > .open > a {
background-color: #d6d6d6 !important;
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus {
background-color: #e5e5e5 !important;
}
.well {
background-color: #e5e5e5;
padding-right: 25px;
padding-left: 25px;
}
td {
vertical-align: middle !important;
.content-text {
font-size: 0.85rem;
}
.responsive-button {
white-space: normal;
}
.discrete-link {
.no-real-button {
pointer-events: none;
}
.timeago-contextual {
font-style: italic;
font-size: 0.8em;
}
a.discrete-link {
color: inherit !important;
transition: all 0.3s !important;
}
@@ -120,65 +28,153 @@ td {
a.discrete-link:hover {
color: #337ab7 !important;
text-decoration: none !important;
transition: all 0.3s !important;
}
a.discrete-link:focus {
color: #ab2230 !important;
text-decoration: none !important;
}
.card {
border: 2px solid;
border-color: #d6d6d6;
border-radius: 0;
}
.card-header {
background-color: #e5e5e5;
}
.card-body {
flex-grow: 0;
}
.content-text .invalid-feedback {
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;
border-bottom: 2px solid !important;
border-color: #d6d6d6 !important;
}
.navbar-sidenav {
overflow: hidden;
border-top: 2px solid !important;
}
.navbar-sidenav,
.sidenav-second-level {
background-color: #e5e5e5 !important;
border-right: 2px solid !important;
border-color: #d6d6d6 !important;
}
.navbar-nav .dropdown-menu {
background-color: #e5e5e5 !important;
border: 0;
border-radius: 0;
}
.navbar-nav .dropdown-divider {
border-top: 2px solid !important;
border-color: #d6d6d6 !important;
}
.sidenav-toggler {
background-color: #d6d6d6 !important;
border-right: 2px solid !important;
border-color: #d6d6d6 !important;
}
.navbar-sidenav > li,
.sidenav-second-level > li {
transition: all 0.3s !important;
}
.navbar-sidenav > li:hover,
.sidenav-second-level > li:hover,
.navbar-nav .dropdown-item:hover {
box-shadow: inset 5px 0 0 #337ab7 !important;
background-color: #d6d6d6 !important;
}
.navbar-sidenav > li > a:focus,
.sidenav-second-level > li > a:focus,
.navbar-nav .dropdown-item:focus {
box-shadow: inset 5px 0 0 #ab2230 !important;
background-color: #d6d6d6 !important;
}
.active-page {
box-shadow: inset 5px 0 0 #ab2230 !important;
background-color: #d6d6d6 !important;
}
/* Third party component customizations - DataTables */
td {
vertical-align: middle !important;
}
.table td.fit-content,
.table th.fit-content {
white-space: nowrap;
width: 1%;
}
.dataTables_info,
.dataTables_length,
.dataTables_filter {
font-style: italic;
}
.timeago-contextual {
font-style: italic;
font-size: 0.8em;
}
.disabled,
.no-real-button {
pointer-events: none;
margin-top: 2px;
margin-bottom: 2px;
}
.discrete-content-separator-2x {
padding-top: 10px;
padding-bottom: 10px;
}
.warning-bg {
background-color: #fcf8e3 !important;
}
.error-bg {
background-color: #f2dede !important;
}
.info-bg {
background-color: #afd9ee !important;
.dataTables_filter,
.dataTables_info {
display: none;
}
/* Third party component customizations - toastr */
#toast-container > div {
opacity: 1;
filter: alpha(opacity=100);
}
.toast-success {
background-color: #4c994c;
background-color: #28a745;
}
.toast-error {
background-color: #dc3545;
}
#toast-container > div {
box-shadow: none;
}
/* Third party component customizations - SB Admin 2 */
#mainNav .navbar-collapse .navbar-nav > .nav-item.dropdown > .nav-link:after,
#mainNav .navbar-collapse .navbar-sidenav .nav-link-collapse:after {
font-family: 'Font Awesome 5 Free';
font-weight: 900;
}
@media (max-width:992px) {
#mainNav .navbar-collapse .navbar-sidenav > .nav-item > .nav-link {
padding: 0.8em;
}
}
/* Third party component customizations - Tempus Dominus */
.date-only-datetimepicker .bootstrap-datetimepicker-widget.dropdown-menu {
width: auto !important;
}
/* Third party component customizations - Bootstrap Combobox */
.typeahead .active {
background-color: #e5e5e5;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

20
public/img/grocy_icon.svg Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="60.000000pt" height="93.000000pt" viewBox="0 0 60.000000 93.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,93.000000) scale(0.100000,-0.100000)"
fill="#0b024c" stroke="none">
<path d="M165 905 c-52 -18 -109 -82 -132 -148 -14 -39 -18 -82 -18 -172 0
-104 3 -127 23 -170 43 -94 114 -144 205 -145 59 0 112 21 156 63 l33 32 -7
-75 c-10 -96 -17 -116 -57 -140 -43 -26 -130 -26 -233 0 -43 11 -80 20 -82 20
-2 0 -3 -30 -1 -67 l3 -68 50 -13 c28 -8 100 -14 160 -15 172 -1 255 38 304
142 l26 56 3 353 4 352 -75 0 -75 0 -7 -40 -7 -40 -36 31 c-67 59 -150 75
-237 44z m206 -141 c45 -23 62 -72 62 -180 1 -112 -18 -152 -79 -172 -125 -42
-201 80 -163 260 21 96 97 135 180 92z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1002 B

33
public/img/grocy_logo.svg Normal file
View File

@@ -0,0 +1,33 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="242.000000pt" height="93.000000pt" viewBox="0 0 242.000000 93.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,93.000000) scale(0.100000,-0.100000)"
fill="#0b024c" stroke="none">
<path d="M165 905 c-52 -18 -109 -82 -132 -148 -14 -39 -18 -82 -18 -172 0
-104 3 -127 23 -170 43 -94 114 -144 205 -145 59 0 112 21 156 63 l33 32 -7
-75 c-10 -96 -17 -116 -57 -140 -43 -26 -130 -26 -233 0 -43 11 -80 20 -82 20
-2 0 -3 -30 -1 -67 l3 -68 50 -13 c28 -8 100 -14 160 -15 121 -1 183 14 244
60 36 28 81 112 81 155 0 54 6 58 90 58 l78 0 4 193 c3 180 4 194 25 223 20
28 99 72 110 61 2 -3 -1 -24 -6 -48 -6 -24 -11 -79 -11 -121 0 -137 53 -233
158 -285 50 -24 69 -28 147 -28 107 0 158 20 219 83 l40 41 23 -34 c13 -20 46
-45 80 -62 51 -25 69 -28 153 -28 68 0 108 5 143 18 l47 19 0 74 0 74 -42 -21
c-58 -30 -154 -37 -197 -15 -85 44 -98 250 -21 328 24 24 36 28 84 28 99 0 92
9 200 -260 l97 -242 -23 -46 c-32 -65 -67 -87 -134 -87 l-54 0 0 -66 0 -67 45
-6 c108 -17 215 34 269 128 20 33 296 754 296 771 0 3 -40 5 -89 5 l-90 0 -64
-197 c-35 -109 -69 -214 -75 -233 -10 -34 -10 -34 -11 -7 -1 16 -31 120 -68
232 l-66 202 -143 8 c-116 5 -154 4 -197 -9 -61 -18 -126 -61 -145 -98 l-14
-25 -52 53 c-40 39 -67 56 -106 68 -87 26 -181 19 -272 -19 -14 -5 -18 -2 -18
14 0 19 -6 21 -52 21 -64 0 -129 -30 -164 -76 -15 -19 -30 -34 -34 -34 -4 0
-13 23 -20 50 l-12 50 -133 0 -133 0 -7 -40 -7 -40 -36 31 c-67 59 -150 75
-237 44z m206 -141 c45 -23 62 -72 62 -180 1 -112 -18 -152 -79 -172 -125 -42
-201 80 -163 260 21 96 97 135 180 92z m888 -10 c40 -33 54 -89 49 -184 -7
-118 -41 -160 -131 -160 -87 0 -121 53 -121 185 0 135 34 185 125 185 36 0 55
-6 78 -26z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -19,16 +19,64 @@ U = function(relativePath)
return Grocy.BaseUrl.replace(/\/$/, '') + relativePath;
}
Pluralize = function(number, singularForm, pluralForm)
{
var text = singularForm;
if (number != 1 && pluralForm !== null && !pluralForm.isEmpty())
{
text = pluralForm;
}
return text;
}
if (!Grocy.ActiveNav.isEmpty())
{
var menuItem = $('.nav').find("[data-nav-for-page='" + Grocy.ActiveNav + "']");
menuItem.addClass('active');
}
var menuItem = $('#sidebarResponsive').find("[data-nav-for-page='" + Grocy.ActiveNav + "']");
menuItem.addClass('active-page');
var parentMenuSelector = menuItem.data("sub-menu-of");
if (typeof parentMenuSelector !== "undefined")
{
$(parentMenuSelector).collapse("show");
$(parentMenuSelector).prev(".nav-link-collapse").addClass("active-page");
}
}
var observer = new MutationObserver(function(mutations)
{
mutations.forEach(function(mutation)
{
if (mutation.attributeName === "class")
{
var attributeValue = $(mutation.target).prop(mutation.attributeName);
if (attributeValue.contains("sidenav-toggled"))
{
window.localStorage.setItem("sidebar_state", "collapsed");
}
else
{
window.localStorage.setItem("sidebar_state", "expanded");
}
}
});
});
observer.observe(document.body, {
attributes: true
});
if (window.localStorage.getItem("sidebar_state") === "collapsed")
{
$("#sidenavToggler").click();
}
$.timeago.settings.allowFuture = true;
RefreshContextualTimeago = function()
{
$('time.timeago').timeago();
$("time.timeago").each(function()
{
var element = $(this);
var timestamp = element.attr("datetime");
element.timeago("update", timestamp);
});
}
RefreshContextualTimeago();
@@ -39,6 +87,10 @@ toastr.options = {
extendedTimeOut: 5000
};
window.FontAwesomeConfig = {
searchPseudoElements: true
}
Grocy.Api = { };
Grocy.Api.Get = function(apiFunction, success, error)
{
@@ -100,3 +152,19 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(jsonData));
};
Grocy.FrontendHelpers = { };
Grocy.FrontendHelpers.ValidateForm = function(formId)
{
var form = document.getElementById(formId);
if (form.checkValidity() === true)
{
$(form).find(':submit').removeClass('disabled');
}
else
{
$(form).find(':submit').addClass('disabled');
}
$(form).addClass('was-validated');
}

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.battery-delete-button', function(e)
var batteriesTable = $('#batteries-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
batteriesTable.search(value).draw();
});
$(document).on('click', '.battery-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-battery-name');
var objectId = $(e.currentTarget).attr('data-battery-id');
@@ -33,12 +56,3 @@
}
});
});
$('#batteries-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});

View File

@@ -1,10 +1,24 @@
$('#batteries-overview-table').DataTable({
'pageLength': 50,
var batteriesOverviewTable = $('#batteries-overview-table').DataTable({
'paginate': false,
'order': [[2, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
batteriesOverviewTable.search(value).draw();
});
$(document).on('click', '.track-charge-cycle-button', function(e)
@@ -24,6 +38,7 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
RefreshContextualTimeago();
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryName, trackedTime));
RefreshStatistics();
},
function(xhr)
{
@@ -31,3 +46,37 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
}
);
});
function RefreshStatistics()
{
var nextXDays = $("#info-due-batteries").data("next-x-days");
Grocy.Api.Get('batteries/get-current',
function(result)
{
var dueCount = 0;
var overdueCount = 0;
var now = moment();
var nextXDaysThreshold = moment().add(nextXDays, "days");
result.forEach(element => {
var date = moment(element.next_estimated_charge_time);
if (date.isBefore(now))
{
overdueCount++;
}
else if (date.isBefore(nextXDaysThreshold))
{
dueCount++;
}
});
$("#info-due-batteries").text(Pluralize(dueCount, L('#1 battery is due to be charged within the next #2 days', dueCount, nextXDays), L('#1 batteries are due to be charged within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-batteries").text(Pluralize(overdueCount, L('#1 battery is overdue to be charged', overdueCount), L('#1 batteries are overdue to be charged', overdueCount)));
},
function(xhr)
{
console.error(xhr);
}
);
}
RefreshStatistics();

View File

@@ -30,6 +30,26 @@
}
});
$('#battery-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('battery-form');
});
$('#battery-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('battery-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-battery-button').click();
}
}
});
$('#name').focus();
$('#battery-form').validator();
$('#battery-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('battery-form');

View File

@@ -7,18 +7,18 @@
Grocy.Api.Get('batteries/get-battery-details/' + jsonForm.battery_id,
function (batteryDetails)
{
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').val(),
Grocy.Api.Get('batteries/track-charge-cycle/' + jsonForm.battery_id + '?tracked_time=' + $('#tracked_time').find('input').val(),
function(result)
{
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').val()));
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryDetails.battery.name, $('#tracked_time').find('input').val()));
$('#battery_id').val('');
$('#battery_id_text_input').focus();
$('#battery_id_text_input').val('');
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').find('input').trigger('change');
$('#battery_id_text_input').trigger('change');
$('#batterytracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
},
function(xhr)
{
@@ -35,31 +35,16 @@
$('#battery_id').on('change', function(e)
{
var batteryId = $(e.target).val();
var input = $('#battery_id_text_input').val().toString();
$('#battery_id_text_input').val(input);
$('#battery_id').data('combobox').refresh();
var batteryId = $(e.target).val();
if (batteryId)
{
Grocy.Components.BatteryCard.Refresh(batteryId);
$('#tracked_time').focus();
}
});
$('.datetimepicker').datetimepicker(
{
format: 'YYYY-MM-DD HH:mm:ss',
showTodayButton: true,
calendarWeeks: true,
maxDate: moment()
});
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').on('focus', function(e)
{
if ($('#battery_id_text_input').val().length === 0)
{
$('#battery_id_text_input').focus();
$('#tracked_time').find('input').focus();
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
}
});
@@ -71,79 +56,31 @@ $('#battery_id').val('');
$('#battery_id_text_input').focus();
$('#battery_id_text_input').val('');
$('#battery_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
$('#batterytracking-form').validator();
$('#batterytracking-form').validator('validate');
$('#batterytracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
});
$('#batterytracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#batterytracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('batterytracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-batterytracking-button').click();
}
}
});
$('#tracked_time').on('change', function(e)
$('#tracked_time').find('input').on('keypress', function (e)
{
var value = $('#tracked_time').val();
var now = new Date();
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
if (value === 'x' || value === 'X') {
value = '29991231';
}
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
{
value = (new Date()).getFullYear().toString() + value;
}
if (value.length === 8 && $.isNumeric(value))
{
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
$('#tracked_time').val(value);
$('#batterytracking-form').validator('validate');
}
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
});
$('#tracked_time').on('keypress', function(e)
{
var element = $(e.target);
var value = element.val();
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
$('.datepicker').datepicker('hide');
//If input is empty and any arrow key is pressed, set date to today
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
{
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
}
if (dateObj.isValid())
{
if (e.keyCode === 38) //Up
{
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 40) //Down
{
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 37) //Left
{
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
}
else if (e.keyCode === 39) //Right
{
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
}
}
$('#batterytracking-form').validator('validate');
});

View File

@@ -7,7 +7,7 @@ Grocy.Components.BatteryCard.Refresh = function(batteryId)
{
$('#batterycard-battery-name').text(batteryDetails.battery.name);
$('#batterycard-battery-used_in').text(batteryDetails.battery.used_in);
$('#batterycard-battery-last-charged').text((batteryDetails.last_charged || 'never'));
$('#batterycard-battery-last-charged').text((batteryDetails.last_charged || L('never')));
$('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
$('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));

View File

@@ -0,0 +1,40 @@
$('#calendar').datetimepicker(
{
format: 'L',
buttons: {
showToday: true,
showClose: false
},
calendarWeeks: true,
locale: moment.locale(),
icons: {
time: 'far fa-clock',
date: 'far fa-calendar',
up: 'fas fa-arrow-up',
down: 'fas fa-arrow-down',
previous: 'fas fa-chevron-left',
next: 'fas fa-chevron-right',
today: 'fas fa-calendar-check',
clear: 'far fa-trash-alt',
close: 'far fa-times-circle'
},
keepOpen: true,
inline: true,
keyBinds: {
up: function(widget) { },
down: function(widget) { },
'control up': function(widget) { },
'control down': function(widget) { },
left: function(widget) { },
right: function(widget) { },
pageUp: function(widget) { },
pageDown: function(widget) { },
enter: function(widget) { },
escape: function(widget) { },
'control space': function(widget) { },
t: function(widget) { },
'delete': function(widget) { }
}
});
$('#calendar').datetimepicker('show');

View File

@@ -1,92 +0,0 @@
$(function()
{
$('.datepicker').datepicker(
{
format: 'yyyy-mm-dd',
startDate: '+0d',
todayHighlight: true,
autoclose: true,
calendarWeeks: true,
orientation: 'bottom auto',
weekStart: 1,
showOnFocus: false,
language: L('bootstrap_datepicker_locale')
});
$('.datepicker').trigger('change');
EmptyElementWhenMatches('#datepicker-timeago', L('timeago_nan'));
});
$('.datepicker').on('keydown', function(e)
{
if (e.keyCode === 13) //Enter
{
$('.datepicker').trigger('change');
}
});
$('.datepicker').on('keypress', function(e)
{
var element = $(e.target);
var value = element.val();
var dateObj = moment(element.val(), 'YYYY-MM-DD', true);
$('.datepicker').datepicker('hide');
//If input is empty and any arrow key is pressed, set date to today
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
{
dateObj = moment(new Date(), 'YYYY-MM-DD', true);
}
if (dateObj.isValid())
{
if (e.keyCode === 38) //Up
{
element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 40) //Down
{
element.val(dateObj.add(1, 'days').format('YYYY-MM-DD'));
}
else if (e.keyCode === 37) //Left
{
element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD'));
}
else if (e.keyCode === 39) //Right
{
element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD'));
}
}
});
$('.datepicker').on('change', function(e)
{
var value = $('.datepicker').val();
var now = new Date();
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
if (value === 'x' || value === 'X') {
value = '29991231';
}
if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
{
value = (new Date()).getFullYear().toString() + value;
}
if (value.length === 8 && $.isNumeric(value))
{
value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
$('.datepicker').val(value);
}
$('#datepicker-timeago').text($.timeago($('.datepicker').val()));
EmptyElementWhenMatches('#datepicker-timeago', L('timeago_nan'));
});
$('#datepicker-button').on('click', function(e)
{
$('.datepicker').datepicker('show');
});

View File

@@ -1,11 +1,173 @@
$(function()
Grocy.Components.DateTimePicker = { };
Grocy.Components.DateTimePicker.GetInputElement = function()
{
$('.datetimepicker').datetimepicker(
{
format: 'YYYY-MM-DD HH:mm:ss',
showTodayButton: true,
calendarWeeks: true,
maxDate: moment(),
locale: moment.locale('de')
});
return $('.datetimepicker').find('input');
}
Grocy.Components.DateTimePicker.GetValue = function()
{
return Grocy.Components.DateTimePicker.GetInputElement().val();
}
Grocy.Components.DateTimePicker.SetValue = function(value)
{
Grocy.Components.DateTimePicker.GetInputElement().val(value);
Grocy.Components.DateTimePicker.GetInputElement().trigger('change');
}
var startDate = null;
if (Grocy.Components.DateTimePicker.GetInputElement().data('init-with-now') === true)
{
startDate = moment().format(Grocy.Components.DateTimePicker.GetInputElement().data('format'));
}
var limitDate = moment('2999-12-31 23:59:59');
if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-end-to-now') === true)
{
limitDate = moment();
}
$('.datetimepicker').datetimepicker(
{
format: Grocy.Components.DateTimePicker.GetInputElement().data('format'),
buttons: {
showToday: true,
showClose: true
},
calendarWeeks: true,
maxDate: limitDate,
locale: moment.locale(),
defaultDate: startDate,
useCurrent: false,
icons: {
time: 'far fa-clock',
date: 'far fa-calendar',
up: 'fas fa-arrow-up',
down: 'fas fa-arrow-down',
previous: 'fas fa-chevron-left',
next: 'fas fa-chevron-right',
today: 'fas fa-calendar-check',
clear: 'far fa-trash-alt',
close: 'far fa-times-circle'
},
sideBySide: true,
keyBinds: {
up: function(widget) { },
down: function(widget) { },
'control up': function(widget) { },
'control down': function(widget) { },
left: function(widget) { },
right: function(widget) { },
pageUp: function(widget) { },
pageDown: function(widget) { },
enter: function(widget) { },
escape: function(widget) { },
'control space': function(widget) { },
t: function(widget) { },
'delete': function(widget) { }
}
});
Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e)
{
$('.datetimepicker').datetimepicker('hide');
var value = Grocy.Components.DateTimePicker.GetValue();
var now = new Date();
var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00');
var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99');
var format = Grocy.Components.DateTimePicker.GetInputElement().data('format');
var nextInputElement = $(Grocy.Components.DateTimePicker.GetInputElement().data('next-input-selector'));
//If input is empty and any arrow key is pressed, set date to today
if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39))
{
Grocy.Components.DateTimePicker.SetValue(moment(new Date(), format, true).format(format));
nextInputElement.focus();
}
else if (value === 'x' || value === 'X')
{
Grocy.Components.DateTimePicker.SetValue(moment('2999-12-31 23:59:59').format(format));
nextInputElement.focus();
}
else if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
{
var date = moment((new Date()).getFullYear().toString() + value);
if (date.isBefore(moment()))
{
date.add(1, "year");
}
Grocy.Components.DateTimePicker.SetValue(date.format(format));
nextInputElement.focus();
}
else if (value.length === 8 && $.isNumeric(value))
{
Grocy.Components.DateTimePicker.SetValue(value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3'));
nextInputElement.focus();
}
else if (value.length === 7 && $.isNumeric(value.substring(0, 6)) && (value.substring(6, 7).toLowerCase() === "e" || value.substring(6, 7).toLowerCase() === "+"))
{
var date = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month");
Grocy.Components.DateTimePicker.SetValue(date.format(format));
nextInputElement.focus();
}
else
{
var dateObj = moment(value, format, true);
if (dateObj.isValid())
{
if (e.keyCode === 38) //Up
{
Grocy.Components.DateTimePicker.SetValue(dateObj.add(-1, 'days').format(format));
}
else if (e.keyCode === 40) //Down
{
Grocy.Components.DateTimePicker.SetValue(dateObj.add(1, 'days').format(format));
}
else if (e.keyCode === 37) //Left
{
Grocy.Components.DateTimePicker.SetValue(dateObj.add(-1, 'weeks').format(format));
}
else if (e.keyCode === 39) //Right
{
Grocy.Components.DateTimePicker.SetValue(dateObj.add(1, 'weeks').format(format));
}
}
}
//Custom validation
value = Grocy.Components.DateTimePicker.GetValue();
dateObj = moment(value, format, true);
var element = Grocy.Components.DateTimePicker.GetInputElement()[0];
if (!dateObj.isValid())
{
element.setCustomValidity("error");
}
else
{
if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-end-to-now') === true && dateObj.isAfter(moment()))
{
element.setCustomValidity("error");
}
else if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-start-to-now') === true && dateObj.isBefore(moment()))
{
element.setCustomValidity("error");
}
else
{
element.setCustomValidity("");
}
}
});
Grocy.Components.DateTimePicker.GetInputElement().on('input', function(e)
{
$('#datetimepicker-timeago').text($.timeago(Grocy.Components.DateTimePicker.GetValue()));
EmptyElementWhenMatches('#datetimepicker-timeago', L('timeago_nan'));
});
$('.datetimepicker').on('update.datetimepicker', function(e)
{
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');
});

View File

@@ -6,9 +6,10 @@ Grocy.Components.HabitCard.Refresh = function(habitId)
function(habitDetails)
{
$('#habitcard-habit-name').text(habitDetails.habit.name);
$('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
$('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || L('never')));
$('#habitcard-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
$('#habitcard-habit-tracked-count').text((habitDetails.tracked_count || '0'));
$('#habitcard-habit-last-done-by').text((habitDetails.last_done_by.display_name || L('Unknown')));
EmptyElementWhenMatches('#habitcard-habit-last-tracked-timeago', L('timeago_nan'));
},

View File

@@ -5,15 +5,25 @@ Grocy.Components.ProductCard.Refresh = function(productId)
Grocy.Api.Get('stock/get-product-details/' + productId,
function(productDetails)
{
var stockAmount = productDetails.stock_amount || '0';
$('#productcard-product-name').text(productDetails.product.name);
$('#productcard-product-stock-amount').text(productDetails.stock_amount || '0');
$('#productcard-product-stock-amount').text(stockAmount);
$('#productcard-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
$('#productcard-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
$('#productcard-product-stock-qu-name2').text(Pluralize(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural));
$('#productcard-product-last-purchased').text((productDetails.last_purchased || L('never')).substring(0, 10));
$('#productcard-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
$('#productcard-product-last-used').text((productDetails.last_used || L('never')).substring(0, 10));
$('#productcard-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
if (productDetails.last_price !== null)
{
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency);
}
else
{
$('#productcard-product-last-price').text(L('Unknown'));
}
EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', L('timeago_nan'));
EmptyElementWhenMatches('#productcard-product-last-used-timeago', L('timeago_nan'));
},
@@ -22,4 +32,88 @@ Grocy.Components.ProductCard.Refresh = function(productId)
console.error(xhr);
}
);
Grocy.Api.Get('stock/get-product-price-history/' + productId,
function(priceHistoryDataPoints)
{
if (priceHistoryDataPoints.length > 0)
{
$("#productcard-product-price-history-chart").removeClass("d-none");
$("#productcard-no-price-data-hint").addClass("d-none");
Grocy.Components.ProductCard.ReInitPriceHistoryChart();
priceHistoryDataPoints.forEach((dataPoint) =>
{
Grocy.Components.ProductCard.PriceHistoryChart.data.labels.push(moment(dataPoint.date).toDate());
var dataset = Grocy.Components.ProductCard.PriceHistoryChart.data.datasets[0];
dataset.data.push(dataPoint.price);
});
Grocy.Components.ProductCard.PriceHistoryChart.update();
}
else
{
$("#productcard-product-price-history-chart").addClass("d-none");
$("#productcard-no-price-data-hint").removeClass("d-none");
}
},
function(xhr)
{
console.error(xhr);
}
);
};
Grocy.Components.ProductCard.ReInitPriceHistoryChart = function()
{
if (typeof Grocy.Components.ProductCard.PriceHistoryChart !== "undefined")
{
Grocy.Components.ProductCard.PriceHistoryChart.destroy();
}
var format = 'YYYY-MM-DD';
Grocy.Components.ProductCard.PriceHistoryChart = new Chart(document.getElementById("productcard-product-price-history-chart"), {
type: "line",
data: {
labels: [ //Date objects
// Will be populated in Grocy.Components.ProductCard.Refresh
],
datasets: [{
data: [
// Will be populated in Grocy.Components.ProductCard.Refresh
],
fill: false,
borderColor: '#17a2b8'
}]
},
options: {
scales: {
xAxes: [{
type: 'time',
time: {
parser: format,
round: 'day',
tooltipFormat: format,
unit: 'day',
unitStepSize: 10,
displayFormats: {
'day': format
}
},
ticks: {
autoSkip: true,
maxRotation: 0
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
legend: {
display: false
}
}
});
}

View File

@@ -0,0 +1,160 @@
Grocy.Components.ProductPicker = { };
Grocy.Components.ProductPicker.GetPicker = function()
{
return $('#product_id');
}
Grocy.Components.ProductPicker.GetInputElement = function()
{
return $('#product_id_text_input');
}
Grocy.Components.ProductPicker.GetValue = function()
{
return $('#product_id').val();
}
Grocy.Components.ProductPicker.SetValue = function(value)
{
Grocy.Components.ProductPicker.GetInputElement().val(value);
Grocy.Components.ProductPicker.GetInputElement().trigger('change');
}
Grocy.Components.ProductPicker.InProductAddWorkflow = function()
{
return typeof GetUriParam('createdproduct') !== "undefined";
}
Grocy.Components.ProductPicker.InProductModifyWorkflow = function()
{
return typeof GetUriParam('addbarcodetoselection') !== "undefined";
}
Grocy.Components.ProductPicker.ShowCustomError = function(text)
{
var element = $("#custom-productpicker-error");
element.text(text);
element.removeClass("d-none");
}
Grocy.Components.ProductPicker.HideCustomError = function()
{
$("#custom-productpicker-error").addClass("d-none");
}
$('.product-combobox').combobox({
appendId: '_text_input',
bsVersion: '4'
});
var prefillProduct = GetUriParam('createdproduct');
var prefillProduct2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-name').toString();
if (!prefillProduct2.isEmpty())
{
prefillProduct = prefillProduct2;
}
if (typeof prefillProduct !== "undefined")
{
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
if (possibleOptionElement.length === 0)
{
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
}
if (possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
var nextInputElement = $(Grocy.Components.ProductPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
}
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
$('#addbarcodetoselection').text(addBarcode);
$('#flow-info-addbarcodetoselection').removeClass('d-none');
$('#barcode-lookup-disabled-hint').removeClass('d-none');
}
$('#product_id_text_input').on('change', function(e)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
else
{
var optionElement = $("#product_id option:contains('" + input + "')").first();
if (input.length > 0 && optionElement.length === 0 && typeof GetUriParam('addbarcodetoselection') === "undefined")
{
var addProductWorkflowsAdditionalCssClasses = "";
if (Grocy.Components.ProductPicker.GetPicker().parent().data('disallow-add-product-workflows').toString() === "true")
{
addProductWorkflowsAdditionalCssClasses = "d-none";
}
bootbox.dialog({
message: L('"#1" could not be resolved to a product, how do you want to proceed?', input),
title: L('Create or assign product'),
onEscape: function() { },
size: 'large',
backdrop: true,
buttons: {
cancel: {
label: 'Cancel',
className: 'btn-default responsive-button',
callback: function() { }
},
addnewproduct: {
label: '<strong>P</strong> ' + L('Add as new product'),
className: 'btn-success add-new-product-dialog-button responsive-button ' + addProductWorkflowsAdditionalCssClasses,
callback: function()
{
window.location.href = U('/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
},
addbarcode: {
label: '<strong>B</strong> ' + L('Add as barcode to existing product'),
className: 'btn-info add-new-barcode-dialog-button responsive-button',
callback: function()
{
window.location.href = U(window.location.pathname + '?addbarcodetoselection=' + encodeURIComponent(input));
}
},
addnewproductwithbarcode: {
label: '<strong>A</strong> ' + L('Add as new product and prefill barcode'),
className: 'btn-warning add-new-product-with-barcode-dialog-button responsive-button ' + addProductWorkflowsAdditionalCssClasses,
callback: function()
{
window.location.href = U('/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
}
}
}).on('keypress', function(e)
{
if (e.key === 'B' || e.key === 'b')
{
$('.add-new-barcode-dialog-button').not(".d-none").click();
}
if (e.key === 'p' || e.key === 'P')
{
$('.add-new-product-dialog-button').not(".d-none").click();
}
if (e.key === 'a' || e.key === 'A')
{
$('.add-new-product-with-barcode-dialog-button').not(".d-none").click();
}
});
}
}
});

View File

@@ -0,0 +1,62 @@
Grocy.Components.UserPicker = { };
Grocy.Components.UserPicker.GetPicker = function()
{
return $('#user_id');
}
Grocy.Components.UserPicker.GetInputElement = function()
{
return $('#user_id_text_input');
}
Grocy.Components.UserPicker.GetValue = function()
{
return $('#user_id').val();
}
Grocy.Components.UserPicker.SetValue = function(value)
{
Grocy.Components.UserPicker.GetInputElement().val(value);
Grocy.Components.UserPicker.GetInputElement().trigger('change');
}
$('.user-combobox').combobox({
appendId: '_text_input',
bsVersion: '4'
});
var prefillUser = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-username').toString();
if (typeof prefillUser !== "undefined")
{
var possibleOptionElement = $("#user_id option[data-additional-searchdata*='" + prefillUser + "']").first();
if (possibleOptionElement.length === 0)
{
possibleOptionElement = $("#user_id option:contains('" + prefillUser + "')").first();
}
if (possibleOptionElement.length > 0)
{
$('#user_id').val(possibleOptionElement.val());
$('#user_id').data('combobox').refresh();
$('#user_id').trigger('change');
var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
}
}
var prefillUserId = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-user-id').toString();
if (typeof prefillUserId !== "undefined")
{
var possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first();
if (possibleOptionElement.length > 0)
{
$('#user_id').val(possibleOptionElement.val());
$('#user_id').data('combobox').refresh();
$('#user_id').trigger('change');
var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
}
}

View File

@@ -19,11 +19,9 @@
toastr.success(L('Removed #1 #2 of #3 from stock', jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.product.name));
$('#amount').val(1);
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#consume-form').validator('validate');
Grocy.Components.ProductPicker.SetValue('');
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('consume-form');
},
function(xhr)
{
@@ -38,7 +36,7 @@
);
});
$('#product_id').on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
@@ -50,26 +48,19 @@ $('#product_id').on('change', function(e)
function (productDetails)
{
$('#amount').attr('max', productDetails.stock_amount);
$('#consume-form').validator('update');
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
if ((productDetails.stock_amount || 0) === 0)
{
$('#product_id').val('');
$('#product_id_text_input').val('');
$('#product_id_text_input').addClass('has-error');
$('#product_id_text_input').parent('.input-group').addClass('has-error');
$('#product_id_text_input').closest('.form-group').addClass('has-error');
$('#product-error').text(L('This product is not in stock'));
$('#product-error').show();
$('#product_id_text_input').focus();
Grocy.Components.ProductPicker.SetValue('');
Grocy.FrontendHelpers.ValidateForm('consume-form');
Grocy.Components.ProductPicker.ShowCustomError(L('This product is not in stock'));
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
$('#product_id_text_input').removeClass('has-error');
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
$('#product-error').hide();
Grocy.Components.ProductPicker.HideCustomError();
Grocy.FrontendHelpers.ValidateForm('consume-form');
$('#amount').focus();
}
},
@@ -81,52 +72,32 @@ $('#product_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#product_id_text_input').on('change', function(e)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
});
$('#amount').val(1);
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#consume-form').validator();
$('#consume-form').validator('validate');
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('consume-form');
$('#amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
{
$('#product_id_text_input').focus();
}
else
{
$(this).select();
}
$(this).select();
});
$('#consume-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('consume-form');
});
$('#consume-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#consume-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('consume-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-consume-button').click();
}
}
});

View File

@@ -30,9 +30,29 @@
}
});
$('#habit-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('habit-form');
});
$('#habit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('habit-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habit-button').click();
}
}
});
$('#name').focus();
$('#habit-form').validator();
$('#habit-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habit-form');
$('.input-group-habit-period-type').on('change', function(e)
{
@@ -42,10 +62,10 @@ $('.input-group-habit-period-type').on('change', function(e)
if (periodType === 'dynamic-regular')
{
$('#habit-period-type-info').text(L('This means it is estimated that a new execution of this habit is tracked #1 days after the last was tracked', periodDays.toString()));
$('#habit-period-type-info').show();
$('#habit-period-type-info').removeClass('d-none');
}
else
{
$('#habit-period-type-info').hide();
$('#habit-period-type-info').addClass('d-none');
}
});

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.habit-delete-button', function(e)
var habitsTable = $('#habits-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
habitsTable.search(value).draw();
});
$(document).on('click', '.habit-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-habit-name');
var objectId = $(e.currentTarget).attr('data-habit-id');
@@ -33,12 +56,3 @@
}
});
});
$('#habits-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});

View File

@@ -0,0 +1,37 @@
var habitsAnalysisTable = $('#habits-analysis-table').DataTable({
'paginate': false,
'order': [[1, 'desc']],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#habit-filter").on("change", function()
{
var value = $(this).val();
var text = $("#habit-filter option:selected").text();
if (value === "all")
{
text = "";
}
habitsAnalysisTable.column(0).search(text).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
habitsAnalysisTable.search(value).draw();
});
if (typeof GetUriParam("habit") !== "undefined")
{
$("#habit-filter").val(GetUriParam("habit"));
$("#habit-filter").trigger("change");
}

View File

@@ -1,10 +1,24 @@
$('#habits-overview-table').DataTable({
'pageLength': 50,
var habitsOverviewTable = $('#habits-overview-table').DataTable({
'paginate': false,
'order': [[2, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
habitsOverviewTable.search(value).draw();
});
$(document).on('click', '.track-habit-button', function(e)
@@ -24,6 +38,7 @@ $(document).on('click', '.track-habit-button', function(e)
RefreshContextualTimeago();
toastr.success(L('Tracked execution of habit #1 on #2', habitName, trackedTime));
RefreshStatistics();
},
function(xhr)
{
@@ -31,3 +46,37 @@ $(document).on('click', '.track-habit-button', function(e)
}
);
});
function RefreshStatistics()
{
var nextXDays = $("#info-due-habits").data("next-x-days");
Grocy.Api.Get('habits/get-current',
function(result)
{
var dueCount = 0;
var overdueCount = 0;
var now = moment();
var nextXDaysThreshold = moment().add(nextXDays, "days");
result.forEach(element => {
var date = moment(element.next_estimated_execution_time);
if (date.isBefore(now))
{
overdueCount++;
}
else if (date.isBefore(nextXDaysThreshold))
{
dueCount++;
}
});
$("#info-due-habits").text(Pluralize(dueCount, L('#1 habit is due to be done within the next #2 days', dueCount, nextXDays), L('#1 habits are due to be done within the next #2 days', dueCount, nextXDays)));
$("#info-overdue-habits").text(Pluralize(overdueCount, L('#1 habit is overdue to be done', overdueCount), L('#1 habits are overdue to be done', overdueCount)));
},
function(xhr)
{
console.error(xhr);
}
);
}
RefreshStatistics();

View File

@@ -7,18 +7,17 @@
Grocy.Api.Get('habits/get-habit-details/' + jsonForm.habit_id,
function (habitDetails)
{
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + $('#tracked_time').val(),
Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(),
function(result)
{
toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, $('#tracked_time').val()));
toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, Grocy.Components.DateTimePicker.GetValue()));
$('#habit_id').val('');
$('#habit_id_text_input').focus();
$('#habit_id_text_input').val('');
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#habit_id_text_input').trigger('change');
$('#habittracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
},
function(xhr)
{
@@ -35,23 +34,16 @@
$('#habit_id').on('change', function(e)
{
var habitId = $(e.target).val();
var input = $('#habit_id_text_input').val().toString();
$('#habit_id_text_input').val(input);
$('#habit_id').data('combobox').refresh();
var habitId = $(e.target).val();
if (habitId)
{
Grocy.Components.HabitCard.Refresh(habitId);
$('#tracked_time').focus();
}
});
$('#tracked_time').val(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#tracked_time').trigger('change');
$('#tracked_time').on('focus', function(e)
{
if ($('#habit_id_text_input').val().length === 0)
{
$('#habit_id_text_input').focus();
Grocy.Components.DateTimePicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
}
});
@@ -59,27 +51,32 @@ $('.combobox').combobox({
appendId: '_text_input'
});
$('#habit_id').val('');
$('#habit_id_text_input').focus();
$('#habit_id_text_input').val('');
$('#habit_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
$('#habittracking-form').validator();
$('#habittracking-form').validator('validate');
$('#habittracking-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});
$('#habittracking-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#habittracking-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('habittracking-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-habittracking-button').click();
}
}
});
$('#tracked_time').on('keypress', function(e)
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
$('#habittracking-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
});

View File

@@ -7,7 +7,7 @@
Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id,
function (productDetails)
{
Grocy.Api.Get('stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
Grocy.Api.Get('stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(),
function(result)
{
var addBarcode = GetUriParam('addbarcodetoselection');
@@ -40,14 +40,12 @@
}
else
{
$('#inventory-change-info').hide();
$('#inventory-change-info').addClass('d-none');
$('#new_amount').val('');
$('#best_before_date').val('');
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#inventory-form').validator('validate');
Grocy.Components.DateTimePicker.SetValue('');
Grocy.Components.ProductPicker.SetValue('');
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('inventory-form');
}
},
function(xhr)
@@ -63,7 +61,7 @@
);
});
$('#product_id').on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
@@ -87,121 +85,23 @@ $('#product_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#product_id_text_input').on('change', function(e)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
else
{
var optionElement = $("#product_id option:contains('" + input + "')").first();
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
{
bootbox.dialog({
message: L('#1 could not be resolved to a product, how do you want to proceed?', input),
title: L('Create or assign product'),
onEscape: function() { },
size: 'large',
backdrop: true,
buttons: {
cancel: {
label: L('Cancel'),
className: 'btn-default',
callback: function() { }
},
addnewproduct: {
label: '<strong>P</strong> ' + L('Add as new product'),
className: 'btn-success add-new-product-dialog-button',
callback: function()
{
window.location.href = U('/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
},
addbarcode: {
label: '<strong>B</strong> ' + L('Add as barcode to existing product'),
className: 'btn-info add-new-barcode-dialog-button',
callback: function()
{
window.location.href = U('/inventory?addbarcodetoselection=' + encodeURIComponent(input));
}
},
addnewproductwithbarcode: {
label: '<strong>A</strong> ' + L('Add as new product and prefill barcode'),
className: 'btn-warning add-new-product-with-barcode-dialog-button',
callback: function()
{
window.location.href = U('/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
}
}
}).on('keypress', function(e)
{
if (e.key === 'B' || e.key === 'b')
{
$('.add-new-barcode-dialog-button').click();
}
if (e.key === 'p' || e.key === 'P')
{
$('.add-new-product-dialog-button').click();
}
if (e.key === 'a' || e.key === 'A')
{
$('.add-new-product-with-barcode-dialog-button').click();
}
});
}
}
});
$('#new_amount').val('');
$('#best_before_date').val('');
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
$('#inventory-form').validator({
custom: {
'isodate': function($el)
{
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
{
return 'Wrong date format, needs to be YYYY-MM-DD';
}
else if (moment($el.val()).isValid())
{
if (moment($el.val()).isBefore(moment(), 'day'))
{
return 'This value cannot be before today.';
}
}
},
'notequal': function($el)
{
if ($el.val().length !== 0 && $el.val().toString() === $el.attr('not-equal').toString())
{
return 'This value cannot be equal to ' + $el.attr('not-equal').toString();
}
}
}
});
$('#inventory-form').validator('validate');
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
$('#new_amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
$('#product_id_text_input').focus();
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
@@ -209,106 +109,74 @@ $('#new_amount').on('focus', function(e)
}
});
$('#inventory-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#inventory-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#inventory-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('inventory-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-inventory-button').click();
}
}
});
var prefillProduct = GetUriParam('createdproduct');
if (prefillProduct !== undefined)
{
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
if (possibleOptionElement.length === 0)
{
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
}
if (possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
$('#new_amount').focus();
}
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
$('#addbarcodetoselection').text(addBarcode);
$('#flow-info-addbarcodetoselection').removeClass('hide');
$('#barcode-lookup-disabled-hint').removeClass('hide');
}
$('#new_amount').on('keypress', function(e)
{
$('#new_amount').trigger('change');
});
$('#best_before_date').on('change', function(e)
Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e)
{
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#best_before_date').on('keypress', function(e)
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
});
$('#best_before_date').on('keydown', function(e)
$('#new_amount').on('keyup', function(e)
{
if (e.keyCode === 13) //Enter
{
$('#best_before_date').trigger('change');
}
});
$('#new_amount').on('change', function(e)
{
if ($('#product_id').parent().hasClass('has-error'))
{
$('#inventory-change-info').hide();
return;
}
var productId = $('#product_id').val();
var newAmount = $('#new_amount').val();
var productId = Grocy.Components.ProductPicker.GetValue();
var newAmount = parseInt($('#new_amount').val());
if (productId)
{
Grocy.Api.Get('stock/get-product-details/' + productId,
function(productDetails)
{
var productStockAmount = productDetails.stock_amount || '0';
var productStockAmount = parseInt(productDetails.stock_amount || '0');
if (newAmount > productStockAmount)
{
var amountToAdd = newAmount - productDetails.stock_amount;
$('#inventory-change-info').text(L('This means #1 will be added to stock', amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name));
$('#inventory-change-info').show();
$('#best_before_date').attr('required', 'required');
$('#inventory-change-info').removeClass('d-none');
Grocy.Components.DateTimePicker.GetInputElement().attr('required', '');
}
else if (newAmount < productStockAmount)
{
var amountToRemove = productStockAmount - newAmount;
$('#inventory-change-info').text(L('This means #1 will be removed from stock', amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name));
$('#inventory-change-info').show();
$('#best_before_date').removeAttr('required');
$('#inventory-change-info').removeClass('d-none');
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
}
else
{
$('#inventory-change-info').hide();
$('#inventory-change-info').addClass('d-none');
}
$('#inventory-form').validator('update');
$('#inventory-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('inventory-form');
},
function(xhr)
{

View File

@@ -30,6 +30,26 @@
}
});
$('#location-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('location-form');
});
$('#location-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('location-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-location-button').click();
}
}
});
$('#name').focus();
$('#location-form').validator();
$('#location-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('location-form');

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.location-delete-button', function(e)
var locationsTable = $('#locations-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
locationsTable.search(value).draw();
});
$(document).on('click', '.location-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-location-name');
var objectId = $(e.currentTarget).attr('data-location-id');
@@ -33,12 +56,3 @@
}
});
});
$('#locations-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});

View File

@@ -1,9 +1,7 @@
$('.logout-button').hide();
$('#username').focus();
$('#username').focus();
if (GetUriParam('invalid') === 'true')
{
$('#login-error').text(L('Invalid credentials, please try again'));
$('#login-error').show();
$('#login-error').removeClass('d-none');
}

View File

@@ -1,4 +1,33 @@
$(document).on('click', '.apikey-delete-button', function(e)
var apiKeysTable = $('#apikeys-table').DataTable({
'paginate': false,
'order': [[4, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
var createdApiKeyId = GetUriParam('CreatedApiKeyId');
if (createdApiKeyId !== undefined)
{
$('#apiKeyRow_' + createdApiKeyId).effect('highlight', {}, 3000);
}
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
apiKeysTable.search(value).draw();
});
$(document).on('click', '.apikey-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-apikey-apikey');
var objectId = $(e.currentTarget).attr('data-apikey-id');
@@ -33,18 +62,3 @@
}
});
});
$('#apikeys-table').DataTable({
'pageLength': 50,
'order': [[4, 'desc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});
var createdApiKeyId = GetUriParam('CreatedApiKeyId');
if (createdApiKeyId !== undefined)
{
$('#apiKeyRow_' + createdApiKeyId).effect('highlight', { }, 3000);
}

View File

@@ -82,15 +82,35 @@ $('.input-group-qu').on('change', function(e)
if (factor > 1)
{
$('#qu-conversion-info').text(L('This means 1 #1 purchased will be converted into #2 #3 in stock', $("#qu_id_purchase option:selected").text(), (1 * factor).toString(), $("#qu_id_stock option:selected").text()));
$('#qu-conversion-info').show();
$('#qu-conversion-info').removeClass('d-none');
}
else
{
$('#qu-conversion-info').hide();
$('#qu-conversion-info').addClass('d-none');
}
});
$('#product-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
});
$('#product-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-product-button').click();
}
}
});
$('#name').focus();
$('#product-form').validator();
$('#product-form').validator('validate');
$('.input-group-qu').trigger('change');
Grocy.FrontendHelpers.ValidateForm('product-form');

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.product-delete-button', function(e)
var productsTable = $('#products-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
productsTable.search(value).draw();
});
$(document).on('click', '.product-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-product-name');
var objectId = $(e.currentTarget).attr('data-product-id');
@@ -33,12 +56,3 @@
}
});
});
$('#products-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});

View File

@@ -9,7 +9,13 @@
{
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
Grocy.Api.Get('stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
var price = "";
if (!jsonForm.price.toString().isEmpty())
{
price = parseFloat(jsonForm.price).toFixed(2);
}
Grocy.Api.Get('stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue() + '&price=' + price,
function(result)
{
var addBarcode = GetUriParam('addbarcodetoselection');
@@ -43,12 +49,11 @@
else
{
$('#amount').val(0);
$('#best_before_date').val('');
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
$('#purchase-form').validator('validate');
$('#price').val('');
Grocy.Components.DateTimePicker.SetValue('');
Grocy.Components.ProductPicker.SetValue('');
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('purchase-form');
}
},
function(xhr)
@@ -64,7 +69,7 @@
);
});
$('#product_id').on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
@@ -76,16 +81,16 @@ $('#product_id').on('change', function(e)
function(productDetails)
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
$('#price').val(productDetails.last_price);
if (productDetails.product.default_best_before_days.toString() !== '0')
{
$('#best_before_date').val(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
$('#best_before_date').trigger('change');
Grocy.Components.DateTimePicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
$('#amount').focus();
}
else
{
$('#best_before_date').focus();
Grocy.Components.DateTimePicker.GetInputElement().focus();
}
},
function(xhr)
@@ -96,122 +101,23 @@ $('#product_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#product_id_text_input').on('change', function(e)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
else
{
var optionElement = $("#product_id option:contains('" + input + "')").first();
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
{
bootbox.dialog({
message: L('"#1" could not be resolved to a product, how do you want to proceed?', input),
title: L('Create or assign product'),
onEscape: function() { },
size: 'large',
backdrop: true,
buttons: {
cancel: {
label: 'Cancel',
className: 'btn-default',
callback: function() { }
},
addnewproduct: {
label: '<strong>P</strong> ' + L('Add as new product'),
className: 'btn-success add-new-product-dialog-button',
callback: function()
{
window.location.href = U('/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
},
addbarcode: {
label: '<strong>B</strong> ' + L('Add as barcode to existing product'),
className: 'btn-info add-new-barcode-dialog-button',
callback: function()
{
window.location.href = U('/purchase?addbarcodetoselection=' + encodeURIComponent(input));
}
},
addnewproductwithbarcode: {
label: '<strong>A</strong> ' + L('Add as new product and prefill barcode'),
className: 'btn-warning add-new-product-with-barcode-dialog-button',
callback: function()
{
window.location.href = U('/product/new?prefillbarcode=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname));
}
}
}
}).on('keypress', function(e)
{
if (e.key === 'B' || e.key === 'b')
{
$('.add-new-barcode-dialog-button').click();
}
if (e.key === 'p' || e.key === 'P')
{
$('.add-new-product-dialog-button').click();
}
if (e.key === 'a' || e.key === 'A')
{
$('.add-new-product-with-barcode-dialog-button').click();
}
});
}
}
});
$('#amount').val(0);
$('#best_before_date').val('');
$('#product_id').val('');
$('#product_id_text_input').focus();
$('#product_id_text_input').val('');
$('#product_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
$('#purchase-form').validator({
custom: {
'isodate': function($el)
{
if ($el.val().length !== 0 && !moment($el.val(), 'YYYY-MM-DD', true).isValid())
{
return 'Wrong date format, needs to be YYYY-MM-DD';
}
else if (moment($el.val()).isValid())
{
if (moment($el.val()).isBefore(moment(), 'day'))
{
return 'This value cannot be before today.';
}
}
}
}
});
$('#purchase-form').validator('validate');
$('#best_before_date').on('focus', function(e)
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
if ($('#product_id_text_input').val().length === 0)
{
$('#product_id_text_input').focus();
}
});
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
$('#amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
$('#product_id_text_input').focus();
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
@@ -219,50 +125,38 @@ $('#amount').on('focus', function(e)
}
});
$('#purchase-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#purchase-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if ($('#purchase-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-purchase-button').click();
}
}
});
var prefillProduct = GetUriParam('createdproduct');
if (prefillProduct !== undefined)
Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e)
{
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
if (possibleOptionElement.length === 0)
{
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
}
if (possibleOptionElement.length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
$('#best_before_date').focus();
}
}
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
$('#addbarcodetoselection').text(addBarcode);
$('#flow-info-addbarcodetoselection').removeClass('hide');
$('#barcode-lookup-disabled-hint').removeClass('hide');
}
$('#best_before_date').on('change', function(e)
{
$('#purchase-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#best_before_date').on('keypress', function(e)
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
$('#purchase-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#amount').on('change', function (e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});

View File

@@ -30,6 +30,26 @@
}
});
$('#quantityunit-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
});
$('#quantityunit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-quantityunit-button').click();
}
}
});
$('#name').focus();
$('#quantityunit-form').validator();
$('#quantityunit-form').validator('validate');
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.quantityunit-delete-button', function(e)
var quantityUnitsTable = $('#quantityunits-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
quantityUnitsTable.search(value).draw();
});
$(document).on('click', '.quantityunit-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-quantityunit-name');
var objectId = $(e.currentTarget).attr('data-quantityunit-id');
@@ -33,12 +56,3 @@
}
});
});
$('#quantityunits-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
});

161
public/viewjs/recipeform.js Normal file
View File

@@ -0,0 +1,161 @@
$('#save-recipe-button').on('click', function(e)
{
e.preventDefault();
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
window.location.href = U('/recipes');
},
function(xhr)
{
console.error(xhr);
}
);
});
var recipesPosTables = $('#recipes-pos-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function ()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
recipesPosTables.search(value).draw();
});
Grocy.FrontendHelpers.ValidateForm('recipe-form');
$("#name").focus();
$('#recipe-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('recipe-form');
});
$('#recipe-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('recipe-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-recipe-button').click();
}
}
});
$(document).on('click', '.recipe-pos-delete-button', function(e)
{
var objectName = $(e.currentTarget).attr('data-recipe-pos-name');
var objectId = $(e.currentTarget).attr('data-recipe-pos-id');
bootbox.confirm({
message: L('Are you sure to delete recipe ingredient "#1"?', objectName),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Get('delete-object/recipes_pos/' + objectId,
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId);
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});
$(document).on('click', '.recipe-pos-order-missing-button', function(e)
{
var productName = $(e.currentTarget).attr('data-product-name');
var productId = $(e.currentTarget).attr('data-product-id');
var productAmount = $(e.currentTarget).attr('data-product-amount');
var recipeName = $(e.currentTarget).attr('data-recipe-name');
var jsonData = {};
jsonData.product_id = productId;
jsonData.amount = productAmount;
jsonData.note = L('Added for recipe #1', recipeName);
Grocy.Api.Post('add-object/shopping_list', jsonData,
function(result)
{
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { });
window.location.href = U('/recipe/' + Grocy.EditObjectId);
},
function(xhr)
{
console.error(xhr);
}
);
});
$(document).on('click', '.recipe-pos-show-note-button', function(e)
{
var note = $(e.currentTarget).attr('data-recipe-pos-note');
bootbox.alert(note);
});
$(document).on('click', '.recipe-pos-edit-button', function (e)
{
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId);
},
function(xhr)
{
console.error(xhr);
}
);
});
$("#recipe-pos-add-button").on("click", function(e)
{
Grocy.Api.Post('edit-object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new');
},
function(xhr)
{
console.error(xhr);
}
);
});

View File

@@ -0,0 +1,98 @@
$('#save-recipe-pos-button').on('click', function(e)
{
e.preventDefault();
var jsonData = $('#recipe-pos-form').serializeJSON();
jsonData.recipe_id = Grocy.EditObjectParentId;
console.log(jsonData);
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('add-object/recipes_pos', jsonData,
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
},
function(xhr)
{
console.error(xhr);
}
);
}
else
{
Grocy.Api.Post('edit-object/recipes_pos/' + Grocy.EditObjectId, jsonData,
function(result)
{
window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
},
function(xhr)
{
console.error(xhr);
}
);
}
});
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/get-product-details/' + productId,
function (productDetails)
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
$('#amount').focus();
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
},
function(xhr)
{
console.error(xhr);
}
);
}
});
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
Grocy.Components.ProductPicker.GetPicker().trigger('change');
$('#amount').on('focus', function(e)
{
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
$(this).select();
}
});
$('#recipe-pos-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
});
$('#recipe-pos-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('recipe-pos-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-recipe-pos-button').click();
}
}
});

119
public/viewjs/recipes.js Normal file
View File

@@ -0,0 +1,119 @@
var recipesTables = $('#recipes-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true,
'select': 'single',
'initComplete': function()
{
this.api().row({ order: 'current' }, 0).select();
}
});
var rowSelect = GetUriParam("row");
if (typeof rowSelect !== "undefined")
{
recipesTables.row(rowSelect).select();
}
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
recipesTables.search(value).draw();
});
$(document).on('click', '.recipe-delete-button', function(e)
{
var objectName = $(e.currentTarget).attr('data-recipe-name');
var objectId = $(e.currentTarget).attr('data-recipe-id');
bootbox.confirm({
message: L('Are you sure to delete recipe "#1"?', objectName),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Get('delete-object/recipes/' + objectId,
function(result)
{
window.location.href = U('/recipes');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});
$(document).on('click', '.recipe-order-missing-button', function(e)
{
var objectName = $(e.currentTarget).attr('data-recipe-name');
var objectId = $(e.currentTarget).attr('data-recipe-id');
bootbox.confirm({
message: L('Are you sure to put all missing ingredients for recipe "#1" on the shopping list?', objectName),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Get('recipes/add-not-fulfilled-products-to-shopping-list/' + objectId,
function(result)
{
window.location.href = U('/recipes');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});
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");
});

View File

@@ -1,4 +1,27 @@
$(document).on('click', '.shoppinglist-delete-button', function(e)
var shoppingListTable = $('#shoppinglist-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
shoppingListTable.search(value).draw();
});
$(document).on('click', '.shoppinglist-delete-button', function (e)
{
Grocy.Api.Get('delete-object/shopping_list/' + $(e.currentTarget).attr('data-shoppinglist-id'),
function(result)
@@ -26,11 +49,35 @@ $(document).on('click', '#add-products-below-min-stock-amount', function(e)
);
});
$('#shoppinglist-table').DataTable({
'pageLength': 50,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization'))
$(document).on('click', '#clear-shopping-list', function(e)
{
bootbox.confirm({
message: L('Are you sure to empty the shopping list?'),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Get('stock/clear-shopping-list',
function(result)
{
window.location.href = U('/shoppinglist');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});

View File

@@ -30,7 +30,7 @@
}
});
$('#product_id').on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
@@ -42,43 +42,8 @@ $('#product_id').on('change', function(e)
function (productDetails)
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
if ($('#product_id').hasClass('suppress-next-custom-validate-event'))
{
$('#product_id').removeClass('suppress-next-custom-validate-event');
}
else
{
Grocy.Api.Get('get-objects/shopping_list',
function (currentShoppingListItems)
{
if (currentShoppingListItems.filter(function (e) { return e.product_id === productId; }).length > 0)
{
$('#product_id').val('');
$('#product_id_text_input').val('');
$('#product_id_text_input').addClass('has-error');
$('#product_id_text_input').parent('.input-group').addClass('has-error');
$('#product_id_text_input').closest('.form-group').addClass('has-error');
$('#product-error').text('This product is already on the shopping list.');
$('#product-error').show();
$('#product_id_text_input').focus();
}
else
{
$('#product_id_text_input').removeClass('has-error');
$('#product_id_text_input').parent('.input-group').removeClass('has-error');
$('#product_id_text_input').closest('.form-group').removeClass('has-error');
$('#product-error').hide();
$('#amount').focus();
}
},
function(xhr)
{
console.error(xhr);
}
);
}
$('#amount').focus();
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
},
function(xhr)
{
@@ -88,50 +53,46 @@ $('#product_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
$('#product_id_text_input').on('change', function(e)
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (possibleOptionElement.length > 0 && possibleOptionElement.text().length > 0) {
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
});
$('#product_id_text_input').focus();
$('#product_id_text_input').trigger('change');
if (Grocy.EditMode === 'edit')
{
$('#product_id').addClass('suppress-next-custom-validate-event');
$('#product_id').trigger('change');
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
$('#shoppinglist-form').validator();
$('#shoppinglist-form').validator('validate');
$('#amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
$('#product_id_text_input').focus();
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
$(this).select();
}
});
$('#shoppinglist-form input').keydown(function(event)
$('#shoppinglist-form input').keyup(function (event)
{
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
});
$('#shoppinglist-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if ($('#shoppinglist-form').validator('validate').has('.has-error').length !== 0) //There is at least one validation error
if (document.getElementById('shoppinglist-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-shoppinglist-button').click();
}
}
});

View File

@@ -1,10 +1,36 @@
$('#stock-overview-table').DataTable({
'pageLength': 50,
var stockOverviewTable = $('#stock-overview-table').DataTable({
'paginate': false,
'order': [[3, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
{ 'orderable': false, 'targets': 0 },
{ 'visible': false, 'targets': 4 }
],
'language': JSON.parse(L('datatables_localization'))
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#location-filter").on("change", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
stockOverviewTable.column(4).search(value).draw();
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
stockOverviewTable.search(value).draw();
});
$(document).on('click', '.product-consume-button', function(e)
@@ -37,6 +63,7 @@ $(document).on('click', '.product-consume-button', function(e)
}
toastr.success(L('Removed #1 #2 of #3 from stock', consumeAmount, productQuName, productName));
RefreshStatistics();
},
function(xhr)
{
@@ -44,3 +71,37 @@ $(document).on('click', '.product-consume-button', function(e)
}
);
});
function RefreshStatistics()
{
Grocy.Api.Get('stock/get-current-stock',
function(result)
{
var amountSum = 0;
result.forEach(element => {
amountSum += parseInt(element.amount);
});
$("#info-current-stock").text(result.length + " " + Pluralize(result.length, L('Product'), L('Products')) + ", " + amountSum.toString() + " " + Pluralize(amountSum, L('Unit'), L('Units')));
},
function(xhr)
{
console.error(xhr);
}
);
var nextXDays = $("#info-expiring-products").data("next-x-days");
Grocy.Api.Get('stock/get-current-volatil-stock?expiring_days=' + nextXDays,
function(result)
{
$("#info-expiring-products").text(Pluralize(result.expiring_products.length, L('#1 product expires within the next #2 days', result.expiring_products.length, nextXDays), L('#1 products expiring within the next #2 days', result.expiring_products.length, nextXDays)));
$("#info-expired-products").text(Pluralize(result.expired_products.length, L('#1 product is already expired', result.expired_products.length), L('#1 products are already expired', result.expired_products.length)));
$("#info-missing-products").text(Pluralize(result.missing_products.length, L('#1 product is below defined min. stock amount', result.missing_products.length), L('#1 products are below defined min. stock amount', result.missing_products.length)));
},
function(xhr)
{
console.error(xhr);
}
);
}
RefreshStatistics();

73
public/viewjs/userform.js Normal file
View File

@@ -0,0 +1,73 @@
$('#save-user-button').on('click', function(e)
{
e.preventDefault();
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('users/create', $('#user-form').serializeJSON(),
function(result)
{
window.location.href = U('/users');
},
function(xhr)
{
console.error(xhr);
}
);
}
else
{
Grocy.Api.Post('users/edit/' + Grocy.EditObjectId, $('#user-form').serializeJSON(),
function(result)
{
window.location.href = U('/users');
},
function(xhr)
{
console.error(xhr);
}
);
}
});
$('#user-form input').keyup(function (event)
{
var element = document.getElementById("password_confirm");
if ($("#password").val() !== $("#password_confirm").val())
{
element.setCustomValidity("error");
}
else
{
element.setCustomValidity("");
}
Grocy.FrontendHelpers.ValidateForm('user-form');
});
$('#user-form input').keydown(function (event)
{
if (event.keyCode === 13) //Enter
{
if (document.getElementById('user-form').checkValidity() === false) //There is at least one validation error
{
event.preventDefault();
return false;
}
else
{
$('#save-user-button').click();
}
}
});
if (GetUriParam("changepw") === "true")
{
$('#password').focus();
}
else
{
$('#username').focus();
}
Grocy.FrontendHelpers.ValidateForm('user-form');

58
public/viewjs/users.js Normal file
View File

@@ -0,0 +1,58 @@
var usersTable = $('#users-table').DataTable({
'paginate': false,
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 }
],
'language': JSON.parse(L('datatables_localization')),
'scrollY': false,
'colReorder': true,
'stateSave': true
});
$("#search").on("keyup", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
usersTable.search(value).draw();
});
$(document).on('click', '.user-delete-button', function (e)
{
var objectName = $(e.currentTarget).attr('data-user-username');
var objectId = $(e.currentTarget).attr('data-user-id');
bootbox.confirm({
message: L('Are you sure to delete user "#1"?', objectName),
buttons: {
confirm: {
label: L('Yes'),
className: 'btn-success'
},
cancel: {
label: L('No'),
className: 'btn-danger'
}
},
callback: function(result)
{
if (result === true)
{
Grocy.Api.Get('users/delete/' + objectId,
function(result)
{
window.location.href = U('/users');
},
function(xhr)
{
console.error(xhr);
}
);
}
}
});
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 110 KiB

View File

@@ -1,7 +1,6 @@
<?php
use \Grocy\Middleware\JsonMiddleware;
use \Grocy\Middleware\CliMiddleware;
use \Grocy\Middleware\SessionAuthMiddleware;
use \Grocy\Middleware\ApiKeyAuthMiddleware;
use \Tuupola\Middleware\CorsMiddleware;
@@ -16,67 +15,92 @@ $app->group('', function()
$this->post('/login', 'LoginControllerInstance:ProcessLogin')->setName('login');
$this->get('/logout', 'LoginControllerInstance:Logout');
// User routes
$this->get('/users', '\Grocy\Controllers\UsersController:UsersList');
$this->get('/user/{userId}', '\Grocy\Controllers\UsersController:UserEditForm');
// Stock routes
$this->get('/stockoverview', 'Grocy\Controllers\StockController:Overview');
$this->get('/purchase', 'Grocy\Controllers\StockController:Purchase');
$this->get('/consume', 'Grocy\Controllers\StockController:Consume');
$this->get('/inventory', 'Grocy\Controllers\StockController:Inventory');
$this->get('/stockoverview', '\Grocy\Controllers\StockController:Overview');
$this->get('/purchase', '\Grocy\Controllers\StockController:Purchase');
$this->get('/consume', '\Grocy\Controllers\StockController:Consume');
$this->get('/inventory', '\Grocy\Controllers\StockController:Inventory');
$this->get('/products', '\Grocy\Controllers\StockController:ProductsList');
$this->get('/product/{productId}', '\Grocy\Controllers\StockController:ProductEditForm');
$this->get('/locations', '\Grocy\Controllers\StockController:LocationsList');
$this->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm');
$this->get('/quantityunits', '\Grocy\Controllers\StockController:QuantityUnitsList');
$this->get('/quantityunit/{quantityunitId}', '\Grocy\Controllers\StockController:QuantityUnitEditForm');
$this->get('/shoppinglist', '\Grocy\Controllers\StockController:ShoppingList');
$this->get('/shoppinglistitem/{itemId}', '\Grocy\Controllers\StockController:ShoppingListItemEditForm');
$this->get('/products', 'Grocy\Controllers\StockController:ProductsList');
$this->get('/product/{productId}', 'Grocy\Controllers\StockController:ProductEditForm');
$this->get('/locations', 'Grocy\Controllers\StockController:LocationsList');
$this->get('/location/{locationId}', 'Grocy\Controllers\StockController:LocationEditForm');
$this->get('/quantityunits', 'Grocy\Controllers\StockController:QuantityUnitsList');
$this->get('/quantityunit/{quantityunitId}', 'Grocy\Controllers\StockController:QuantityUnitEditForm');
$this->get('/shoppinglist', 'Grocy\Controllers\StockController:ShoppingList');
$this->get('/shoppinglistitem/{itemId}', 'Grocy\Controllers\StockController:ShoppingListItemEditForm');
// Recipe routes
$this->get('/recipes', '\Grocy\Controllers\RecipesController:Overview');
$this->get('/recipe/{recipeId}', '\Grocy\Controllers\RecipesController:RecipeEditForm');
$this->get('/recipe/{recipeId}/pos/{recipePosId}', '\Grocy\Controllers\RecipesController:RecipePosEditForm');
// Habit routes
$this->get('/habitsoverview', 'Grocy\Controllers\HabitsController:Overview');
$this->get('/habittracking', 'Grocy\Controllers\HabitsController:TrackHabitExecution');
$this->get('/habitsoverview', '\Grocy\Controllers\HabitsController:Overview');
$this->get('/habittracking', '\Grocy\Controllers\HabitsController:TrackHabitExecution');
$this->get('/habitsanalysis', '\Grocy\Controllers\HabitsController:Analysis');
$this->get('/habits', 'Grocy\Controllers\HabitsController:HabitsList');
$this->get('/habit/{habitId}', 'Grocy\Controllers\HabitsController:HabitEditForm');
$this->get('/habits', '\Grocy\Controllers\HabitsController:HabitsList');
$this->get('/habit/{habitId}', '\Grocy\Controllers\HabitsController:HabitEditForm');
// Batterry routes
$this->get('/batteriesoverview', 'Grocy\Controllers\BatteriesController:Overview');
$this->get('/batterytracking', 'Grocy\Controllers\BatteriesController:TrackChargeCycle');
// Battery routes
$this->get('/batteriesoverview', '\Grocy\Controllers\BatteriesController:Overview');
$this->get('/batterytracking', '\Grocy\Controllers\BatteriesController:TrackChargeCycle');
$this->get('/batteries', 'Grocy\Controllers\BatteriesController:BatteriesList');
$this->get('/battery/{batteryId}', 'Grocy\Controllers\BatteriesController:BatteryEditForm');
$this->get('/batteries', '\Grocy\Controllers\BatteriesController:BatteriesList');
$this->get('/battery/{batteryId}', '\Grocy\Controllers\BatteriesController:BatteryEditForm');
// Other routes
$this->get('/api', 'Grocy\Controllers\OpenApiController:DocumentationUi');
$this->get('/manageapikeys', 'Grocy\Controllers\OpenApiController:ApiKeysList');
$this->get('/manageapikeys/new', 'Grocy\Controllers\OpenApiController:CreateNewApiKey');
// OpenAPI routes
$this->get('/api', '\Grocy\Controllers\OpenApiController:DocumentationUi');
$this->get('/manageapikeys', '\Grocy\Controllers\OpenApiController:ApiKeysList');
$this->get('/manageapikeys/new', '\Grocy\Controllers\OpenApiController:CreateNewApiKey');
})->add(new SessionAuthMiddleware($appContainer, $appContainer->LoginControllerInstance->GetSessionCookieName()));
$app->group('/api', function()
{
$this->get('/get-openapi-specification', 'Grocy\Controllers\OpenApiController:DocumentationSpec');
// OpenAPI
$this->get('/get-openapi-specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec');
$this->get('/get-objects/{entity}', 'Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/get-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/add-object/{entity}', 'Grocy\Controllers\GenericEntityApiController:AddObject');
$this->post('/edit-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:EditObject');
$this->get('/delete-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:DeleteObject');
// Generic entity interaction
$this->get('/get-objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/get-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/add-object/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject');
$this->post('/edit-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject');
$this->get('/delete-object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject');
$this->get('/stock/add-product/{productId}/{amount}', 'Grocy\Controllers\StockApiController:AddProduct');
$this->get('/stock/consume-product/{productId}/{amount}', 'Grocy\Controllers\StockApiController:ConsumeProduct');
$this->get('/stock/inventory-product/{productId}/{newAmount}', 'Grocy\Controllers\StockApiController:InventoryProduct');
$this->get('/stock/get-product-details/{productId}', 'Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/get-current-stock', 'Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/add-missing-products-to-shoppinglist', 'Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
$this->get('/stock/external-barcode-lookup/{barcode}', 'Grocy\Controllers\StockApiController:ExternalBarcodeLookup');
// Users
$this->get('/users/get', '\Grocy\Controllers\UsersApiController:GetUsers');
$this->post('/users/create', '\Grocy\Controllers\UsersApiController:CreateUser');
$this->post('/users/edit/{userId}', '\Grocy\Controllers\UsersApiController:EditUser');
$this->get('/users/delete/{userId}', '\Grocy\Controllers\UsersApiController:DeleteUser');
$this->get('/habits/track-habit-execution/{habitId}', 'Grocy\Controllers\HabitsApiController:TrackHabitExecution');
$this->get('/habits/get-habit-details/{habitId}', 'Grocy\Controllers\HabitsApiController:HabitDetails');
// Stock
$this->get('/stock/add-product/{productId}/{amount}', '\Grocy\Controllers\StockApiController:AddProduct');
$this->get('/stock/consume-product/{productId}/{amount}', '\Grocy\Controllers\StockApiController:ConsumeProduct');
$this->get('/stock/inventory-product/{productId}/{newAmount}', '\Grocy\Controllers\StockApiController:InventoryProduct');
$this->get('/stock/get-product-details/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/get-product-price-history/{productId}', '\Grocy\Controllers\StockApiController:ProductPriceHistory');
$this->get('/stock/get-current-stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/get-current-volatil-stock', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
$this->get('/stock/add-missing-products-to-shoppinglist', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
$this->get('/stock/clear-shopping-list', '\Grocy\Controllers\StockApiController:ClearShoppingList');
$this->get('/stock/external-barcode-lookup/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup');
// Recipes
$this->get('/recipes/add-not-fulfilled-products-to-shopping-list/{recipeId}', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList');
// Habits
$this->get('/habits/track-habit-execution/{habitId}', '\Grocy\Controllers\HabitsApiController:TrackHabitExecution');
$this->get('/habits/get-habit-details/{habitId}', '\Grocy\Controllers\HabitsApiController:HabitDetails');
$this->get('/habits/get-current', '\Grocy\Controllers\HabitsApiController:Current');
$this->get('/batteries/track-charge-cycle/{batteryId}', 'Grocy\Controllers\BatteriesApiController:TrackChargeCycle');
$this->get('/batteries/get-battery-details/{batteryId}', 'Grocy\Controllers\BatteriesApiController:BatteryDetails');
// Batteries
$this->get('/batteries/track-charge-cycle/{batteryId}', '\Grocy\Controllers\BatteriesApiController:TrackChargeCycle');
$this->get('/batteries/get-battery-details/{batteryId}', '\Grocy\Controllers\BatteriesApiController:BatteryDetails');
$this->get('/batteries/get-current', '\Grocy\Controllers\BatteriesApiController:Current');
})->add(new ApiKeyAuthMiddleware($appContainer, $appContainer->LoginControllerInstance->GetSessionCookieName(), $appContainer->ApiKeyHeaderName))
->add(JsonMiddleware::class)
->add(new CorsMiddleware([
@@ -87,8 +111,3 @@ $app->group('/api', function()
'credentials' => false,
'cache' => 0,
]));
$app->group('/cli', function()
{
$this->get('/recreatedemo', 'Grocy\Controllers\CliController:RecreateDemo');
})->add(CliMiddleware::class);

View File

@@ -39,6 +39,7 @@ class ApiKeyService extends BaseService
$apiKeyRow = $this->Database->api_keys()->createRow(array(
'api_key' => $newApiKey,
'user_id' => GROCY_USER_ID,
'expires' => '2999-12-31 23:59:59' // Default is that API keys expire never
));
$apiKeyRow->save();
@@ -57,6 +58,16 @@ class ApiKeyService extends BaseService
return $apiKey->id;
}
public function GetUserByApiKey($apiKey)
{
$apiKeyRow = $this->Database->api_keys()->where('api_key', $apiKey)->fetch();
if ($apiKeyRow !== null)
{
return $this->Database->users($apiKeyRow->user_id);
}
return null;
}
private function GenerateApiKey()
{
return RandomString(50);

View File

@@ -4,14 +4,6 @@ namespace Grocy\Services;
class ApplicationService extends BaseService
{
/**
* @return boolean
*/
public function IsDemoInstallation()
{
return file_exists(__DIR__ . '/../data/demo.txt');
}
private $InstalledVersion;
public function GetInstalledVersion()
{

View File

@@ -3,14 +3,19 @@
namespace Grocy\Services;
use \Grocy\Services\DatabaseService;
use \Grocy\Services\LocalizationService;
class BaseService
{
public function __construct() {
$this->DatabaseService = new DatabaseService();
$this->Database = $this->DatabaseService->GetDbConnection();
$localizationService = new LocalizationService(GROCY_CULTURE);
$this->LocalizationService = $localizationService;
}
protected $DatabaseService;
protected $Database;
protected $LocalizationService;
}

View File

@@ -10,28 +10,6 @@ class BatteriesService extends BaseService
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
}
public function GetNextChargeTime(int $batteryId)
{
if (!$this->BatteryExists($batteryId))
{
throw new \Exception('Battery does not exist');
}
$battery = $this->Database->batteries($batteryId);
$batteryLastLogRow = $this->DatabaseService->ExecuteDbQuery("SELECT * from batteries_current WHERE battery_id = $batteryId LIMIT 1")->fetch(\PDO::FETCH_OBJ);
if ($battery->charge_interval_days > 0)
{
return date('Y-m-d H:i:s', strtotime('+' . $battery->charge_interval_days . ' day', strtotime($batteryLastLogRow->last_tracked_time)));
}
else
{
return date('2999-12-31 23:59:59');
}
return null;
}
public function GetBatteryDetails(int $batteryId)
{
if (!$this->BatteryExists($batteryId))

View File

@@ -8,21 +8,38 @@ class DatabaseMigrationService extends BaseService
{
$this->DatabaseService->ExecuteDbStatement("CREATE TABLE IF NOT EXISTS migrations (migration INTEGER NOT NULL PRIMARY KEY UNIQUE, execution_time_timestamp DATETIME DEFAULT (datetime('now', 'localtime')))");
$migrationFiles = array();
$sqlMigrationFiles = array();
foreach (new \FilesystemIterator(__DIR__ . '/../migrations') as $file)
{
$migrationFiles[$file->getBasename('.sql')] = $file->getPathname();
if ($file->getExtension() === 'sql')
{
$sqlMigrationFiles[$file->getBasename('.sql')] = $file->getPathname();
}
}
ksort($migrationFiles);
foreach($migrationFiles as $migrationNumber => $migrationFile)
ksort($sqlMigrationFiles);
foreach($sqlMigrationFiles as $migrationNumber => $migrationFile)
{
$migrationNumber = ltrim($migrationNumber, '0');
$this->ExecuteMigrationWhenNeeded($migrationNumber, file_get_contents($migrationFile));
$this->ExecuteSqlMigrationWhenNeeded($migrationNumber, file_get_contents($migrationFile));
}
$phpMigrationFiles = array();
foreach (new \FilesystemIterator(__DIR__ . '/../migrations') as $file)
{
if ($file->getExtension() === 'php')
{
$phpMigrationFiles[$file->getBasename('.php')] = $file->getPathname();
}
}
ksort($phpMigrationFiles);
foreach($phpMigrationFiles as $migrationNumber => $migrationFile)
{
$migrationNumber = ltrim($migrationNumber, '0');
$this->ExecutePhpMigrationWhenNeeded($migrationNumber, $migrationFile);
}
}
private function ExecuteMigrationWhenNeeded(int $migrationId, string $sql)
private function ExecuteSqlMigrationWhenNeeded(int $migrationId, string $sql)
{
$rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
if (intval($rowCount) === 0)
@@ -31,4 +48,14 @@ class DatabaseMigrationService extends BaseService
$this->DatabaseService->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
private function ExecutePhpMigrationWhenNeeded(int $migrationId, string $phpFile)
{
$rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn();
if (intval($rowCount) === 0)
{
include $phpFile;
$this->DatabaseService->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
}
}
}

View File

@@ -14,7 +14,7 @@ class DatabaseService
{
if ($this->DbConnectionRaw == null)
{
$pdo = new \PDO('sqlite:' . __DIR__ . '/../data/grocy.db');
$pdo = new \PDO('sqlite:' . GROCY_DATAPATH . '/grocy.db');
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->DbConnectionRaw = $pdo;
}

Some files were not shown because too many files have changed in this diff Show More