save default search options (#2445)
* set default times for daterange objects * allow to show order and order by fields * move search to modal * more options for page size * save export visibility in cookie
This commit is contained in:
52
src/Repository/BookmarkRepository.php
Normal file
52
src/Repository/BookmarkRepository.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Bookmark;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\ORMException;
|
||||
|
||||
/**
|
||||
* @extends \Doctrine\ORM\EntityRepository<Bookmark>
|
||||
*/
|
||||
class BookmarkRepository extends EntityRepository
|
||||
{
|
||||
public function saveBookmark(Bookmark $bookmark)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->persist($bookmark);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
public function deleteBookmark(Bookmark $bookmark)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
$em->remove($bookmark);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (ORMException $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchDefaultOptions(User $user, string $name): ?Bookmark
|
||||
{
|
||||
return $this->findOneBy([
|
||||
'user' => $user->getId(),
|
||||
'type' => Bookmark::SEARCH_DEFAULT,
|
||||
'name' => substr($name, 0, 50)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,16 @@ class CustomerRepository extends EntityRepository
|
||||
->from(Customer::class, 'c')
|
||||
;
|
||||
|
||||
$qb->orderBy('c.' . $query->getOrderBy(), $query->getOrder());
|
||||
$orderBy = $query->getOrderBy();
|
||||
switch ($orderBy) {
|
||||
case 'vat_id':
|
||||
$orderBy = 'c.vatId';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'c.' . $orderBy;
|
||||
break;
|
||||
}
|
||||
$qb->orderBy($orderBy, $query->getOrder());
|
||||
|
||||
if ($query->isShowVisible()) {
|
||||
$qb->andWhere($qb->expr()->eq('c.visible', ':visible'));
|
||||
|
||||
@@ -271,6 +271,12 @@ class ProjectRepository extends EntityRepository
|
||||
case 'customer':
|
||||
$orderBy = 'c.name';
|
||||
break;
|
||||
case 'project_start':
|
||||
$orderBy = 'p.start';
|
||||
break;
|
||||
case 'project_end':
|
||||
$orderBy = 'p.end';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'p.' . $orderBy;
|
||||
break;
|
||||
|
||||
@@ -16,7 +16,7 @@ use App\Entity\Project;
|
||||
*/
|
||||
class ActivityQuery extends ProjectQuery
|
||||
{
|
||||
public const ACTIVITY_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'project', 'visible'];
|
||||
public const ACTIVITY_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'project', 'budget', 'timeBudget', 'visible'];
|
||||
|
||||
/**
|
||||
* @var Project[]|int[]
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\Bookmark;
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use App\Utils\SearchTerm;
|
||||
@@ -78,6 +79,14 @@ class BaseQuery
|
||||
* @var SearchTerm|null
|
||||
*/
|
||||
private $searchTerm;
|
||||
/**
|
||||
* @var Bookmark
|
||||
*/
|
||||
private $bookmark;
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @param Team[] $teams
|
||||
@@ -274,6 +283,32 @@ class BaseQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setBookmark(Bookmark $bookmark): void
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
}
|
||||
|
||||
public function getBookmark(): ?Bookmark
|
||||
{
|
||||
return $this->bookmark;
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
if (null !== $this->name) {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
$shortClass = explode('\\', static::class);
|
||||
|
||||
return array_pop($shortClass);
|
||||
}
|
||||
|
||||
public function copyTo(BaseQuery $query): BaseQuery
|
||||
{
|
||||
$query->setDefaults($this->defaults);
|
||||
|
||||
@@ -18,7 +18,7 @@ class CustomerQuery extends BaseQuery implements VisibilityInterface
|
||||
|
||||
public const CUSTOMER_ORDER_ALLOWED = [
|
||||
'id', 'name', 'comment', 'country', 'number', 'homepage', 'email', 'mobile', 'fax',
|
||||
'phone', 'currency', 'address', 'contact', 'company', 'vatId', 'visible'
|
||||
'phone', 'currency', 'address', 'contact', 'company', 'vat_id', 'budget', 'timeBudget', 'visible'
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -19,8 +19,7 @@ class ProjectQuery extends BaseQuery implements VisibilityInterface
|
||||
use VisibilityTrait;
|
||||
|
||||
public const PROJECT_ORDER_ALLOWED = [
|
||||
'id', 'name', 'comment', 'customer', 'orderNumber', 'projectStart',
|
||||
'projectEnd', 'orderNumber', 'orderDate', 'start', 'end', 'visible'
|
||||
'id', 'name', 'comment', 'customer', 'orderNumber', 'orderDate', 'project_start', 'project_end', 'budget', 'timeBudget', 'visible'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user