Make it possible to track any information on chore execution (by using Userfields, closes #825)

This commit is contained in:
Bernd Bestel 2021-07-11 19:44:06 +02:00
parent 27b46e1abf
commit 198216f38b
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
7 changed files with 44 additions and 16 deletions

View File

@ -70,7 +70,10 @@
- This happens automatically on consuming a recipe/product from the meal plan page
- Fixed that stock fulfillment checking used the desired servings of the recipe (those selected on the recipes page, not them from the meal plan entry)
### Chores fixes
### Chores improvements(fixes
- It's now possible to track any addtional info on a chore execution by using Userfields
- => Configure the desired Userfields for the entity `chores_log`
- => The on chore execution tracking entered information is then visible on the corresponding chore journal entry
- Fixed that tracking chores with "Done by" a different user was not possible
### Userfield fixes

View File

@ -62,7 +62,9 @@ class ChoresController extends BaseController
return $this->renderPage($response, 'choresjournal', [
'choresLog' => $this->getDatabase()->chores_log()->orderBy('tracked_time', 'DESC'),
'chores' => $this->getDatabase()->chores()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'users' => $this->getDatabase()->users()->orderBy('username')
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('chores_log'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores_log')
]);
}
@ -85,7 +87,8 @@ class ChoresController extends BaseController
{
return $this->renderPage($response, 'choretracking', [
'chores' => $this->getDatabase()->chores()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'users' => $this->getDatabase()->users()->orderBy('username')
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('chores_log'),
]);
}

View File

@ -5447,7 +5447,7 @@
"stock_log",
"stock",
"stock_current_locations",
"api_keys"
"chores_log"
]
},
"ExposedEntityNoListing": {
@ -5462,7 +5462,8 @@
"stock_log",
"api_keys",
"stock",
"stock_current_locations"
"stock_current_locations",
"chores_log"
]
},
"ExposedEntityNoDelete": {
@ -5470,7 +5471,8 @@
"enum": [
"stock_log",
"stock",
"stock_current_locations"
"stock_current_locations",
"chores_log"
]
},
"ExposedEntityEditRequiresAdmin": {

View File

@ -16,16 +16,20 @@
Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute', { 'tracked_time': Grocy.Components.DateTimePicker.GetValue(), 'done_by': $("#user_id").val() },
function(result)
{
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
toastr.success(__t('Tracked execution of chore %1$s on %2$s', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChoreExecution(' + result.id + ')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>');
Grocy.Components.ChoreCard.Refresh($('#chore_id').val());
Grocy.EditObjectId = result.id;
Grocy.Components.UserfieldsForm.Save(function()
{
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
toastr.success(__t('Tracked execution of chore %1$s on %2$s', choreDetails.chore.name, Grocy.Components.DateTimePicker.GetValue()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoChoreExecution(' + result.id + ')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>');
Grocy.Components.ChoreCard.Refresh($('#chore_id').val());
$('#chore_id').val('');
$('#chore_id_text_input').focus();
$('#chore_id_text_input').val('');
Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#chore_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
$('#chore_id').val('');
$('#chore_id_text_input').focus();
$('#chore_id_text_input').val('');
Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss'));
$('#chore_id_text_input').trigger('change');
Grocy.FrontendHelpers.ValidateForm('choretracking-form');
});
},
function(xhr)
{

View File

@ -59,7 +59,9 @@ class UserfieldsService extends BaseService
$userEntities[] = 'userentity-' . $userentity->name;
}
return array_merge($exposedDefaultEntities, $userEntities, $specialEntities);
$entitiesSorted = array_merge($exposedDefaultEntities, $userEntities, $specialEntities);
sort($entitiesSorted);
return $entitiesSorted;
}
public function GetField($fieldId)

View File

@ -77,6 +77,10 @@
@if(GROCY_FEATURE_FLAG_CHORES_ASSIGNMENTS)
<th>{{ $__t('Done by') }}</th>
@endif
@include('components.userfields_thead', array(
'userfields' => $userfields
))
</tr>
</thead>
<tbody class="d-none">
@ -116,6 +120,11 @@
@endif
</td>
@endif
@include('components.userfields_tbody', array(
'userfields' => $userfields,
'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $choreLogEntry->id)
))
</tr>
@endforeach
</tbody>

View File

@ -52,6 +52,11 @@
value="{{ GROCY_USER_ID }}">
@endif
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'chores_log'
))
<button id="save-choretracking-button"
class="btn btn-success">{{ $__t('OK') }}</button>