|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Dcat\Admin\Controllers;
|
|
|
|
|
|
+use Dcat\Admin\Admin;
|
|
|
use Dcat\Admin\Auth\Permission;
|
|
|
use Dcat\Admin\Models\Repositories\Administrator;
|
|
|
use Dcat\Admin\Models\Administrator as AdministratorModel;
|
|
@@ -65,7 +66,7 @@ class UserController extends Controller
|
|
|
return $content
|
|
|
->header(trans('admin.administrator'))
|
|
|
->description(trans('admin.edit'))
|
|
|
- ->body($this->form($id)->edit($id));
|
|
|
+ ->body($this->form()->edit($id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -88,52 +89,48 @@ class UserController extends Controller
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- $grid = new Grid(new Administrator());
|
|
|
+ return Admin::grid(new Administrator('roles'), function (Grid $grid) {
|
|
|
+ $grid->disableBatchDelete();
|
|
|
+ $grid->disableCreateButton();
|
|
|
|
|
|
- $grid->disableBatchDelete();
|
|
|
- $grid->disableCreateButton();
|
|
|
+ $grid->id('ID')->bold()->sortable();
|
|
|
+ $grid->username;
|
|
|
+ $grid->name;
|
|
|
+ $grid->roles->pluck('name')->label('primary');
|
|
|
|
|
|
- $grid->model()->with('roles');
|
|
|
-
|
|
|
- $grid->id('ID')->bold()->sortable();
|
|
|
- $grid->username;
|
|
|
- $grid->name;
|
|
|
- $grid->roles->pluck('name')->label('primary');
|
|
|
-
|
|
|
- $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) {
|
|
|
- $tree->nodes($nodes);
|
|
|
+ $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) {
|
|
|
+ $tree->nodes($nodes);
|
|
|
|
|
|
- foreach (array_column($this->roles, 'slug') as $slug) {
|
|
|
- if ($roleModel::isAdministrator($slug)) {
|
|
|
- $tree->checkedAll();
|
|
|
+ foreach (array_column($this->roles, 'slug') as $slug) {
|
|
|
+ if ($roleModel::isAdministrator($slug)) {
|
|
|
+ $tree->checkedAll();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- $grid->created_at;
|
|
|
- $grid->updated_at->sortable();
|
|
|
+ $grid->created_at;
|
|
|
+ $grid->updated_at->sortable();
|
|
|
|
|
|
- $grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
|
- if ($actions->getKey() == AdministratorModel::DEFAULT_ID) {
|
|
|
- $actions->disableDelete();
|
|
|
- }
|
|
|
- });
|
|
|
+ $grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
|
+ if ($actions->getKey() == AdministratorModel::DEFAULT_ID) {
|
|
|
+ $actions->disableDelete();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- $grid->filter(function (Grid\Filter $filter) {
|
|
|
- $filter->equal('id');
|
|
|
- $filter->like('username');
|
|
|
- $filter->like('name');
|
|
|
+ $grid->filter(function (Grid\Filter $filter) {
|
|
|
+ $filter->equal('id');
|
|
|
+ $filter->like('username');
|
|
|
+ $filter->like('name');
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
- return $grid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -169,58 +166,59 @@ class UserController extends Controller
|
|
|
*/
|
|
|
protected function detail($id)
|
|
|
{
|
|
|
- $show = new Show(new Administrator());
|
|
|
+ return Admin::show($id, new Administrator('roles'), function (Show $show) {
|
|
|
+ $show->id;
|
|
|
+ $show->username;
|
|
|
+ $show->name;
|
|
|
|
|
|
- $show->setId($id);
|
|
|
+ $show->avatar->image();
|
|
|
|
|
|
- $show->id;
|
|
|
- $show->username;
|
|
|
- $show->name;
|
|
|
+ $show->newline();
|
|
|
|
|
|
- $show->avatar->image();
|
|
|
+ $show->created_at;
|
|
|
+ $show->updated_at;
|
|
|
|
|
|
- $show->newline();
|
|
|
+ $show->divider();
|
|
|
|
|
|
- $show->created_at;
|
|
|
- $show->updated_at;
|
|
|
+ $show->roles->width(6)->as(function ($roles) {
|
|
|
+ if (! $roles) return;
|
|
|
|
|
|
- $show->divider();
|
|
|
+ return collect($roles)->pluck('name');
|
|
|
+ })->label('primary');
|
|
|
|
|
|
- $show->roles->width(6)->as(function ($roles) {
|
|
|
- return collect($roles)->pluck('name');
|
|
|
- })->label('primary');
|
|
|
+ $show->permissions->width(6)->unescape()->as(function () {
|
|
|
+ $roles = (array) $this->roles;
|
|
|
|
|
|
- $show->permissions->width(6)->unescape()->as(function () {
|
|
|
- $permissionModel = config('admin.database.permissions_model');
|
|
|
- $roleModel = config('admin.database.roles_model');
|
|
|
- $permissionModel = new $permissionModel;
|
|
|
- $nodes = $permissionModel->allNodes();
|
|
|
+ $permissionModel = config('admin.database.permissions_model');
|
|
|
+ $roleModel = config('admin.database.roles_model');
|
|
|
+ $permissionModel = new $permissionModel;
|
|
|
+ $nodes = $permissionModel->allNodes();
|
|
|
+
|
|
|
+ $tree = Tree::make($nodes);
|
|
|
|
|
|
- $tree = Tree::make($nodes);
|
|
|
+ $isAdministrator = false;
|
|
|
+ foreach (array_column($roles, 'slug') as $slug) {
|
|
|
+ if ($roleModel::isAdministrator($slug)) {
|
|
|
+ $tree->checkedAll();
|
|
|
+ $isAdministrator = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $isAdministrator = false;
|
|
|
- foreach (array_column($this->roles, 'slug') as $slug) {
|
|
|
- if ($roleModel::isAdministrator($slug)) {
|
|
|
- $tree->checkedAll();
|
|
|
- $isAdministrator = true;
|
|
|
+ if (!$isAdministrator) {
|
|
|
+ $keyName = $permissionModel->getKeyName();
|
|
|
+ $tree->checked(
|
|
|
+ $roleModel::getPermissionId(array_column($roles, $keyName))->flatten()
|
|
|
+ );
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!$isAdministrator) {
|
|
|
- $keyName = $permissionModel->getKeyName();
|
|
|
- $tree->checked(
|
|
|
- $roleModel::getPermissionId(array_column($this->roles, $keyName))->flatten()
|
|
|
- );
|
|
|
+ return $tree->render();
|
|
|
+ });
|
|
|
+
|
|
|
+ if ($show->getId() == AdministratorModel::DEFAULT_ID) {
|
|
|
+ $show->disableDeleteButton();
|
|
|
}
|
|
|
|
|
|
- return $tree->render();
|
|
|
});
|
|
|
-
|
|
|
- if ($id == AdministratorModel::DEFAULT_ID) {
|
|
|
- $show->disableDeleteButton();
|
|
|
- }
|
|
|
-
|
|
|
- return $show;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -228,57 +226,61 @@ class UserController extends Controller
|
|
|
*
|
|
|
* @return Form
|
|
|
*/
|
|
|
- public function form($id = null)
|
|
|
+ public function form()
|
|
|
{
|
|
|
- $userTable = config('admin.database.users_table');
|
|
|
+ return Admin::form(new Administrator('roles'), function (Form $form) {
|
|
|
+ $userTable = config('admin.database.users_table');
|
|
|
|
|
|
- $connection = config('admin.database.connection');
|
|
|
+ $connection = config('admin.database.connection');
|
|
|
|
|
|
- $form = new Form(new Administrator());
|
|
|
+ $id = $form->getKey();
|
|
|
|
|
|
- $form->display('id', 'ID');
|
|
|
+ $form->display('id', 'ID');
|
|
|
|
|
|
- $form->text('username', trans('admin.username'))
|
|
|
- ->required()
|
|
|
- ->creationRules(['required', "unique:{$connection}.{$userTable}"])
|
|
|
- ->updateRules(['required', "unique:{$connection}.{$userTable},username,$id"]);
|
|
|
- $form->text('name', trans('admin.name'))->required();
|
|
|
- $form->image('avatar', trans('admin.avatar'));
|
|
|
-
|
|
|
- if ($id) {
|
|
|
- $form->password('password', trans('admin.password'))
|
|
|
- ->rules('confirmed')
|
|
|
- ->customFormat(function ($v) {
|
|
|
- if ($v == $this->password) {
|
|
|
- return;
|
|
|
- }
|
|
|
- return $v;
|
|
|
- });
|
|
|
- $form->password('password_confirmation', trans('admin.password_confirmation'));
|
|
|
- } else {
|
|
|
- $form->password('password', trans('admin.password'))
|
|
|
+ $form->text('username', trans('admin.username'))
|
|
|
->required()
|
|
|
- ->rules('confirmed');
|
|
|
-
|
|
|
- $form->password('password_confirmation', trans('admin.password_confirmation'));
|
|
|
- }
|
|
|
+ ->creationRules(['required', "unique:{$connection}.{$userTable}"])
|
|
|
+ ->updateRules(['required', "unique:{$connection}.{$userTable},username,$id"]);
|
|
|
+ $form->text('name', trans('admin.name'))->required();
|
|
|
+ $form->image('avatar', trans('admin.avatar'));
|
|
|
+
|
|
|
+ if ($id) {
|
|
|
+ $form->password('password', trans('admin.password'))
|
|
|
+ ->rules('confirmed')
|
|
|
+ ->customFormat(function ($v) {
|
|
|
+ if ($v == $this->password) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return $v;
|
|
|
+ });
|
|
|
+ $form->password('password_confirmation', trans('admin.password_confirmation'));
|
|
|
+ } else {
|
|
|
+ $form->password('password', trans('admin.password'))
|
|
|
+ ->required()
|
|
|
+ ->rules('confirmed');
|
|
|
+
|
|
|
+ $form->password('password_confirmation', trans('admin.password_confirmation'));
|
|
|
+ }
|
|
|
|
|
|
- $form->ignore(['password_confirmation']);
|
|
|
+ $form->ignore(['password_confirmation']);
|
|
|
|
|
|
- $form->multipleSelect('roles', trans('admin.roles'))
|
|
|
- ->options(function () {
|
|
|
- $roleModel = config('admin.database.roles_model');
|
|
|
+ $form->multipleSelect('roles', trans('admin.roles'))
|
|
|
+ ->options(function () {
|
|
|
+ $roleModel = config('admin.database.roles_model');
|
|
|
|
|
|
- return $roleModel::all()->pluck('name', 'id');
|
|
|
- })
|
|
|
- ->customFormat(function ($v) {
|
|
|
- return array_column($v, 'id');
|
|
|
- });
|
|
|
+ return $roleModel::all()->pluck('name', 'id');
|
|
|
+ })
|
|
|
+ ->customFormat(function ($v) {
|
|
|
+ return array_column($v, 'id');
|
|
|
+ });
|
|
|
|
|
|
- $form->display('created_at', trans('admin.created_at'));
|
|
|
- $form->display('updated_at', trans('admin.updated_at'));
|
|
|
+ $form->display('created_at', trans('admin.created_at'));
|
|
|
+ $form->display('updated_at', trans('admin.updated_at'));
|
|
|
|
|
|
- $form->saving(function (Form $form) {
|
|
|
+ if ($id == AdministratorModel::DEFAULT_ID) {
|
|
|
+ $form->disableDeleteButton();
|
|
|
+ }
|
|
|
+ })->saving(function (Form $form) {
|
|
|
if ($form->password && $form->model()->get('password') != $form->password) {
|
|
|
$form->password = bcrypt($form->password);
|
|
|
}
|
|
@@ -287,12 +289,6 @@ class UserController extends Controller
|
|
|
$form->deleteInput('password');
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- if ($id == AdministratorModel::DEFAULT_ID) {
|
|
|
- $form->disableDeleteButton();
|
|
|
- }
|
|
|
-
|
|
|
- return $form;
|
|
|
}
|
|
|
|
|
|
/**
|