Skip to content

Commit

Permalink
Merge pull request #40 from mesour/devel
Browse files Browse the repository at this point in the history
Devel -> master
  • Loading branch information
mesour committed Nov 2, 2015
2 parents 4464a97 + 5e1c860 commit 394551e
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 264 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[![Latest Stable Version](https://img.shields.io/github/release/mesour/datagrid.svg)](https://github.com/mesour/DataGrid/releases "Latest Stable Version") [![Build status](https://img.shields.io/travis/mesour/DataGrid/v2.0.6.svg)](https://travis-ci.org/mesour/DataGrid "Build status")

Mesour DataGrid is datagrid for Nette with options like to dump tree, inline edit, export to csv, sort data using jQuery.ui.nestedSortable and much more.
Mesour DataGrid is datagrid for Nette with options like to dump tree, create sub grids and sub items, inline edit, export to csv, sort data using jQuery.ui.nestedSortable and much more.

- [Documentation/Demo](http://grid.mesour.com)
- [API](http://apis.mesour.com/api/DataGrid2.0.6/)
- [API](http://apis.mesour.com/api/DataGrid2.0.7/)
- [Author](http://mesour.com)
- [Contact](http://mesour.com/contact)

Expand All @@ -14,5 +14,5 @@ Mesour DataGrid is datagrid for Nette with options like to dump tree, inline edi
- With [Composer](https://getcomposer.org)

"require": {
"mesour/datagrid": "~2.0.6"
"mesour/datagrid": "~2.0.7"
}
2 changes: 1 addition & 1 deletion public/mesourGrid.js

Large diffs are not rendered by default.

921 changes: 675 additions & 246 deletions public/src/js/ext/default_filter.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/DataSources/ArrayDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct(array $data, array $relations = array())
*/
private function getExportSelect()
{
if(!$this->exportSelect) {
$this->getSelect();
}
return $this->exportSelect;
}

Expand Down
20 changes: 15 additions & 5 deletions src/Extensions/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ public function handleExport() {
}

if (empty($this->export_columns)) {
foreach ($this->parent->getColumns() as $column) {
$column->setGridComponent($this->parent);
if ($this->hasExport($column)) {
$export_columns[] = $column;
$columns = $this->parent->getColumns();
if(count($columns) === 0) {
$export_columns = $this->parent->getRealColumnNames();
} else {
foreach ($columns as $column) {
$column->setGridComponent($this->parent);
if ($this->hasExport($column)) {
$export_columns[] = $column;
}
}
}
} else {
Expand Down Expand Up @@ -123,6 +128,7 @@ public function handleExport() {
}
}
}

fputcsv($file, $header_arr, $this->delimiter);

$first = TRUE;
Expand All @@ -140,7 +146,7 @@ public function handleExport() {
if ($first && !isset($data[$column_name]) && !is_null($data[$column_name])) {
throw new Grid_Exception('Column "' . $column_name . '" does not exist in data.');
}
$line_data[] = strip_tags($data[$column_name]);
$line_data[] = strip_tags($this->fixVariable($data[$column_name]));
}
}
fputcsv($file, $line_data, $this->delimiter);
Expand All @@ -151,6 +157,10 @@ public function handleExport() {
$this->presenter->sendResponse(new FileResponse($this->file_path, (is_null($this->file_name) ? $this->parent->getGridName() : $this->file_name) . '.csv'));
}

private function fixVariable($var) {
return $var === FALSE ? 0 : $var;
}

public function __destruct() {
if (is_file($this->file_path)) {
unlink($this->file_path);
Expand Down
28 changes: 28 additions & 0 deletions src/Extensions/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
class Filter extends BaseControl {

const MESOUR_TRUE = '-mesour-bool-1';
const MESOUR_FALSE = '-mesour-bool-0';
const MESOUR_NULL = '-mesour-null';

/**
* @var Form
*/
Expand Down Expand Up @@ -57,6 +61,10 @@ public function setFilterForm(Form $filter_form, $template = NULL) {
$this->form_template = $template;
}

public function getDefaultFilterValues() {
return $this->settings;
}

/**
* Get filter values for manual filtering
* If filter form is not set return NULL
Expand Down Expand Up @@ -154,6 +162,25 @@ public function handleApplyDefaultFilter() {
$this->presenter->redrawControl();
}

private function fixCheckers($checkerValues) {
if(!is_array($checkerValues)) {
return $checkerValues;
}
$out = array();
foreach ($checkerValues as $val) {
if($val === self::MESOUR_FALSE) {
$out[] = FALSE;
} else if($val === self::MESOUR_TRUE) {
$out[] = TRUE;
} else if($val === self::MESOUR_NULL) {
$out[] = NULL;
} else {
$out[] = $val;
}
}
return $out;
}

private function applyAutoFiltering() {
$realColumnNames = $this->parent->getRealColumnNamesForFilter();
foreach ($this->settings as $column_name => $values) {
Expand All @@ -167,6 +194,7 @@ private function applyAutoFiltering() {
case 'priority':
continue;
case 'checkers':
$value = $this->fixCheckers($value);
$this->parent->getDataSource()->applyCheckers($column_name, $value, $values['type']);
break;
case 'custom':
Expand Down
25 changes: 25 additions & 0 deletions src/Extensions/SubItem/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ abstract class Item extends Object {

protected $callback;

protected $checkCallback;

protected $type;

protected $name;

protected $disabled = FALSE;

protected $description;

protected $page_limit;
Expand All @@ -43,6 +47,27 @@ public function setCallback($callback) {
return $this;
}

public function setCheckCallback($callback) {
Callback::check($callback);
$this->checkCallback = $callback;
return $this;
}

public function check($rowData) {
if($this->checkCallback) {
Callback::invokeArgs($this->checkCallback, array($rowData, $this));
}
}

public function isDisabled() {
return $this->disabled;
}

public function setDisabled($disabled = TRUE) {
$this->disabled = $disabled;
return $this;
}

public function getName() {
return $this->name;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Extensions/templates/Filter/Filter.latte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
11: {_('November')},
12: {_('December')}
},
closeAll: {_('close all')}
closeAll: {_('close all')},
'true': {_('true')},
'false': {_('false')},
'empty': {_('empty')}
};
</script>
{foreach $control->parent->getColumns() as $column}
Expand Down
18 changes: 14 additions & 4 deletions src/Grid/BasicGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
\Nette\Localization\ITranslator,
Mesour\DataGrid\Render\Table\RendererFactory;
use Mesour\DataGrid\Column\InlineEdit;
use Mesour\DataGrid\Extensions\Item;
use Nette\Utils\Html;

/**
Expand Down Expand Up @@ -383,9 +384,9 @@ public function createBody($table_class = 'table') {
if (isset($this['subitem'])) {
foreach($this['subitem']->getItems() as $name => $item) {
if (isset($sub_items[$key][$name])) {
$this->addOpenedSubItemRow($body, $rowData, $name, $key);
$this->addOpenedSubItemRow($body, $rowData, $name, $key, $item);
} else {
$this->addClosedSubItemRow($body, $rowData, $name, $key);
$this->addClosedSubItemRow($body, $rowData, $name, $key, $item);
}
}
}
Expand All @@ -396,7 +397,12 @@ public function createBody($table_class = 'table') {
return $table;
}

protected function addClosedSubItemRow(Render\Body &$body, $rowData, $name, $key) {
protected function addClosedSubItemRow(Render\Body &$body, $rowData, $name, $key, Item $item) {
$item->check($rowData);
if($item->isDisabled()) {
return;
}

$columns_count = count($this->column_arr);
$name = $this['subitem']->getItem($name)->getName();
$column = new Column\SubItemButton();
Expand All @@ -415,7 +421,11 @@ protected function addClosedSubItemRow(Render\Body &$body, $rowData, $name, $key
$body->addRow($row);
}

protected function addOpenedSubItemRow(Render\Body &$body, $rowData, $name, $key) {
protected function addOpenedSubItemRow(Render\Body &$body, $rowData, $name, $keyItem, Item $item) {
$item->check($rowData);
if($item->isDisabled()) {
return;
}
$columns_count = count($this->column_arr);
$columns_count--;
$content = $this['subitem']->getItem($name)->render($key, $rowData);
Expand Down
9 changes: 7 additions & 2 deletions src/Grid/ExtendedGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Mesour\DataGrid;

use Mesour\DataGrid\Extensions\Filter;
use Nette\Application\UI\Form;

/**
Expand Down Expand Up @@ -41,10 +42,14 @@ public function getRealColumnNamesForFilter()
public function enableFilter(Form $filer_form = NULL, $template = NULL, $date = 'Y-m-d')
{
new Extensions\Filter($this, 'filter');

/** @var Filter $filter */
$filter = $this['filter'];
if (!is_null($filer_form)) {
$this['filter']->setFilterForm($filer_form, $template);
$filter->setFilterForm($filer_form, $template);
}
$this['filter']->setDateFormat($date);
$filter->setDateFormat($date);
return $filter;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/locales/cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@
'close all' => 'zavřít vše',
'Page' => 'Strana',
'Go!' => 'Přejít!',
'Inverse selection' => 'Obrátit pořadí'
'Inverse selection' => 'Obrátit pořadí',
'true' => 'pravda',
'false' => 'nepravda',
'empty' => 'prázdný',
);
5 changes: 4 additions & 1 deletion src/locales/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@
'close all' => 'close all',
'Page' => 'Page',
'Go!' => 'Go!',
'Inverse selection' => 'Inverse selection'
'Inverse selection' => 'Inverse selection',
'true' => 'true',
'false' => 'false',
'empty' => 'empty',
);

0 comments on commit 394551e

Please sign in to comment.