From 765b1592f61b7df33add9a3afcf8d4221d0e3a75 Mon Sep 17 00:00:00 2001 From: apexwire Date: Mon, 18 Dec 2017 20:31:32 +0300 Subject: [PATCH] Update item select and others: - AssignmentController. Add comment. Remove duplicate lines: 'assign' => ['post']. - Assignment and AuthItem. Update getItems(). getItems() return array with parametr 'description' to display the list of items - in ./views/assignnets/view.php and ./views/item/view.php add $labels - localization support js. Update _script.js too. --- controllers/AssignmentController.php | 3 +- models/Assignment.php | 18 +++++--- models/AuthItem.php | 23 +++++++--- views/assignment/_script.js | 12 +++-- views/assignment/view.php | 31 +++++++------ views/item/_script.js | 14 ++++-- views/item/view.php | 68 +++++++++++++++------------- 7 files changed, 102 insertions(+), 67 deletions(-) diff --git a/controllers/AssignmentController.php b/controllers/AssignmentController.php index e4921d95..53518ba3 100644 --- a/controllers/AssignmentController.php +++ b/controllers/AssignmentController.php @@ -17,6 +17,7 @@ */ class AssignmentController extends Controller { + /** @type \yii\web\IdentityInterface */ public $userClassName; public $idField = 'id'; public $usernameField = 'username'; @@ -45,7 +46,6 @@ public function behaviors() 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ - 'assign' => ['post'], 'assign' => ['post'], 'revoke' => ['post'], ], @@ -59,7 +59,6 @@ public function behaviors() */ public function actionIndex() { - if ($this->searchClass === null) { $searchModel = new AssignmentSearch; $dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams(), $this->userClassName, $this->usernameField); diff --git a/models/Assignment.php b/models/Assignment.php index c677bd0c..8338e021 100644 --- a/models/Assignment.php +++ b/models/Assignment.php @@ -26,7 +26,7 @@ class Assignment extends \mdm\admin\BaseObject /** * @inheritdoc */ - public function __construct($id, $user = null, $config = array()) + public function __construct($id, $user = null, $config = []) { $this->id = $id; $this->user = $user; @@ -87,13 +87,19 @@ public function getItems() { $manager = Configs::authManager(); $available = []; - foreach (array_keys($manager->getRoles()) as $name) { - $available[$name] = 'role'; + foreach ($manager->getRoles() as $item) { + $avaliable[$item->name] = [ + 'type' => 'role', + 'desc' => $item->description, + ]; } - foreach (array_keys($manager->getPermissions()) as $name) { - if ($name[0] != '/') { - $available[$name] = 'permission'; + foreach ($manager->getPermissions() as $item) { + if ($item->name[0] != '/') { + $avaliable[$item->name] = [ + 'type' => 'permission', + 'desc' => $item->description, + ]; } } diff --git a/models/AuthItem.php b/models/AuthItem.php index 79813675..05d33b35 100644 --- a/models/AuthItem.php +++ b/models/AuthItem.php @@ -37,7 +37,7 @@ class AuthItem extends Model /** * Initialize object - * @param Item $item + * @param Item $item * @param array $config */ public function __construct($item = null, $config = []) @@ -248,17 +248,28 @@ public function getItems() $manager = Configs::authManager(); $available = []; if ($this->type == Item::TYPE_ROLE) { - foreach (array_keys($manager->getRoles()) as $name) { - $available[$name] = 'role'; + foreach ($manager->getRoles() as $item) { + $avaliable[$item->name] = [ + 'type' => 'role', + 'desc' => $item->description, + ]; } } - foreach (array_keys($manager->getPermissions()) as $name) { - $available[$name] = $name[0] == '/' ? 'route' : 'permission'; + foreach ($manager->getPermissions() as $item) { + $avaliable[$item->name] = [ + 'type' => $item->name[0] == '/' ? 'route' : 'permission', + ]; + if ($item->name[0] != '/') { + $avaliable[$item->name]['desc'] = $item->description; + } } $assigned = []; foreach ($manager->getChildren($this->_item->name) as $item) { - $assigned[$item->name] = $item->type == 1 ? 'role' : ($item->name[0] == '/' ? 'route' : 'permission'); + $assigned[$item->name] = [ + 'type' => $item->type == 1 ? 'role' : ($item->name[0] == '/' ? 'route' : 'permission'), + 'desc' => $item->description, + ]; unset($available[$item->name]); } unset($available[$this->name]); diff --git a/views/assignment/_script.js b/views/assignment/_script.js index deb2d541..0c0e5541 100644 --- a/views/assignment/_script.js +++ b/views/assignment/_script.js @@ -32,13 +32,17 @@ function search(target) { var q = $('.search[data-target="' + target + '"]').val(); var groups = { - role: [$(''), false], - permission: [$(''), false], + role: [$(''), false], + permission: [$(''), false], }; $.each(_opts.items[target], function (name, group) { if (name.indexOf(q) >= 0) { - $('