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:
@@ -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 ==========
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Timesheet>
|
||||
*/
|
||||
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<FavoriteTimesheet>
|
||||
*/
|
||||
public function favoriteEntries(User $user, int $limit = 5): array
|
||||
|
||||
Reference in New Issue
Block a user