API: changed date-format, camelCase instead of snake_case, null values, update and create for customer and project (#718)
This commit is contained in:
@@ -15,6 +15,8 @@ use App\Form\Type\ActivityType;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\DateTimePickerType;
|
||||
use App\Form\Type\DurationType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YesNoType;
|
||||
@@ -23,7 +25,6 @@ use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
@@ -77,6 +78,7 @@ class TimesheetEditForm extends AbstractType
|
||||
$currency = false;
|
||||
$end = null;
|
||||
$begin = null;
|
||||
$customerCount = $this->customers->countCustomer(true);
|
||||
|
||||
if (isset($options['data'])) {
|
||||
/** @var Timesheet $entry */
|
||||
@@ -104,12 +106,20 @@ class TimesheetEditForm extends AbstractType
|
||||
$timezone = $begin->getTimezone()->getName();
|
||||
}
|
||||
|
||||
$dateTimeOptions = [
|
||||
'model_timezone' => $timezone,
|
||||
'view_timezone' => $timezone,
|
||||
];
|
||||
|
||||
// primarily for API usage, where we cannot use a user/locale specific format
|
||||
if (null !== $options['date_format']) {
|
||||
$dateTimeOptions['format'] = $options['date_format'];
|
||||
}
|
||||
|
||||
if (null === $end || !$this->configuration->isDurationOnly()) {
|
||||
$builder->add('begin', DateTimePickerType::class, [
|
||||
'label' => 'label.begin',
|
||||
'model_timezone' => $timezone,
|
||||
'view_timezone' => $timezone,
|
||||
]);
|
||||
$builder->add('begin', DateTimePickerType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'label.begin'
|
||||
]));
|
||||
}
|
||||
|
||||
if ($this->configuration->isDurationOnly()) {
|
||||
@@ -126,7 +136,7 @@ class TimesheetEditForm extends AbstractType
|
||||
function (FormEvent $event) {
|
||||
/** @var Timesheet $data */
|
||||
$data = $event->getData();
|
||||
if (null === $data->getEnd()) {
|
||||
if (null === $data || null === $data->getEnd()) {
|
||||
$event->getForm()->get('duration')->setData(null);
|
||||
}
|
||||
}
|
||||
@@ -148,24 +158,19 @@ class TimesheetEditForm extends AbstractType
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$builder->add('end', DateTimePickerType::class, [
|
||||
$builder->add('end', DateTimePickerType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'label.end',
|
||||
'model_timezone' => $timezone,
|
||||
'view_timezone' => $timezone,
|
||||
'required' => false,
|
||||
]);
|
||||
]));
|
||||
}
|
||||
|
||||
$projectOptions = [];
|
||||
|
||||
if ($this->customers->countCustomer(true) > 1) {
|
||||
if ($customerCount < 2) {
|
||||
$projectOptions['group_by'] = null;
|
||||
} elseif ($options['customer']) {
|
||||
$builder
|
||||
->add('customer', CustomerType::class, [
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'integer',
|
||||
'description' => 'Customer ID',
|
||||
],
|
||||
'query_builder' => function (CustomerRepository $repo) use ($customer) {
|
||||
return $repo->builderForEntityType($customer);
|
||||
},
|
||||
@@ -175,8 +180,6 @@ class TimesheetEditForm extends AbstractType
|
||||
'mapped' => false,
|
||||
'project_enabled' => true,
|
||||
]);
|
||||
} else {
|
||||
$projectOptions['group_by'] = null;
|
||||
}
|
||||
|
||||
if ($this->projects->countProject(true) <= 1) {
|
||||
@@ -188,16 +191,11 @@ class TimesheetEditForm extends AbstractType
|
||||
'project',
|
||||
ProjectType::class,
|
||||
array_merge($projectOptions, [
|
||||
'placeholder' => '',
|
||||
'activity_enabled' => true,
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'documentation' => [
|
||||
'type' => 'integer',
|
||||
'description' => 'Project ID',
|
||||
],
|
||||
'query_builder' => function (ProjectRepository $repo) use ($project, $customer) {
|
||||
return $repo->builderForEntityType($project, $customer);
|
||||
},
|
||||
'placeholder' => '',
|
||||
'activity_enabled' => true,
|
||||
'query_builder' => function (ProjectRepository $repo) use ($project, $customer) {
|
||||
return $repo->builderForEntityType($project, $customer);
|
||||
},
|
||||
])
|
||||
);
|
||||
|
||||
@@ -223,12 +221,7 @@ class TimesheetEditForm extends AbstractType
|
||||
|
||||
$builder
|
||||
->add('activity', ActivityType::class, [
|
||||
// documentation is for NelmioApiDocBundle
|
||||
'placeholder' => '',
|
||||
'documentation' => [
|
||||
'type' => 'integer',
|
||||
'description' => 'Activity ID',
|
||||
],
|
||||
'query_builder' => function (ActivityRepository $repo) use ($activity, $project) {
|
||||
return $repo->builderForEntityType($activity, $project);
|
||||
},
|
||||
@@ -262,20 +255,10 @@ class TimesheetEditForm extends AbstractType
|
||||
|
||||
if ($options['include_rate']) {
|
||||
$builder
|
||||
->add('fixedRate', MoneyType::class, [
|
||||
'documentation' => [
|
||||
'type' => 'float'
|
||||
],
|
||||
'label' => 'label.fixedRate',
|
||||
'required' => false,
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', MoneyType::class, [
|
||||
'documentation' => [
|
||||
'type' => 'float'
|
||||
],
|
||||
'label' => 'label.hourlyRate',
|
||||
'required' => false,
|
||||
->add('hourlyRate', HourlyRateType::class, [
|
||||
'currency' => $currency,
|
||||
]);
|
||||
}
|
||||
@@ -306,6 +289,8 @@ class TimesheetEditForm extends AbstractType
|
||||
'include_rate' => true,
|
||||
'docu_chapter' => 'timesheet.html',
|
||||
'method' => 'POST',
|
||||
'date_format' => null,
|
||||
'customer' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user