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

@@ -1410,6 +1410,14 @@
},
"stock_amount": {
"type": "integer"
},
"next_best_before_date": {
"type": "string",
"format": "date-time"
},
"last_price": {
"type": "number",
"format": "double"
}
}
},
@@ -1472,6 +1480,10 @@
},
"last_done_by": {
"$ref": "#/components/schemas/UserDto"
},
"next_estimated_execution_time": {
"type": "string",
"format": "date-time"
}
}
},
@@ -1489,6 +1501,10 @@
"charge_cycles_count": {
"type": "integer",
"description": "How often this battery was charged so far"
},
"next_estimated_charge_time": {
"type": "string",
"format": "date-time"
}
}
},

View File

@@ -28,16 +28,46 @@ $(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()
{
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);
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 () {
$('#battery-' + batteryId + '-last-tracked-time').fadeOut(500, function()
{
$(this).text(trackedTime).fadeIn(500);
});
$('#battery-' + batteryId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
RefreshContextualTimeago();
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)
@@ -45,6 +75,12 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
console.error(xhr);
}
);
},
function(xhr)
{
console.error(xhr);
}
);
});
function RefreshStatistics()

View File

@@ -28,16 +28,46 @@ $(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()
{
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);
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 () {
$('#habit-' + habitId + '-last-tracked-time').fadeOut(500, function()
{
$(this).text(trackedTime).fadeIn(500);
});
$('#habit-' + habitId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
RefreshContextualTimeago();
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)
@@ -45,6 +75,12 @@ $(document).on('click', '.track-habit-button', function(e)
console.error(xhr);
}
);
},
function(xhr)
{
console.error(xhr);
}
);
});
function RefreshStatistics()

View File

@@ -41,8 +41,27 @@ $(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()
{
Grocy.Api.Get('stock/get-product-details/' + productId,
function(result)
{
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);
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)
@@ -60,9 +79,17 @@ $(document).on('click', '.product-consume-button', function(e)
$(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)
@@ -70,6 +97,12 @@ $(document).on('click', '.product-consume-button', function(e)
console.error(xhr);
}
);
},
function(xhr)
{
console.error(xhr);
}
);
});
function RefreshStatistics()

View File

@@ -20,11 +20,13 @@ class BatteriesService extends BaseService
$battery = $this->Database->batteries($batteryId);
$batteryChargeCylcesCount = $this->Database->battery_charge_cycles()->where('battery_id', $batteryId)->count();
$batteryLastChargedTime = $this->Database->battery_charge_cycles()->where('battery_id', $batteryId)->max('tracked_time');
$nextChargeTime = $this->Database->batteries_current()->where('battery_id', $batteryId)->min('next_estimated_charge_time');
return array(
'battery' => $battery,
'last_charged' => $batteryLastChargedTime,
'charge_cycles_count' => $batteryChargeCylcesCount
'charge_cycles_count' => $batteryChargeCylcesCount,
'next_estimated_charge_time' => $nextChargeTime
);
}

View File

@@ -23,6 +23,7 @@ class HabitsService extends BaseService
$habit = $this->Database->habits($habitId);
$habitTrackedCount = $this->Database->habits_log()->where('habit_id', $habitId)->count();
$habitLastTrackedTime = $this->Database->habits_log()->where('habit_id', $habitId)->max('tracked_time');
$nextExeuctionTime = $this->Database->habits_current()->where('habit_id', $habitId)->min('next_estimated_execution_time');
$lastHabitLogRow = $this->Database->habits_log()->where('habit_id = :1 AND tracked_time = :2', $habitId, $habitLastTrackedTime)->fetch();
$lastDoneByUser = null;
@@ -37,7 +38,8 @@ class HabitsService extends BaseService
'habit' => $habit,
'last_tracked' => $habitLastTrackedTime,
'tracked_count' => $habitTrackedCount,
'last_done_by' => $lastDoneByUser
'last_done_by' => $lastDoneByUser,
'next_estimated_execution_time' => $nextExeuctionTime
);
}

View File

@@ -37,6 +37,7 @@ class StockService extends BaseService
$productStockAmount = $this->Database->stock()->where('product_id', $productId)->sum('amount');
$productLastPurchased = $this->Database->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_PURCHASE)->max('purchased_date');
$productLastUsed = $this->Database->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->max('used_date');
$nextBestBeforeDate = $this->Database->stock()->where('product_id', $productId)->min('best_before_date');
$quPurchase = $this->Database->quantity_units($product->qu_id_purchase);
$quStock = $this->Database->quantity_units($product->qu_id_stock);
@@ -54,7 +55,8 @@ class StockService extends BaseService
'stock_amount' => $productStockAmount,
'quantity_unit_purchase' => $quPurchase,
'quantity_unit_stock' => $quStock,
'last_price' => $lastPrice
'last_price' => $lastPrice,
'next_best_before_date' => $nextBestBeforeDate
);
}

View File

@@ -37,7 +37,7 @@
</thead>
<tbody>
@foreach($current as $curentBatteryEntry)
<tr class="@if(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s')) table-danger @elseif(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) table-warning @endif">
<tr id="battery-{{ $curentBatteryEntry->battery_id }}-row" class="@if(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s')) table-danger @elseif(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0 && $curentBatteryEntry->next_estimated_charge_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) table-warning @endif">
<td class="fit-content">
<a class="btn btn-success btn-sm track-charge-cycle-button" href="#" title="{{ $L('Track charge cycle of battery #1', FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->name) }}"
data-battery-id="{{ $curentBatteryEntry->battery_id }}"
@@ -54,8 +54,8 @@
</td>
<td>
@if(FindObjectInArrayByPropertyValue($batteries, 'id', $curentBatteryEntry->battery_id)->charge_interval_days > 0)
{{ $curentBatteryEntry->next_estimated_charge_time }}
<time class="timeago timeago-contextual" datetime="{{ $curentBatteryEntry->next_estimated_charge_time }}"></time>
<span id="battery-{{ $curentBatteryEntry->battery_id }}-next-charge-time">{{ $curentBatteryEntry->next_estimated_charge_time }}</span>
<time id="battery-{{ $curentBatteryEntry->battery_id }}-next-charge-time-timeago" class="timeago timeago-contextual" datetime="{{ $curentBatteryEntry->next_estimated_charge_time }}"></time>
@else
...
@endif

View File

@@ -37,7 +37,7 @@
</thead>
<tbody>
@foreach($currentHabits as $curentHabitEntry)
<tr class="@if(FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->period_type === \Grocy\Services\HabitsService::HABIT_TYPE_DYNAMIC_REGULAR && $curentHabitEntry->next_estimated_execution_time < date('Y-m-d H:i:s')) table-danger @elseif(FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->period_type === \Grocy\Services\HabitsService::HABIT_TYPE_DYNAMIC_REGULAR && $curentHabitEntry->next_estimated_execution_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) table-warning @endif">
<tr id="habit-{{ $curentHabitEntry->habit_id }}-row" class="@if(FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->period_type === \Grocy\Services\HabitsService::HABIT_TYPE_DYNAMIC_REGULAR && $curentHabitEntry->next_estimated_execution_time < date('Y-m-d H:i:s')) table-danger @elseif(FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->period_type === \Grocy\Services\HabitsService::HABIT_TYPE_DYNAMIC_REGULAR && $curentHabitEntry->next_estimated_execution_time < date('Y-m-d H:i:s', strtotime("+$nextXDays days"))) table-warning @endif">
<td class="fit-content">
<a class="btn btn-success btn-sm track-habit-button" href="#" title="{{ $L('Track execution of habit #1', FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->name) }}"
data-habit-id="{{ $curentHabitEntry->habit_id }}"
@@ -53,8 +53,8 @@
</td>
<td>
@if(FindObjectInArrayByPropertyValue($habits, 'id', $curentHabitEntry->habit_id)->period_type === \Grocy\Services\HabitsService::HABIT_TYPE_DYNAMIC_REGULAR)
{{ $curentHabitEntry->next_estimated_execution_time }}
<time class="timeago timeago-contextual" datetime="{{ $curentHabitEntry->next_estimated_execution_time }}"></time>
<span id="habit-{{ $curentHabitEntry->habit_id }}-next-execution-time">{{ $curentHabitEntry->next_estimated_execution_time }}</span>
<time id="habit-{{ $curentHabitEntry->habit_id }}-next-execution-time-timeago" class="timeago timeago-contextual" datetime="{{ $curentHabitEntry->next_estimated_execution_time }}"></time>
@else
...
@endif

View File

@@ -72,8 +72,8 @@
<span id="product-{{ $currentStockEntry->product_id }}-amount">{{ $currentStockEntry->amount }}</span> {{ Pluralize($currentStockEntry->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name_plural) }}
</td>
<td>
{{ $currentStockEntry->best_before_date }}
<time class="timeago timeago-contextual" datetime="{{ $currentStockEntry->best_before_date }}"></time>
<span id="product-{{ $currentStockEntry->product_id }}-next-best-before-date">{{ $currentStockEntry->best_before_date }}</span>
<time id="product-{{ $currentStockEntry->product_id }}-next-best-before-date-timeago" class="timeago timeago-contextual" datetime="{{ $currentStockEntry->best_before_date }}"></time>
</td>
<td class="hidden">
{{ FindObjectInArrayByPropertyValue($locations, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->location_id)->name }}