Refresh the complete row on all overview pages on changes, including the background color (closes #39)

This commit is contained in:
Bernd Bestel
2018-08-07 20:11:08 +02:00
parent 339d81318f
commit c4b0ef4d49
10 changed files with 176 additions and 49 deletions

View File

@@ -28,17 +28,53 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('batteries/track-charge-cycle/' + batteryId + '?tracked_time=' + trackedTime,
function(result)
function()
{
$('#battery-' + batteryId + '-last-tracked-time').parent().effect('highlight', {}, 500);
$('#battery-' + batteryId + '-last-tracked-time').fadeOut(500, function () {
$(this).text(trackedTime).fadeIn(500);
});
$('#battery-' + batteryId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
RefreshContextualTimeago();
Grocy.Api.Get('batteries/get-battery-details/' + batteryId,
function(result)
{
var batteryRow = $('#battery-' + batteryId + '-row');
var nextXDaysThreshold = moment().add($("#info-due-batteries").data("next-x-days"), "days");
var now = moment();
var nextExecutionTime = moment(result.next_estimated_charge_time);
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryName, trackedTime));
RefreshStatistics();
batteryRow.removeClass("table-warning");
batteryRow.removeClass("table-danger");
if (nextExecutionTime.isBefore(now))
{
batteryRow.addClass("table-danger");
}
else if (nextExecutionTime.isBefore(nextXDaysThreshold))
{
batteryRow.addClass("table-warning");
}
$('#battery-' + batteryId + '-last-tracked-time').parent().effect('highlight', { }, 500);
$('#battery-' + batteryId + '-last-tracked-time').fadeOut(500, function()
{
$(this).text(trackedTime).fadeIn(500);
});
$('#battery-' + batteryId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
if (result.battery.charge_interval_days != 0)
{
$('#battery-' + batteryId + '-next-charge-time').parent().effect('highlight', { }, 500);
$('#battery-' + batteryId + '-next-charge-time').fadeOut(500, function()
{
$(this).text(result.next_estimated_charge_time).fadeIn(500);
});
$('#battery-' + batteryId + '-next-charge-time-timeago').attr('datetime', result.next_estimated_charge_time);
}
toastr.success(L('Tracked charge cylce of battery #1 on #2', batteryName, trackedTime));
RefreshContextualTimeago();
RefreshStatistics();
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{

View File

@@ -28,17 +28,53 @@ $(document).on('click', '.track-habit-button', function(e)
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('habits/track-habit-execution/' + habitId + '?tracked_time=' + trackedTime,
function(result)
function()
{
$('#habit-' + habitId + '-last-tracked-time').parent().effect('highlight', {}, 500);
$('#habit-' + habitId + '-last-tracked-time').fadeOut(500, function () {
$(this).text(trackedTime).fadeIn(500);
});
$('#habit-' + habitId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
RefreshContextualTimeago();
Grocy.Api.Get('habits/get-habit-details/' + habitId,
function(result)
{
var habitRow = $('#habit-' + habitId + '-row');
var nextXDaysThreshold = moment().add($("#info-due-habits").data("next-x-days"), "days");
var now = moment();
var nextExecutionTime = moment(result.next_estimated_execution_time);
toastr.success(L('Tracked execution of habit #1 on #2', habitName, trackedTime));
RefreshStatistics();
habitRow.removeClass("table-warning");
habitRow.removeClass("table-danger");
if (nextExecutionTime.isBefore(now))
{
habitRow.addClass("table-danger");
}
else if (nextExecutionTime.isBefore(nextXDaysThreshold))
{
habitRow.addClass("table-warning");
}
$('#habit-' + habitId + '-last-tracked-time').parent().effect('highlight', { }, 500);
$('#habit-' + habitId + '-last-tracked-time').fadeOut(500, function()
{
$(this).text(trackedTime).fadeIn(500);
});
$('#habit-' + habitId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
if (result.habit.period_type == "dynamic-regular")
{
$('#habit-' + habitId + '-next-execution-time').parent().effect('highlight', { }, 500);
$('#habit-' + habitId + '-next-execution-time').fadeOut(500, function()
{
$(this).text(result.next_estimated_execution_time).fadeIn(500);
});
$('#habit-' + habitId + '-next-execution-time-timeago').attr('datetime', result.next_estimated_execution_time);
}
toastr.success(L('Tracked execution of habit #1 on #2', habitName, trackedTime));
RefreshContextualTimeago();
RefreshStatistics();
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{

View File

@@ -41,29 +41,62 @@ $(document).on('click', '.product-consume-button', function(e)
var consumeAmount = $(e.currentTarget).attr('data-consume-amount');
Grocy.Api.Get('stock/consume-product/' + productId + '/' + consumeAmount,
function(result)
function()
{
var oldAmount = parseInt($('#product-' + productId + '-amount').text());
var newAmount = oldAmount - consumeAmount;
if (newAmount === 0)
{
$('#product-' + productId + '-row').fadeOut(500, function()
Grocy.Api.Get('stock/get-product-details/' + productId,
function(result)
{
$(this).remove();
});
}
else
{
$('#product-' + productId + '-amount').parent().effect('highlight', { }, 500);
$('#product-' + productId + '-amount').fadeOut(500, function()
{
$(this).text(newAmount).fadeIn(500);
});
$('#product-' + productId + '-consume-all-button').attr('data-consume-amount', newAmount);
}
var productRow = $('#product-' + productId + '-row');
var expiringThreshold = moment().add("-" + $("#info-expiring-products").data("next-x-days"), "days");
var now = moment();
var nextBestBeforeDate = moment(result.next_best_before_date);
toastr.success(L('Removed #1 #2 of #3 from stock', consumeAmount, productQuName, productName));
RefreshStatistics();
productRow.removeClass("table-warning");
productRow.removeClass("table-danger");
if (now.isAfter(nextBestBeforeDate))
{
productRow.addClass("table-danger");
}
if (expiringThreshold.isAfter(nextBestBeforeDate))
{
productRow.addClass("table-warning");
}
var oldAmount = parseInt($('#product-' + productId + '-amount').text());
var newAmount = oldAmount - consumeAmount;
if (newAmount === 0)
{
$('#product-' + productId + '-row').fadeOut(500, function()
{
$(this).remove();
});
}
else
{
$('#product-' + productId + '-amount').parent().effect('highlight', { }, 500);
$('#product-' + productId + '-amount').fadeOut(500, function()
{
$(this).text(newAmount).fadeIn(500);
});
$('#product-' + productId + '-consume-all-button').attr('data-consume-amount', newAmount);
$('#product-' + productId + '-next-best-before-date').parent().effect('highlight', { }, 500);
$('#product-' + productId + '-next-best-before-date').fadeOut(500, function()
{
$(this).text(result.next_best_before_date).fadeIn(500);
});
$('#product-' + productId + '-next-best-before-date-timeago').attr('datetime', result.next_best_before_date);
}
toastr.success(L('Removed #1 #2 of #3 from stock', consumeAmount, productQuName, productName));
RefreshContextualTimeago();
RefreshStatistics();
},
function(xhr)
{
console.error(xhr);
}
);
},
function(xhr)
{