add "duration + fixed start time" tracking mode (#859)

This commit is contained in:
Kevin Papst
2019-06-15 23:04:53 +02:00
committed by GitHub
parent 92f3f4ee57
commit 59d2946b91
36 changed files with 1094 additions and 265 deletions

View File

@@ -9,11 +9,17 @@
namespace App\Form;
use Symfony\Component\Form\FormBuilderInterface;
class TimesheetAdminEditForm extends TimesheetEditForm
{
protected function showTimeFields(array $options): bool
public function buildForm(FormBuilderInterface $builder, array $options)
{
return true;
$options['allow_begin_datetime'] = true;
$options['allow_end_datetime'] = true;
$options['allow_duration'] = false;
parent::buildForm($builder, $options);
}
protected function showCustomer(array $options, bool $isNew, int $customerCount): bool

View File

@@ -114,14 +114,14 @@ class TimesheetEditForm extends AbstractType
$dateTimeOptions['format'] = $options['date_format'];
}
if ($this->showTimeFields($options)) {
if ($options['allow_begin_datetime']) {
$this->addBegin($builder, $dateTimeOptions);
}
if ($options['use_duration']) {
$this->addDuration($builder);
} else {
$this->addEnd($builder, $dateTimeOptions);
}
if ($options['allow_duration']) {
$this->addDuration($builder);
} elseif ($options['allow_end_datetime']) {
$this->addEnd($builder, $dateTimeOptions);
}
if ($this->showCustomer($options, $isNew, $customerCount)) {
@@ -154,11 +154,6 @@ class TimesheetEditForm extends AbstractType
return true;
}
protected function showTimeFields(array $options): bool
{
return $options['include_datetime'];
}
protected function addCustomer(FormBuilderInterface $builder, ?Customer $customer = null)
{
$builder
@@ -377,8 +372,9 @@ class TimesheetEditForm extends AbstractType
'method' => 'POST',
'date_format' => null,
'customer' => false, // for API usage
'use_duration' => false, // duration instead of end (for duration_only mode)
'include_datetime' => true,
'allow_begin_datetime' => true,
'allow_end_datetime' => true,
'allow_duration' => false,
'attr' => [
'data-form-event' => 'kimai.timesheetUpdate',
'data-msg-success' => 'action.update.success',

View File

@@ -9,7 +9,7 @@
namespace App\Form\Type;
use App\Configuration\TimesheetConfiguration;
use App\Timesheet\TrackingModeService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -17,20 +17,30 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select the timesheet mode.
*/
class TimesheetModeType extends AbstractType
class TrackingModeType extends AbstractType
{
protected $service;
public function __construct(TrackingModeService $service)
{
$this->service = $service;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$choices = [];
foreach ($this->service->getModes() as $mode) {
$id = $mode->getId();
$choices['label.timesheet.mode_' . $id] = $id;
}
$resolver->setDefaults([
'label' => 'label.timesheet.mode',
'choices' => [
'label.timesheet.mode_default' => TimesheetConfiguration::MODE_DEFAULT,
'label.timesheet.mode_punch' => TimesheetConfiguration::MODE_PUNCH_IN_OUT,
'label.timesheet.mode_duration_only' => TimesheetConfiguration::MODE_DURATION_ONLY,
],
'choices' => $choices,
]);
}