added table-column ordering (#1086)

This commit is contained in:
Kevin Papst
2019-09-09 23:47:42 +02:00
committed by GitHub
parent d041a3f4f9
commit a651e55dc9
82 changed files with 932 additions and 516 deletions

View File

@@ -16,6 +16,8 @@ use App\Entity\Project;
*/
class ActivityQuery extends ProjectQuery
{
public const ACTIVITY_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'project'];
/**
* @var Project|int|null
*/
@@ -28,7 +30,9 @@ class ActivityQuery extends ProjectQuery
public function __construct()
{
parent::__construct();
$this->setOrderBy('name');
$this->setDefaults([
'orderBy' => 'name',
]);
}
/**
@@ -68,24 +72,4 @@ class ActivityQuery extends ProjectQuery
return $this;
}
/**
* {@inheritdoc}
*/
public function isDirty(): bool
{
if (parent::isDirty()) {
return true;
}
if ($this->project !== null) {
return true;
}
if ($this->globalsOnly !== false) {
return true;
}
return false;
}
}

View File

@@ -12,6 +12,7 @@ namespace App\Repository\Query;
use App\Entity\Team;
use App\Entity\User;
use App\Utils\SearchTerm;
use Symfony\Component\Form\FormErrorIterator;
/**
* Base class for advanced Repository queries.
@@ -28,6 +29,13 @@ class BaseQuery
public const RESULT_TYPE_PAGER = 'PagerFanta';
public const RESULT_TYPE_QUERYBUILDER = 'QueryBuilder';
private $defaults = [
'page' => self::DEFAULT_PAGE,
'pageSize' => self::DEFAULT_PAGESIZE,
'orderBy' => 'id',
'order' => self::ORDER_ASC,
'searchTerm' => null,
];
/**
* @var int
*/
@@ -214,29 +222,43 @@ class BaseQuery
return $this;
}
/**
* Returns whether the query has changed fields, compared to the original state.
*
* @return bool
*/
public function isDirty(): bool
protected function set($name, $value)
{
if ($this->page !== self::DEFAULT_PAGE) {
return true;
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} elseif (property_exists($this, $name)) {
$this->$name = $value;
}
}
/**
* @param array $defaults
* @return self
*/
protected function setDefaults(array $defaults)
{
$this->defaults = array_merge($this->defaults, $defaults);
foreach ($this->defaults as $key => $value) {
$this->set($key, $value);
}
if ($this->pageSize !== self::DEFAULT_PAGESIZE) {
return true;
return $this;
}
/**
* @param FormErrorIterator $errors
* @return self
*/
public function resetByFormError(FormErrorIterator $errors)
{
foreach ($errors as $error) {
$key = $error->getOrigin()->getName();
if (array_key_exists($key, $this->defaults)) {
$this->set($key, $this->defaults[$key]);
}
}
if (!empty($this->teams)) {
return true;
}
if (null !== $this->searchTerm) {
return true;
}
return false;
return $this;
}
}

View File

@@ -14,8 +14,12 @@ namespace App\Repository\Query;
*/
class CustomerQuery extends VisibilityQuery
{
public const CUSTOMER_ORDER_ALLOWED = ['id', 'name', 'comment', 'country', 'number'];
public function __construct()
{
$this->setOrderBy('name');
$this->setDefaults([
'orderBy' => 'name',
]);
}
}

View File

@@ -16,6 +16,8 @@ use App\Entity\Customer;
*/
class ProjectQuery extends CustomerQuery
{
public const PROJECT_ORDER_ALLOWED = ['id', 'name', 'comment', 'customer', 'orderNumber'];
/**
* @var Customer|int|null
*/
@@ -24,7 +26,9 @@ class ProjectQuery extends CustomerQuery
public function __construct()
{
parent::__construct();
$this->setOrderBy('name');
$this->setDefaults([
'orderBy' => 'name',
]);
}
/**
@@ -45,20 +49,4 @@ class ProjectQuery extends CustomerQuery
return $this;
}
/**
* {@inheritdoc}
*/
public function isDirty(): bool
{
if (parent::isDirty()) {
return true;
}
if ($this->customer !== null) {
return true;
}
return false;
}
}

View File

@@ -11,8 +11,12 @@ namespace App\Repository\Query;
class TagQuery extends BaseQuery
{
public const TAG_ORDER_ALLOWED = ['id', 'name', 'amount'];
public function __construct()
{
$this->setOrderBy('name');
$this->setDefaults([
'orderBy' => 'name',
]);
}
}

View File

@@ -11,8 +11,12 @@ namespace App\Repository\Query;
class TeamQuery extends BaseQuery
{
public const TEAM_ORDER_ALLOWED = ['id', 'name', 'teamlead'];
public function __construct()
{
$this->setOrderBy('name');
$this->setDefaults([
'orderBy' => 'name',
]);
}
}

View File

@@ -25,6 +25,8 @@ class TimesheetQuery extends ActivityQuery
public const STATE_EXPORTED = 4;
public const STATE_NOT_EXPORTED = 5;
public const TIMESHEET_ORDER_ALLOWED = ['begin', 'end', 'duration', 'rate', 'customer', 'project', 'activity', 'description'];
/**
* @var User|null
*/
@@ -57,9 +59,11 @@ class TimesheetQuery extends ActivityQuery
public function __construct()
{
parent::__construct();
$this->setOrder(self::ORDER_DESC);
$this->setOrderBy('begin');
$this->dateRange = new DateRange();
$this->setDefaults([
'order' => self::ORDER_DESC,
'orderBy' => 'begin',
'dateRange' => new DateRange()
]);
}
public function addUser(User $user): self
@@ -266,40 +270,4 @@ class TimesheetQuery extends ActivityQuery
return $this;
}
/**
* {@inheritdoc}
*/
public function isDirty(): bool
{
if (parent::isDirty()) {
return true;
}
if ($this->activity !== null) {
return true;
}
if (!empty($this->tags)) {
return true;
}
if ($this->timesheetUser !== null) {
return true;
}
if ($this->state !== self::STATE_ALL) {
return true;
}
if ($this->exported !== self::STATE_ALL) {
return true;
}
if ($this->dateRange->getBegin() !== null || $this->dateRange->getEnd() !== null) {
return true;
}
return false;
}
}

View File

@@ -14,11 +14,20 @@ namespace App\Repository\Query;
*/
class UserQuery extends VisibilityQuery
{
public const USER_ORDER_ALLOWED = ['id', 'alias', 'username', 'title', 'email'];
/**
* @var string|null
*/
protected $role;
public function __construct()
{
$this->setDefaults([
'orderBy' => 'username',
]);
}
/**
* @return string|null
*/

View File

@@ -54,20 +54,4 @@ class VisibilityQuery extends BaseQuery
return $this;
}
/**
* {@inheritdoc}
*/
public function isDirty(): bool
{
if (parent::isDirty()) {
return true;
}
if ($this->visibility !== self::SHOW_VISIBLE) {
return true;
}
return false;
}
}