toolbar - always allow to choose global activities (#410)
This commit is contained in:
@@ -16,20 +16,13 @@ $(document).ready(function () {
|
||||
$('.toolbar form select').change(function (event) {
|
||||
switch (event.target.id) {
|
||||
case 'customer':
|
||||
if ($(this).val() === '') {
|
||||
$('.toolbar form select#project').parent().remove();
|
||||
//$('.toolbar form select#project').parent().parent().remove();
|
||||
} else {
|
||||
$('.toolbar form select#project').val('');
|
||||
if ($('.toolbar form select#activity').find(':selected').attr('data-project')) {
|
||||
$('.toolbar form select#activity').val('');
|
||||
}
|
||||
$('.toolbar form select#activity').parent().remove();
|
||||
//$('.toolbar form select#activity').parent().parent().remove();
|
||||
break;
|
||||
case 'project':
|
||||
if ($(this).val() === '') {
|
||||
$('.toolbar form select#activity').parent().remove();
|
||||
//$('.toolbar form select#activity').parent().parent().remove();
|
||||
} else {
|
||||
if ($('.toolbar form select#activity').find(':selected').attr('data-project')) {
|
||||
$('.toolbar form select#activity').val('');
|
||||
}
|
||||
break;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"build/app.js": "/build/app.js?ad0631335484158d704a",
|
||||
"build/app.js": "/build/app.js?3650fbe8241d54cb493c",
|
||||
"build/app.css": "/build/app.css?6501689dff217d14b179e3049295343e",
|
||||
"build/images/blue@2x.png": "/build/images/blue@2x.png?2694acfd",
|
||||
"build/images/blue.png": "/build/images/blue.png?96f8a905",
|
||||
|
||||
@@ -19,8 +19,11 @@ use App\Form\Type\VisibilityType;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
@@ -137,6 +140,12 @@ abstract class AbstractToolbarForm extends AbstractType
|
||||
*/
|
||||
protected function addProjectChoice(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('project', ChoiceType::class, [
|
||||
'group_by' => null,
|
||||
'required' => false,
|
||||
'label' => 'label.project',
|
||||
]);
|
||||
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SUBMIT,
|
||||
function (FormEvent $event) {
|
||||
@@ -149,10 +158,12 @@ abstract class AbstractToolbarForm extends AbstractType
|
||||
'group_by' => null,
|
||||
'required' => false,
|
||||
'query_builder' => function (ProjectRepository $repo) use ($data) {
|
||||
$qb = $repo->builderForEntityType();
|
||||
$qb->andWhere('p.customer = :customer')->setParameter('customer', $data['customer']);
|
||||
$query = new ProjectQuery();
|
||||
$query->setCustomer($data['customer']);
|
||||
$query->setResultType(ProjectQuery::RESULT_TYPE_QUERYBUILDER);
|
||||
$query->setVisibility(ProjectQuery::SHOW_BOTH);
|
||||
|
||||
return $qb;
|
||||
return $repo->findByQuery($query);
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -164,6 +175,20 @@ abstract class AbstractToolbarForm extends AbstractType
|
||||
*/
|
||||
protected function addActivityChoice(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('activity', ActivityType::class, [
|
||||
'group_by' => null,
|
||||
'required' => false,
|
||||
'query_builder' => function (ActivityRepository $repo) {
|
||||
$query = new ActivityQuery();
|
||||
$query->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER);
|
||||
$query->setGlobalsOnly(true);
|
||||
$query->setOrderGlobalsFirst(true);
|
||||
$query->setVisibility(ActivityQuery::SHOW_BOTH);
|
||||
|
||||
return $repo->findByQuery($query);
|
||||
},
|
||||
]);
|
||||
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SUBMIT,
|
||||
function (FormEvent $event) {
|
||||
@@ -176,9 +201,13 @@ abstract class AbstractToolbarForm extends AbstractType
|
||||
'group_by' => null,
|
||||
'required' => false,
|
||||
'query_builder' => function (ActivityRepository $repo) use ($data) {
|
||||
$qb = $repo->builderForEntityType(null, $data['project']);
|
||||
$query = new ActivityQuery();
|
||||
$query->setResultType(ActivityQuery::RESULT_TYPE_QUERYBUILDER);
|
||||
$query->setProject($data['project']);
|
||||
$query->setOrderGlobalsFirst(true);
|
||||
$query->setVisibility(ActivityQuery::SHOW_BOTH);
|
||||
|
||||
return $qb;
|
||||
return $repo->findByQuery($query);
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,27 @@ class ActivityType extends AbstractType
|
||||
return $activity->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $choiceValue
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function choiceAttr($choiceValue, $key, $value)
|
||||
{
|
||||
$project = null;
|
||||
|
||||
if (!($choiceValue instanceof Activity)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (null !== $choiceValue->getProject()) {
|
||||
$project = $choiceValue->getProject()->getId();
|
||||
}
|
||||
|
||||
return ['data-project' => $project];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -50,17 +71,10 @@ class ActivityType extends AbstractType
|
||||
'class' => Activity::class,
|
||||
'choice_label' => [$this, 'choiceLabel'],
|
||||
'group_by' => [$this, 'groupBy'],
|
||||
'choice_attr' => [$this, 'choiceAttr'],
|
||||
'query_builder' => function (ActivityRepository $repo) {
|
||||
return $repo->builderForEntityType();
|
||||
},
|
||||
'choice_attr' => function (Activity $activity, $key, $value) {
|
||||
$attributes = [];
|
||||
if (null !== $activity->getProject()) {
|
||||
$attributes['data-project'] = $activity->getProject()->getId();
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
},
|
||||
//'attr' => ['class' => 'selectpicker', 'data-size' => 10, 'data-live-search' => true, 'data-width' => '100%']
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,27 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class ProjectType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @param Project $choiceValue
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
public function choiceAttr($choiceValue, $key, $value)
|
||||
{
|
||||
$customer = null;
|
||||
|
||||
if (!($choiceValue instanceof Project)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (null !== $choiceValue->getCustomer()) {
|
||||
$customer = $choiceValue->getCustomer()->getId();
|
||||
}
|
||||
|
||||
return ['data-customer' => $customer];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -29,6 +50,7 @@ class ProjectType extends AbstractType
|
||||
'label' => 'label.project',
|
||||
'class' => Project::class,
|
||||
'choice_label' => 'name',
|
||||
'choice_attr' => [$this, 'choiceAttr'],
|
||||
'group_by' => function (Project $project, $key, $index) {
|
||||
return $project->getCustomer()->getName();
|
||||
},
|
||||
|
||||
@@ -133,7 +133,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getActivity()->getId());
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getActivity()->getId());
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(2, $entry->getActivity()->getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getActivity()->getId());
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getProject()->getCustomer()->getId());
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(2, $entry->getProject()->getCustomer()->getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getActivity()->getId());
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(1, $entry->getProject()->getId());
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(10, count($timesheets));
|
||||
|
||||
/** @var Timesheet $entry */
|
||||
foreach($timesheets as $entry) {
|
||||
foreach ($timesheets as $entry) {
|
||||
$this->assertEquals(2, $entry->getProject()->getId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user