simplify timesheet edit form if only one customer is existing (#443)
This commit is contained in:
2
.github/lock.yml
vendored
2
.github/lock.yml
vendored
@@ -14,6 +14,8 @@ lockComment: >
|
|||||||
This thread has been automatically locked since there has not been
|
This thread has been automatically locked since there has not been
|
||||||
any recent activity after it was closed. Please open a new issue for
|
any recent activity after it was closed. Please open a new issue for
|
||||||
related bugs.
|
related bugs.
|
||||||
|
If you use Kimai on a daily basis, please [consider donating](https://www.kimai.org/donate/) to
|
||||||
|
support further development of Kimai.
|
||||||
|
|
||||||
# Assign `resolved` as the reason for locking. Set to `false` to disable
|
# Assign `resolved` as the reason for locking. Set to `false` to disable
|
||||||
setLockReason: false
|
setLockReason: false
|
||||||
|
|||||||
@@ -32,6 +32,26 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
*/
|
*/
|
||||||
class TimesheetEditForm extends AbstractType
|
class TimesheetEditForm extends AbstractType
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CustomerRepository
|
||||||
|
*/
|
||||||
|
private $customers;
|
||||||
|
/**
|
||||||
|
* @var ProjectRepository
|
||||||
|
*/
|
||||||
|
private $projects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CustomerRepository $customer
|
||||||
|
* @param ProjectRepository $project
|
||||||
|
*/
|
||||||
|
public function __construct(CustomerRepository $customer, ProjectRepository $project)
|
||||||
|
{
|
||||||
|
$this->customers = $customer;
|
||||||
|
$this->projects = $project;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +102,9 @@ class TimesheetEditForm extends AbstractType
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$projectOptions = [];
|
||||||
|
|
||||||
|
if ($this->customers->countCustomer(true) > 1) {
|
||||||
$builder
|
$builder
|
||||||
->add('customer', CustomerType::class, [
|
->add('customer', CustomerType::class, [
|
||||||
// documentation is for NelmioApiDocBundle
|
// documentation is for NelmioApiDocBundle
|
||||||
@@ -89,7 +112,6 @@ class TimesheetEditForm extends AbstractType
|
|||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'description' => 'Customer ID',
|
'description' => 'Customer ID',
|
||||||
],
|
],
|
||||||
'label' => 'label.customer',
|
|
||||||
'query_builder' => function (CustomerRepository $repo) use ($customer) {
|
'query_builder' => function (CustomerRepository $repo) use ($customer) {
|
||||||
return $repo->builderForEntityType($customer);
|
return $repo->builderForEntityType($customer);
|
||||||
},
|
},
|
||||||
@@ -100,16 +122,25 @@ class TimesheetEditForm extends AbstractType
|
|||||||
'data-related-select' => $this->getBlockPrefix() . '_project',
|
'data-related-select' => $this->getBlockPrefix() . '_project',
|
||||||
'data-api-url' => ['get_projects', ['customer' => '-s-']],
|
'data-api-url' => ['get_projects', ['customer' => '-s-']],
|
||||||
],
|
],
|
||||||
])
|
]);
|
||||||
->add('project', ProjectType::class, [
|
} else {
|
||||||
|
$projectOptions['group_by'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->projects->countProject(true) > 1) {
|
||||||
|
$projectOptions['placeholder'] = null;
|
||||||
|
} else {
|
||||||
|
$projectOptions['group_by'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$builder
|
||||||
|
->add('project', ProjectType::class, array_merge($projectOptions, [
|
||||||
// documentation is for NelmioApiDocBundle
|
// documentation is for NelmioApiDocBundle
|
||||||
'documentation' => [
|
'documentation' => [
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'description' => 'Project ID',
|
'description' => 'Project ID',
|
||||||
],
|
],
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'placeholder' => '',
|
|
||||||
'label' => 'label.project',
|
|
||||||
'query_builder' => function (ProjectRepository $repo) use ($project) {
|
'query_builder' => function (ProjectRepository $repo) use ($project) {
|
||||||
return $repo->builderForEntityType($project);
|
return $repo->builderForEntityType($project);
|
||||||
},
|
},
|
||||||
@@ -117,14 +148,15 @@ class TimesheetEditForm extends AbstractType
|
|||||||
'data-related-select' => $this->getBlockPrefix() . '_activity',
|
'data-related-select' => $this->getBlockPrefix() . '_activity',
|
||||||
'data-api-url' => ['get_activities', ['project' => '-s-']],
|
'data-api-url' => ['get_activities', ['project' => '-s-']],
|
||||||
],
|
],
|
||||||
])
|
]));
|
||||||
|
|
||||||
|
$builder
|
||||||
->add('activity', ActivityType::class, [
|
->add('activity', ActivityType::class, [
|
||||||
// documentation is for NelmioApiDocBundle
|
// documentation is for NelmioApiDocBundle
|
||||||
'documentation' => [
|
'documentation' => [
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'description' => 'Activity ID',
|
'description' => 'Activity ID',
|
||||||
],
|
],
|
||||||
'label' => 'label.activity',
|
|
||||||
'query_builder' => function (ActivityRepository $repo) use ($activity) {
|
'query_builder' => function (ActivityRepository $repo) use ($activity) {
|
||||||
return $repo->builderForEntityType($activity);
|
return $repo->builderForEntityType($activity);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,10 +35,15 @@ class CustomerRepository extends AbstractRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param null|bool $visible
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function countCustomer()
|
public function countCustomer($visible = null)
|
||||||
{
|
{
|
||||||
|
if (null !== $visible) {
|
||||||
|
return $this->count(['visible' => (int) $visible]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->count([]);
|
return $this->count([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,15 @@ class ProjectRepository extends AbstractRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param null|bool $visible
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function countProject()
|
public function countProject($visible = null)
|
||||||
{
|
{
|
||||||
|
if (null !== $visible) {
|
||||||
|
return $this->count(['visible' => (int) $visible]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->count([]);
|
return $this->count([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user