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) {
|
$('.toolbar form select').change(function (event) {
|
||||||
switch (event.target.id) {
|
switch (event.target.id) {
|
||||||
case 'customer':
|
case 'customer':
|
||||||
if ($(this).val() === '') {
|
|
||||||
$('.toolbar form select#project').parent().remove();
|
|
||||||
//$('.toolbar form select#project').parent().parent().remove();
|
|
||||||
} else {
|
|
||||||
$('.toolbar form select#project').val('');
|
$('.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;
|
break;
|
||||||
case 'project':
|
case 'project':
|
||||||
if ($(this).val() === '') {
|
if ($('.toolbar form select#activity').find(':selected').attr('data-project')) {
|
||||||
$('.toolbar form select#activity').parent().remove();
|
|
||||||
//$('.toolbar form select#activity').parent().parent().remove();
|
|
||||||
} else {
|
|
||||||
$('.toolbar form select#activity').val('');
|
$('.toolbar form select#activity').val('');
|
||||||
}
|
}
|
||||||
break;
|
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/app.css": "/build/app.css?6501689dff217d14b179e3049295343e",
|
||||||
"build/images/blue@2x.png": "/build/images/blue@2x.png?2694acfd",
|
"build/images/blue@2x.png": "/build/images/blue@2x.png?2694acfd",
|
||||||
"build/images/blue.png": "/build/images/blue.png?96f8a905",
|
"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\ActivityRepository;
|
||||||
use App\Repository\CustomerRepository;
|
use App\Repository\CustomerRepository;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
|
use App\Repository\Query\ActivityQuery;
|
||||||
use App\Repository\Query\CustomerQuery;
|
use App\Repository\Query\CustomerQuery;
|
||||||
|
use App\Repository\Query\ProjectQuery;
|
||||||
use Symfony\Component\Form\AbstractType;
|
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\Extension\Core\Type\DateType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
@@ -137,6 +140,12 @@ abstract class AbstractToolbarForm extends AbstractType
|
|||||||
*/
|
*/
|
||||||
protected function addProjectChoice(FormBuilderInterface $builder)
|
protected function addProjectChoice(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
|
$builder->add('project', ChoiceType::class, [
|
||||||
|
'group_by' => null,
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'label.project',
|
||||||
|
]);
|
||||||
|
|
||||||
$builder->addEventListener(
|
$builder->addEventListener(
|
||||||
FormEvents::PRE_SUBMIT,
|
FormEvents::PRE_SUBMIT,
|
||||||
function (FormEvent $event) {
|
function (FormEvent $event) {
|
||||||
@@ -149,10 +158,12 @@ abstract class AbstractToolbarForm extends AbstractType
|
|||||||
'group_by' => null,
|
'group_by' => null,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'query_builder' => function (ProjectRepository $repo) use ($data) {
|
'query_builder' => function (ProjectRepository $repo) use ($data) {
|
||||||
$qb = $repo->builderForEntityType();
|
$query = new ProjectQuery();
|
||||||
$qb->andWhere('p.customer = :customer')->setParameter('customer', $data['customer']);
|
$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)
|
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(
|
$builder->addEventListener(
|
||||||
FormEvents::PRE_SUBMIT,
|
FormEvents::PRE_SUBMIT,
|
||||||
function (FormEvent $event) {
|
function (FormEvent $event) {
|
||||||
@@ -176,9 +201,13 @@ abstract class AbstractToolbarForm extends AbstractType
|
|||||||
'group_by' => null,
|
'group_by' => null,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'query_builder' => function (ActivityRepository $repo) use ($data) {
|
'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();
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -50,17 +71,10 @@ class ActivityType extends AbstractType
|
|||||||
'class' => Activity::class,
|
'class' => Activity::class,
|
||||||
'choice_label' => [$this, 'choiceLabel'],
|
'choice_label' => [$this, 'choiceLabel'],
|
||||||
'group_by' => [$this, 'groupBy'],
|
'group_by' => [$this, 'groupBy'],
|
||||||
|
'choice_attr' => [$this, 'choiceAttr'],
|
||||||
'query_builder' => function (ActivityRepository $repo) {
|
'query_builder' => function (ActivityRepository $repo) {
|
||||||
return $repo->builderForEntityType();
|
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%']
|
//'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
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -29,6 +50,7 @@ class ProjectType extends AbstractType
|
|||||||
'label' => 'label.project',
|
'label' => 'label.project',
|
||||||
'class' => Project::class,
|
'class' => Project::class,
|
||||||
'choice_label' => 'name',
|
'choice_label' => 'name',
|
||||||
|
'choice_attr' => [$this, 'choiceAttr'],
|
||||||
'group_by' => function (Project $project, $key, $index) {
|
'group_by' => function (Project $project, $key, $index) {
|
||||||
return $project->getCustomer()->getName();
|
return $project->getCustomer()->getName();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user