Skip to content

Commit

Permalink
Add latest updates from 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Petit Yoann committed Oct 17, 2012
1 parent bc43444 commit 3acdd32
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 20 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,16 @@
`14 October 2012`
* Don't redirect with an AJAX request

`13 October 2012`
* Fix bug - Fixed errors with default values in Column __initialize.
* Add escape option for the value of a cell

`7 October 2012`
* Fix bug - Fix file Content-Length calculation for export.

`2 October 2012`
* Fix bug - Fix field name in DQL for multi level entities

`21 September 2012`
* Fix bug - Wrong regex for the eq operator for the vector source and the setData function
* Fix bug - Fix excpetion in ArrayColumn class
Expand Down
24 changes: 23 additions & 1 deletion Grid/Column/Column.php
Expand Up @@ -97,6 +97,7 @@ abstract class Column
protected $selectMulti;
protected $selectExpanded;
protected $searchOnClick = false;
protected $safe;
protected $separator;
protected $dataJunction;

Expand Down Expand Up @@ -181,7 +182,8 @@ public function __initialize(array $params)
$this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_LIKE));

// Features
$this->setSearchOnClick($this->getParam('searchOnClick'), false);
$this->setSearchOnClick($this->getParam('searchOnClick', false));
$this->setSafe($this->getParam('safe', 'html'));
$this->setSeparator($this->getParam('separator', "<br />"));
}

Expand Down Expand Up @@ -913,4 +915,24 @@ public function getSearchOnClick()
{
return $this->searchOnClick;
}

/**
* Allows to set twig escaping parameter (html, js, css, url, html_attr)
* or to display raw value if type is false
*
* @param type $safeOption can be one of raw, html, js, css, url, html_attr
*
* @return \APY\DataGridBundle\Grid\Column\Column
*/
public function setSafe($safeOption)
{
$this->safe = $safeOption;

return $this;
}

public function getSafe()
{
return $this->safe;
}
}
2 changes: 1 addition & 1 deletion Grid/Export/Export.php
Expand Up @@ -100,7 +100,7 @@ public function getResponse()
// Response
if (function_exists('mb_strlen')) {
$this->content = mb_convert_encoding($this->content, $this->charset, $this->container->getParameter('kernel.charset'));
$filesize = mb_strlen($this->content, $this->charset);
$filesize = mb_strlen($this->content, '8bit');
} else {
$filesize = strlen($this->content);
$this->charset = $this->container->getParameter('kernel.charset');
Expand Down
18 changes: 11 additions & 7 deletions Grid/Grid.php
Expand Up @@ -332,7 +332,9 @@ public function isReadyForRedirect()
}

$this->redirect = true;
} else {
}

if ($this->redirect === null || ($this->request->isXmlHttpRequest() && !$this->isReadyForExport)) {
if ($this->newSession) {
$this->setDefaultSessionData();

Expand Down Expand Up @@ -1553,11 +1555,13 @@ public function __clone()
*/
public function getGridResponse($param1 = null, $param2 = null, Response $response = null)
{
if ($this->isReadyForRedirect()) {
if ($this->isReadyForExport()) {
return $this->getExportResponse();
}
$isReadyForRedirect = $this->isReadyForRedirect();

if ($this->isReadyForExport()) {
return $this->getExportResponse();
}

if ($isReadyForRedirect) {
return new RedirectResponse($this->getRouteUrl());
} else {
if (is_array($param1) || $param1 === null) {
Expand All @@ -1567,9 +1571,9 @@ public function getGridResponse($param1 = null, $param2 = null, Response $respon
$parameters = (array) $param2;
$view = $param1;
}

$parameters = array_merge(array('grid' => $this), $parameters);

if ($view === null) {
return $parameters;
} else {
Expand Down
10 changes: 6 additions & 4 deletions Grid/GridManager.php
Expand Up @@ -132,11 +132,13 @@ public function isReadyForExport()
*/
public function getGridManagerResponse($param1 = null, $param2 = null, Response $response = null)
{
if ($this->isReadyForRedirect()) {
if ($this->isReadyForExport()) {
return $this->exportGrid->getExportResponse();
}
$isReadyForRedirect = $this->isReadyForRedirect();

if ($this->isReadyForExport()) {
return $this->exportGrid->getExportResponse();
}

if ($isReadyForRedirect) {
return new RedirectResponse($this->getRouteUrl());
} else {
if (is_array($param1) || $param1 === null) {
Expand Down
3 changes: 1 addition & 2 deletions Grid/Source/Entity.php
Expand Up @@ -116,15 +116,14 @@ protected function getFieldName($column, $withAlias = false, $forHavingClause =
$name = $column->getField();

if (strpos($name, '.') !== false ) {
$parent = self::TABLE_ALIAS;
$previousParent = '';

$elements = explode('.', $name);
while ($element = array_shift($elements)) {
if (count($elements) > 0) {
$parent = ($previousParent == '') ? self::TABLE_ALIAS : $previousParent;
$previousParent .= '_' . $element;
$this->joins[$previousParent] = $parent . '.' . $element;
$parent = '_' . $element;
} else {
$name = $previousParent . '.' . $element;
}
Expand Down
125 changes: 125 additions & 0 deletions Resources/translations/messages.tr.xliff
@@ -0,0 +1,125 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="tr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="13">
<source>eq</source>
<target>Eşittir</target>
</trans-unit>
<trans-unit id="14">
<source>neq</source>
<target>Eşit değildir</target>
</trans-unit>
<trans-unit id="15">
<source>lt</source>
<target>Küçüktür</target>
</trans-unit>
<trans-unit id="16">
<source>lte</source>
<target>Küçük ya da eşittir</target>
</trans-unit>
<trans-unit id="17">
<source>gt</source>
<target>Büyüktür</target>
</trans-unit>
<trans-unit id="18">
<source>gte</source>
<target>Büyük ya da eşittir</target>
</trans-unit>
<trans-unit id="19">
<source>req</source>
<target>Düzenli ifade</target>
</trans-unit>
<trans-unit id="20">
<source>like</source>
<target>İçerir</target>
</trans-unit>
<trans-unit id="21">
<source>nlike</source>
<target>İçermez</target>
</trans-unit>
<trans-unit id="22">
<source>rlike</source>
<target>İle Başlar</target>
</trans-unit>
<trans-unit id="23">
<source>llike</source>
<target>İle biter</target>
</trans-unit>
<trans-unit id="24">
<source>btw</source>
<target>Bunları kapsamaz</target>
</trans-unit>
<trans-unit id="25">
<source>btwe</source>
<target>Bunları kapsar</target>
</trans-unit>
<trans-unit id="26">
<source>isNull</source>
<target>Tanımlanmamış</target>
</trans-unit>
<trans-unit id="27">
<source>isNotNull</source>
<target>Tanımlanmış</target>
</trans-unit>
<trans-unit id="28">
<source>%count% Results, </source>
<target>{0,1}%count% Sonuç, |[2, Inf]%count% Sonuç, </target>
</trans-unit>

<!-- with symbols -->
<!--trans-unit id="26">
<source>eqs</source>
<target>=</target>
</trans-unit>
<trans-unit id="27">
<source>neqs</source>
<target>≠</target>
</trans-unit>
<trans-unit id="28">
<source>lts</source>
<target>&lt;</target>
</trans-unit>
<trans-unit id="29">
<source>ltes</source>
<target>≤</target>
</trans-unit>
<trans-unit id="30">
<source>gts</source>
<target>&gt;</target>
</trans-unit>
<trans-unit id="31">
<source>gtes</source>
<target>≥</target>
</trans-unit>
<trans-unit id="32">
<source>reqs</source>
<target>^x$</target>
</trans-unit>
<trans-unit id="33">
<source>likes</source>
<target>(x)</target>
</trans-unit>
<trans-unit id="34">
<source>nlikes</source>
<target>()x</target>
</trans-unit>
<trans-unit id="35">
<source>rlikes</source>
<target>x*</target>
</trans-unit>
<trans-unit id="36">
<source>llikes</source>
<target>*x</target>
</trans-unit>
<trans-unit id="37">
<source>btws</source>
<target>&lt;x&lt;</target>
</trans-unit>
<trans-unit id="38">
<source>btwes</source>
<target>&lt;=x&lt;<=/target>
</trans-unit-->
</body>
</file>
</xliff>
8 changes: 6 additions & 2 deletions Resources/views/blocks.html.twig
Expand Up @@ -29,7 +29,9 @@
{{ grid_exports(grid) }}
{% endif %}
</div>
{{ grid_scripts(grid) }}
{% if withjs %}
{{ grid_scripts(grid) }}
{% endif %}
</form>
{% else %}
{{ grid_no_data(grid) }}
Expand Down Expand Up @@ -218,8 +220,10 @@
{% if column.filterable and column.searchOnClick %}
{% set sourceValue = sourceValue is defined ? sourceValue : row.field(column.id) %}
<a href="?{{ grid.hash }}[{{ column.id }}][from]={{ sourceValue | url_encode() }}">{{ value }}</a>
{% elseif column.safe is sameas(false) %}
{{ value|raw }}
{% else %}
{{ value }}
{{ value|escape(column.safe) }}
{% endif %}
{% endblock grid_column_cell %}
{# -------------------------------------------- grid_column_operator --------------------------------------- #}
Expand Down
3 changes: 2 additions & 1 deletion Resources/views/blocks_js.jquery.html.twig
Expand Up @@ -25,7 +25,8 @@ function {{ grid.hash }}_submitForm(event, form, force)
var data = '';
$('.grid-filter-operator select, .grid-filter-input-query-from, .grid-filter-input-query-to, .grid-filter-select-query-from, .grid-filter-select-query-to', form).each(function () {
if ($(this).is(':disabled') == false) {
data += '&' + $(this).attr('name') + '=' + $(this).val();
var value = $(this).val() == null ? '' : $(this).val();
data += '&' + $(this).attr('name') + '=' + value;
}
});

Expand Down
20 changes: 18 additions & 2 deletions Twig/DataGridExtension.php
Expand Up @@ -103,6 +103,7 @@ public function getFunctions()
{
return array(
'grid' => new \Twig_Function_Method($this, 'getGrid', array('is_safe' => array('html'))),
'grid_html' => new \Twig_Function_Method($this, 'getGridHtml', array('is_safe' => array('html'))),
'grid_url' => new \Twig_Function_Method($this, 'getGridUrl', array('is_safe' => array('html'))),
'grid_filter' => new \Twig_Function_Method($this, 'getGridFilter', array('is_safe' => array('html'))),
'grid_cell' => new \Twig_Function_Method($this, 'getGridCell', array('is_safe' => array('html'))),
Expand All @@ -129,16 +130,31 @@ public function initGrid($grid, $theme = null, $id = '', array $params = array()
* @param \APY\DataGridBundle\Grid\Grid $grid
* @param string $theme
* @param string $id
*
* @return string
*/
public function getGrid($grid, $theme = null, $id = '', array $params = array())
public function getGrid($grid, $theme = null, $id = '', array $params = array(), $withjs = true)
{
$this->initGrid($grid, $theme, $id, $params);

// For export
$grid->setTemplate($theme);

return $this->renderBlock('grid', array('grid' => $grid));
return $this->renderBlock('grid', array('grid' => $grid, 'withjs' => $withjs));
}

/**
* Render grid block (html only)
*
* @param \APY\DataGridBundle\Grid\Grid $grid
* @param string $theme
* @param string $id
*
* @return string
*/
public function getGridHtml($grid, $theme = null, $id = '', array $params = array())
{
return getGrid($grid, $theme, $id, $params, false);
}

public function getGrid_($name, $grid)
Expand Down

0 comments on commit 3acdd32

Please sign in to comment.