jqh il y a 5 ans
Parent
commit
5a8fde309d
5 fichiers modifiés avec 60 ajouts et 31 suppressions
  1. 15 1
      src/Form.php
  2. 16 19
      src/Form/Builder.php
  3. 2 3
      src/Form/MultipleForm.php
  4. 2 0
      src/Grid/Exporters/AbstractExporter.php
  5. 25 8
      src/Grid/Model.php

+ 15 - 1
src/Form.php

@@ -247,7 +247,7 @@ class Form implements Renderable
     /**
      * Field rows in form.
      *
-     * @var array
+     * @var Row[]
      */
     protected $rows = [];
 
@@ -1363,14 +1363,25 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * @return Row[]
+     */
+    public function getRows()
+    {
+        return $this->rows;
+    }
+
     /**
      * Tools setting for form.
      *
      * @param Closure $callback
+     * @return $this;
      */
     public function tools(Closure $callback)
     {
         $callback->call($this, $this->builder->getTools());
+
+        return $this;
     }
 
     /**
@@ -1495,10 +1506,13 @@ class Form implements Renderable
      * Footer setting for form.
      *
      * @param Closure $callback
+     * @return $this
      */
     public function footer(Closure $callback)
     {
         call_user_func($callback, $this->builder->getFooter());
+
+        return $this;
     }
 
     /**

+ 16 - 19
src/Form/Builder.php

@@ -438,18 +438,15 @@ class Builder
 
     /**
      * @param $column
-     * @return $this
+     * @return void
      */
     public function removeField($column)
     {
         $this->fields = $this->fields->filter(function (Field $field) use ($column) {
             return $field->column() != $column;
         });
-
-        return $this;
     }
 
-
     /**
      * If the parant form has rows.
      *
@@ -457,7 +454,7 @@ class Builder
      */
     public function hasRows()
     {
-        return !empty($this->form->rows);
+        return !empty($this->form->getRows());
     }
 
     /**
@@ -467,7 +464,7 @@ class Builder
      */
     public function getRows()
     {
-        return $this->form->rows;
+        return $this->form->getRows();
     }
 
     /**
@@ -510,7 +507,7 @@ class Builder
      * @param string $option
      * @param mixed  $value
      *
-     * @return $this
+     * @return void
      */
     public function option($option, $value = null)
     {
@@ -519,41 +516,33 @@ class Builder
         }
 
         $this->options[$option] = $value;
-
-        return $this;
     }
 
     /**
      * @param bool $disable
-     * @return $this
+     * @return void
      */
     public function disableHeader(bool $disable = true)
     {
         $this->showHeader = !$disable;
-
-        return $this;
     }
 
     /**
      * @param bool $disable
-     * @return $this
+     * @return void
      */
     public function disableFooter(bool $disable = true)
     {
         $this->showFooter = !$disable;
-
-        return $this;
     }
 
     /**
      * @param $id
-     * @return $this
+     * @return void
      */
     public function setFormId($id)
     {
         $this->formId = $id;
-
-        return $this;
     }
 
     /**
@@ -733,7 +722,9 @@ class Builder
             $this->setupTabScript();
         }
 
-        $this->form->allowAjaxSubmit() && $this->setupSubmitScript();
+        if ($this->form->allowAjaxSubmit()) {
+            $this->setupSubmitScript();
+        }
 
         $open = $this->open(['class' => 'form-horizontal']);
 
@@ -769,6 +760,9 @@ EOF;
         return "<div class='card material'>{$view->render()}</div>";
     }
 
+    /**
+     * @return void
+     */
     protected function setupSubmitScript()
     {
         Admin::script(
@@ -801,6 +795,9 @@ JS
         );
     }
 
+    /**
+     * @return void
+     */
     protected function setupTabScript()
     {
         $formId = $this->getFormId();

+ 2 - 3
src/Form/MultipleForm.php

@@ -2,11 +2,10 @@
 
 namespace Dcat\Admin\Form;
 
-use Dcat\Admin\Admin;
 use Dcat\Admin\Form;
-use Dcat\Admin\Widgets\Form as WidgetsForm;
+use Dcat\Admin\Widgets\Form as WidgetForm;
 
-class MultipleForm extends WidgetsForm
+class MultipleForm extends WidgetForm
 {
     /**
      * @var Form

+ 2 - 0
src/Grid/Exporters/AbstractExporter.php

@@ -3,6 +3,7 @@
 namespace Dcat\Admin\Grid\Exporters;
 
 use Dcat\Admin\Grid;
+use Illuminate\Support\Collection;
 use Illuminate\Support\Str;
 
 /**
@@ -207,6 +208,7 @@ abstract class AbstractExporter implements ExporterInterface
         $array = $this->grid->getFilter()->execute(true);
 
         $model->reset();
+        $model->rejectQueries('forPage');
 
         if ($this->builder) {
             return ($this->builder)($array);

+ 25 - 8
src/Grid/Model.php

@@ -149,7 +149,16 @@ class Model
      */
     public function getQueries()
     {
-        return $this->queries;
+        return $this->queries = $this->queries->unique();
+    }
+
+    /**
+     * @param Collection $query
+     * @return void
+     */
+    public function setQueries(Collection $query)
+    {
+        $this->queries = $query;
     }
 
     /**
@@ -625,6 +634,19 @@ class Model
         }
     }
 
+    /**
+     * @param string|array $method
+     * @return void
+     */
+    public function rejectQueries($method)
+    {
+        $method = (array) $method;
+
+        $this->queries = $this->queries->reject(function ($query) use ($method) {
+            return in_array($query['method'], $method);
+        });
+    }
+
     /**
      * Reset orderBy query.
      *
@@ -632,9 +654,7 @@ class Model
      */
     public function resetOrderBy()
     {
-        $this->queries = $this->queries->reject(function ($query) {
-            return $query['method'] == 'orderBy' || $query['method'] == 'orderByDesc';
-        });
+        $this->rejectQueries(['orderBy', 'orderByDesc']);
     }
 
     /**
@@ -704,14 +724,11 @@ class Model
     }
 
     /**
-     * @return $this
+     * @return void
      */
     public function reset()
     {
         $this->data    = null;
         $this->model   = null;
-        $this->queries = collect();
-
-        return $this;
     }
 }