Skip to content

Commit

Permalink
fix #619
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Oct 26, 2020
1 parent 2c0c0e7 commit 81b1c20
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/Grid/Column/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dcat\Admin\Grid\Column;

use Dcat\Admin\Grid\Column;
use Dcat\Admin\Grid\Events\Fetching;
use Dcat\Admin\Grid\Model;
use Dcat\Admin\Support\Helper;
use Illuminate\Contracts\Support\Renderable;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function setParent(Column $column)
{
$this->parent = $column;

$this->parent->grid()->fetching(function () {
$this->parent->grid()->listen(Fetching::class, function () {
$this->addResetButton();

$this->parent->grid()->model()->treeUrlWithoutQuery(
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Column/HasDisplayers.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function tree(bool $showAll = false, bool $sortable = true)
{
$this->grid->model()->enableTree($showAll, $sortable);

$this->grid->fetching(function () use ($showAll) {
$this->grid->listen(Grid\Events\Fetching::class, function () use ($showAll) {
if ($this->grid->model()->getParentIdFromRequest()) {
$this->grid->disableFilter();
$this->grid->disableToolbar();
Expand Down
4 changes: 2 additions & 2 deletions src/Grid/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function listen(string $class, \Closure $callback)
*/
public function fire(Events\Event $event)
{
Event::dispatch($event);

$this->dispatched[get_class($event)] = $event;

Event::dispatch($event);
}

/**
Expand Down
27 changes: 0 additions & 27 deletions src/Grid/Concerns/HasFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ trait HasFilter
*/
protected $filter;

/**
* @var array
*/
protected $beforeApplyFilterCallbacks = [];

/**
* Setup grid filter.
*
Expand Down Expand Up @@ -69,28 +64,6 @@ public function filter(Closure $callback = null)
return $this;
}

/**
* @param Closure $callback
*
* @return void
*/
public function fetching(\Closure $callback)
{
$this->beforeApplyFilterCallbacks[] = $callback;
}

/**
* @return void
*/
protected function callFetchingCallbacks()
{
foreach ($this->beforeApplyFilterCallbacks as $callback) {
$callback($this);
}

$this->beforeApplyFilterCallbacks = [];
}

/**
* Render the grid filter.
*
Expand Down
7 changes: 4 additions & 3 deletions src/Grid/Concerns/HasTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Dcat\Admin\Admin;
use Dcat\Admin\Grid\Events\Fetched;
use Dcat\Admin\Grid\Events\Fetching;
use Dcat\Admin\Support\Helper;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -46,7 +47,7 @@ public function enableTree(bool $showAll, bool $sortable)
{
$this->showAllChildrenNodes = $showAll;

$this->grid->fetching(function () use ($sortable) {
$this->grid()->listen(Fetching::class, function () use ($sortable) {
$this->sortTree($sortable);
$this->bindChildrenNodesQuery();

Expand All @@ -59,7 +60,7 @@ public function enableTree(bool $showAll, bool $sortable)
$this->addIgnoreQueries();
});

$this->grid()->listen(Fetched::class, function (Grid $grid, Collection $collection) {
$this->grid()->listen(Fetched::class, function ($grid, Collection $collection) {
if (! $this->getParentIdFromRequest()) {
return;
}
Expand Down Expand Up @@ -126,7 +127,7 @@ public function treeUrlWithoutQuery($keys)
public function generateTreeUrl()
{
return Helper::urlWithoutQuery(
$this->grid->filter()->urlWithoutFilters(),
$this->grid()->filter()->urlWithoutFilters(),
$this->treeIgnoreQueryNames
);
}
Expand Down
24 changes: 24 additions & 0 deletions src/Grid/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ public function getPageName()
return $this->grid->makeName($this->pageName);
}

/**
* @param string $name
*
* @return $this
*/
public function setPageName($name)
{
$this->pageName = $name;

return $this;
}

/**
* Get the query string variable used to store the sort.
*
Expand All @@ -267,6 +279,18 @@ public function getSortName()
return $this->grid->makeName($this->sortName);
}

/**
* @param string $name
*
* @return $this
*/
public function setSortName($name)
{
$this->sortName = $name;

return $this;
}

/**
* Set parent grid instance.
*
Expand Down

0 comments on commit 81b1c20

Please sign in to comment.