From 2d68e2d5637b023e0cb822a786356a9917316250 Mon Sep 17 00:00:00 2001 From: Marvin Hinz <35603466+marvinhinz@users.noreply.github.com> Date: Wed, 14 Mar 2018 11:07:25 +0100 Subject: [PATCH 1/4] Fix ajax grid filtering - value not urlencoded When submitting an ajax filter with a value like "AT&T" the filter is interpreted wrong because it is not passed as encoded string to the request and gets cut off. --- Resources/views/blocks_js.jquery.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/views/blocks_js.jquery.html.twig b/Resources/views/blocks_js.jquery.html.twig index e7c57b22..d05361d2 100644 --- a/Resources/views/blocks_js.jquery.html.twig +++ b/Resources/views/blocks_js.jquery.html.twig @@ -31,10 +31,10 @@ function {{ grid.hash }}_submitForm(event, form) if ($(this).attr('multiple') == 'multiple') { for(var i= 0; i < value.length; i++) { - data += '&' + name + '=' + value[i]; + data += '&' + name + '=' + encodeURIComponent(value[i]); } } else { - data += '&' + name + '=' + value; + data += '&' + name + '=' + encodeURIComponent(value); } } else { data += '&' + name + '='; From b9f19a9c025b6230a4942db2314f18a6d2ad058d Mon Sep 17 00:00:00 2001 From: Romaric Drigon Date: Mon, 30 Sep 2019 16:11:58 +0200 Subject: [PATCH 2/4] Fixed YAML in example configuration --- Resources/doc/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/configuration.md b/Resources/doc/configuration.md index c3e59c05..0110fb8f 100644 --- a/Resources/doc/configuration.md +++ b/Resources/doc/configuration.md @@ -14,7 +14,7 @@ apy_data_grid: actions_columns_separator: "
" pagerfanta: enable: false - view_class: "Pagerfanta\View\DefaultView" + view_class: "Pagerfanta\\View\\DefaultView" options: prev_message: "«" next_message: "»" From 66d1f20990c840e0443466ccc8f0913e5831282a Mon Sep 17 00:00:00 2001 From: Nicolas Potier Date: Wed, 1 Apr 2020 11:33:14 +0200 Subject: [PATCH 3/4] composer memory limit Adding COMPOSER_MEMORY_LIMIT=-1 to composer update --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2fadf99c..3b0677ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ before_script: install: - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction + - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction - curl -s http://getcomposer.org/installer | php - php composer.phar install --dev --no-interaction From a738da5a5866560f0a73c065d75867c767e04c9f Mon Sep 17 00:00:00 2001 From: Romain Guerrero Date: Sat, 6 Apr 2019 12:30:35 +0200 Subject: [PATCH 4/4] DateTime and Date columns : add input filter format option --- Grid/Column/DateColumn.php | 2 + Grid/Column/DateTimeColumn.php | 21 ++++++- .../types/date_column.md | 2 +- .../types/datetime_column.md | 5 +- Tests/Grid/Column/DateTimeColumnTest.php | 58 ++++++++++++++++++- 5 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Grid/Column/DateColumn.php b/Grid/Column/DateColumn.php index b28d69b2..8689e7b7 100644 --- a/Grid/Column/DateColumn.php +++ b/Grid/Column/DateColumn.php @@ -20,6 +20,8 @@ class DateColumn extends DateTimeColumn protected $fallbackFormat = 'Y-m-d'; + protected $fallbackInputFormat = 'Y-m-d'; + public function getFilters($source) { $parentFilters = parent::getFilters($source); diff --git a/Grid/Column/DateTimeColumn.php b/Grid/Column/DateTimeColumn.php index f516423d..b4291bee 100644 --- a/Grid/Column/DateTimeColumn.php +++ b/Grid/Column/DateTimeColumn.php @@ -24,6 +24,10 @@ class DateTimeColumn extends Column protected $fallbackFormat = 'Y-m-d H:i:s'; + protected $inputFormat; + + protected $fallbackInputFormat = 'Y-m-d H:i:s'; + protected $timezone; public function __initialize(array $params) @@ -31,6 +35,7 @@ public function __initialize(array $params) parent::__initialize($params); $this->setFormat($this->getParam('format')); + $this->setInputFormat($this->getParam('inputFormat', $this->fallbackInputFormat)); $this->setOperators($this->getParam('operators', [ self::OPERATOR_EQ, self::OPERATOR_NEQ, @@ -56,7 +61,7 @@ public function isQueryValid($query) protected function isDateTime($query) { - return strtotime($query) !== false; + return false !== \DateTime::createFromFormat($this->inputFormat, $query); } public function getFilters($source) @@ -65,7 +70,7 @@ public function getFilters($source) $filters = []; foreach ($parentFilters as $filter) { - $filters[] = ($filter->getValue() === null) ? $filter : $filter->setValue(new \DateTime($filter->getValue())); + $filters[] = ($filter->getValue() === null) ? $filter : $filter->setValue(\DateTime::createFromFormat($this->inputFormat, $filter->getValue())); } return $filters; @@ -160,6 +165,18 @@ public function getFormat() return $this->format; } + public function setInputFormat($inputFormat) + { + $this->inputFormat = $inputFormat; + + return $this; + } + + public function getInputFormat() + { + return $this->inputFormat; + } + public function getTimezone() { return $this->timezone; diff --git a/Resources/doc/columns_configuration/types/date_column.md b/Resources/doc/columns_configuration/types/date_column.md index bb218aa3..a0ed0a42 100644 --- a/Resources/doc/columns_configuration/types/date_column.md +++ b/Resources/doc/columns_configuration/types/date_column.md @@ -1,7 +1,7 @@ Date Column =========== -The Date Column extends the [DateTime Column](datetime_column.md) and the default fallback format is `Y-m-d`. +The Date Column extends the [DateTime Column](datetime_column.md) and the default fallback format and filter input format are `Y-m-d`. With this column, the time part of a datetime value is ignored when you filter the column. So, if you filter the column with the value `2012-04-26` or `2012-04-26 12:23:45` and with the operator `=`, the query will be `date >= '2012-04-26 0:00:00' AND date <= '2012-04-26 23:59:59'`. diff --git a/Resources/doc/columns_configuration/types/datetime_column.md b/Resources/doc/columns_configuration/types/datetime_column.md index af4ff602..c1027b9c 100644 --- a/Resources/doc/columns_configuration/types/datetime_column.md +++ b/Resources/doc/columns_configuration/types/datetime_column.md @@ -15,6 +15,9 @@ See [Column annotation for properties](../annotations/column_annotation_property |:--:|:--|:--|:--|:--| |format|string| | |Define this attribute if you want to force the format of the displayed value.
(e.g. "Y-m-d H:i:s")| |timezone|string|System default timezone| |The timezone to use for rendering.
(e.g. "Europe/Paris")| +|inputFormat|string|"Y-m-d H:i:s"| |Define this attribute if you want to force the format of the filtered value.
(e.g. "Y-m-d H:i:s")| + +**Note**: If you want to filter using date input (and not datetime input), you should use the [Date Column](date_column.md) type instead and configure the display format to render the time (e.g. "Y-m-d H:i:s"). ## Filter #### Valid values @@ -41,4 +44,4 @@ Wrong values are ignored. |btw|Between exclusive| |btwe|Between inclusive| |isNull|Is not defined| -|isNotNull|Is defined| \ No newline at end of file +|isNotNull|Is defined| diff --git a/Tests/Grid/Column/DateTimeColumnTest.php b/Tests/Grid/Column/DateTimeColumnTest.php index 066fbfa9..b7630c1d 100644 --- a/Tests/Grid/Column/DateTimeColumnTest.php +++ b/Tests/Grid/Column/DateTimeColumnTest.php @@ -36,6 +36,26 @@ public function testGetFormat() $this->assertEquals($format, $column->getFormat()); } + public function testSetInputFormat() + { + $inputFormat = 'Y-m-d'; + + $column = new DateTimeColumn(); + $column->setInputFormat($inputFormat); + + $this->assertAttributeEquals($inputFormat, 'inputFormat', $column); + } + + public function testGetInputFormat() + { + $inputFormat = 'Y-m-d'; + + $column = new DateTimeColumn(); + $column->setInputFormat($inputFormat); + + $this->assertEquals($inputFormat, $column->getInputFormat()); + } + public function testSetTimezone() { $timezone = 'UTC'; @@ -98,11 +118,23 @@ public function testRenderCellWithCallback() public function testFilterWithValue() { $column = new DateTimeColumn(); - $column->setData(['operator' => Column::OPERATOR_BTW, 'from' => '2017-03-22', 'to' => '2017-03-23']); + $column->setData(['operator' => Column::OPERATOR_BTW, 'from' => '2017-03-22 01:30:00', 'to' => '2017-03-23 19:00:00']); $this->assertEquals([ - new Filter(Column::OPERATOR_GT, new \DateTime('2017-03-22')), - new Filter(Column::OPERATOR_LT, new \DateTime('2017-03-23')), + new Filter(Column::OPERATOR_GT, new \DateTime('2017-03-22 01:30:00')), + new Filter(Column::OPERATOR_LT, new \DateTime('2017-03-23 19:00:00')), + ], $column->getFilters('asource')); + } + + public function testFilterWithFormattedValue() + { + $column = new DateTimeColumn(); + $column->setInputFormat('m/d/Y H-i-s'); + $column->setData(['operator' => Column::OPERATOR_BTW, 'from' => '03/22/2017 01-30-00', 'to' => '03/23/2017 19-00-00']); + + $this->assertEquals([ + new Filter(Column::OPERATOR_GT, new \DateTime('2017-03-22 01:30:00')), + new Filter(Column::OPERATOR_LT, new \DateTime('2017-03-23 19:00:00')), ], $column->getFilters('asource')); } @@ -128,11 +160,28 @@ public function testQueryIsInvalid() $this->assertFalse($column->isQueryValid('foo')); } + public function testInputFormattedQueryIsValid() + { + $column = new DateTimeColumn(); + $column->setInputFormat('m/d/Y H-i-s'); + + $this->assertTrue($column->isQueryValid('03/22/2017 23-00-00')); + } + + public function testInputFormattedQueryIsInvalid() + { + $column = new DateTimeColumn(); + $column->setInputFormat('m/d/Y H-i-s'); + + $this->assertFalse($column->isQueryValid('2017-03-22 23:00:00')); + } + public function testInitializeDefaultParams() { $column = new DateTimeColumn(); $this->assertAttributeEquals(null, 'format', $column); + $this->assertAttributeEquals('Y-m-d H:i:s', 'inputFormat', $column); $this->assertAttributeEquals([ Column::OPERATOR_EQ, Column::OPERATOR_NEQ, @@ -152,10 +201,12 @@ public function testInitializeDefaultParams() public function testInitialize() { $format = 'Y-m-d H:i:s'; + $inputFormat = 'Y-m-d H:i:s'; $timezone = 'UTC'; $params = [ 'format' => $format, + 'inputFormat' => $inputFormat, 'operators' => [Column::OPERATOR_LT, Column::OPERATOR_LTE], 'defaultOperator' => Column::OPERATOR_LT, 'timezone' => $timezone, @@ -164,6 +215,7 @@ public function testInitialize() $column = new DateTimeColumn($params); $this->assertAttributeEquals($format, 'format', $column); + $this->assertAttributeEquals($inputFormat, 'inputFormat', $column); $this->assertAttributeEquals([ Column::OPERATOR_LT, Column::OPERATOR_LTE, ], 'operators', $column);