* fixed annotation #1 * added default label #1 * added project toolbar #1
This commit is contained in:
@@ -30,7 +30,7 @@ trait VisibilityTrait
|
||||
|
||||
/**
|
||||
* @param int $visibility
|
||||
* @return self
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
|
||||
@@ -68,14 +68,11 @@ class CustomerController extends AbstractController
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Customer::class)->findByQuery($query);
|
||||
|
||||
return $this->render(
|
||||
'TimesheetBundle:admin:customer.html.twig',
|
||||
[
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $this->getToolbarForm($query)->createView(),
|
||||
]
|
||||
);
|
||||
return $this->render('TimesheetBundle:admin:customer.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $this->getToolbarForm($query)->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace TimesheetBundle\Controller\Admin;
|
||||
use AppBundle\Controller\AbstractController;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use TimesheetBundle\Entity\Activity;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
use TimesheetBundle\Entity\Project;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
@@ -21,6 +22,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use TimesheetBundle\Form\ProjectEditForm;
|
||||
use TimesheetBundle\Form\ProjectToolbarForm;
|
||||
use TimesheetBundle\Repository\Query\ProjectQuery;
|
||||
|
||||
/**
|
||||
@@ -33,22 +35,54 @@ use TimesheetBundle\Repository\Query\ProjectQuery;
|
||||
*/
|
||||
class ProjectController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return ProjectQuery
|
||||
*/
|
||||
protected function getQueryForRequest(Request $request)
|
||||
{
|
||||
$visibility = $request->get('visibility');
|
||||
if (strlen($visibility) == 0 || (int)$visibility != $visibility) {
|
||||
$visibility = ProjectQuery::SHOW_BOTH;
|
||||
}
|
||||
$pageSize = (int) $request->get('pageSize');
|
||||
$customer = $request->get('customer');
|
||||
$customer = !empty(trim($customer)) ? trim($customer) : null;
|
||||
|
||||
if ($customer !== null) {
|
||||
$repo = $this->getDoctrine()->getRepository(Customer::class);
|
||||
$customer = $repo->getById($customer);
|
||||
}
|
||||
|
||||
$query = new ProjectQuery();
|
||||
$query
|
||||
->setPageSize($pageSize)
|
||||
->setVisibility($visibility)
|
||||
->setCustomer($customer)
|
||||
;
|
||||
|
||||
return $query ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", defaults={"page": 1}, name="admin_project")
|
||||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_project_paginated")
|
||||
* @Method("GET")
|
||||
* @Cache(smaxage="10")
|
||||
*/
|
||||
public function indexAction($page)
|
||||
public function indexAction($page, Request $request)
|
||||
{
|
||||
$query = new ProjectQuery();
|
||||
$query->setVisibility(ProjectQuery::SHOW_BOTH);
|
||||
$query = $this->getQueryForRequest($request);
|
||||
$query->setPage($page);
|
||||
|
||||
/* @var $entries Pagerfanta */
|
||||
$entries = $this->getDoctrine()->getRepository(Project::class)->findByQuery($query);
|
||||
|
||||
return $this->render('TimesheetBundle:admin:project.html.twig', ['entries' => $entries]);
|
||||
return $this->render('TimesheetBundle:admin:project.html.twig', [
|
||||
'entries' => $entries,
|
||||
'query' => $query,
|
||||
'toolbarForm' => $this->getToolbarForm($query)->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,6 +134,24 @@ class ProjectController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProjectQuery $query
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
protected function getToolbarForm(ProjectQuery $query)
|
||||
{
|
||||
return $this->createForm(
|
||||
ProjectToolbarForm::class,
|
||||
$query,
|
||||
[
|
||||
'action' => $this->generateUrl('admin_project_paginated', [
|
||||
'page' => $query->getPage(),
|
||||
]),
|
||||
'method' => 'GET',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project $project
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
|
||||
53
src/TimesheetBundle/Form/ProjectToolbarForm.php
Normal file
53
src/TimesheetBundle/Form/ProjectToolbarForm.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TimesheetBundle\Form\Type\CustomerType;
|
||||
use TimesheetBundle\Repository\Query\ProjectQuery;
|
||||
|
||||
/**
|
||||
* Defines the form used for filtering the projects.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ProjectToolbarForm extends CustomerToolbarForm
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
/** @var ProjectQuery $query */
|
||||
$query = $options['data'];
|
||||
|
||||
parent::buildForm($builder, $options);
|
||||
$builder
|
||||
->add('customer', CustomerType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => ProjectQuery::class,
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,6 @@ class TimesheetToolbarForm extends AbstractType
|
||||
],
|
||||
])
|
||||
->add('customer', CustomerType::class, [
|
||||
'label' => 'label.customer',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
@@ -86,7 +85,6 @@ class TimesheetToolbarForm extends AbstractType
|
||||
|
||||
$builder
|
||||
->add('project', ProjectType::class, [
|
||||
'label' => 'label.project',
|
||||
'required' => false,
|
||||
'choices' => $choices,
|
||||
]);
|
||||
@@ -110,7 +108,6 @@ class TimesheetToolbarForm extends AbstractType
|
||||
|
||||
$builder
|
||||
->add('activity', ActivityType::class, [
|
||||
'label' => 'label.activity',
|
||||
'required' => false,
|
||||
'choices' => $choices,
|
||||
]);
|
||||
|
||||
@@ -32,6 +32,7 @@ class ActivityType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'label' => 'label.activity',
|
||||
'class' => 'TimesheetBundle:Activity',
|
||||
'choice_label' => 'name',
|
||||
'group_by' => function (Activity $activity, $key, $index) {
|
||||
|
||||
@@ -31,6 +31,7 @@ class CustomerType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'label' => 'label.customer',
|
||||
'class' => 'TimesheetBundle:Customer',
|
||||
'choice_label' => 'name',
|
||||
'query_builder' => function (CustomerRepository $repo) {
|
||||
|
||||
@@ -32,6 +32,7 @@ class ProjectType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'label' => 'label.project',
|
||||
'class' => 'TimesheetBundle:Project',
|
||||
'choice_label' => 'name',
|
||||
'group_by' => function (Project $project, $key, $index) {
|
||||
|
||||
@@ -73,6 +73,11 @@ class ProjectRepository extends AbstractRepository
|
||||
// TODO check for visibility of customer
|
||||
}
|
||||
|
||||
if ($query->getCustomer() !== null) {
|
||||
$qb->andWhere('p.customer = :customer')
|
||||
->setParameter('customer', $query->getCustomer());
|
||||
}
|
||||
|
||||
return $this->getBaseQueryResult($qb, $query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace TimesheetBundle\Repository\Query;
|
||||
use AppBundle\Repository\Query\BaseQuery;
|
||||
use AppBundle\Repository\Query\VisibilityInterface;
|
||||
use AppBundle\Repository\Query\VisibilityTrait;
|
||||
use TimesheetBundle\Entity\Customer;
|
||||
|
||||
/**
|
||||
* Can be used for advanced queries with the: ProjectRepository
|
||||
@@ -23,4 +24,27 @@ use AppBundle\Repository\Query\VisibilityTrait;
|
||||
class ProjectQuery extends BaseQuery implements VisibilityInterface
|
||||
{
|
||||
use VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomer(Customer $customer = null)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
{% block page_title %}{{ 'admin_project.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_project.subtitle'|trans }} {{ 'subtitle.amount'|trans({'%count%': entries.count}) }}{% endblock %}
|
||||
{% block javascript_imports %}<script src="{{ asset('js/timesheet.js') }}"></script>{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if entries.count == 0 %}
|
||||
@@ -19,7 +20,7 @@
|
||||
'label.budget': 'hidden-xs',
|
||||
'label.visible': '',
|
||||
'label.actions': '',
|
||||
}, null, {'plus-square': path('admin_project_create')}) }}
|
||||
}, toolbarForm, {'plus-square': path('admin_project_create')}) }}
|
||||
|
||||
{% for entry in entries %}
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user