added UI configuration for default start-time (#1506)
This commit is contained in:
@@ -14,12 +14,14 @@ use App\Event\SystemConfigurationEvent;
|
||||
use App\Form\Model\Configuration;
|
||||
use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
|
||||
use App\Form\SystemConfigurationForm;
|
||||
use App\Form\Type\DateTimeTextType;
|
||||
use App\Form\Type\LanguageType;
|
||||
use App\Form\Type\RoundingModeType;
|
||||
use App\Form\Type\SkinType;
|
||||
use App\Form\Type\TrackingModeType;
|
||||
use App\Form\Type\WeekDaysType;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Validator\Constraints\DateTimeFormat;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@@ -216,6 +218,11 @@ final class SystemConfigurationController extends AbstractController
|
||||
->setName('timesheet.mode')
|
||||
->setType(TrackingModeType::class)
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('timesheet.default_begin')
|
||||
->setType(DateTimeTextType::class)
|
||||
->setConstraints([new DateTimeFormat(), new NotNull()])
|
||||
->setTranslationDomain('system-configuration'),
|
||||
(new Configuration())
|
||||
->setName('timesheet.rules.allow_future_times')
|
||||
->setType(CheckboxType::class)
|
||||
|
||||
24
src/Form/Type/DateTimeTextType.php
Normal file
24
src/Form/Type/DateTimeTextType.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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\TextType;
|
||||
|
||||
class DateTimeTextType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return TextType::class;
|
||||
}
|
||||
}
|
||||
28
src/Validator/Constraints/DateTimeFormat.php
Normal file
28
src/Validator/Constraints/DateTimeFormat.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
class DateTimeFormat extends Constraint
|
||||
{
|
||||
public const INVALID_FORMAT = 'kimai-datetime-00';
|
||||
|
||||
protected static $errorNames = [
|
||||
self::INVALID_FORMAT => 'The given value is not a valid datetime format.',
|
||||
];
|
||||
|
||||
public $message = 'This datetime format is invalid.';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return self::PROPERTY_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
43
src/Validator/Constraints/DateTimeFormatValidator.php
Normal file
43
src/Validator/Constraints/DateTimeFormatValidator.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class DateTimeFormatValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* @param string|mixed $value
|
||||
* @param Constraint $constraint
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!($constraint instanceof DateTimeFormat)) {
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\DateTimeFormat');
|
||||
}
|
||||
|
||||
$valid = true;
|
||||
|
||||
try {
|
||||
$test = new \DateTime($value);
|
||||
} catch (\Exception $ex) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
if (false === $valid) {
|
||||
$this->context->buildViolation('The given value is not a valid datetime format.')
|
||||
->setTranslationDomain('validators')
|
||||
->setCode(DateTimeFormat::INVALID_FORMAT)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
'system_configuration_form_timesheet' => [
|
||||
'configuration' => [
|
||||
['name' => 'timesheet.mode', 'value' => 'duration_only'],
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => false],
|
||||
['name' => 'timesheet.active_entries.hard_limit', 'value' => 99],
|
||||
['name' => 'timesheet.active_entries.soft_limit', 'value' => 77],
|
||||
@@ -122,6 +123,7 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
'system_configuration_form_timesheet' => [
|
||||
'configuration' => [
|
||||
['name' => 'timesheet.mode', 'value' => 'foo'],
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '23:59'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => 1],
|
||||
['name' => 'timesheet.active_entries.hard_limit', 'value' => -1],
|
||||
['name' => 'timesheet.active_entries.soft_limit', 'value' => -1],
|
||||
@@ -130,8 +132,8 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
|
||||
],
|
||||
[
|
||||
'#system_configuration_form_timesheet_configuration_0_value', // mode
|
||||
'#system_configuration_form_timesheet_configuration_2_value', // hard_limit
|
||||
'#system_configuration_form_timesheet_configuration_3_value', // soft_limit
|
||||
'#system_configuration_form_timesheet_configuration_3_value', // hard_limit
|
||||
'#system_configuration_form_timesheet_configuration_4_value', // soft_limit
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
85
tests/Validator/Constraints/DateTimeFormatValidatorTest.php
Normal file
85
tests/Validator/Constraints/DateTimeFormatValidatorTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\Tests\Validator\Constraints;
|
||||
|
||||
use App\Validator\Constraints\DateTimeFormat;
|
||||
use App\Validator\Constraints\DateTimeFormatValidator;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Validator\Constraints\DateTimeFormatValidator
|
||||
*/
|
||||
class DateTimeFormatValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
protected function createValidator()
|
||||
{
|
||||
return new DateTimeFormatValidator();
|
||||
}
|
||||
|
||||
public function getValidData()
|
||||
{
|
||||
return [
|
||||
['10:00'],
|
||||
['now'],
|
||||
['2020-12-31 13:31:29'],
|
||||
['monday this week 12:44'],
|
||||
[''], // empty is now
|
||||
[null], // null is now
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstraintIsInvalid()
|
||||
{
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
|
||||
$this->validator->validate('foo', new NotBlank());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidData
|
||||
* @param string $input
|
||||
*/
|
||||
public function testConstraintWithValidData($input)
|
||||
{
|
||||
$constraint = new DateTimeFormat();
|
||||
$this->validator->validate($input, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getInvalidData()
|
||||
{
|
||||
return [
|
||||
['13-13'],
|
||||
['3127::00'],
|
||||
['3127:00:'],
|
||||
[':3127:00'],
|
||||
['::3127'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidData
|
||||
* @param mixed $input
|
||||
*/
|
||||
public function testValidationError($input)
|
||||
{
|
||||
$constraint = new DateTimeFormat();
|
||||
|
||||
$this->validator->validate($input, $constraint);
|
||||
|
||||
$expectedFormat = is_string($input) ? '"' . $input . '"' : $input;
|
||||
|
||||
$this->buildViolation('The given value is not a valid datetime format.')
|
||||
->setCode(DateTimeFormat::INVALID_FORMAT)
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,10 @@
|
||||
<source>Floor</source>
|
||||
<target>Floor: Start, Ende und Dauer werden nach unten gerundet</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="label.timesheet.default_begin">
|
||||
<source>label.timesheet.default_begin</source>
|
||||
<target>Standard Startzeit (wird nicht in jedem Zeiterfassungs Modus verwendet)</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
||||
@@ -190,6 +190,10 @@
|
||||
<source>Floor</source>
|
||||
<target>Floor: begin, end and duration will be rounded down</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="label.timesheet.default_begin">
|
||||
<source>label.timesheet.default_begin</source>
|
||||
<target>Default start-time (not used in all timetracking modes)</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
||||
Reference in New Issue
Block a user