瀏覽代碼

调整部分接口

jqh 5 年之前
父節點
當前提交
4c8c412917

+ 4 - 4
database/migrations/2016_01_04_173148_create_admin_tables.php

@@ -26,15 +26,15 @@ class CreateAdminTables extends Migration
 
         Schema::connection($connection)->create(config('admin.database.roles_table'), function (Blueprint $table) {
             $table->increments('id');
-            $table->string('name', 50)->unique();
-            $table->string('slug', 50);
+            $table->string('name', 50);
+            $table->string('slug', 50)->unique();
             $table->timestamps();
         });
 
         Schema::connection($connection)->create(config('admin.database.permissions_table'), function (Blueprint $table) {
             $table->increments('id');
-            $table->string('name', 50)->unique();
-            $table->string('slug', 50);
+            $table->string('name', 50);
+            $table->string('slug', 50)->unique();
             $table->string('http_method')->nullable();
             $table->text('http_path')->nullable();
             $table->integer('order')->default(0);

+ 1 - 1
resources/views/helpers/scaffold.blade.php

@@ -16,7 +16,7 @@
         'controller' => ucfirst(trans('admin.scaffold.create_controller')),
         'migrate' => ucfirst(trans('admin.scaffold.run_migrate')),
         'lang' => ucfirst(trans('admin.scaffold.create_lang')),
-    ])->checkedAll(['migrate', 'repository', 'migration']);
+    ])->checkedAll(['migrate', 'migration']);
 @endphp
 <style>
     /*.table>thead>tr>th {*/

+ 0 - 80
src/Admin.php

@@ -110,86 +110,6 @@ class Admin
         static::$favicon = $favicon;
     }
 
-    /**
-     * @param $repository
-     * @param Closure|null $callback
-     *
-     * @return Grid
-     */
-    public static function grid($repository = null, \Closure $callback = null)
-    {
-        if ($repository instanceof \Closure) {
-            return new Grid(null, $callback);
-        }
-
-        return new Grid($repository, $callback);
-    }
-
-    /**
-     * @param $repository
-     * @param Closure $callable
-     *
-     * @return Form
-     */
-    public static function form($repository, Closure $callable = null)
-    {
-        return new Form($repository, $callable);
-    }
-
-    /**
-     * Build a tree.
-     *
-     * @param $model
-     * @param Closure|null $callable
-     *
-     * @return Tree
-     */
-    public static function tree($model, Closure $callable = null)
-    {
-        return new Tree($model, $callable);
-    }
-
-    /**
-     * Build show page.
-     *
-     * @example
-     *     $show = Admin::show();
-     *
-     *     $show = Admin::show(new Repository);
-     *
-     *     $show = Admin::show(new Repository, function (Show $show) {});
-     *
-     *     $show = Admin::show($id, new Repository, function (Show $show) {});
-     *
-     * @param $repository
-     * @param mixed $callable
-     *
-     * @return Show
-     */
-    public static function show($id = null, $repository = null, \Closure $callable = null)
-    {
-        switch (func_num_args()) {
-            case 0:
-                $show = new Show();
-
-                break;
-            case 1:
-                $show = new Show($id);
-
-                break;
-            case 2:
-                $show = new Show($id, $repository);
-
-                break;
-            case 3:
-                $show = new Show($repository, $callable);
-
-                $show->key($id);
-        }
-
-        return $show;
-    }
-
     /**
      * @param Closure $callable
      *

+ 1 - 1
src/Controllers/PermissionController.php

@@ -289,7 +289,7 @@ class PermissionController extends Controller
      */
     public function form()
     {
-        return Admin::form(new Permission(), function (Form $form) {
+        return Form::make(new Permission(), function (Form $form) {
             $permissionTable = config('admin.database.permissions_table');
             $connection = config('admin.database.connection');
 

+ 4 - 4
src/Controllers/RoleController.php

@@ -130,7 +130,7 @@ class RoleController extends Controller
      */
     protected function detail($id)
     {
-        return Admin::show($id, new Role('permissions'), function (Show $show) {
+        return Show::make(new Role('permissions'), function (Show $show) use ($id) {
             $show->id;
             $show->slug;
             $show->name;
@@ -144,10 +144,10 @@ class RoleController extends Controller
             $show->created_at;
             $show->updated_at;
 
-            if ($show->key() == RoleModel::ADMINISTRATOR_ID) {
+            if ($id == RoleModel::ADMINISTRATOR_ID) {
                 $show->disableDeleteButton();
             }
-        });
+        })->key($id);
     }
 
     /**
@@ -157,7 +157,7 @@ class RoleController extends Controller
      */
     public function form()
     {
-        return Admin::form(new Role('permissions'), function (Form $form) {
+        return Form::make(new Role('permissions'), function (Form $form) {
             $roleTable = config('admin.database.roles_table');
             $connection = config('admin.database.connection');
 

+ 5 - 5
src/Controllers/UserController.php

@@ -89,7 +89,7 @@ class UserController extends Controller
      */
     protected function grid()
     {
-        return Admin::grid(new Administrator('roles'), function (Grid $grid) {
+        return Grid::make(new Administrator('roles'), function (Grid $grid) {
             $grid->id('ID')->bold()->sortable();
             $grid->username;
             $grid->name;
@@ -160,7 +160,7 @@ class UserController extends Controller
      */
     protected function detail($id)
     {
-        return Admin::show($id, new Administrator('roles'), function (Show $show) {
+        return Show::make(new Administrator('roles'), function (Show $show) use ($id) {
             $show->id;
             $show->username;
             $show->name;
@@ -210,10 +210,10 @@ class UserController extends Controller
                 return $tree->render();
             });
 
-            if ($show->key() == AdministratorModel::DEFAULT_ID) {
+            if ($id == AdministratorModel::DEFAULT_ID) {
                 $show->disableDeleteButton();
             }
-        });
+        })->key($id);
     }
 
     /**
@@ -223,7 +223,7 @@ class UserController extends Controller
      */
     public function form()
     {
-        return Admin::form(new Administrator('roles'), function (Form $form) {
+        return Form::make(new Administrator('roles'), function (Form $form) {
             $userTable = config('admin.database.users_table');
 
             $connection = config('admin.database.connection');

+ 4 - 5
src/Scaffold/stubs/controller.stub

@@ -6,7 +6,6 @@ use DummyModelNamespace;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
-use Dcat\Admin\Admin;
 use Dcat\Admin\Controllers\AdminController;
 
 class DummyClass extends AdminController
@@ -25,7 +24,7 @@ class DummyClass extends AdminController
      */
     protected function grid()
     {
-        return Admin::grid(new DummyModel(), function (Grid $grid) {
+        return Grid::make(new DummyModel(), function (Grid $grid) {
             {grid}
         });
     }
@@ -39,9 +38,9 @@ class DummyClass extends AdminController
      */
     protected function detail($id)
     {
-        return Admin::show($id, new DummyModel(), function (Show $show) {
+        return Show::make(new DummyModel(), function (Show $show) {
             {show}
-        });
+        })->key($id);
     }
 
     /**
@@ -51,7 +50,7 @@ class DummyClass extends AdminController
      */
     protected function form()
     {
-        return Admin::form(new DummyModel(), function (Form $form) {
+        return Form::make(new DummyModel(), function (Form $form) {
             {form}
         });
     }

+ 5 - 1
src/Show.php

@@ -176,12 +176,14 @@ class Show implements Renderable
         }
 
         $this->__id = $id;
+
+        return $this;
     }
 
     /**
      * @param Fluent|null $model
      *
-     * @return Fluent
+     * @return Fluent|$this
      */
     public function model(Fluent $model = null)
     {
@@ -194,6 +196,8 @@ class Show implements Renderable
         }
 
         $this->model = $model;
+
+        return $this;
     }
 
     protected function setupModel()