optimizations (#2904)
* calc once, then re-use * prevent invalid theme switch * allow to turn off weekly-quick-entries by permissions * remove 00:00 from date-times that likely do not need a time * fix datepicker out of window
This commit is contained in:
@@ -25,7 +25,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
* Controller used to enter times in weekly form.
|
||||
*
|
||||
* @Route(path="/quick_entry")
|
||||
* @Security("is_granted('edit_own_timesheet')")
|
||||
* @Security("is_granted('weekly_own_timesheet') and is_granted('edit_own_timesheet')")
|
||||
*/
|
||||
class QuickEntryController extends AbstractController
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ final class MenuSubscriber implements EventSubscriberInterface
|
||||
$timesheets->setChildRoutes(['timesheet_export', 'timesheet_edit', 'timesheet_create', 'timesheet_multi_update']);
|
||||
$menu->addItem($timesheets);
|
||||
|
||||
if ($auth->isGranted('edit_own_timesheet')) {
|
||||
if ($auth->isGranted('weekly_own_timesheet') && $auth->isGranted('edit_own_timesheet')) {
|
||||
$mode = $this->trackingModeService->getActiveMode();
|
||||
if ($mode->canEditDuration() || $mode->canEditEnd()) {
|
||||
$menu->addItem(
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\EventSubscriber;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Form\Type\SkinType;
|
||||
use KevinPapst\AdminLTEBundle\Helper\ContextHelper;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\KernelEvent;
|
||||
@@ -70,7 +71,7 @@ final class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
$name = $ref->getName();
|
||||
switch ($name) {
|
||||
case UserPreference::SKIN:
|
||||
if (!empty($ref->getValue())) {
|
||||
if (!empty($ref->getValue()) && \in_array($ref->getValue(), SkinType::THEMES)) {
|
||||
$this->helper->setOption('skin', 'skin-' . $ref->getValue());
|
||||
}
|
||||
break;
|
||||
@@ -79,7 +80,7 @@ final class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
if ($ref->getValue() === 'boxed') {
|
||||
$this->helper->setOption('boxed_layout', true);
|
||||
$this->helper->setOption('fixed_layout', false);
|
||||
} elseif ($ref->getValue() === 'fixed') {
|
||||
} else {
|
||||
$this->helper->setOption('boxed_layout', false);
|
||||
$this->helper->setOption('fixed_layout', true);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,21 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class SkinType extends AbstractType
|
||||
{
|
||||
public const THEMES = [
|
||||
'blue' => 'blue',
|
||||
'black' => 'black',
|
||||
'green' => 'green',
|
||||
'purple' => 'purple',
|
||||
'red' => 'red',
|
||||
'yellow' => 'yellow',
|
||||
'blue-light' => 'blue-light',
|
||||
'black-light' => 'black-light',
|
||||
'green-light' => 'green-light',
|
||||
'purple-light' => 'purple-light',
|
||||
'red-light' => 'red-light',
|
||||
'yellow-light' => 'yellow-light',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -25,20 +40,7 @@ class SkinType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'required' => true,
|
||||
'choices' => [
|
||||
'blue' => 'blue',
|
||||
'black' => 'black',
|
||||
'green' => 'green',
|
||||
'purple' => 'purple',
|
||||
'red' => 'red',
|
||||
'yellow' => 'yellow',
|
||||
'blue-light' => 'blue-light',
|
||||
'black-light' => 'black-light',
|
||||
'green-light' => 'green-light',
|
||||
'purple-light' => 'purple-light',
|
||||
'red-light' => 'red-light',
|
||||
'yellow-light' => 'yellow-light',
|
||||
]
|
||||
'choices' => self::THEMES,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,11 +164,12 @@ final class LocaleFormatExtensions extends AbstractExtension
|
||||
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @param bool $stripMidnight
|
||||
* @return bool|false|string
|
||||
*/
|
||||
public function dateTimeFull($date)
|
||||
public function dateTimeFull($date, bool $stripMidnight = false)
|
||||
{
|
||||
return $this->getFormatter()->dateTimeFull($date);
|
||||
return $this->getFormatter()->dateTimeFull($date, $stripMidnight);
|
||||
}
|
||||
|
||||
public function createDate(string $date, ?User $user = null): \DateTime
|
||||
|
||||
@@ -239,9 +239,10 @@ final class LocaleFormatter
|
||||
|
||||
/**
|
||||
* @param DateTime|string $date
|
||||
* @param bool $stripMidnight
|
||||
* @return bool|false|string
|
||||
*/
|
||||
public function dateTimeFull($date)
|
||||
public function dateTimeFull($date, bool $stripMidnight = false)
|
||||
{
|
||||
if (null === $this->dateTimeTypeFormat) {
|
||||
$this->dateTimeTypeFormat = $this->localeFormats->getDateTimeTypeFormat();
|
||||
@@ -255,13 +256,19 @@ final class LocaleFormatter
|
||||
}
|
||||
}
|
||||
|
||||
$format = $this->dateTimeTypeFormat;
|
||||
|
||||
if ($stripMidnight && $date->format('H') == '00' && $date->format('i') == '00') {
|
||||
$format = $this->localeFormats->getDateTypeFormat();
|
||||
}
|
||||
|
||||
$formatter = new IntlDateFormatter(
|
||||
$this->locale,
|
||||
IntlDateFormatter::MEDIUM,
|
||||
IntlDateFormatter::MEDIUM,
|
||||
date_default_timezone_get(),
|
||||
IntlDateFormatter::GREGORIAN,
|
||||
$this->dateTimeTypeFormat
|
||||
$format
|
||||
);
|
||||
|
||||
return $formatter->format($date);
|
||||
|
||||
Reference in New Issue
Block a user