jqh 5 năm trước cách đây
mục cha
commit
e2f830f05d
2 tập tin đã thay đổi với 21 bổ sung9 xóa
  1. 9 7
      src/Controllers/UserController.php
  2. 12 2
      src/Grid/Column/Condition.php

+ 9 - 7
src/Controllers/UserController.php

@@ -98,11 +98,11 @@ class UserController extends Controller
             $permissionModel = config('admin.database.permissions_model');
             $roleModel = config('admin.database.roles_model');
             $nodes = (new $permissionModel)->allNodes();
-            $grid->permissions->display(function ($v, $column) use (&$nodes, $roleModel) {
-                if (empty($this->roles)) {
-                    return;
-                }
-                return $column->tree(function (Grid\Displayers\Tree $tree) use (&$nodes, $roleModel) {
+            $grid->permissions
+                ->if(function () {
+                    return ! empty($this->roles);
+                })
+                ->tree(function (Grid\Displayers\Tree $tree) use (&$nodes, $roleModel) {
                     $tree->nodes($nodes);
 
                     foreach (array_column($this->roles, 'slug') as $slug) {
@@ -110,8 +110,10 @@ class UserController extends Controller
                             $tree->checkedAll();
                         }
                     }
-                });
-            });
+                })
+                ->else()
+                ->showEmpty();
+
 
             $grid->created_at;
             $grid->updated_at->sortable();

+ 12 - 2
src/Grid/Column/Condition.php

@@ -21,6 +21,11 @@ class Condition
      */
     protected $condition;
 
+    /**
+     * @var bool
+     */
+    protected $result;
+
     /**
      * @var \Closure[]
      */
@@ -45,7 +50,7 @@ class Condition
         $self = $this;
 
         $condition = $this->column->if(function () use ($self) {
-            return ! $self->is();
+            return ! $self->getResult();
         });
 
         if ($next) {
@@ -100,7 +105,12 @@ class Condition
             $condition = $this->call($condition);
         }
 
-        return $condition ? true : false;
+        return$this->result = $condition ? true : false;
+    }
+
+    public function getResult()
+    {
+        return $this->result;
     }
 
     protected function call(\Closure $callback, $column = null)