Skip to content

Create 3.0 branch for Laravel 6.0 release #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"laravel",
"pjax",
"grid",
"laravel-5",
"laravel5"
"laravel-6",
"laravel6"
],
"homepage": "https://github.com/leantony/laravel-grid",
"authors": [
Expand All @@ -22,23 +22,23 @@
}
],
"require": {
"illuminate/view": "~5.5",
"illuminate/support": "~5.5",
"illuminate/console": "~5.5",
"illuminate/contracts": "~5.5",
"illuminate/http": "~5.5",
"illuminate/database": "~5.5",
"illuminate/pagination": "~5.5"
"illuminate/view": "~6",
"illuminate/support": "~6",
"illuminate/console": "~6",
"illuminate/contracts": "~6",
"illuminate/http": "~6",
"illuminate/database": "~6",
"illuminate/pagination": "~6"
},
"suggest": {
"maatwebsite/excel": "For exporting grid data as excel (~3.0)",
"barryvdh/laravel-dompdf": "For exporting grid data as PDF (^0.8.2)"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
"phpunit/phpunit": "^8.0",
"orchestra/testbench": "~3.0",
"orchestra/testbench-dusk": "^3.5",
"phpunit/php-code-coverage": "^6.0",
"phpunit/php-code-coverage": "^7.0.5",
"barryvdh/laravel-dompdf": "^0.8.2",
"maatwebsite/excel": "^3.0"
},
Expand Down
2,483 changes: 1,650 additions & 833 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/Buttons/GenericButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Illuminate\Contracts\Support\Htmlable;
use InvalidArgumentException;
use Illuminate\Support\Arr;

class GenericButton implements Htmlable
{
Expand Down Expand Up @@ -352,7 +353,7 @@ public function render(...$args)

// collapse the array of args into a single 1d array, so that the values passed can be
// accessed as key value pair
$args = array_collapse($args);
$args = Arr::collapse($args);

return view($this->getButtonView(), $this->compactData($args))->render();
}
Expand Down Expand Up @@ -469,4 +470,4 @@ public function getButtonView(): string
{
return 'leantony::grid.buttons.button';
}
}
}
6 changes: 4 additions & 2 deletions src/Buttons/RendersButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace Leantony\Grid\Buttons;

use InvalidArgumentException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

trait RendersButtons
{
Expand Down Expand Up @@ -251,7 +253,7 @@ public function hasButtons(string $section = 'toolbar')
return false;
}
// no buttons on section
return count(array_get($this->buttons, $section, [])) === 0 ? false : true;
return count(Arr::get($this->buttons, $section, [])) === 0 ? false : true;
}

/**
Expand Down Expand Up @@ -303,7 +305,7 @@ protected function makeCustomButton(array $properties, $position = null): Generi
*/
protected function makeButtonKey(string $name)
{
return str_slug($name);
return Str::slug($name);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/GenerateGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Leantony\Grid\HasGridConfigurations;
use Illuminate\Support\Arr;

class GenerateGrid extends Command
{
Expand Down Expand Up @@ -466,7 +467,7 @@ protected function replaceRows($rows, $stub)
*/
protected function replaceOtherContent(array $replacements, &$stub)
{
$replaced = str_replace(array_values(array_except($this->searches, 'rows')), [
$replaced = str_replace(array_values(Arr::except($this->searches, 'rows')), [
$replacements['namespace'],
$replacements['modelName'],
$replacements['tableName'],
Expand Down
5 changes: 3 additions & 2 deletions src/Events/UserActionRequested.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\Request;
use Leantony\Grid\Grid;
use Leantony\Grid\GridInterface;
use Illuminate\Support\Arr;

class UserActionRequested
{
Expand Down Expand Up @@ -51,6 +52,6 @@ public function __construct(GridInterface $grid, Request $request, $builder, $va
$this->request = $request;
$this->builder = $builder;
$this->validTableColumns = $validTableColumns;
$this->args = array_collapse($args);
$this->args = Arr::collapse($args);
}
}
}
7 changes: 4 additions & 3 deletions src/Filters/GenericFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Collection;
use InvalidArgumentException;
use Illuminate\Support\Arr;

class GenericFilter implements Htmlable
{
Expand Down Expand Up @@ -159,11 +160,11 @@ public function render()
// all filters apart from dropdowns are rendered as text elements.
// css classes or js libraries can be used to change this
return view('leantony::grid.filters.text', $this->compactData(
array_collapse(func_get_args())
Arr::collapse(func_get_args())
))->render();
case 'select':
return view('leantony::grid.filters.dropdown', $this->compactData(
array_collapse(func_get_args())
Arr::collapse(func_get_args())
))->render();
default:
throw new \Exception("Unknown filter type.");
Expand Down Expand Up @@ -283,4 +284,4 @@ public function setClass(string $class): GenericFilter
$this->class = $class;
return $this;
}
}
}
30 changes: 29 additions & 1 deletion src/Listeners/DataExportHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,22 @@ public function getExportData(array $params = []): Collection

$records = [];

// Update to correct column name if set in settings.
$columnsInGrid = $this->getGrid()->getColumns();
foreach ($pinch as $key => $columnName) {
if (isset($columnsInGrid[$columnName])) {
$pinch[$key] = $this->tableColumnName($columnName, $columnsInGrid[$columnName]);
}
}

$query = $this->getQuery();
if ($this->getGridStrictExportStatus() === true) {
$query = $this->getQuery()->select($pinch);
}

// we process the query columns in chunks of a configured size
$query->chunk($this->getGridExportQueryChunkSize(), function ($items) use ($columns, $params, $doNotFormatKeys, &$records) {

// we run a map over each item from the chunk and run a formatter function over it
// the formatter function takes into account the various user defined customizations for
// each column entry
Expand Down Expand Up @@ -261,4 +270,23 @@ protected function dataFormatter($item, Collection $columns, bool $doNotFormatKe
// collapse the data to a 1d array
return $data->collapse()->toArray();
}
}

/**
* Check if table column name is set.
*
* @param string $columnName
* @param array $columnData
* @return string
*/
public function tableColumnName(string $columnName, array $columnData)
{
if (isset($columnData['table_column_name'])) {
$columnName = $columnData['table_column_name'] . ' AS ' . $columnName;
}
else {
$columnName;
}

return $columnName;
}
}
24 changes: 21 additions & 3 deletions src/Listeners/RowFilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function filterRows()
if (!empty($this->request->query())) {
$columns = $this->getGrid()->getColumns();
$tableColumns = $this->getValidGridColumns();

foreach ($columns as $columnName => $columnData) {
// skip rows that are not to be filtered
if (!$this->canFilter($columnName, $columnData)) {
Expand All @@ -57,7 +56,7 @@ public function filterRows()
}
$operator = $this->extractFilterOperator($columnName, $columnData)['operator'];

$this->doFilter($columnName, $columnData, $operator, $this->getRequest()->get($columnName));
$this->doFilter($this->tableColumnName($columnName, $columnData), $columnData, $operator, $this->getRequest()->get($columnName));
}
}
}
Expand Down Expand Up @@ -114,6 +113,25 @@ public function extractFilterOperator(string $columnName, array $columnData)
return compact('operator');
}

/**
* Check if table column name is set.
*
* @param string $columnName
* @param array $columnData
* @return string
*/
public function tableColumnName(string $columnName, array $columnData)
{
if (isset($columnData['table_column_name'])) {
$columnName = $columnData['table_column_name'];
}
else {
$columnName;
}

return $columnName;
}

/**
* Filter the data
*
Expand Down Expand Up @@ -158,4 +176,4 @@ public function doFilter(string $columnName, array $columnData, string $operator
}
}
}
}
}