Add customer functionality (#26)
* improved toolbar * added "create customer" functionality #22
This commit is contained in:
@@ -26,6 +26,10 @@
|
|||||||
<source>This is a mandatory field</source>
|
<source>This is a mandatory field</source>
|
||||||
<target>Pflichtfeld</target>
|
<target>Pflichtfeld</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="create">
|
||||||
|
<source>create</source>
|
||||||
|
<target>Erstellen</target>
|
||||||
|
</trans-unit>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Login / Security
|
Login / Security
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
{% macro data_table_header(entries, form, tools) %}
|
{% macro data_table_header(entries, form, tools) %}
|
||||||
<div class="box">
|
<div class="box data_table">
|
||||||
{% if form or tools %}
|
{% if form or tools %}
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
{% if form %}
|
<div class="box-title toolbar">
|
||||||
<div class="box-title toolbar">
|
{% if form %}
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
{{ form_widget(form) }}
|
{{ form_widget(form) }}
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
</div>
|
||||||
{% if tools %}
|
<div class="box-tools">
|
||||||
<div class="box-tools">
|
{% if tools %}
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
{% for url,icon in tools %}
|
{% for icon,url in tools %}
|
||||||
<a class="btn btn-default" href="{{ url }}"><i class="fa fa-{{ icon }}"></i></a>
|
<a class="btn btn-default" href="{{ url }}"><i class="fa fa-{{ icon }}"></i></a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="box-body no-padding">
|
<div class="box-body no-padding">
|
||||||
|
|||||||
@@ -14,14 +14,13 @@ namespace TimesheetBundle\Controller\Admin;
|
|||||||
use AppBundle\Controller\AbstractController;
|
use AppBundle\Controller\AbstractController;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
||||||
use TimesheetBundle\Entity\Customer;
|
use TimesheetBundle\Entity\Customer;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||||
use TimesheetBundle\Form\CustomerEditForm;
|
use TimesheetBundle\Form\CustomerEditForm;
|
||||||
use TimesheetBundle\Repository\CustomerRepository;
|
use TimesheetBundle\Model\Query\CustomerQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller used to manage activities in the admin part of the site.
|
* Controller used to manage activities in the admin part of the site.
|
||||||
@@ -41,21 +40,40 @@ class CustomerController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function indexAction($page)
|
public function indexAction($page)
|
||||||
{
|
{
|
||||||
|
$query = new CustomerQuery();
|
||||||
|
$query->setVisibility(CustomerQuery::SHOW_BOTH);
|
||||||
|
$query->setPage($page);
|
||||||
|
|
||||||
/* @var $entries Pagerfanta */
|
/* @var $entries Pagerfanta */
|
||||||
$entries = $this->getDoctrine()->getRepository(Customer::class)->findAll($page);
|
$entries = $this->getDoctrine()->getRepository(Customer::class)->findByQuery($query);
|
||||||
|
|
||||||
return $this->render('TimesheetBundle:admin:customer.html.twig', ['entries' => $entries]);
|
return $this->render('TimesheetBundle:admin:customer.html.twig', ['entries' => $entries]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/create", name="admin_customer_create")
|
||||||
|
* @Method({"GET", "POST"})
|
||||||
|
*/
|
||||||
|
public function createAction(Request $request)
|
||||||
|
{
|
||||||
|
return $this->renderCustomerForm(new Customer(), $request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/{id}/edit", name="admin_customer_edit")
|
* @Route("/{id}/edit", name="admin_customer_edit")
|
||||||
* @Method({"GET", "POST"})
|
* @Method({"GET", "POST"})
|
||||||
*
|
*/
|
||||||
|
public function editAction(Customer $customer, Request $request)
|
||||||
|
{
|
||||||
|
return $this->renderCustomerForm($customer, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @param Customer $customer
|
* @param Customer $customer
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function editAction(Customer $customer, Request $request)
|
protected function renderCustomerForm(Customer $customer, Request $request)
|
||||||
{
|
{
|
||||||
$editForm = $this->createEditForm($customer);
|
$editForm = $this->createEditForm($customer);
|
||||||
|
|
||||||
@@ -84,15 +102,21 @@ class CustomerController extends AbstractController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Customer $customer
|
* @param Customer $customer
|
||||||
* @return \Symfony\Component\Form\Form
|
* @return \Symfony\Component\Form\FormInterface
|
||||||
*/
|
*/
|
||||||
private function createEditForm(Customer $customer)
|
private function createEditForm(Customer $customer)
|
||||||
{
|
{
|
||||||
|
if ($customer->getId() === null) {
|
||||||
|
$url = $this->generateUrl('admin_customer_create');
|
||||||
|
} else {
|
||||||
|
$url = $this->generateUrl('admin_customer_edit', ['id' => $customer->getId()]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->createForm(
|
return $this->createForm(
|
||||||
CustomerEditForm::class,
|
CustomerEditForm::class,
|
||||||
$customer,
|
$customer,
|
||||||
[
|
[
|
||||||
'action' => $this->generateUrl('admin_customer_edit', ['id' => $customer->getId()]),
|
'action' => $url,
|
||||||
'method' => 'POST'
|
'method' => 'POST'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
95
src/TimesheetBundle/Model/Query/BaseQuery.php
Normal file
95
src/TimesheetBundle/Model/Query/BaseQuery.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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\Model\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for advanced Repository queries.
|
||||||
|
*
|
||||||
|
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||||
|
*/
|
||||||
|
class BaseQuery
|
||||||
|
{
|
||||||
|
|
||||||
|
const DEFAULT_PAGESIZE = 25;
|
||||||
|
const DEFAULT_PAGE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $page = self::DEFAULT_PAGE;
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $pageSize = self::DEFAULT_PAGESIZE;
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $orderBy = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPage()
|
||||||
|
{
|
||||||
|
return $this->page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $page
|
||||||
|
* @return BaseQuery
|
||||||
|
*/
|
||||||
|
public function setPage($page)
|
||||||
|
{
|
||||||
|
$this->page = $page;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPageSize()
|
||||||
|
{
|
||||||
|
return $this->pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $pageSize
|
||||||
|
* @return BaseQuery
|
||||||
|
*/
|
||||||
|
public function setPageSize($pageSize)
|
||||||
|
{
|
||||||
|
if (!empty($pageSize) && (int)$pageSize > 0) {
|
||||||
|
$this->pageSize = (int)$pageSize;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOrderBy()
|
||||||
|
{
|
||||||
|
return $this->orderBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You need to validate carefully if this value is used from a user-input.
|
||||||
|
*
|
||||||
|
* @param string $orderBy
|
||||||
|
* @return BaseQuery
|
||||||
|
*/
|
||||||
|
public function setOrderBy($orderBy)
|
||||||
|
{
|
||||||
|
$this->orderBy = $orderBy;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/TimesheetBundle/Model/Query/CustomerQuery.php
Normal file
44
src/TimesheetBundle/Model/Query/CustomerQuery.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?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\Model\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for advanced queries with the: CustomerRepository
|
||||||
|
*
|
||||||
|
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||||
|
*/
|
||||||
|
class CustomerQuery extends BaseQuery
|
||||||
|
{
|
||||||
|
const SHOW_VISIBLE = 1;
|
||||||
|
const SHOW_HIDDEN = 0;
|
||||||
|
const SHOW_BOTH = 2;
|
||||||
|
|
||||||
|
protected $visibility = self::SHOW_VISIBLE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getVisibility()
|
||||||
|
{
|
||||||
|
return $this->visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $visibility
|
||||||
|
* @return CustomerQuery
|
||||||
|
*/
|
||||||
|
public function setVisibility($visibility)
|
||||||
|
{
|
||||||
|
$this->visibility = $visibility;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,12 +56,13 @@ abstract class AbstractRepository extends EntityRepository
|
|||||||
/**
|
/**
|
||||||
* @param Query $query
|
* @param Query $query
|
||||||
* @param int $page
|
* @param int $page
|
||||||
|
* @param int $maxPerPage
|
||||||
* @return Pagerfanta
|
* @return Pagerfanta
|
||||||
*/
|
*/
|
||||||
protected function getPager(Query $query, $page = 1)
|
protected function getPager(Query $query, $page = 1, $maxPerPage = 25)
|
||||||
{
|
{
|
||||||
$paginator = new Pagerfanta(new DoctrineORMAdapter($query, false));
|
$paginator = new Pagerfanta(new DoctrineORMAdapter($query, false));
|
||||||
$paginator->setMaxPerPage(25);
|
$paginator->setMaxPerPage($maxPerPage);
|
||||||
$paginator->setCurrentPage($page);
|
$paginator->setCurrentPage($page);
|
||||||
|
|
||||||
return $paginator;
|
return $paginator;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace TimesheetBundle\Repository;
|
|||||||
|
|
||||||
use TimesheetBundle\Entity\Customer;
|
use TimesheetBundle\Entity\Customer;
|
||||||
use TimesheetBundle\Model\CustomerStatistic;
|
use TimesheetBundle\Model\CustomerStatistic;
|
||||||
|
use TimesheetBundle\Model\Query\CustomerQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CustomerRepository
|
* Class CustomerRepository
|
||||||
@@ -47,4 +48,25 @@ class CustomerRepository extends AbstractRepository
|
|||||||
$stats->setTotalAmount($countAll);
|
$stats->setTotalAmount($countAll);
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CustomerQuery $query
|
||||||
|
* @return \Pagerfanta\Pagerfanta
|
||||||
|
*/
|
||||||
|
public function findByQuery(CustomerQuery $query)
|
||||||
|
{
|
||||||
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||||
|
|
||||||
|
$qb->select('c')
|
||||||
|
->from('TimesheetBundle:Customer', 'c')
|
||||||
|
->orderBy('c.' . $query->getOrderBy(), 'ASC');
|
||||||
|
|
||||||
|
if ($query->getVisibility() === CustomerQuery::SHOW_VISIBLE) {
|
||||||
|
$qb->andWhere('c.visible = 1');
|
||||||
|
} elseif ($query->getVisibility() === CustomerQuery::SHOW_HIDDEN) {
|
||||||
|
$qb->andWhere('c.visible = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getPager($qb->getQuery(), $query->getPage(), $query->getPageSize());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
'label.currency': 'hidden-xs',
|
'label.currency': 'hidden-xs',
|
||||||
'label.visible': '',
|
'label.visible': '',
|
||||||
'label.actions': '',
|
'label.actions': '',
|
||||||
}) }}
|
}, null, {'user-plus': path('admin_customer_create')}) }}
|
||||||
|
|
||||||
{% for entry in entries %}
|
{% for entry in entries %}
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
{{ include('default/_form.html.twig', {
|
{{ include('default/_form.html.twig', {
|
||||||
'title': customer.name,
|
'title': customer.name|default('create'|trans),
|
||||||
'form': form,
|
'form': form,
|
||||||
'back': path('admin_customer')
|
'back': path('admin_customer')
|
||||||
}) }}
|
}) }}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ li.open .ticktac i.running{
|
|||||||
|
|
||||||
/* ================================ TOOLBAR ================================ */
|
/* ================================ TOOLBAR ================================ */
|
||||||
|
|
||||||
|
.data_table .box-header>.box-tools {
|
||||||
|
top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.box-header .box-title.toolbar form {
|
.box-header .box-title.toolbar form {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user