allow changing calendar entry title (#3272)

This commit is contained in:
Kevin Papst
2022-04-25 18:18:48 +02:00
committed by GitHub
parent e94d47bf0f
commit ef5977bcfe
9 changed files with 116 additions and 3 deletions

View File

@@ -114,6 +114,7 @@ final class CalendarService
'timeframeBegin' => $this->configuration->getCalendarTimeframeBegin(),
'timeframeEnd' => $this->configuration->getCalendarTimeframeEnd(),
'dragDropAmount' => $this->configuration->getCalendarDragAndDropMaxEntries(),
'entryTitlePattern' => $this->configuration->find('calendar.title_pattern'),
];
$event = new CalendarConfigurationEvent($config);

View File

@@ -16,6 +16,7 @@ use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
use App\Form\SystemConfigurationForm;
use App\Form\Type\ActivityTypePatternType;
use App\Form\Type\ArrayToCommaStringType;
use App\Form\Type\CalendarTitlePatternType;
use App\Form\Type\CustomerTypePatternType;
use App\Form\Type\DatePickerType;
use App\Form\Type\DateTimeTextType;
@@ -623,6 +624,10 @@ final class SystemConfigurationController extends AbstractController
->setTranslationDomain('system-configuration')
->setType(IntegerType::class)
->setConstraints([new Range(['min' => 0, 'max' => 20]), new NotNull()]),
(new Configuration())
->setName('calendar.title_pattern')
->setTranslationDomain('system-configuration')
->setType(CalendarTitlePatternType::class),
]),
(new SystemConfigurationModel('branding'))
->setConfiguration([

View File

@@ -429,6 +429,10 @@ class Configuration implements ConfigurationInterface
->thenInvalid('The dragdrop_amount must be between 0 and 20')
->end()
->end()
->enumNode('title_pattern')
->values(['{activity}', '{project}', '{customer}', '{description}'])
->defaultValue('{activity}')
->end()
->end()
;

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Select the pattern that will be used for calendar entry titles.
*/
class CalendarTitlePatternType extends AbstractType
{
public const PATTERN_CUSTOMER = '{customer}';
public const PATTERN_PROJECT = '{project}';
public const PATTERN_ACTIVITY = '{activity}';
public const PATTERN_DESCRIPTION = '{description}';
public const SPACER = ' - ';
public const PATTERN_ACTIVITY_DESCRIPTION = self::PATTERN_ACTIVITY . self::SPACER . self::PATTERN_DESCRIPTION;
public const PATTERN_PROJECT_DESCRIPTION = self::PATTERN_PROJECT . self::SPACER . self::PATTERN_DESCRIPTION;
public const PATTERN_CUSTOMER_DESCRIPTION = self::PATTERN_CUSTOMER . self::SPACER . self::PATTERN_DESCRIPTION;
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function configureOptions(OptionsResolver $resolver): void
{
$customer = $this->translator->trans('label.customer');
$project = $this->translator->trans('label.project');
$activity = $this->translator->trans('label.activity');
$description = $this->translator->trans('label.description');
$resolver->setDefaults([
'label' => 'label.choice_pattern',
'choices' => [
$activity => CalendarTitlePatternType::PATTERN_ACTIVITY,
$project => CalendarTitlePatternType::PATTERN_PROJECT,
$customer => CalendarTitlePatternType::PATTERN_CUSTOMER,
$description => CalendarTitlePatternType::PATTERN_DESCRIPTION,
$activity . self::SPACER . $description => CalendarTitlePatternType::PATTERN_ACTIVITY_DESCRIPTION,
$project . self::SPACER . $description => CalendarTitlePatternType::PATTERN_PROJECT_DESCRIPTION,
$customer . self::SPACER . $description => CalendarTitlePatternType::PATTERN_CUSTOMER_DESCRIPTION,
]
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}