From 198216f38bf062ae7b92118c9c55733496bb515c Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 11 Jul 2021 19:44:06 +0200 Subject: [PATCH] Make it possible to track any information on chore execution (by using Userfields, closes #825) --- changelog/62_UNRELEASED_xxxx-xx-xx.md | 5 ++++- controllers/ChoresController.php | 7 +++++-- grocy.openapi.json | 8 +++++--- public/viewjs/choretracking.js | 22 +++++++++++++--------- services/UserfieldsService.php | 4 +++- views/choresjournal.blade.php | 9 +++++++++ views/choretracking.blade.php | 5 +++++ 7 files changed, 44 insertions(+), 16 deletions(-) diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index 765cbd27..857a9369 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -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 diff --git a/controllers/ChoresController.php b/controllers/ChoresController.php index 403e8e9d..9a8e621a 100644 --- a/controllers/ChoresController.php +++ b/controllers/ChoresController.php @@ -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'), ]); } diff --git a/grocy.openapi.json b/grocy.openapi.json index 07e84b26..8d8aeccc 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -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": { diff --git a/public/viewjs/choretracking.js b/public/viewjs/choretracking.js index 40d2add9..eaf23ea7 100644 --- a/public/viewjs/choretracking.js +++ b/public/viewjs/choretracking.js @@ -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()) + '
' + __t("Undo") + ''); - 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()) + '
' + __t("Undo") + ''); + 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) { diff --git a/services/UserfieldsService.php b/services/UserfieldsService.php index 1c7f8c4c..75161e5a 100644 --- a/services/UserfieldsService.php +++ b/services/UserfieldsService.php @@ -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) diff --git a/views/choresjournal.blade.php b/views/choresjournal.blade.php index 714c688c..8f6f9d99 100644 --- a/views/choresjournal.blade.php +++ b/views/choresjournal.blade.php @@ -77,6 +77,10 @@ @if(GROCY_FEATURE_FLAG_CHORES_ASSIGNMENTS) {{ $__t('Done by') }} @endif + + @include('components.userfields_thead', array( + 'userfields' => $userfields + )) @@ -116,6 +120,11 @@ @endif @endif + + @include('components.userfields_tbody', array( + 'userfields' => $userfields, + 'userfieldValues' => FindAllObjectsInArrayByPropertyValue($userfieldValues, 'object_id', $choreLogEntry->id) + )) @endforeach diff --git a/views/choretracking.blade.php b/views/choretracking.blade.php index 400a2b27..e77b1401 100644 --- a/views/choretracking.blade.php +++ b/views/choretracking.blade.php @@ -52,6 +52,11 @@ value="{{ GROCY_USER_ID }}"> @endif + @include('components.userfieldsform', array( + 'userfields' => $userfields, + 'entity' => 'chores_log' + )) +