mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Finalize project reorganization
This commit is contained in:
parent
5a1d21ef31
commit
642f95a3f8
@ -25,7 +25,7 @@ class LoginController extends BaseController
|
||||
if ($postParams['username'] === HTTP_USER && $postParams['password'] === HTTP_PASSWORD)
|
||||
{
|
||||
$sessionKey = $this->SessionService->CreateSession();
|
||||
setcookie('grocy_session', $sessionKey, time()+2592000); //30 days
|
||||
setcookie('grocy_session', $sessionKey, time() + 31536000); // Cookie expires in 1 year, but session validity is up to SessionService
|
||||
|
||||
return $response->withRedirect('/');
|
||||
}
|
||||
|
12
middleware/BaseMiddleware.php
Normal file
12
middleware/BaseMiddleware.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Grocy\Middleware;
|
||||
|
||||
class BaseMiddleware
|
||||
{
|
||||
public function __construct(\Slim\Container $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected $container;
|
||||
}
|
@ -2,14 +2,8 @@
|
||||
|
||||
namespace Grocy\Middleware;
|
||||
|
||||
class CliMiddleware
|
||||
class CliMiddleware extends BaseMiddleware
|
||||
{
|
||||
public function __construct(\Slim\Container $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next)
|
||||
{
|
||||
if (PHP_SAPI !== 'cli')
|
||||
|
@ -2,14 +2,8 @@
|
||||
|
||||
namespace Grocy\Middleware;
|
||||
|
||||
class JsonMiddleware
|
||||
class JsonMiddleware extends BaseMiddleware
|
||||
{
|
||||
public function __construct(\Slim\Container $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next)
|
||||
{
|
||||
$response = $next($request, $response, $next);
|
||||
|
@ -4,14 +4,8 @@ namespace Grocy\Middleware;
|
||||
|
||||
use \Grocy\Services\SessionService;
|
||||
|
||||
class SessionAuthMiddleware
|
||||
class SessionAuthMiddleware extends BaseMiddleware
|
||||
{
|
||||
public function __construct(\Slim\Container $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next)
|
||||
{
|
||||
$route = $request->getAttribute('route');
|
||||
|
6
migrations/0020.sql
Normal file
6
migrations/0020.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE sessions (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
session_key TEXT NOT NULL UNIQUE,
|
||||
expires DATETIME,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
@ -23,7 +23,7 @@
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-color: #e5e5e5;
|
||||
border-right: 1px solid #d6d6d6;
|
||||
border-right: 2px solid #d6d6d6;
|
||||
min-width: 220px;
|
||||
max-width: 260px;
|
||||
}
|
||||
@ -42,12 +42,14 @@
|
||||
.nav-sidebar > li > a {
|
||||
padding-right: 20px;
|
||||
padding-left: 20px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.nav-sidebar > .active > a,
|
||||
.nav-sidebar > .active > a:hover,
|
||||
.nav-sidebar > .active > a:focus {
|
||||
background-color: #d6d6d6;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.navbar-default {
|
||||
@ -73,7 +75,6 @@
|
||||
color: #a7a7a7;
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
font-family: 'Arial', sans-serif;
|
||||
}
|
||||
|
||||
.discrete-link {
|
||||
@ -94,15 +95,15 @@ a.discrete-link:focus {
|
||||
}
|
||||
|
||||
.navbar-fixed-top {
|
||||
border-bottom: solid;
|
||||
border-bottom: 2px solid;
|
||||
border-color: #d6d6d6;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
letter-spacing: -2px;
|
||||
letter-spacing: -5px;
|
||||
font-size: 2.2em;
|
||||
font-family: 'Arial', sans-serif;
|
||||
|
||||
}
|
||||
|
||||
.table td.fit-content,
|
||||
|
33
public/js/extensions.js
Normal file
33
public/js/extensions.js
Normal file
@ -0,0 +1,33 @@
|
||||
EmptyElementWhenMatches = function(selector, text)
|
||||
{
|
||||
if ($(selector).text() === text)
|
||||
{
|
||||
$(selector).text('');
|
||||
}
|
||||
};
|
||||
|
||||
String.prototype.contains = function(search)
|
||||
{
|
||||
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
||||
};
|
||||
|
||||
String.prototype.isEmpty = function()
|
||||
{
|
||||
return (this.length === 0 || !this.trim());
|
||||
};
|
||||
|
||||
GetUriParam = function(key)
|
||||
{
|
||||
var currentUri = decodeURIComponent(window.location.search.substring(1));
|
||||
var vars = currentUri.split('&');
|
||||
|
||||
for (i = 0; i < vars.length; i++)
|
||||
{
|
||||
var currentParam = vars[i].split('=');
|
||||
|
||||
if (currentParam[0] === key)
|
||||
{
|
||||
return currentParam[1] === undefined ? true : currentParam[1];
|
||||
}
|
||||
}
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
var Grocy = { };
|
||||
Grocy.Components = { };
|
||||
|
||||
$(function()
|
||||
{
|
||||
@ -70,42 +71,3 @@ Grocy.PostJson = function(url, jsonData, success, error)
|
||||
xhr.setRequestHeader('Content-type', 'application/json');
|
||||
xhr.send(JSON.stringify(jsonData));
|
||||
};
|
||||
|
||||
Grocy.EmptyElementWhenMatches = function(selector, text)
|
||||
{
|
||||
if ($(selector).text() === text)
|
||||
{
|
||||
$(selector).text('');
|
||||
}
|
||||
};
|
||||
|
||||
String.prototype.contains = function(search)
|
||||
{
|
||||
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
||||
};
|
||||
|
||||
String.prototype.isEmpty = function()
|
||||
{
|
||||
return (this.length === 0 || !this.trim());
|
||||
};
|
||||
|
||||
Grocy.GetUriParam = function(key)
|
||||
{
|
||||
var currentUri = decodeURIComponent(window.location.search.substring(1));
|
||||
var vars = currentUri.split('&');
|
||||
|
||||
for (i = 0; i < vars.length; i++)
|
||||
{
|
||||
var currentParam = vars[i].split('=');
|
||||
|
||||
if (currentParam[0] === key)
|
||||
{
|
||||
return currentParam[1] === undefined ? true : currentParam[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Grocy.Wait = function(ms)
|
||||
{
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
@ -39,23 +39,8 @@ $('#battery_id').on('change', function(e)
|
||||
|
||||
if (batteryId)
|
||||
{
|
||||
Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId,
|
||||
function(batteryDetails)
|
||||
{
|
||||
$('#selected-battery-name').text(batteryDetails.battery.name);
|
||||
$('#selected-battery-last-charged').text((batteryDetails.last_charged || 'never'));
|
||||
$('#selected-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
|
||||
$('#selected-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
|
||||
|
||||
$('#tracked_time').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-battery-last-charged-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
Grocy.Components.BatteryCard.Refresh(batteryId);
|
||||
$('#tracked_time').focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
20
public/viewjs/components/batterycard.js
Normal file
20
public/viewjs/components/batterycard.js
Normal file
@ -0,0 +1,20 @@
|
||||
Grocy.Components.BatteryCard = { };
|
||||
|
||||
Grocy.Components.BatteryCard.Refresh = function(batteryId)
|
||||
{
|
||||
Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId,
|
||||
function(batteryDetails)
|
||||
{
|
||||
$('#batterycard-battery-name').text(batteryDetails.battery.name);
|
||||
$('#batterycard-battery-last-charged').text((batteryDetails.last_charged || 'never'));
|
||||
$('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || ''));
|
||||
$('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0'));
|
||||
|
||||
EmptyElementWhenMatches('#batterycard-battery-last-charged-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
};
|
20
public/viewjs/components/habitcard.js
Normal file
20
public/viewjs/components/habitcard.js
Normal file
@ -0,0 +1,20 @@
|
||||
Grocy.Components.HabitCard = { };
|
||||
|
||||
Grocy.Components.HabitCard.Refresh = function (habitId)
|
||||
{
|
||||
Grocy.FetchJson('/api/habits/get-habit-details/' + habitId,
|
||||
function(habitDetails)
|
||||
{
|
||||
$('#habitcard-habit-name').text(habitDetails.habit.name);
|
||||
$('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
|
||||
$('#habitcard-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
|
||||
$('#habitcard-habit-tracked-count').text((habitDetails.tracked_count || '0'));
|
||||
|
||||
EmptyElementWhenMatches('#habitcard-habit-last-tracked-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
};
|
25
public/viewjs/components/productcard.js
Normal file
25
public/viewjs/components/productcard.js
Normal file
@ -0,0 +1,25 @@
|
||||
Grocy.Components.ProductCard = { };
|
||||
|
||||
Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
{
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#productcard-product-name').text(productDetails.product.name);
|
||||
$('#productcard-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#productcard-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#productcard-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
|
||||
$('#productcard-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#productcard-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#productcard-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#productcard-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
|
||||
EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', 'NaN years ago');
|
||||
EmptyElementWhenMatches('#productcard-product-last-used-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
};
|
@ -44,24 +44,15 @@ $('#product_id').on('change', function(e)
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function (productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount').attr('max', productDetails.stock_amount);
|
||||
$('#consume-form').validator('update');
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
|
||||
if ((productDetails.stock_amount || 0) === 0)
|
||||
{
|
||||
$('#product_id').val('');
|
||||
|
@ -39,23 +39,8 @@ $('#habit_id').on('change', function(e)
|
||||
|
||||
if (habitId)
|
||||
{
|
||||
Grocy.FetchJson('/api/habits/get-habit-details/' + habitId,
|
||||
function(habitDetails)
|
||||
{
|
||||
$('#selected-habit-name').text(habitDetails.habit.name);
|
||||
$('#selected-habit-last-tracked').text((habitDetails.last_tracked || 'never'));
|
||||
$('#selected-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || ''));
|
||||
$('#selected-habit-tracked-count').text((habitDetails.tracked_count || '0'));
|
||||
|
||||
$('#tracked_time').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-habit-last-tracked-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
Grocy.Components.HabitCard.Refresh(habitId);
|
||||
$('#tracked_time').focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
@ -33,7 +33,6 @@
|
||||
}
|
||||
|
||||
toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name);
|
||||
Grocy.Wait(1000);
|
||||
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
@ -70,24 +69,15 @@ $('#product_id').on('change', function(e)
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#new_amount').attr('not-equal', productDetails.stock_amount);
|
||||
$('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name);
|
||||
|
||||
$('#new_amount').focus();
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@ -121,7 +111,7 @@ $(function()
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
@ -130,7 +120,7 @@ $(function()
|
||||
else
|
||||
{
|
||||
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
|
||||
{
|
||||
bootbox.dialog({
|
||||
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||
@ -246,7 +236,7 @@ $(function()
|
||||
}
|
||||
});
|
||||
|
||||
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||
var prefillProduct = GetUriParam('createdproduct');
|
||||
if (prefillProduct !== undefined)
|
||||
{
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||
@ -264,7 +254,7 @@ $(function()
|
||||
}
|
||||
}
|
||||
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
$('#addbarcodetoselection').text(addBarcode);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
$('#username').focus();
|
||||
|
||||
if (Grocy.GetUriParam('invalid') === 'true')
|
||||
if (GetUriParam('invalid') === 'true')
|
||||
{
|
||||
$('#login-error').text('Invalid credentials, please try again.');
|
||||
$('#login-error').show();
|
||||
|
@ -3,7 +3,7 @@
|
||||
e.preventDefault();
|
||||
|
||||
var redirectDestination = '/products';
|
||||
var returnTo = Grocy.GetUriParam('returnto');
|
||||
var returnTo = GetUriParam('returnto');
|
||||
if (returnTo !== undefined)
|
||||
{
|
||||
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
|
||||
@ -69,14 +69,14 @@ $(function()
|
||||
$('#product-form').validator();
|
||||
$('#product-form').validator('validate');
|
||||
|
||||
var prefillName = Grocy.GetUriParam('prefillname');
|
||||
var prefillName = GetUriParam('prefillname');
|
||||
if (prefillName !== undefined)
|
||||
{
|
||||
$('#name').val(prefillName);
|
||||
$('#name').focus();
|
||||
}
|
||||
|
||||
var prefillBarcode = Grocy.GetUriParam('prefillbarcode');
|
||||
var prefillBarcode = GetUriParam('prefillbarcode');
|
||||
if (prefillBarcode !== undefined)
|
||||
{
|
||||
$('#barcode-taginput').tagsManager('pushTag', prefillBarcode);
|
||||
|
@ -12,7 +12,7 @@
|
||||
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||
function(result)
|
||||
{
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
@ -35,7 +35,6 @@
|
||||
}
|
||||
|
||||
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
||||
Grocy.Wait(1000);
|
||||
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
@ -71,17 +70,11 @@ $('#product_id').on('change', function(e)
|
||||
|
||||
if (productId)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
Grocy.FetchJson('/api/stock/get-product-details/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#selected-product-name').text(productDetails.product.name);
|
||||
$('#selected-product-stock-amount').text(productDetails.stock_amount || '0');
|
||||
$('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name);
|
||||
$('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10));
|
||||
$('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || ''));
|
||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
||||
@ -93,10 +86,7 @@ $('#product_id').on('change', function(e)
|
||||
else
|
||||
{
|
||||
$('#best_before_date').focus();
|
||||
}
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@ -130,7 +120,7 @@ $(function()
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||
|
||||
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').data('combobox').refresh();
|
||||
@ -139,7 +129,7 @@ $(function()
|
||||
else
|
||||
{
|
||||
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||
if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined )
|
||||
{
|
||||
bootbox.dialog({
|
||||
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||
@ -256,7 +246,7 @@ $(function()
|
||||
}
|
||||
});
|
||||
|
||||
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||
var prefillProduct = GetUriParam('createdproduct');
|
||||
if (prefillProduct !== undefined)
|
||||
{
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||
@ -274,7 +264,7 @@ $(function()
|
||||
}
|
||||
}
|
||||
|
||||
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
$('#addbarcodetoselection').text(addBarcode);
|
||||
@ -282,7 +272,7 @@ $(function()
|
||||
$('#barcode-lookup-disabled-hint').removeClass('hide');
|
||||
}
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
});
|
||||
|
||||
$('#best_before_date-datepicker-button').on('click', function(e)
|
||||
@ -314,7 +304,7 @@ $('#best_before_date').on('change', function(e)
|
||||
}
|
||||
|
||||
$('#best-before-timeago').text($.timeago($('#best_before_date').val()));
|
||||
Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago');
|
||||
});
|
||||
|
||||
$('#best_before_date').on('keydown', function(e)
|
||||
|
@ -49,8 +49,8 @@ $('#product_id').on('change', function(e)
|
||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||
EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||
|
||||
if ($('#product_id').hasClass('suppress-next-custom-validate-event'))
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ class SessionService extends BaseService
|
||||
}
|
||||
else
|
||||
{
|
||||
return file_exists(__DIR__ . "/../data/sessions/$sessionKey.txt");
|
||||
return $this->Database->sessions()->where('session_key = :1 AND expires > :2', $sessionKey, time())->count() === 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,27 +24,19 @@ class SessionService extends BaseService
|
||||
*/
|
||||
public function CreateSession()
|
||||
{
|
||||
if (!file_exists(__DIR__ . '/../data/sessions'))
|
||||
{
|
||||
mkdir(__DIR__ . '/../data/sessions');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
foreach (new \FilesystemIterator(__DIR__ . '/../data/sessions') as $file)
|
||||
{
|
||||
if ($now - $file->getCTime() >= 2678400) //31 days
|
||||
{
|
||||
unlink(__DIR__ . '/../data/sessions/' . $file->getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
$newSessionKey = uniqid() . uniqid() . uniqid();
|
||||
file_put_contents(__DIR__ . "/../data/sessions/$newSessionKey.txt", '');
|
||||
|
||||
$sessionRow = $this->Database->sessions()->createRow(array(
|
||||
'session_key' => $newSessionKey,
|
||||
'expires' => time() + 2592000 //30 days
|
||||
));
|
||||
$sessionRow->save();
|
||||
|
||||
return $newSessionKey;
|
||||
}
|
||||
|
||||
public function RemoveSession($sessionKey)
|
||||
{
|
||||
unlink(__DIR__ . "/../data/sessions/$sessionKey.txt");
|
||||
$this->Database->sessions()->where('session_key', $sessionKey)->delete();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'batteries')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Batteries
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'batteriesoverview')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Batteries overview</h1>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'batteryform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'batterytracking')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Battery tracking</h1>
|
||||
|
||||
@ -39,12 +39,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-5 col-lg-3 main well">
|
||||
<h3>Battery overview <strong><span id="selected-battery-name"></span></strong></h3>
|
||||
|
||||
<p>
|
||||
<strong>Charge cycles count:</strong> <span id="selected-battery-charge-cycles-count"></span><br>
|
||||
<strong>Last charged:</strong> <span id="selected-battery-last-charged"></span> <time id="selected-battery-last-charged-timeago" class="timeago timeago-contextual"></time><br>
|
||||
</p>
|
||||
<div class="col-sm-6 col-md-5 col-lg-3">
|
||||
@include('components.batterycard')
|
||||
</div>
|
||||
@stop
|
||||
|
16
views/components/batterycard.blade.php
Normal file
16
views/components/batterycard.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
@extends('layout.basecomponent')
|
||||
|
||||
@section('componentJsName', 'batterycard')
|
||||
|
||||
@section('componentContent')
|
||||
<div class="main well">
|
||||
|
||||
<h3>Battery overview <strong><span id="batterycard-battery-name"></span></strong></h3>
|
||||
|
||||
<p>
|
||||
<strong>Charge cycles count:</strong> <span id="batterycard-battery-charge-cycles-count"></span><br>
|
||||
<strong>Last charged:</strong> <span id="batterycard-battery-last-charged"></span> <time id="batterycard-battery-last-charged-timeago" class="timeago timeago-contextual"></time><br>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
@stop
|
16
views/components/habitcard.blade.php
Normal file
16
views/components/habitcard.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
@extends('layout.basecomponent')
|
||||
|
||||
@section('componentJsName', 'habitcard')
|
||||
|
||||
@section('componentContent')
|
||||
<div class="main well">
|
||||
|
||||
<h3>Habit overview <strong><span id="habitcard-habit-name"></span></strong></h3>
|
||||
|
||||
<p>
|
||||
<strong>Tracked count:</strong> <span id="habitcard-habit-tracked-count"></span><br>
|
||||
<strong>Last tracked:</strong> <span id="habitcard-habit-last-tracked"></span> <time id="habitcard-habit-last-tracked-timeago" class="timeago timeago-contextual"></time><br>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
@stop
|
18
views/components/productcard.blade.php
Normal file
18
views/components/productcard.blade.php
Normal file
@ -0,0 +1,18 @@
|
||||
@extends('layout.basecomponent')
|
||||
|
||||
@section('componentJsName', 'productcard')
|
||||
|
||||
@section('componentContent')
|
||||
<div class="main well">
|
||||
|
||||
<h3>Product overview <strong><span id="productcard-product-name"></span></strong></h3>
|
||||
<h4><strong>Stock quantity unit:</strong> <span id="productcard-product-stock-qu-name"></span></h4>
|
||||
|
||||
<p>
|
||||
<strong>Stock amount:</strong> <span id="productcard-product-stock-amount"></span> <span id="productcard-product-stock-qu-name2"></span><br>
|
||||
<strong>Last purchased:</strong> <span id="productcard-product-last-purchased"></span> <time id="productcard-product-last-purchased-timeago" class="timeago timeago-contextual"></time><br>
|
||||
<strong>Last used:</strong> <span id="productcard-product-last-used"></span> <time id="productcard-product-last-used-timeago" class="timeago timeago-contextual"></time>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
@stop
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'consume')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Consume</h1>
|
||||
|
||||
@ -40,14 +40,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-5 col-lg-3 main well">
|
||||
<h3>Product overview <strong><span id="selected-product-name"></span></strong></h3>
|
||||
<h4><strong>Stock quantity unit:</strong> <span id="selected-product-stock-qu-name"></span></h4>
|
||||
|
||||
<p>
|
||||
<strong>Stock amount:</strong> <span id="selected-product-stock-amount"></span> <span id="selected-product-stock-qu-name2"></span><br>
|
||||
<strong>Last purchased:</strong> <span id="selected-product-last-purchased"></span> <time id="selected-product-last-purchased-timeago" class="timeago timeago-contextual"></time><br>
|
||||
<strong>Last used:</strong> <span id="selected-product-last-used"></span> <time id="selected-product-last-used-timeago" class="timeago timeago-contextual"></time>
|
||||
</p>
|
||||
<div class="col-sm-6 col-md-5 col-lg-3">
|
||||
@include('components.productcard')
|
||||
</div>
|
||||
@stop
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'habitform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'habits')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Habits
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'habitsoverview')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Habits overview</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'habittracking')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Habit tracking</h1>
|
||||
|
||||
@ -39,12 +39,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-5 col-lg-3 main well">
|
||||
<h3>Habit overview <strong><span id="selected-habit-name"></span></strong></h3>
|
||||
|
||||
<p>
|
||||
<strong>Tracked count:</strong> <span id="selected-habit-tracked-count"></span><br>
|
||||
<strong>Last tracked:</strong> <span id="selected-habit-last-tracked"></span> <time id="selected-habit-last-tracked-timeago" class="timeago timeago-contextual"></time><br>
|
||||
</p>
|
||||
<div class="col-sm-6 col-md-5 col-lg-3">
|
||||
@include('components.habitcard')
|
||||
</div>
|
||||
@stop
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'inventory')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-4 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-4 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Inventory</h1>
|
||||
|
||||
@ -47,14 +47,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-5 col-lg-3 main well">
|
||||
<h3>Product overview <strong><span id="selected-product-name"></span></strong></h3>
|
||||
<h4><strong>Purchase quantity:</strong> <span id="selected-product-purchase-qu-name"></span></h4>
|
||||
|
||||
<p>
|
||||
<strong>Stock amount:</strong> <span id="selected-product-stock-amount"></span> <span id="selected-product-stock-qu-name"></span><br>
|
||||
<strong>Last purchased:</strong> <span id="selected-product-last-purchased"></span> <time id="selected-product-last-purchased-timeago" class="timeago timeago-contextual"></time><br>
|
||||
<strong>Last used:</strong> <span id="selected-product-last-used"></span> <time id="selected-product-last-used-timeago" class="timeago timeago-contextual"></time>
|
||||
</p>
|
||||
<div class="col-sm-6 col-md-5 col-lg-3">
|
||||
@include('components.productcard')
|
||||
</div>
|
||||
@stop
|
||||
|
6
views/layout/basecomponent.blade.php
Normal file
6
views/layout/basecomponent.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
@section('componentContent')
|
||||
@show
|
||||
|
||||
@push('componentScripts')
|
||||
<script src="/viewjs/components/@yield('componentJsName').js"></script>
|
||||
@endpush
|
@ -27,6 +27,7 @@
|
||||
|
||||
<script src="/bower_components/jquery/dist/jquery.min.js?v={{ $version }}"></script>
|
||||
<script src="/js/grocy.js?v={{ $version }}"></script>
|
||||
<script src="/js/extensions.js?v={{ $version }}"></script>
|
||||
<script>Grocy.ActiveNav = '@yield('activeNav', '')';</script>
|
||||
</head>
|
||||
|
||||
@ -228,6 +229,7 @@
|
||||
<script src="/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js?v={{ $version }}"></script>
|
||||
|
||||
<script src="/viewjs/@yield('viewJsName').js"></script>
|
||||
@stack('componentScripts')
|
||||
|
||||
@if(file_exists(__DIR__ . '/../../data/add_before_end_body.html'))
|
||||
@php include __DIR__ . '/../../data/add_before_end_body.html' @endphp
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'locationform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'locations')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Locations
|
||||
|
@ -4,7 +4,7 @@
|
||||
@section('viewJsName', 'login')
|
||||
|
||||
@section('content')
|
||||
<div class="col-md-4 col-md-offset-5 main">
|
||||
<div class="col-md-4 col-md-offset-5">
|
||||
|
||||
<h1 class="page-header text-center">Login</h1>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'productform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'products')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Products
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'purchase')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-4 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-4 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Purchase</h1>
|
||||
|
||||
@ -46,14 +46,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-md-5 col-lg-3 main well">
|
||||
<h3>Product overview <strong><span id="selected-product-name"></span></strong></h3>
|
||||
<h4><strong>Purchase quantity:</strong> <span id="selected-product-purchase-qu-name"></span></h4>
|
||||
|
||||
<p>
|
||||
<strong>Stock amount:</strong> <span id="selected-product-stock-amount"></span> <span id="selected-product-stock-qu-name"></span><br>
|
||||
<strong>Last purchased:</strong> <span id="selected-product-last-purchased"></span> <time id="selected-product-last-purchased-timeago" class="timeago timeago-contextual"></time><br>
|
||||
<strong>Last used:</strong> <span id="selected-product-last-used"></span> <time id="selected-product-last-used-timeago" class="timeago timeago-contextual"></time>
|
||||
</p>
|
||||
<div class="col-sm-6 col-md-5 col-lg-3">
|
||||
@include('components.productcard')
|
||||
</div>
|
||||
@stop
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'quantityunitform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-4 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'quantityunits')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Quantity units
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'shoppinglist')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">
|
||||
Shopping list
|
||||
|
@ -9,7 +9,7 @@
|
||||
@section('viewJsName', 'shoppinglistform')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2 main">
|
||||
<div class="col-sm-3 col-sm-offset-3 col-md-3 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">@yield('title')</h1>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
@section('viewJsName', 'stockoverview')
|
||||
|
||||
@section('content')
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2">
|
||||
|
||||
<h1 class="page-header">Stock overview <span class="text-muded small"><strong>{{ count($currentStock) }}</strong> products with <strong>{{ SumArrayValue($currentStock, 'amount') }}</strong> units in stock</span></h1>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user