grocy/public/js/grocy_dbchangedhandling.js
fipwmaqzufheoxq92ebc a85998dd40
Improvements (#1049)
* Fixes #1035: Check available amount after filtering by stock_entry_id

* Fixes #1036: Remove stock-related buttons/options from Shopping-list  if FEATURE_FLAG_STOCK is disabled

* Fixes #1010: Repair recipe-picture upload.

* Fixes #958: Disable auto-reload of equipments-page.

* Fix uncaught exception in locationpicker.js

* Fixes #761 and #762: Add "Remove exact amount" for products with tare weight handling and use it for recipe-consumption.

* Fixes #1048: Repair product-group-filter on "Master Data"/Products

* Renamed variable

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
2020-10-14 17:48:37 +02:00

69 lines
1.6 KiB
JavaScript

if (Grocy.UserId !== -1)
{
Grocy.Api.Get('system/db-changed-time',
function(result)
{
Grocy.DatabaseChangedTime = moment(result.changed_time);
},
function(xhr)
{
console.error(xhr);
}
);
}
// Check if the database has changed once a minute
// If a change is detected, reload the current page, but only if already idling for at least 50 seconds,
// when there is no unsaved form data and when the user enabled auto reloading
if (Grocy.DbChangedHandlingEnabledForPage)
{
setInterval(function()
{
Grocy.Api.Get('system/db-changed-time',
function(result)
{
var newDbChangedTime = moment(result.changed_time);
if (newDbChangedTime.isAfter(Grocy.DatabaseChangedTime))
{
if (Grocy.IdleTime >= 50)
{
if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change) && $("form.is-dirty").length === 0 && !$("body").hasClass("fullscreen-card"))
{
window.location.reload();
}
}
Grocy.DatabaseChangedTime = newDbChangedTime;
}
},
function(xhr)
{
console.error(xhr);
}
);
}, 60000);
}
Grocy.IdleTime = 0;
Grocy.ResetIdleTime = function()
{
Grocy.IdleTime = 0;
}
window.onmousemove = Grocy.ResetIdleTime;
window.onmousedown = Grocy.ResetIdleTime;
window.onclick = Grocy.ResetIdleTime;
window.onscroll = Grocy.ResetIdleTime;
window.onkeypress = Grocy.ResetIdleTime;
// Increase the idle time once every second
// On any interaction it will be reset to 0 (see above)
setInterval(function()
{
Grocy.IdleTime += 1;
}, 1000);
if (Grocy.UserId !== -1 && BoolVal(Grocy.UserSettings.auto_reload_on_db_change))
{
$("#auto-reload-enabled").prop("checked", true);
}