jqh 5 lat temu
rodzic
commit
3cf4163a4f

+ 5 - 2
src/Grid/Concerns/HasQuickSearch.php

@@ -99,8 +99,11 @@ trait HasQuickSearch
             return;
         }
 
-        $this->model()->disableBindTreeQuery();
-        $this->model()->treeUrlWithoutQuery($this->quickSearch->queryName());
+        $this->model()
+            ->disableBindTreeQuery()
+            ->treeUrlWithoutQuery(
+                $this->quickSearch->queryName()
+            );
 
         if ($this->search instanceof \Closure) {
             return call_user_func($this->search, $this->model(), $query);

+ 14 - 7
src/Grid/Tools/Selector.php

@@ -33,7 +33,7 @@ class Selector
     /**
      * @var string
      */
-    protected $queryName;
+    protected $queryNameSuffix = '_selector';
 
     /**
      * Selector constructor.
@@ -43,7 +43,6 @@ class Selector
         $this->grid = $grid;
         $this->request = request();
         $this->selectors = new Collection();
-        $this->queryName = $grid->getName().'_selector';
     }
 
     /**
@@ -102,6 +101,14 @@ class Selector
         return $this;
     }
 
+    /**
+     * @return string
+     */
+    public function queryName()
+    {
+        return $this->grid->getName().$this->queryNameSuffix;
+    }
+
     /**
      * Get all selectors.
      *
@@ -121,7 +128,7 @@ class Selector
             return $this->selected;
         }
 
-        $selected = $this->request->get($this->queryName, []);
+        $selected = $this->request->get($this->queryName(), []);
         if (! is_array($selected)) {
             return [];
         }
@@ -149,11 +156,11 @@ class Selector
         $query = $this->request->query();
 
         $selected = $this->parseSelected();
-
         $options = Arr::get($selected, $column, []);
+        $queryName = "{$this->queryName()}.{$column}";
 
         if (is_null($value)) {
-            Arr::forget($query, "{$this->queryName}.{$column}");
+            Arr::forget($query, $queryName);
 
             return $this->request->fullUrlWithQuery($query);
         }
@@ -168,9 +175,9 @@ class Selector
         }
 
         if (! empty($options)) {
-            Arr::set($query, "{$this->queryName}.{$column}", implode(',', $options));
+            Arr::set($query, $queryName, implode(',', $options));
         } else {
-            Arr::forget($query, "{$this->queryName}.{$column}");
+            Arr::forget($query, $queryName);
         }
 
         return $this->request->fullUrlWithQuery($query);

+ 21 - 0
src/Layout/Content.php

@@ -381,4 +381,25 @@ CSS
 
         return view($this->view, $items)->render();
     }
+
+    /**
+     * Register a composed event.
+     *
+     * @param callable $callback
+     * @param bool     $once
+     */
+    public static function composed(callable $callback, bool $once = false)
+    {
+        static::addBuilderListeners('builder.composed', $callback, $once);
+    }
+
+    /**
+     * Call the composed callbacks.
+     *
+     * @param array ...$params
+     */
+    protected function callComposed(...$params)
+    {
+        $this->fireBuilderEvent('builder.composed', ...$params);
+    }
 }

+ 6 - 27
src/Traits/HasBuilderEvents.php

@@ -12,7 +12,7 @@ trait HasBuilderEvents
      */
     public static function resolving(callable $callback, bool $once = false)
     {
-        static::setListeners('builder.resolving', $callback, $once);
+        static::addBuilderListeners('builder.resolving', $callback, $once);
     }
 
     /**
@@ -22,7 +22,7 @@ trait HasBuilderEvents
      */
     protected function callResolving(...$params)
     {
-        $this->callBuilderListeners('builder.resolving', ...$params);
+        $this->fireBuilderEvent('builder.resolving', ...$params);
     }
 
     /**
@@ -33,7 +33,7 @@ trait HasBuilderEvents
      */
     public static function composing(callable $callback, bool $once = false)
     {
-        static::setListeners('builder.composing', $callback, $once);
+        static::addBuilderListeners('builder.composing', $callback, $once);
     }
 
     /**
@@ -43,35 +43,14 @@ trait HasBuilderEvents
      */
     protected function callComposing(...$params)
     {
-        $this->callBuilderListeners('builder.composing', ...$params);
-    }
-
-    /**
-     * Register a composed event.
-     *
-     * @param callable $callback
-     * @param bool     $once
-     */
-    public static function composed(callable $callback, bool $once = false)
-    {
-        static::setListeners('builder.composed', $callback, $once);
-    }
-
-    /**
-     * Call the composed callbacks.
-     *
-     * @param array ...$params
-     */
-    protected function callComposed(...$params)
-    {
-        $this->callBuilderListeners('builder.composed', ...$params);
+        $this->fireBuilderEvent('builder.composing', ...$params);
     }
 
     /**
      * @param $listeners
      * @param array ...$params
      */
-    protected function callBuilderListeners($key, ...$params)
+    protected function fireBuilderEvent($key, ...$params)
     {
         $storage = app('admin.context');
 
@@ -97,7 +76,7 @@ trait HasBuilderEvents
      * @param callable $callback
      * @param bool     $once
      */
-    protected static function setListeners($key, $callback, $once)
+    protected static function addBuilderListeners($key, $callback, $once)
     {
         $storage = app('admin.context');