mirror of
https://github.com/grocy/grocy.git
synced 2025-04-30 01:55:47 +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
|
### 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
|
### Equipment
|
||||||
|
|
||||||
|
@ -73,7 +73,9 @@ class BatteriesController extends BaseController
|
|||||||
|
|
||||||
return $this->renderPage($response, 'batteriesjournal', [
|
return $this->renderPage($response, 'batteriesjournal', [
|
||||||
'chargeCycles' => $this->getDatabase()->battery_charge_cycles()->where($where)->orderBy('tracked_time', 'DESC'),
|
'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)
|
public function TrackChargeCycle(Request $request, Response $response, array $args)
|
||||||
{
|
{
|
||||||
return $this->renderPage($response, 'batterytracking', [
|
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_last_purchased",
|
||||||
"products_average_price",
|
"products_average_price",
|
||||||
"quantity_unit_conversions_resolved",
|
"quantity_unit_conversions_resolved",
|
||||||
"recipes_pos_resolved"
|
"recipes_pos_resolved",
|
||||||
|
"battery_charge_cycles"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ExposedEntityNoListing": {
|
"ExposedEntityNoListing": {
|
||||||
@ -5924,7 +5925,8 @@
|
|||||||
"products_last_purchased",
|
"products_last_purchased",
|
||||||
"products_average_price",
|
"products_average_price",
|
||||||
"quantity_unit_conversions_resolved",
|
"quantity_unit_conversions_resolved",
|
||||||
"recipes_pos_resolved"
|
"recipes_pos_resolved",
|
||||||
|
"battery_charge_cycles"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ExposedEntityNoDelete": {
|
"ExposedEntityNoDelete": {
|
||||||
@ -5937,7 +5939,8 @@
|
|||||||
"products_last_purchased",
|
"products_last_purchased",
|
||||||
"products_average_price",
|
"products_average_price",
|
||||||
"quantity_unit_conversions_resolved",
|
"quantity_unit_conversions_resolved",
|
||||||
"recipes_pos_resolved"
|
"recipes_pos_resolved",
|
||||||
|
"battery_charge_cycles"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ExposedEntityEditRequiresAdmin": {
|
"ExposedEntityEditRequiresAdmin": {
|
||||||
|
@ -21,16 +21,20 @@
|
|||||||
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge', { 'tracked_time': $('#tracked_time').find('input').val() },
|
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge', { 'tracked_time': $('#tracked_time').find('input').val() },
|
||||||
function(result)
|
function(result)
|
||||||
{
|
{
|
||||||
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
|
Grocy.EditObjectId = result.id;
|
||||||
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.UserfieldsForm.Save(function()
|
||||||
Grocy.Components.BatteryCard.Refresh($('#battery_id').val());
|
{
|
||||||
|
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').val('');
|
||||||
$('#battery_id_text_input').focus();
|
$('#battery_id_text_input').focus();
|
||||||
$('#battery_id_text_input').val('');
|
$('#battery_id_text_input').val('');
|
||||||
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
$('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss'));
|
||||||
$('#battery_id_text_input').trigger('change');
|
$('#battery_id_text_input').trigger('change');
|
||||||
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
|
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function(xhr)
|
function(xhr)
|
||||||
{
|
{
|
||||||
|
@ -91,6 +91,10 @@
|
|||||||
</th>
|
</th>
|
||||||
<th class="allow-grouping">{{ $__t('Battery') }}</th>
|
<th class="allow-grouping">{{ $__t('Battery') }}</th>
|
||||||
<th>{{ $__t('Tracked time') }}</th>
|
<th>{{ $__t('Tracked time') }}</th>
|
||||||
|
|
||||||
|
@include('components.userfields_thead', array(
|
||||||
|
'userfields' => $userfields
|
||||||
|
))
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="d-none">
|
<tbody class="d-none">
|
||||||
@ -121,6 +125,11 @@
|
|||||||
<time class="timeago timeago-contextual"
|
<time class="timeago timeago-contextual"
|
||||||
datetime="{{ $chargeCycleEntry->tracked_time }}"></time>
|
datetime="{{ $chargeCycleEntry->tracked_time }}"></time>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
@include('components.userfields_tbody', array(
|
||||||
|
'userfields' => $userfields,
|
||||||
|
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $chargeCycleEntry->id)
|
||||||
|
))
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -44,6 +44,11 @@
|
|||||||
'invalidFeedback' => $__t('This can only be before now')
|
'invalidFeedback' => $__t('This can only be before now')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@include('components.userfieldsform', array(
|
||||||
|
'userfields' => $userfields,
|
||||||
|
'entity' => 'battery_charge_cycles'
|
||||||
|
))
|
||||||
|
|
||||||
<button id="save-batterytracking-button"
|
<button id="save-batterytracking-button"
|
||||||
class="btn btn-success">{{ $__t('OK') }}</button>
|
class="btn btn-success">{{ $__t('OK') }}</button>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user