From 81b1c20ebf293a91897cbb1ebfe4d9cce1ef9ab0 Mon Sep 17 00:00:00 2001 From: jqh <841324345@qq.com> Date: Tue, 27 Oct 2020 00:24:11 +0800 Subject: [PATCH] fix #619 --- src/Grid/Column/Filter.php | 3 ++- src/Grid/Column/HasDisplayers.php | 2 +- src/Grid/Concerns/HasEvents.php | 4 ++-- src/Grid/Concerns/HasFilter.php | 27 --------------------------- src/Grid/Concerns/HasTree.php | 7 ++++--- src/Grid/Model.php | 24 ++++++++++++++++++++++++ 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/Grid/Column/Filter.php b/src/Grid/Column/Filter.php index 70fd0f8d3..1ef582b53 100644 --- a/src/Grid/Column/Filter.php +++ b/src/Grid/Column/Filter.php @@ -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; @@ -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( diff --git a/src/Grid/Column/HasDisplayers.php b/src/Grid/Column/HasDisplayers.php index fdcde723f..709ae7c63 100644 --- a/src/Grid/Column/HasDisplayers.php +++ b/src/Grid/Column/HasDisplayers.php @@ -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(); diff --git a/src/Grid/Concerns/HasEvents.php b/src/Grid/Concerns/HasEvents.php index a1644f759..45e805f7c 100644 --- a/src/Grid/Concerns/HasEvents.php +++ b/src/Grid/Concerns/HasEvents.php @@ -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); } /** diff --git a/src/Grid/Concerns/HasFilter.php b/src/Grid/Concerns/HasFilter.php index a659f6a6f..d6806d427 100644 --- a/src/Grid/Concerns/HasFilter.php +++ b/src/Grid/Concerns/HasFilter.php @@ -15,11 +15,6 @@ trait HasFilter */ protected $filter; - /** - * @var array - */ - protected $beforeApplyFilterCallbacks = []; - /** * Setup grid filter. * @@ -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. * diff --git a/src/Grid/Concerns/HasTree.php b/src/Grid/Concerns/HasTree.php index 2d8f70d5f..4760fb11a 100644 --- a/src/Grid/Concerns/HasTree.php +++ b/src/Grid/Concerns/HasTree.php @@ -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; @@ -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(); @@ -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; } @@ -126,7 +127,7 @@ public function treeUrlWithoutQuery($keys) public function generateTreeUrl() { return Helper::urlWithoutQuery( - $this->grid->filter()->urlWithoutFilters(), + $this->grid()->filter()->urlWithoutFilters(), $this->treeIgnoreQueryNames ); } diff --git a/src/Grid/Model.php b/src/Grid/Model.php index 1ef5d458c..8089792fc 100755 --- a/src/Grid/Model.php +++ b/src/Grid/Model.php @@ -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. * @@ -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. *