2018-09-24 13:53:18 +02:00
|
|
|
|
Grocy.Api.Get('system/get-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
|
2018-09-30 11:17:28 +02:00
|
|
|
|
// 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
|
2018-09-24 13:53:18 +02:00
|
|
|
|
setInterval(function()
|
|
|
|
|
{
|
|
|
|
|
Grocy.Api.Get('system/get-db-changed-time',
|
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
var newDbChangedTime = moment(result.changed_time);
|
2018-09-25 08:44:12 +02:00
|
|
|
|
if (newDbChangedTime.isAfter(Grocy.DatabaseChangedTime))
|
2018-09-24 13:53:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (Grocy.IdleTime >= 50)
|
|
|
|
|
{
|
2018-10-13 09:18:16 +02:00
|
|
|
|
if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change) && $("form.is-dirty").length === 0 && !$("body").hasClass("fullscreen-card"))
|
2018-09-30 09:57:42 +02:00
|
|
|
|
{
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
2018-09-24 13:53:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2018-09-30 11:17:28 +02:00
|
|
|
|
|
2018-09-30 17:14:04 +02:00
|
|
|
|
if (BoolVal(Grocy.UserSettings.auto_reload_on_db_change))
|
2018-09-30 11:17:28 +02:00
|
|
|
|
{
|
|
|
|
|
$("#auto-reload-enabled").prop("checked", true);
|
|
|
|
|
}
|