mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Add userfields to battery charge cycle tracking (#2490)
Co-authored-by: Manuel Worschech <mw@abot.xyz>
This commit is contained in:
parent
e01e0f3abe
commit
477f333466
@ -44,7 +44,9 @@
|
||||
|
||||
### Batteries
|
||||
|
||||
- xxx
|
||||
- It's now possible to track any addtional info on a battery charge cycle by using Userfields
|
||||
- => Configure the desired Userfields for the entity `battery_charge_cycles`
|
||||
- => On a battery charge cycle tracking entered information is then visible in the corresponding battery charge cycle journal entry
|
||||
|
||||
### Equipment
|
||||
|
||||
|
@ -73,7 +73,9 @@ class BatteriesController extends BaseController
|
||||
|
||||
return $this->renderPage($response, 'batteriesjournal', [
|
||||
'chargeCycles' => $this->getDatabase()->battery_charge_cycles()->where($where)->orderBy('tracked_time', 'DESC'),
|
||||
'batteries' => $this->getDatabase()->batteries()->where('active = 1')->orderBy('name', 'COLLATE NOCASE')
|
||||
'batteries' => $this->getDatabase()->batteries()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('battery_charge_cycles'),
|
||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('battery_charge_cycles')
|
||||
]);
|
||||
}
|
||||
|
||||
@ -115,7 +117,8 @@ class BatteriesController extends BaseController
|
||||
public function TrackChargeCycle(Request $request, Response $response, array $args)
|
||||
{
|
||||
return $this->renderPage($response, 'batterytracking', [
|
||||
'batteries' => $this->getDatabase()->batteries()->where('active = 1')->orderBy('name', 'COLLATE NOCASE')
|
||||
'batteries' => $this->getDatabase()->batteries()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('battery_charge_cycles')
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -5904,7 +5904,8 @@
|
||||
"products_last_purchased",
|
||||
"products_average_price",
|
||||
"quantity_unit_conversions_resolved",
|
||||
"recipes_pos_resolved"
|
||||
"recipes_pos_resolved",
|
||||
"battery_charge_cycles"
|
||||
]
|
||||
},
|
||||
"ExposedEntityNoListing": {
|
||||
@ -5924,7 +5925,8 @@
|
||||
"products_last_purchased",
|
||||
"products_average_price",
|
||||
"quantity_unit_conversions_resolved",
|
||||
"recipes_pos_resolved"
|
||||
"recipes_pos_resolved",
|
||||
"battery_charge_cycles"
|
||||
]
|
||||
},
|
||||
"ExposedEntityNoDelete": {
|
||||
@ -5937,7 +5939,8 @@
|
||||
"products_last_purchased",
|
||||
"products_average_price",
|
||||
"quantity_unit_conversions_resolved",
|
||||
"recipes_pos_resolved"
|
||||
"recipes_pos_resolved",
|
||||
"battery_charge_cycles"
|
||||
]
|
||||
},
|
||||
"ExposedEntityEditRequiresAdmin": {
|
||||
|
@ -21,16 +21,20 @@
|
||||
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge', { 'tracked_time': $('#tracked_time').find('input').val() },
|
||||
function(result)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
|
||||
toastr.success(__t('Tracked charge cycle of battery %1$s on %2$s', batteryDetails.battery.name, $('#tracked_time').find('input').val()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChargeCycle(' + result.id + ')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
Grocy.Components.BatteryCard.Refresh($('#battery_id').val());
|
||||
Grocy.EditObjectId = result.id;
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
|
||||
toastr.success(__t('Tracked charge cycle of battery %1$s on %2$s', batteryDetails.battery.name, $('#tracked_time').find('input').val()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChargeCycle(' + result.id + ')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>');
|
||||
Grocy.Components.BatteryCard.Refresh($('#battery_id').val());
|
||||
|
||||
$('#battery_id').val('');
|
||||
$('#battery_id_text_input').focus();
|
||||
$('#battery_id_text_input').val('');
|
||||
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#battery_id_text_input').trigger('change');
|
||||
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
|
||||
$('#battery_id').val('');
|
||||
$('#battery_id_text_input').focus();
|
||||
$('#battery_id_text_input').val('');
|
||||
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||
$('#battery_id_text_input').trigger('change');
|
||||
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
@ -91,6 +91,10 @@
|
||||
</th>
|
||||
<th class="allow-grouping">{{ $__t('Battery') }}</th>
|
||||
<th>{{ $__t('Tracked time') }}</th>
|
||||
|
||||
@include('components.userfields_thead', array(
|
||||
'userfields' => $userfields
|
||||
))
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="d-none">
|
||||
@ -121,6 +125,11 @@
|
||||
<time class="timeago timeago-contextual"
|
||||
datetime="{{ $chargeCycleEntry->tracked_time }}"></time>
|
||||
</td>
|
||||
|
||||
@include('components.userfields_tbody', array(
|
||||
'userfields' => $userfields,
|
||||
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $chargeCycleEntry->id)
|
||||
))
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
@ -44,6 +44,11 @@
|
||||
'invalidFeedback' => $__t('This can only be before now')
|
||||
))
|
||||
|
||||
@include('components.userfieldsform', array(
|
||||
'userfields' => $userfields,
|
||||
'entity' => 'battery_charge_cycles'
|
||||
))
|
||||
|
||||
<button id="save-batterytracking-button"
|
||||
class="btn btn-success">{{ $__t('OK') }}</button>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user