improved calendar (#784)
This commit is contained in:
@@ -9,14 +9,11 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Calendar\Service;
|
||||
use App\Calendar\TimesheetEntity;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Calendar\Google;
|
||||
use App\Calendar\Source;
|
||||
use App\Configuration\CalendarConfiguration;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
@@ -30,53 +27,34 @@ class CalendarController extends AbstractController
|
||||
/**
|
||||
* @Route(path="/", name="calendar", methods={"GET"})
|
||||
*/
|
||||
public function userCalendar(Service $calendar, UserDateTimeFactory $dateTime)
|
||||
public function userCalendar(CalendarConfiguration $configuration, UserDateTimeFactory $dateTime)
|
||||
{
|
||||
return $this->render('calendar/user.html.twig', [
|
||||
'config' => $calendar->getConfig(),
|
||||
'google' => $calendar->getGoogle(),
|
||||
'config' => $configuration,
|
||||
'google' => $this->getGoogleSources($configuration),
|
||||
'now' => $dateTime->createDateTime(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/user", name="calendar_entries", methods={"GET"})
|
||||
* @return Google
|
||||
*/
|
||||
public function calendarEntries(Request $request, UserDateTimeFactory $dateTime, TimesheetRepository $repository)
|
||||
protected function getGoogleSources(CalendarConfiguration $configuration)
|
||||
{
|
||||
$start = $request->get('start');
|
||||
$end = $request->get('end');
|
||||
$apiKey = $configuration->getGoogleApiKey() ?? null;
|
||||
$sources = [];
|
||||
|
||||
$start = $dateTime->createDateTimeFromFormat('Y-m-d', $start);
|
||||
if ($start === false) {
|
||||
$start = $dateTime->createDateTime('first day of this month');
|
||||
}
|
||||
$start->setTime(0, 0, 0);
|
||||
foreach ($configuration->getGoogleSources() as $name => $config) {
|
||||
$source = new Source();
|
||||
$source
|
||||
->setColor($config['color'])
|
||||
->setUri($config['id'])
|
||||
->setId($name)
|
||||
;
|
||||
|
||||
$end = $dateTime->createDateTimeFromFormat('Y-m-d', $end);
|
||||
if ($end === false) {
|
||||
$end = clone $start;
|
||||
$end = $end->modify('last day of this month');
|
||||
}
|
||||
$end->setTime(23, 59, 59);
|
||||
|
||||
$query = new TimesheetQuery();
|
||||
$query
|
||||
->setBegin($start)
|
||||
->setUser($this->getUser())
|
||||
->setState(TimesheetQuery::STATE_ALL)
|
||||
->setResultType(TimesheetQuery::RESULT_TYPE_QUERYBUILDER)
|
||||
->setEnd($end)
|
||||
;
|
||||
|
||||
/* @var $entries Timesheet[] */
|
||||
$entries = $repository->findByQuery($query)->getQuery()->execute();
|
||||
$result = [];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$result[] = new TimesheetEntity($entry);
|
||||
$sources[] = $source;
|
||||
}
|
||||
|
||||
return $this->json($result);
|
||||
return new Google($apiKey, $sources);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,13 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CountryType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Validator\Constraints\DateTime;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
|
||||
/**
|
||||
* Controller used for executing system relevant tasks.
|
||||
@@ -84,41 +87,13 @@ class SystemConfigurationController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/theme", name="system_configuration_theme", methods={"POST"})
|
||||
* @Route(path="/update/{section}", name="system_configuration_update", methods={"POST"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function theme(Request $request)
|
||||
{
|
||||
return $this->handleConfigUpdate($request, SystemConfigurationModel::SECTION_THEME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/timesheet", name="system_configuration_timesheet", methods={"POST"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function timesheet(Request $request)
|
||||
{
|
||||
return $this->handleConfigUpdate($request, SystemConfigurationModel::SECTION_TIMESHEET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/customer", name="system_configuration_form_customer", methods={"POST"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function formDefaults(Request $request)
|
||||
{
|
||||
return $this->handleConfigUpdate($request, SystemConfigurationModel::SECTION_FORM_CUSTOMER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $section
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function handleConfigUpdate(Request $request, string $section)
|
||||
public function configUpdate(Request $request, string $section)
|
||||
{
|
||||
$configModel = null;
|
||||
$configSettings = $this->getInitializedConfigurations();
|
||||
@@ -173,15 +148,15 @@ class SystemConfigurationController extends AbstractController
|
||||
*/
|
||||
private function createConfigurationsForm(SystemConfigurationModel $configuration)
|
||||
{
|
||||
return $this->createForm(
|
||||
SystemConfigurationForm::class,
|
||||
$configuration,
|
||||
[
|
||||
'attr' => ['id' => 'system_configuration_form_' . $configuration->getSection()],
|
||||
'action' => $this->generateUrl('system_configuration_' . $configuration->getSection()),
|
||||
'method' => 'POST'
|
||||
]
|
||||
);
|
||||
$options = [
|
||||
'action' => $this->generateUrl('system_configuration_update', ['section' => $configuration->getSection()]),
|
||||
'method' => 'POST',
|
||||
];
|
||||
|
||||
return $this->container
|
||||
->get('form.factory')
|
||||
->createNamedBuilder('system_configuration_form_' . $configuration->getSection(), SystemConfigurationForm::class, $configuration, $options)
|
||||
->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,10 +235,41 @@ class SystemConfigurationController extends AbstractController
|
||||
->setConfiguration([
|
||||
(new Configuration())
|
||||
->setName('theme.select_type')
|
||||
->setLabel('theme.select_type')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(EnhancedSelectboxType::class),
|
||||
]),
|
||||
(new SystemConfigurationModel())
|
||||
->setSection(SystemConfigurationModel::SECTION_CALENDAR)
|
||||
->setConfiguration([
|
||||
(new Configuration())
|
||||
->setName('calendar.week_numbers')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(CheckboxType::class),
|
||||
(new Configuration())
|
||||
->setName('calendar.weekends')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(CheckboxType::class),
|
||||
(new Configuration())
|
||||
->setName('calendar.businessHours.begin')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(TextType::class)
|
||||
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
|
||||
(new Configuration())
|
||||
->setName('calendar.businessHours.end')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(TextType::class)
|
||||
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
|
||||
(new Configuration())
|
||||
->setName('calendar.visibleHours.begin')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(TextType::class)
|
||||
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
|
||||
(new Configuration())
|
||||
->setName('calendar.visibleHours.end')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setType(TextType::class)
|
||||
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,13 +153,7 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function editAction(Timesheet $entry, Request $request)
|
||||
{
|
||||
$route = 'timesheet';
|
||||
|
||||
if ('calendar' === $request->get('origin')) {
|
||||
$route = 'calendar';
|
||||
}
|
||||
|
||||
return $this->edit($entry, $request, $route, 'timesheet/edit.html.twig');
|
||||
return $this->edit($entry, $request, 'timesheet', 'timesheet/edit.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,23 +167,17 @@ class TimesheetController extends AbstractController
|
||||
*/
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
{
|
||||
$route = 'timesheet';
|
||||
if ('calendar' === $request->get('origin')) {
|
||||
$route = 'calendar';
|
||||
}
|
||||
|
||||
return $this->create($request, $route, 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
|
||||
return $this->create($request, 'timesheet', 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getCreateForm(Timesheet $entry, string $redirectRoute)
|
||||
protected function getCreateForm(Timesheet $entry)
|
||||
{
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('timesheet_create', ['origin' => $redirectRoute]),
|
||||
'action' => $this->generateUrl('timesheet_create', []),
|
||||
'include_rate' => $this->isGranted('edit_rate', $entry),
|
||||
'customer' => true,
|
||||
]);
|
||||
@@ -198,16 +186,14 @@ class TimesheetController extends AbstractController
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param int $page
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getEditForm(Timesheet $entry, $page, string $redirectRoute)
|
||||
protected function getEditForm(Timesheet $entry, $page)
|
||||
{
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('timesheet_edit', [
|
||||
'id' => $entry->getId(),
|
||||
'page' => $page,
|
||||
'origin' => $redirectRoute,
|
||||
]),
|
||||
'include_rate' => $this->isGranted('edit_rate', $entry),
|
||||
'include_exported' => $this->isGranted('edit_export', $entry),
|
||||
|
||||
@@ -70,7 +70,7 @@ trait TimesheetControllerTrait
|
||||
*/
|
||||
protected function edit(Timesheet $entry, Request $request, $redirectRoute, $renderTemplate)
|
||||
{
|
||||
$editForm = $this->getEditForm($entry, $request->get('page'), $request->get('origin', 'timesheet'));
|
||||
$editForm = $this->getEditForm($entry, $request->get('page'));
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
@@ -107,17 +107,20 @@ trait TimesheetControllerTrait
|
||||
if ($start !== null) {
|
||||
$start = $this->dateTime->createDateTimeFromFormat('Y-m-d', $start);
|
||||
if ($start !== false) {
|
||||
$start->setTime(10, 0, 0); // TODO make me configurable
|
||||
$entry->setBegin($start);
|
||||
}
|
||||
}
|
||||
|
||||
$end = $request->get('end');
|
||||
if ($end !== null) {
|
||||
$end = $this->dateTime->createDateTimeFromFormat('Y-m-d', $end);
|
||||
if ($end !== false) {
|
||||
$end->setTime(18, 0, 0); // TODO make me configurable
|
||||
$entry->setEnd($end);
|
||||
// only check for an end date if a begin date was given
|
||||
$end = $request->get('end');
|
||||
if ($end !== null) {
|
||||
$end = $this->dateTime->createDateTimeFromFormat('Y-m-d', $end);
|
||||
if ($end !== false) {
|
||||
$start->setTime(10, 0, 0);
|
||||
$end->setTime(18, 0, 0);
|
||||
|
||||
$entry->setEnd($end);
|
||||
$entry->setDuration($end->getTimestamp() - $start->getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,14 +129,16 @@ trait TimesheetControllerTrait
|
||||
$from = $this->dateTime->createDateTime($from);
|
||||
if ($from !== false) {
|
||||
$entry->setBegin($from);
|
||||
}
|
||||
}
|
||||
|
||||
$to = $request->get('to');
|
||||
if ($to !== null) {
|
||||
$to = $this->dateTime->createDateTime($to);
|
||||
if ($to !== false) {
|
||||
$entry->setEnd($to);
|
||||
// only check for an end datetime if a begin datetime was given
|
||||
$to = $request->get('to');
|
||||
if ($to !== null) {
|
||||
$to = $this->dateTime->createDateTime($to);
|
||||
if ($to !== false) {
|
||||
$entry->setEnd($to);
|
||||
$entry->setDuration($to->getTimestamp() - $from->getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +152,7 @@ trait TimesheetControllerTrait
|
||||
$entry->setActivity($activity);
|
||||
}
|
||||
|
||||
$createForm = $this->getCreateForm($entry, $redirectRoute);
|
||||
$createForm = $this->getCreateForm($entry);
|
||||
$createForm->handleRequest($request);
|
||||
|
||||
if ($createForm->isSubmitted() && $createForm->isValid()) {
|
||||
@@ -179,18 +184,16 @@ trait TimesheetControllerTrait
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
abstract protected function getCreateForm(Timesheet $entry, string $redirectRoute);
|
||||
abstract protected function getCreateForm(Timesheet $entry);
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param int $page
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
abstract protected function getEditForm(Timesheet $entry, $page, string $redirectRoute);
|
||||
abstract protected function getEditForm(Timesheet $entry, $page);
|
||||
|
||||
/**
|
||||
* Adds a "successful" flash message to the stack.
|
||||
|
||||
@@ -146,10 +146,9 @@ class TimesheetTeamController extends AbstractController
|
||||
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getCreateForm(Timesheet $entry, string $redirectRoute)
|
||||
protected function getCreateForm(Timesheet $entry)
|
||||
{
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('admin_timesheet_create'),
|
||||
@@ -162,10 +161,9 @@ class TimesheetTeamController extends AbstractController
|
||||
/**
|
||||
* @param Timesheet $entry
|
||||
* @param int $page
|
||||
* @param string $redirectRoute
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getEditForm(Timesheet $entry, $page, string $redirectRoute)
|
||||
protected function getEditForm(Timesheet $entry, $page)
|
||||
{
|
||||
return $this->createForm(TimesheetEditForm::class, $entry, [
|
||||
'action' => $this->generateUrl('admin_timesheet_edit', [
|
||||
|
||||
Reference in New Issue
Block a user