Merge branch 'master' into stacked-working-hours

This commit is contained in:
Kevin Papst
2020-08-17 19:04:00 +02:00
12 changed files with 248 additions and 24 deletions

View File

@@ -51,7 +51,9 @@ export default class KimaiSelectDataAPI extends KimaiPlugin {
const selectValue = jQuery(this).val();
if (selectValue === '' || (Array.isArray(selectValue) && selectValue.length === 0)) {
// Problem: select a project with activities and then select a customer that has no project
// results in a wrong URL, it triggers "activities?project=" instead of using the "emptyUrl"
if (selectValue === undefined || selectValue === null || selectValue === '' || (Array.isArray(selectValue) && selectValue.length === 0)) {
if (this.dataset['emptyUrl'] === undefined) {
self._updateSelect(targetSelect, {});
jQuery(targetSelect).attr('disabled', 'disabled');
@@ -79,8 +81,9 @@ export default class KimaiSelectDataAPI extends KimaiPlugin {
let targetField = jQuery('#' + formPrefix + test[1]);
let newValue = '';
if (targetField.length === 0) {
// debug: this case for example happens in duration only mode, when the end field is not found
//console.log('ERROR: Cannot find field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
// happens for example:
// - in duration only mode, when the end field is not found
// console.log('ERROR: Cannot find field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
} else {
if (targetField.val() !== null) {
newValue = targetField.val();
@@ -98,7 +101,15 @@ export default class KimaiSelectDataAPI extends KimaiPlugin {
newValue = moment(newValue, targetField.data('format')).format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
}
}
} else {
// happens for example:
// - when the end date is not set on a timesheet record and the project list is loaded (as the URL contains the %end% replacer)
// console.log('Empty value found for field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
}
} else {
// happens for example:
// - when a customer without projects is selected
// console.log('ERROR: Empty field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,7 @@
"build/runtime.098eaae1.js",
"build/0.79dbdbb9.js",
"build/1.512c747c.js",
"build/app.bbc43299.js"
"build/app.cafc411b.js"
],
"css": [
"build/app.554717a4.css"
@@ -53,7 +53,7 @@
"build/runtime.098eaae1.js": "sha384-xNNrNinl64G3nCUrIskgSjU0mUXXCB9lj6XCSInBTwxSKXk8uTMafnLHtdWdIGtd",
"build/0.79dbdbb9.js": "sha384-U2Ao0ORAZ8PCeDmyRsqQFET3hc7pfUBimq0PrqFdG4/s0Bdi+qBj4TJK3o70bCd5",
"build/1.512c747c.js": "sha384-SneGUmydV7WMkwkQp+4ql0TCXq1Or/1kQeIObbiMjx9QFM0DruGsytf77g4OxrGI",
"build/app.bbc43299.js": "sha384-WlGU/poBy3KLHz5/X5H3idDqTGW8yTk4Dqoy7GRM+chHibdncGJx6E9lEnkwX/kC",
"build/app.cafc411b.js": "sha384-sc27ZMn3ySrIZOjZ6G5bkSbG5yptYP4Cck2n5p2fOid056W/QaQZN2U4vDt0EipW",
"build/app.554717a4.css": "sha384-dITltEp59C3NH6o/8ZcpZJgHPLx+/I5t9xDQVsbQn7YoJ0GEV82gDDqe64ebjU29",
"build/invoice.74279541.js": "sha384-2BXic5Sgorf2tXai6zSAN4wLY2dbg06L03/xMKW6itMcszvtnRArKzfBh6DNcF3f",
"build/invoice.13d8ef4e.css": "sha384-B6RN/wZJToSBCZk2JeLokIqWEhbh+Eb9arYbt9dM+YoC2Z6PnCeTwTqSGyexWWJh",

View File

@@ -3,7 +3,7 @@
"build/1.512c747c.js": "build/1.512c747c.js",
"build/2.7ab75d0a.js": "build/2.7ab75d0a.js",
"build/app.css": "build/app.554717a4.css",
"build/app.js": "build/app.bbc43299.js",
"build/app.js": "build/app.cafc411b.js",
"build/calendar.css": "build/calendar.1408f57e.css",
"build/calendar.js": "build/calendar.0e49d4da.js",
"build/chart.js": "build/chart.34d60a88.js",

View File

@@ -15,6 +15,7 @@ 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\DayTimeType;
use App\Form\Type\LanguageType;
use App\Form\Type\RoundingModeType;
use App\Form\Type\SkinType;
@@ -23,6 +24,7 @@ use App\Form\Type\WeekDaysType;
use App\Form\Type\YesNoType;
use App\Repository\ConfigurationRepository;
use App\Validator\Constraints\DateTimeFormat;
use App\Validator\Constraints\TimeFormat;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -34,8 +36,8 @@ use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Regex;
@@ -136,15 +138,19 @@ final class SystemConfigurationController extends AbstractController
$form = $this->createConfigurationsForm($configModel);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$this->repository->saveSystemConfiguration($form->getData());
$this->flashSuccess('action.update.success');
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
}
if ($form->isSubmitted()) {
if ($form->isValid()) {
try {
$this->repository->saveSystemConfiguration($form->getData());
$this->flashSuccess('action.update.success');
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
}
return $this->redirectToRoute('system_configuration');
return $this->redirectToRoute('system_configuration');
} else {
$this->flashError('action.update.error', ['%reason%' => 'Validation problem']);
}
}
$configSettings = $this->getInitializedConfigurations();
@@ -393,23 +399,23 @@ final class SystemConfigurationController extends AbstractController
(new Configuration())
->setName('calendar.businessHours.begin')
->setTranslationDomain('system-configuration')
->setType(TextType::class)
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
->setType(DayTimeType::class)
->setConstraints([new NotBlank(), new TimeFormat()]),
(new Configuration())
->setName('calendar.businessHours.end')
->setTranslationDomain('system-configuration')
->setType(TextType::class)
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
->setType(DayTimeType::class)
->setConstraints([new NotBlank(), new TimeFormat()]),
(new Configuration())
->setName('calendar.visibleHours.begin')
->setTranslationDomain('system-configuration')
->setType(TextType::class)
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
->setType(DayTimeType::class)
->setConstraints([new NotBlank(), new TimeFormat()]),
(new Configuration())
->setName('calendar.visibleHours.end')
->setTranslationDomain('system-configuration')
->setType(TextType::class)
->setConstraints([new DateTime(['format' => 'H:i']), new NotNull()]),
->setType(DayTimeType::class)
->setConstraints([new NotBlank(), new TimeFormat()]),
(new Configuration())
->setName('calendar.slot_duration')
->setTranslationDomain('system-configuration')

View File

@@ -0,0 +1,37 @@
<?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;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DayTimeType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'attr' => [
'placeholder' => 'hh:mm'
],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return TextType::class;
}
}

View 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 TimeFormat extends Constraint
{
public const INVALID_FORMAT = 'kimai-time-00';
protected static $errorNames = [
self::INVALID_FORMAT => 'The given value is not a valid time.',
];
public $message = 'This time format is invalid.';
public function getTargets()
{
return self::PROPERTY_CONSTRAINT;
}
}

View 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;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class TimeFormatValidator extends ConstraintValidator
{
/**
* @param string|mixed $value
* @param Constraint $constraint
*/
public function validate($value, Constraint $constraint)
{
if (!($constraint instanceof TimeFormat)) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\TimeFormat');
}
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedValueException($value, 'string');
}
$value = (string) $value;
if (preg_match('/^([01][0-9]|2[0-3]):([0-5][0-9])$/', $value) !== 1) {
$this->context->buildViolation('The given value is not a valid time.')
->setTranslationDomain('validators')
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(TimeFormat::INVALID_FORMAT)
->addViolation();
}
}
}

View File

@@ -353,8 +353,10 @@ class SystemConfigurationControllerTest extends ControllerBaseTest
[
'#system_configuration_form_calendar_configuration_2_value',
'#system_configuration_form_calendar_configuration_3_value',
'#system_configuration_form_calendar_configuration_3_value',
'#system_configuration_form_calendar_configuration_4_value',
'#system_configuration_form_calendar_configuration_5_value',
'#system_configuration_form_calendar_configuration_5_value',
],
true
);

View File

@@ -0,0 +1,89 @@
<?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\TimeFormat;
use App\Validator\Constraints\TimeFormatValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\TimeFormatValidator
*/
class TimeFormatValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
{
return new TimeFormatValidator();
}
public function testConstraintIsInvalid()
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('foo', new NotBlank());
}
public function testWrongValueThrowsException()
{
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('Expected argument of type "string", "stdClass" given');
$this->validator->validate(new \stdClass(), new TimeFormat());
}
/**
* @dataProvider getValidTimes
*/
public function testValidationSucceeds(string $value)
{
$this->validator->validate($value, new TimeFormat());
$this->assertNoViolation();
}
public function getValidTimes()
{
return [
['00:00'],
['00:01'],
['23:00'],
['23:10'],
['23:01'],
['23:59'],
];
}
/**
* @dataProvider getInvalidTimes
*/
public function testValidationProblem(string $value)
{
$this->validator->validate($value, new TimeFormat());
$this->buildViolation('The given value is not a valid time.')
->setParameter('{{ value }}', '"' . $value . '"')
->setCode(TimeFormat::INVALID_FORMAT)
->assertRaised();
}
public function getInvalidTimes()
{
return [
['1:00'],
['01:1'],
['00:60'],
['23:60'],
['23:1'],
['24:00'],
];
}
}

View File

@@ -30,6 +30,10 @@
<source>You already have an entry for this time.</source>
<target>Es existiert bereits ein Eintrag für diesen Zeitpunkt.</target>
</trans-unit>
<trans-unit id="The given value is not a valid time.">
<source>The given value is not a valid time.</source>
<target>Der eingetragene Wert ist keine gültige Uhrzeit.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@@ -30,6 +30,10 @@
<source>You already have an entry for this time.</source>
<target>You already have an entry for this time.</target>
</trans-unit>
<trans-unit id="The given value is not a valid time.">
<source>The given value is not a valid time.</source>
<target>The given value is not a valid time.</target>
</trans-unit>
</body>
</file>
</xliff>