Weekly hours improvements (#4631)

* fix table padding
* reduced minimum quick-entry recent activity row amount
* use activity favorites in weekly hours
This commit is contained in:
Kevin Papst
2024-02-12 14:20:17 +01:00
committed by GitHub
parent 85a16a9363
commit 58cbf1776f
5 changed files with 52 additions and 37 deletions

View File

@@ -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());