Browse Source

统一格式

jqh 5 years ago
parent
commit
b1d8b188b7

+ 72 - 100
src/Controllers/ExtensionController.php

@@ -19,13 +19,6 @@ class ExtensionController extends Controller
 {
     use HasResourceActions;
 
-    /**
-     * Index interface.
-     *
-     * @param Content $content
-     *
-     * @return Content
-     */
     public function index(Content $content)
     {
         $this->define();
@@ -36,9 +29,6 @@ class ExtensionController extends Controller
             ->body($this->grid());
     }
 
-    /**
-     * @return \Illuminate\Http\JsonResponse
-     */
     public function import()
     {
         $extension = request('id');
@@ -63,87 +53,82 @@ class ExtensionController extends Controller
      */
     protected function grid()
     {
-        $grid = new Grid(new Extension());
-
-        $grid->number();
-        $grid->name;
-        $grid->version;
-        $grid->alias;
-
-        $grid->description
-            ->if(function () {
-                return mb_strlen($this->description) > 14;
-            })
-            ->limit(14)
-            ->expand(function ($expand) {
-                if (! $this->description) {
-                    return;
-                }
-
-                return "<div style='padding:10px 20px'>{$this->description}</div>";
-            });
+        return new Grid(new Extension(), function (Grid $grid) {
+            $grid->number();
+            $grid->name;
+            $grid->version;
+            $grid->alias;
+
+            $grid->description
+                ->if(function () {
+                    return mb_strlen($this->description) > 14;
+                })
+                ->display(function ($v) {
+                    return mb_substr($v, 0, 14);
+                })
+                ->expand(function ($expand) {
+                    if (! $this->description) {
+                        return;
+                    }
 
-        $grid->authors;
-        $grid->enable->switch();
-        $grid->imported;
-
-        $view = trans('admin.view');
-        $grid->config
-            ->if(function () {
-                return $this->config ? true : false;
-            })
-            ->display($view)
-            ->expand($this->getExpandHandler('config'))
-            ->else()
-            ->emptyString();
-
-        $grid->require
-            ->if(function () {
-                return $this->require ? true : false;
-            })
-            ->display($view)
-            ->expand($this->getExpandHandler())
-            ->else()
-            ->emptyString();
-
-        $grid->require_dev
-            ->if(function () {
-                return $this->require_dev ? true : false;
-            })
-            ->display($view)
-            ->expand($this->getExpandHandler('require_dev'))
-            ->else()
-            ->emptyString();
-
-        $grid->disablePagination();
-        $grid->disableCreateButton();
-        $grid->disableDeleteButton();
-        $grid->disableBatchDelete();
-        $grid->disableFilterButton();
-        $grid->disableFilter();
-        $grid->disableQuickEditButton();
-        $grid->disableEditButton();
-        $grid->disableDeleteButton();
-        $grid->disableViewButton();
-
-        $grid->actions(new ImportButton());
-
-        $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
-            $create->text('package_name')->required();
-            $create->text('namespace')
-                ->attribute('style', 'width:240px')
-                ->required()
-                ->default('Dcat\\Admin\\Extension\\:Name');
+                    return "<div style='padding:10px 20px'>{$this->description}</div>";
+                });
+
+            $grid->authors;
+            $grid->enable->switch();
+            $grid->imported;
+
+            $view = trans('admin.view');
+            $grid->config
+                ->if(function () {
+                    return $this->config ? true : false;
+                })
+                ->display($view)
+                ->expand($this->getExpandHandler('config'))
+                ->else()
+                ->emptyString();
+
+            $grid->require
+                ->if(function () {
+                    return $this->require ? true : false;
+                })
+                ->display($view)
+                ->expand($this->getExpandHandler())
+                ->else()
+                ->emptyString();
+
+            $grid->require_dev
+                ->if(function () {
+                    return $this->require_dev ? true : false;
+                })
+                ->display($view)
+                ->expand($this->getExpandHandler('require_dev'))
+                ->else()
+                ->emptyString();
+
+            $grid->disablePagination();
+            $grid->disableCreateButton();
+            $grid->disableDeleteButton();
+            $grid->disableBatchDelete();
+            $grid->disableFilterButton();
+            $grid->disableFilter();
+            $grid->disableQuickEditButton();
+            $grid->disableEditButton();
+            $grid->disableDeleteButton();
+            $grid->disableViewButton();
+
+            $grid->actions(new ImportButton());
+
+            $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
+                $create->text('package_name')->required();
+                $create->text('namespace')
+                    ->attribute('style', 'width:240px')
+                    ->required()
+                    ->default('Dcat\\Admin\\Extension\\:Name');
+            });
         });
-
-        return $grid;
     }
 
-    /**
-     * Make a form builder.
-     *
-     * @return Form
-     */
     public function form()
     {
         $form = new Form(new Extension());
@@ -177,11 +162,6 @@ class ExtensionController extends Controller
         return $form;
     }
 
-    /**
-     * 创建扩展.
-     *
-     * @return string
-     */
     public function createExtension($package, $namespace)
     {
         $namespace = trim($namespace, '\\');
@@ -196,11 +176,6 @@ class ExtensionController extends Controller
         return $output->getContent();
     }
 
-    /**
-     * @param string $key
-     *
-     * @return \Closure
-     */
     protected function getExpandHandler($key = 'require')
     {
         return function () use ($key) {
@@ -219,9 +194,6 @@ class ExtensionController extends Controller
         };
     }
 
-    /**
-     * 字段显示定义.
-     */
     protected function define()
     {
         $name = function ($v) {

+ 51 - 68
src/Controllers/LogController.php

@@ -11,13 +11,6 @@ use Illuminate\Support\Arr;
 
 class LogController extends Controller
 {
-    /**
-     * Index interface.
-     *
-     * @param Content $content
-     *
-     * @return Content
-     */
     public function index(Content $content)
     {
         return $content
@@ -26,84 +19,74 @@ class LogController extends Controller
             ->body($this->grid());
     }
 
-    /**
-     * @return Grid
-     */
     protected function grid()
     {
-        $grid = new Grid(new OperationLog());
-
-        $grid->id('ID')->sortable();
-        $grid->user(trans('admin.user'))
-            ->get('name')
-            ->link(function () {
-                if ($this->user) {
-                    return admin_url('auth/users/'.$this->user['id']);
-                }
-            })
-            ->responsive();
+        return new Grid(new OperationLog(), function (Grid $grid) {
+            $grid->id('ID')->sortable();
+            $grid->user(trans('admin.user'))
+                ->get('name')
+                ->link(function () {
+                    if ($this->user) {
+                        return admin_url('auth/users/'.$this->user['id']);
+                    }
+                })
+                ->responsive();
 
-        $grid->method(trans('admin.method'))
-            ->responsive()
-            ->label(OperationLogModel::$methodColors)
-            ->filterByValue();
+            $grid->method(trans('admin.method'))
+                ->responsive()
+                ->label(OperationLogModel::$methodColors)
+                ->filterByValue();
 
-        $grid->path(trans('admin.uri'))->responsive()->display(function ($v) {
-            return "<code>$v</code>";
-        })->filterByValue();
+            $grid->path(trans('admin.uri'))->responsive()->display(function ($v) {
+                return "<code>$v</code>";
+            })->filterByValue();
 
-        $grid->ip('IP')->filterByValue()->responsive();
+            $grid->ip('IP')->filterByValue()->responsive();
 
-        $grid->input->responsive()->display(function ($input) {
-            $input = json_decode($input, true);
-            $input = Arr::except($input, ['_pjax', '_token', '_method', '_previous_']);
-            if (empty($input)) {
-                return '';
-            }
+            $grid->input->responsive()->display(function ($input) {
+                $input = json_decode($input, true);
+                $input = Arr::except($input, ['_pjax', '_token', '_method', '_previous_']);
+                if (empty($input)) {
+                    return '';
+                }
 
-            return '<pre class="dump">'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</pre>';
-        });
+                return '<pre class="dump">'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</pre>';
+            });
 
-        $grid->created_at(trans('admin.created_at'))->responsive();
+            $grid->created_at(trans('admin.created_at'))->responsive();
 
-        $grid->model()->with('user')->orderBy('id', 'DESC');
+            $grid->model()->with('user')->orderBy('id', 'DESC');
 
-        $grid->disableCreateButton();
-        $grid->disableQuickEditButton();
-        $grid->disableEditButton();
-        $grid->disableViewButton();
-        $grid->setActionClass(Grid\Displayers\Actions::class);
+            $grid->disableCreateButton();
+            $grid->disableQuickEditButton();
+            $grid->disableEditButton();
+            $grid->disableViewButton();
+            $grid->setActionClass(Grid\Displayers\Actions::class);
 
-        $grid->filter(function (Grid\Filter $filter) {
-            $filter->equal('user_id', trans('admin.user'))
-                ->selectResource('auth/users')
-                ->options(function ($v) {
-                    if (! $v) {
-                        return $v;
-                    }
-                    $userModel = config('admin.database.users_model');
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->equal('user_id', trans('admin.user'))
+                    ->selectResource('auth/users')
+                    ->options(function ($v) {
+                        if (! $v) {
+                            return $v;
+                        }
+                        $userModel = config('admin.database.users_model');
 
-                    return $userModel::findOrFail($v)->pluck('name', 'id');
-                });
+                        return $userModel::findOrFail($v)->pluck('name', 'id');
+                    });
 
-            $filter->equal('method', trans('admin.method'))
-                ->select(
-                    array_combine(OperationLogModel::$methods, OperationLogModel::$methods)
-                );
+                $filter->equal('method', trans('admin.method'))
+                    ->select(
+                        array_combine(OperationLogModel::$methods, OperationLogModel::$methods)
+                    );
 
-            $filter->like('path', trans('admin.uri'));
-            $filter->equal('ip', 'IP');
-            $filter->between('created_at')->datetime();
+                $filter->like('path', trans('admin.uri'));
+                $filter->equal('ip', 'IP');
+                $filter->between('created_at')->datetime();
+            });
         });
-
-        return $grid;
     }
 
-    /**
-     * @param mixed $id
-     *
-     * @return \Illuminate\Http\JsonResponse
-     */
     public function destroy($id)
     {
         $ids = explode(',', $id);

+ 17 - 30
src/Controllers/MenuController.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Controllers;
 
+use Dcat\Admin\Widgets\Form as WidgetForm;
 use Dcat\Admin\Form;
 use Dcat\Admin\Layout\Column;
 use Dcat\Admin\Layout\Content;
@@ -12,23 +13,11 @@ use Dcat\Admin\Widgets\Box;
 
 class MenuController extends AdminController
 {
-    /**
-     * Get content title.
-     *
-     * @return string
-     */
     public function title()
     {
         return trans('admin.menu');
     }
 
-    /**
-     * Index interface.
-     *
-     * @param Content $content
-     *
-     * @return Content
-     */
     public function index(Content $content)
     {
         return $content
@@ -38,7 +27,7 @@ class MenuController extends AdminController
                 $row->column(7, $this->treeView()->render());
 
                 $row->column(5, function (Column $column) {
-                    $form = new \Dcat\Admin\Widgets\Form();
+                    $form = new WidgetForm();
                     $form->action(admin_url('auth/menu'));
 
                     $menuModel = config('admin.database.menu_model');
@@ -72,29 +61,27 @@ class MenuController extends AdminController
     {
         $menuModel = config('admin.database.menu_model');
 
-        $tree = new Tree(new $menuModel());
+        return new Tree(new $menuModel(), function (Tree $tree) {
+            $tree->disableCreateButton();
+            $tree->disableQuickCreateButton();
+            $tree->disableEditButton();
 
-        $tree->disableCreateButton();
-        $tree->disableQuickCreateButton();
-        $tree->disableEditButton();
+            $tree->branch(function ($branch) {
+                $payload = "<i class='fa {$branch['icon']}'></i>&nbsp;<strong>{$branch['title']}</strong>";
 
-        $tree->branch(function ($branch) {
-            $payload = "<i class='fa {$branch['icon']}'></i>&nbsp;<strong>{$branch['title']}</strong>";
+                if (! isset($branch['children'])) {
+                    if (url()->isValidUrl($branch['uri'])) {
+                        $uri = $branch['uri'];
+                    } else {
+                        $uri = admin_base_path($branch['uri']);
+                    }
 
-            if (! isset($branch['children'])) {
-                if (url()->isValidUrl($branch['uri'])) {
-                    $uri = $branch['uri'];
-                } else {
-                    $uri = admin_base_path($branch['uri']);
+                    $payload .= "&nbsp;&nbsp;&nbsp;<a href=\"$uri\" class=\"dd-nodrag\">$uri</a>";
                 }
 
-                $payload .= "&nbsp;&nbsp;&nbsp;<a href=\"$uri\" class=\"dd-nodrag\">$uri</a>";
-            }
-
-            return $payload;
+                return $payload;
+            });
         });
-
-        return $tree;
     }
 
     /**

+ 34 - 59
src/Controllers/PermissionController.php

@@ -13,23 +13,11 @@ use Illuminate\Support\Str;
 
 class PermissionController extends AdminController
 {
-    /**
-     * Get content title.
-     *
-     * @return string
-     */
     protected function title()
     {
         return trans('admin.permissions');
     }
 
-    /**
-     * Index interface.
-     *
-     * @param Content $content
-     *
-     * @return Content
-     */
     public function index(Content $content)
     {
         if (request(IFrameGrid::QUERY_NAME)) {
@@ -58,69 +46,59 @@ class PermissionController extends AdminController
         return $grid;
     }
 
-    /**
-     * @return \Dcat\Admin\Tree
-     */
     protected function treeView()
     {
         $model = config('admin.database.permissions_model');
 
-        $tree = new Tree(new $model());
+        return new Tree(new $model(), function (Tree $tree) {
+            $tree->disableCreateButton();
+            $tree->disableEditButton();
 
-        $tree->disableCreateButton();
-        $tree->disableEditButton();
+            $tree->branch(function ($branch) {
+                $payload = "<div class='pull-left' style='min-width:310px'><b>{$branch['name']}</b>&nbsp;&nbsp;[<span class='text-primary'>{$branch['slug']}</span>]";
 
-        $tree->branch(function ($branch) {
-            $payload = "<div class='pull-left' style='min-width:310px'><b>{$branch['name']}</b>&nbsp;&nbsp;[<span class='text-primary'>{$branch['slug']}</span>]";
+                $path = array_filter($branch['http_path']);
 
-            $path = array_filter($branch['http_path']);
-
-            if (! $path) {
-                return $payload.'</div>&nbsp;';
-            }
+                if (! $path) {
+                    return $payload.'</div>&nbsp;';
+                }
 
-            $max = 3;
-            if (count($path) > $max) {
-                $path = array_slice($path, 0, $max);
-                array_push($path, '...');
-            }
+                $max = 3;
+                if (count($path) > $max) {
+                    $path = array_slice($path, 0, $max);
+                    array_push($path, '...');
+                }
 
-            $method = $branch['http_method'] ?: [];
+                $method = $branch['http_method'] ?: [];
 
-            $path = collect($path)->map(function ($path) use ($branch, &$method) {
-                if (Str::contains($path, ':')) {
-                    [$me, $path] = explode(':', $path);
+                $path = collect($path)->map(function ($path) use ($branch, &$method) {
+                    if (Str::contains($path, ':')) {
+                        [$me, $path] = explode(':', $path);
 
-                    $method = array_merge($method, explode(',', $me));
-                }
-                if ($path !== '...' && ! empty(config('admin.route.prefix'))) {
-                    $path = trim(admin_base_path($path), '/');
-                }
+                        $method = array_merge($method, explode(',', $me));
+                    }
+                    if ($path !== '...' && ! empty(config('admin.route.prefix'))) {
+                        $path = trim(admin_base_path($path), '/');
+                    }
 
-                $color = Admin::color()->primaryDarker();
+                    $color = Admin::color()->primaryDarker();
 
-                return "<code style='color:{$color}'>$path</code>";
-            })->implode('&nbsp;&nbsp;');
+                    return "<code style='color:{$color}'>$path</code>";
+                })->implode('&nbsp;&nbsp;');
 
-            $method = collect($method ?: ['ANY'])->unique()->map(function ($name) {
-                return strtoupper($name);
-            })->map(function ($name) {
-                return "<span class='label bg-primary'>{$name}</span>";
-            })->implode('&nbsp;').'&nbsp;';
+                $method = collect($method ?: ['ANY'])->unique()->map(function ($name) {
+                        return strtoupper($name);
+                    })->map(function ($name) {
+                        return "<span class='label bg-primary'>{$name}</span>";
+                    })->implode('&nbsp;').'&nbsp;';
 
-            $payload .= "</div>&nbsp; $method<a class=\"dd-nodrag\">$path</a>";
+                $payload .= "</div>&nbsp; $method<a class=\"dd-nodrag\">$path</a>";
 
-            return $payload;
+                return $payload;
+            });
         });
-
-        return $tree;
     }
 
-    /**
-     * Make a form builder.
-     *
-     * @return Form
-     */
     public function form()
     {
         return Form::make(new Permission(), function (Form $form) {
@@ -159,9 +137,6 @@ class PermissionController extends AdminController
         });
     }
 
-    /**
-     * @return array
-     */
     public function getRoutes()
     {
         $prefix = config('admin.route.prefix');

+ 0 - 24
src/Controllers/RoleController.php

@@ -14,11 +14,6 @@ use Dcat\Admin\Widgets\Tree;
 
 class RoleController extends AdminController
 {
-    /**
-     * Get content title.
-     *
-     * @return string
-     */
     public function title()
     {
         return trans('admin.roles');
@@ -63,13 +58,6 @@ class RoleController extends AdminController
         return $grid;
     }
 
-    /**
-     * Make a show builder.
-     *
-     * @param mixed $id
-     *
-     * @return Show
-     */
     protected function detail($id)
     {
         return Show::make($id, new Role('permissions'), function (Show $show) {
@@ -101,11 +89,6 @@ class RoleController extends AdminController
         });
     }
 
-    /**
-     * Make a form builder.
-     *
-     * @return Form
-     */
     public function form()
     {
         return Form::make(new Role('permissions'), function (Form $form) {
@@ -147,13 +130,6 @@ class RoleController extends AdminController
         });
     }
 
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param int $id
-     *
-     * @return \Illuminate\Http\Response
-     */
     public function destroy($id)
     {
         if (in_array(RoleModel::ADMINISTRATOR_ID, Helper::array($id))) {

+ 0 - 32
src/Controllers/UserController.php

@@ -14,21 +14,11 @@ use Dcat\Admin\Widgets\Tree;
 
 class UserController extends AdminController
 {
-    /**
-     * Get content title.
-     *
-     * @return string
-     */
     public function title()
     {
         return trans('admin.administrator');
     }
 
-    /**
-     * Make a grid builder.
-     *
-     * @return Grid
-     */
     protected function grid()
     {
         return Grid::make(new Administrator('roles'), function (Grid $grid) {
@@ -74,9 +64,6 @@ class UserController extends AdminController
         });
     }
 
-    /**
-     * @return IFrameGrid
-     */
     protected function iFrameGrid()
     {
         $grid = new IFrameGrid(new Administrator());
@@ -91,13 +78,6 @@ class UserController extends AdminController
         return $grid;
     }
 
-    /**
-     * Make a show builder.
-     *
-     * @param mixed $id
-     *
-     * @return Show
-     */
     protected function detail($id)
     {
         return Show::make($id, new Administrator('roles'), function (Show $show) {
@@ -148,11 +128,6 @@ class UserController extends AdminController
         });
     }
 
-    /**
-     * Make a form builder.
-     *
-     * @return Form
-     */
     public function form()
     {
         return Form::make(new Administrator('roles'), function (Form $form) {
@@ -216,13 +191,6 @@ class UserController extends AdminController
         });
     }
 
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param int $id
-     *
-     * @return \Illuminate\Http\Response
-     */
     public function destroy($id)
     {
         if (in_array(AdministratorModel::DEFAULT_ID, Helper::array($id))) {