limit amount of items in calendar drag and drop boxes (#2291)

This commit is contained in:
Kevin Papst
2021-07-11 15:03:18 +02:00
committed by GitHub
parent 2583fdf20e
commit a1f90ffaba
13 changed files with 178 additions and 82 deletions

View File

@@ -9,21 +9,11 @@
namespace App\Controller;
use App\Calendar\DragAndDropSource;
use App\Calendar\Google;
use App\Calendar\GoogleSource;
use App\Calendar\RecentActivitiesSource;
use App\Calendar\TimesheetEntry;
use App\Calendar\CalendarService;
use App\Configuration\SystemConfiguration;
use App\Event\CalendarDragAndDropSourceEvent;
use App\Event\CalendarGoogleSourceEvent;
use App\Event\RecentActivityEvent;
use App\Repository\TimesheetRepository;
use App\Timesheet\TrackingModeService;
use App\Utils\Color;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* Controller used to display calendars.
@@ -33,20 +23,17 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
*/
class CalendarController extends AbstractController
{
/**
* @var EventDispatcherInterface
*/
private $dispatcher;
private $calendarService;
public function __construct(EventDispatcherInterface $dispatcher)
public function __construct(CalendarService $calendarService)
{
$this->dispatcher = $dispatcher;
$this->calendarService = $calendarService;
}
/**
* @Route(path="/", name="calendar", methods={"GET"})
*/
public function userCalendar(SystemConfiguration $configuration, TrackingModeService $service, TimesheetRepository $repository)
public function userCalendar(SystemConfiguration $configuration, TrackingModeService $service)
{
$mode = $service->getActiveMode();
$factory = $this->getDateTimeFactory();
@@ -62,19 +49,24 @@ class CalendarController extends AbstractController
'slotDuration' => $configuration->getCalendarSlotDuration(),
'timeframeBegin' => $configuration->getCalendarTimeframeBegin(),
'timeframeEnd' => $configuration->getCalendarTimeframeEnd(),
'dragDropAmount' => $configuration->getCalendarDragAndDropMaxEntries(),
];
$isPunchMode = !$mode->canEditDuration() && !$mode->canEditBegin() && !$mode->canEditEnd();
$dragAndDrop = [];
if ($mode->canEditBegin()) {
$dragAndDrop = $this->getDragAndDropResources($repository);
try {
$dragAndDrop = $this->calendarService->getDragAndDropResources($this->getUser());
} catch (\Exception $ex) {
$this->logException($ex);
}
}
return $this->render('calendar/user.html.twig', [
'config' => $config,
'dragAndDrop' => $dragAndDrop,
'google' => $this->getGoogleSources($configuration),
'google' => $this->calendarService->getGoogleSources($this->getUser()),
'now' => $factory->createDateTime(),
'defaultStartTime' => $defaultStart->format('h:i:s'),
'is_punch_mode' => $isPunchMode,
@@ -83,60 +75,4 @@ class CalendarController extends AbstractController
'can_edit_duration' => $mode->canEditDuration(),
]);
}
/**
* @return DragAndDropSource[]
*/
private function getDragAndDropResources(TimesheetRepository $repository): array
{
$event = new CalendarDragAndDropSourceEvent($this->getUser());
try {
$data = $repository->getRecentActivities(
$this->getUser(),
$this->getDateTimeFactory()->createDateTime('-1 year'),
10
);
$recentActivity = new RecentActivityEvent($this->getUser(), $data);
$this->dispatcher->dispatch($recentActivity);
$entries = [];
$colorHelper = new Color();
foreach ($recentActivity->getRecentActivities() as $timesheet) {
$entries[] = new TimesheetEntry($timesheet, $colorHelper->getTimesheetColor($timesheet));
}
$event->addSource(new RecentActivitiesSource($entries));
} catch (\Exception $ex) {
$this->logException($ex);
}
$this->dispatcher->dispatch($event);
return $event->getSources();
}
private function getGoogleSources(SystemConfiguration $configuration): ?Google
{
$apiKey = $configuration->getCalendarGoogleApiKey();
if ($apiKey === null) {
return null;
}
$sources = [];
foreach ($configuration->getCalendarGoogleSources() as $name => $config) {
$sources[] = new GoogleSource($name, $config['id'], $config['color']);
}
$event = new CalendarGoogleSourceEvent($this->getUser());
$this->dispatcher->dispatch($event);
foreach ($event->getSources() as $source) {
$sources[] = $source;
}
return new Google($apiKey, $sources);
}
}