Timesheet toolbar (#12)
* add toolbar to timesheet #11 * add customer filter #11 * add project filter #11 * add activity filter #11 * add page size selector #11 * added state filter #11 * fixed csrf token names * fixed typo
This commit is contained in:
@@ -133,7 +133,7 @@ class CustomerEditForm extends AbstractType
|
||||
'data_class' => Customer::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_activity_edit',
|
||||
'csrf_token_id' => 'admin_customer_edit',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class ProjectEditForm extends AbstractType
|
||||
'data_class' => Project::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_activity_edit',
|
||||
'csrf_token_id' => 'admin_project_edit',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
use TimesheetBundle\Entity\Timesheet;
|
||||
use TimesheetBundle\Form\Type\ActivityGroupedWithCustomerNameType;
|
||||
|
||||
/**
|
||||
* Defines the form used to manipulate Timesheet entries.
|
||||
@@ -47,18 +48,15 @@ class TimesheetEditForm extends AbstractType
|
||||
])
|
||||
// integer
|
||||
/*
|
||||
->add('duration', RangeType::class, [
|
||||
'label' => 'label.duration',
|
||||
])
|
||||
// User
|
||||
->add('user', UserType::class, [
|
||||
'label' => 'label.user',
|
||||
])
|
||||
*/
|
||||
// Activity
|
||||
->add('activity', ActivityType::class, [
|
||||
->add('activity', ActivityGroupedWithCustomerNameType::class, [
|
||||
'label' => 'label.activity',
|
||||
])
|
||||
*/
|
||||
// customer
|
||||
->add('description', TextareaType::class, [
|
||||
'label' => 'label.description',
|
||||
@@ -81,7 +79,7 @@ class TimesheetEditForm extends AbstractType
|
||||
'data_class' => Timesheet::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_timsheet_edit',
|
||||
'csrf_token_id' => 'timesheet_edit',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
]);
|
||||
}
|
||||
|
||||
131
src/TimesheetBundle/Form/TimesheetToolbarForm.php
Normal file
131
src/TimesheetBundle/Form/TimesheetToolbarForm.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace TimesheetBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Form\Type\ActivityType;
|
||||
use TimesheetBundle\Form\Type\CustomerType;
|
||||
use TimesheetBundle\Form\Type\ProjectType;
|
||||
use TimesheetBundle\Model\Query\Timesheet as TimesheetQuery;
|
||||
|
||||
/**
|
||||
* Defines the form used for filtering the timesheet.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class TimesheetToolbarForm extends AbstractType
|
||||
{
|
||||
/**
|
||||
* Dirty hack to enable easy handling of GET form in controller and javascript.
|
||||
*Cleans up the name of all form elents (and unfortunately of the form itself).
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
/** @var TimesheetQuery $query */
|
||||
$query = $options['data'];
|
||||
|
||||
$builder
|
||||
->add('pageSize', ChoiceType::class, [
|
||||
'label' => 'label.pageSize',
|
||||
'choices' => [10 => 10, 25 => 25, 50 => 50, 75 => 75, 100 => 100],
|
||||
'required' => false,
|
||||
])
|
||||
->add('state', ChoiceType::class, [
|
||||
'label' => 'label.entryState',
|
||||
'choices' => [
|
||||
'entryState.all' => TimesheetQuery::STATE_ALL,
|
||||
'entryState.running' => TimesheetQuery::STATE_RUNNING,
|
||||
'entryState.stopped' => TimesheetQuery::STATE_STOPPED
|
||||
],
|
||||
])
|
||||
->add('customer', CustomerType::class, [
|
||||
'label' => 'label.customer',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
|
||||
$this->addProjectChoice($builder, $query);
|
||||
$this->addActivityChoice($builder, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param TimesheetQuery $query
|
||||
*/
|
||||
protected function addProjectChoice(FormBuilderInterface $builder, TimesheetQuery $query)
|
||||
{
|
||||
if ($query->getCustomer() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$choices = [];
|
||||
foreach ($query->getCustomer()->getProjects() as $project) {
|
||||
$choices[] = $project;
|
||||
//$choices[$project->getName()] = $project->getId();
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('project', ProjectType::class, [
|
||||
'label' => 'label.project',
|
||||
'required' => false,
|
||||
'choices' => $choices,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param TimesheetQuery $query
|
||||
*/
|
||||
protected function addActivityChoice(FormBuilderInterface $builder, TimesheetQuery $query)
|
||||
{
|
||||
if ($query->getProject() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$choices = [];
|
||||
foreach ($query->getProject()->getActivities() as $activity) {
|
||||
$choices[] = $activity;
|
||||
//$choices[$activity->getName()] = $activity->getId();
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('activity', ActivityType::class, [
|
||||
'label' => 'label.activity',
|
||||
'required' => false,
|
||||
'choices' => $choices,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => TimesheetQuery::class,
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace TimesheetBundle\Form\Type;
|
||||
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
|
||||
/**
|
||||
* Custom form field type to select an activity which are grouped by their Projects, preceeded by their customer names.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ActivityGroupedWithCustomerNameType extends ActivityType
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @param $key
|
||||
* @param $index
|
||||
* @return string
|
||||
*/
|
||||
public function groupBy(Activity $activity, $key, $index)
|
||||
{
|
||||
return $activity->getProject()->getCustomer()->getName() . ': ' . $activity->getProject()->getName();
|
||||
}
|
||||
}
|
||||
58
src/TimesheetBundle/Form/Type/ActivityType.php
Normal file
58
src/TimesheetBundle/Form/Type/ActivityType.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace TimesheetBundle\Form\Type;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
|
||||
/**
|
||||
* Custom form field type to select an activity.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ActivityType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @param $key
|
||||
* @param $index
|
||||
* @return string
|
||||
*/
|
||||
public function groupBy(Activity $activity, $key, $index)
|
||||
{
|
||||
return $activity->getProject()->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'class' => 'TimesheetBundle:Activity',
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
'group_by' => array($this, 'groupBy'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
namespace TimesheetBundle\Form\Type;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Entity\Project;
|
||||
|
||||
/**
|
||||
* Custom form field type to select a project.
|
||||
@@ -30,14 +31,10 @@ class ProjectType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'class' => 'TimesheetBundle:Project',
|
||||
'choice_label' => function ($project) {
|
||||
/* @var $project Project */
|
||||
return
|
||||
//'[' . $project->getId() . '] ' .
|
||||
$project->getName() .
|
||||
' (' .
|
||||
$project->getCustomer()->getName() .
|
||||
')';
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
'group_by' => function(Project $project, $key, $index) {
|
||||
return $project->getCustomer()->getName();
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -47,6 +44,6 @@ class ProjectType extends AbstractType
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user