From 58cbf1776f59176a8c6a2c2fb540b51e4b03903a Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Mon, 12 Feb 2024 14:20:17 +0100 Subject: [PATCH] Weekly hours improvements (#4631) * fix table padding * reduced minimum quick-entry recent activity row amount * use activity favorites in weekly hours --- src/Configuration/SystemConfiguration.php | 2 +- src/Controller/QuickEntryController.php | 56 ++++++++++++++--------- src/Repository/TimesheetRepository.php | 6 +-- src/Twig/Runtime/TimesheetExtension.php | 13 +++--- templates/form/blocks.html.twig | 12 +++-- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/Configuration/SystemConfiguration.php b/src/Configuration/SystemConfiguration.php index 21fd4b82..9bb7d79f 100644 --- a/src/Configuration/SystemConfiguration.php +++ b/src/Configuration/SystemConfiguration.php @@ -454,7 +454,7 @@ final class SystemConfiguration public function getQuickEntriesRecentAmount(): int { - return $this->getIncrement('quick_entry.recent_activities', 5, 5); + return $this->getIncrement('quick_entry.recent_activities', 5, 0); } // ========== Company configurations ========== diff --git a/src/Controller/QuickEntryController.php b/src/Controller/QuickEntryController.php index 31ad4b41..38c59aa0 100644 --- a/src/Controller/QuickEntryController.php +++ b/src/Controller/QuickEntryController.php @@ -14,6 +14,7 @@ use App\Form\QuickEntryForm; use App\Model\QuickEntryWeek; use App\Repository\Query\TimesheetQuery; use App\Repository\TimesheetRepository; +use App\Timesheet\FavoriteRecordService; use App\Timesheet\TimesheetService; use App\Utils\PageSetup; use Symfony\Component\HttpFoundation\Request; @@ -28,7 +29,12 @@ use Symfony\Component\Security\Http\Attribute\IsGranted; #[IsGranted('quick-entry')] final class QuickEntryController extends AbstractController { - public function __construct(private SystemConfiguration $configuration, private TimesheetService $timesheetService, private TimesheetRepository $repository) + public function __construct( + private readonly SystemConfiguration $configuration, + private readonly TimesheetService $timesheetService, + private readonly TimesheetRepository $repository, + private readonly FavoriteRecordService $favoriteRecordService + ) { } @@ -95,28 +101,36 @@ final class QuickEntryController extends AbstractController // attach recent activities $amount = $this->configuration->getQuickEntriesRecentAmount(); - $startFrom = null; - $takeOverWeeks = $this->configuration->find('quick_entry.recent_activity_weeks'); - if ($takeOverWeeks !== null && \intval($takeOverWeeks) > 0) { - $startFrom = clone $startWeek; - $startFrom->modify(sprintf('-%s weeks', $takeOverWeeks)); - } - $timesheets = $this->repository->getRecentActivities($user, $startFrom, $amount); - foreach ($timesheets as $timesheet) { - $id = $timesheet->getProject()->getId() . '_' . $timesheet->getActivity()->getId(); - if (\array_key_exists($id, $rows)) { - continue; + if ($amount > 0) { + $takeOverWeeks = $this->configuration->find('quick_entry.recent_activity_weeks'); + $startFrom = null; + if ($takeOverWeeks !== null && \intval($takeOverWeeks) > 0) { + $startFrom = clone $startWeek; + $startFrom->modify(sprintf('-%s weeks', $takeOverWeeks)); } - // there is an edge case possible with a project that starts and ends between the start and end date - // user could still select it from the dropdown, but it is better to hide a row than displaying already ended projects - if ($timesheet->getProject() !== null && (!$timesheet->getProject()->isVisibleAtDate($startWeek) && !$timesheet->getProject()->isVisibleAtDate($endWeek))) { - continue; + + $favorites = $this->favoriteRecordService->favoriteEntries($user, $amount); + foreach ($favorites as $favorite) { + $timesheet = $favorite->getTimesheet(); + if ($startFrom !== null && !$favorite->isFavorite() && $startFrom > $timesheet->getBegin()) { + continue; + } + + $id = $timesheet->getProject()->getId() . '_' . $timesheet->getActivity()->getId(); + if (\array_key_exists($id, $rows)) { + continue; + } + // there is an edge case possible with a project that starts and ends between the start and end date + // user could still select it from the dropdown, but it is better to hide a row than displaying already ended projects + if ($timesheet->getProject() !== null && (!$timesheet->getProject()->isVisibleAtDate($startWeek) && !$timesheet->getProject()->isVisibleAtDate($endWeek))) { + continue; + } + $rows[$id] = [ + 'days' => $week, + 'project' => $timesheet->getProject(), + 'activity' => $timesheet->getActivity() + ]; } - $rows[$id] = [ - 'days' => $week, - 'project' => $timesheet->getProject(), - 'activity' => $timesheet->getActivity() - ]; } $defaultBegin = $factory->createDateTime($this->configuration->getTimesheetDefaultBeginTime()); diff --git a/src/Repository/TimesheetRepository.php b/src/Repository/TimesheetRepository.php index 83b2b242..908638a4 100644 --- a/src/Repository/TimesheetRepository.php +++ b/src/Repository/TimesheetRepository.php @@ -324,11 +324,9 @@ class TimesheetRepository extends EntityRepository } /** - * @param User|null $user - * @param bool $ticktac * @return Timesheet[] */ - public function getActiveEntries(User $user = null, bool $ticktac = false): array + public function getActiveEntries(?User $user = null, bool $ticktack = false): array { $qb = $this->getEntityManager()->createQueryBuilder(); @@ -342,7 +340,7 @@ class TimesheetRepository extends EntityRepository $qb->setParameter('user', $user); } - if ($ticktac) { + if ($ticktack) { $qb->setMaxResults(1); return $qb->getQuery()->getResult(); diff --git a/src/Twig/Runtime/TimesheetExtension.php b/src/Twig/Runtime/TimesheetExtension.php index bdced3ab..e540ab07 100644 --- a/src/Twig/Runtime/TimesheetExtension.php +++ b/src/Twig/Runtime/TimesheetExtension.php @@ -18,23 +18,22 @@ use Twig\Extension\RuntimeExtensionInterface; final class TimesheetExtension implements RuntimeExtensionInterface { - public function __construct(private TimesheetRepository $repository, private FavoriteRecordService $favoriteRecordService) + public function __construct( + private readonly TimesheetRepository $repository, + private readonly FavoriteRecordService $favoriteRecordService + ) { } /** - * @param User $user - * @param bool $ticktac * @return array */ - public function activeEntries(User $user, bool $ticktac = true): array + public function activeEntries(User $user, bool $ticktack = true): array { - return $this->repository->getActiveEntries($user, $ticktac); + return $this->repository->getActiveEntries($user, $ticktack); } /** - * @param User $user - * @param int $limit * @return array */ public function favoriteEntries(User $user, int $limit = 5): array diff --git a/templates/form/blocks.html.twig b/templates/form/blocks.html.twig index 3cb501c3..8e2e531c 100644 --- a/templates/form/blocks.html.twig +++ b/templates/form/blocks.html.twig @@ -31,13 +31,17 @@ {%- endif -%} {%- endblock choice_widget_expanded %} +{% block _quick_entry_form_rows_entry_timesheets_entry_widget %} + {{ form_row(form.duration, {row_attr: {class: 'p-0'}}) }} +{%- endblock %} + {% block quick_entry_week_row %} - {{ form_row(form.project) }} + {{ form_row(form.project, {row_attr: {class: 'p-0'}}) }} - {{ form_row(form.activity) }} + {{ form_row(form.activity, {row_attr: {class: 'p-0'}}) }} {% for timesheet in form.timesheets %} @@ -189,7 +193,7 @@
{% if (form.vars.duration_presets is defined and form.vars.duration_presets is not empty) and (form.vars.disabled is same as (false)) %}
- {% if form.vars.icon is not null %} + {% if form.vars.icon is defined and form.vars.icon is not null %} {{ icon(form.vars.icon) }} @@ -216,7 +220,7 @@
{% else %} - {% if icon is not empty %} + {% if icon is defined and icon is not empty %}