re #25 allow rules edition + assignment

This commit is contained in:
Antonio Ramirez
2017-07-16 02:28:34 +02:00
parent f706ebb4fa
commit 84b009c5f0
17 changed files with 614 additions and 20 deletions

View File

@ -10,6 +10,7 @@
*/
use dosamigos\selectize\SelectizeDropDownList;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@ -32,7 +33,13 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'description') ?>
<?= $form->field($model, 'rule') ?>
<?= $form->field($model, 'rule')->widget(SelectizeDropDownList::class, [
'items' => ArrayHelper::map(Yii::$app->getAuthManager()->getRules(), 'name', 'name'),
'options' => [
'prompt' => 'Select rule...'
]
]) ?>
<?= $form->field($model, 'children')->widget(
SelectizeDropDownList::class,

View File

@ -16,6 +16,7 @@
use Da\User\Helper\AuthHelper;
use dosamigos\selectize\SelectizeDropDownList;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@ -33,7 +34,12 @@ $unassignedItems = Yii::$container->get(AuthHelper::class)->getUnassignedItems($
<?= $form->field($model, 'description') ?>
<?= $form->field($model, 'rule') ?>
<?= $form->field($model, 'rule')->widget(SelectizeDropDownList::class, [
'items' => ArrayHelper::map(Yii::$app->getAuthManager()->getRules(), 'name', 'name'),
'options' => [
'prompt' => 'Select rule...'
]
]) ?>
<?= $form->field($model, 'children')->widget(
SelectizeDropDownList::class,

View File

@ -0,0 +1,27 @@
<?php
/**
* @var $this yii\web\View
* @var $model \Da\User\Model\Rule
*/
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(
[
'enableClientValidation' => false,
'enableAjaxValidation' => true,
]
) ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'className') ?>
<?= Html::submitButton(Yii::t('usuario', 'Save'), ['class' => 'btn btn-success btn-block']) ?>
<?php ActiveForm::end() ?>

View File

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
/**
* @var \Da\User\Model\Role $model
* @var $this yii\web\View
* @var $unassignedItems string[]
*/
$this->title = Yii::t('usuario', 'Create new rule');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginContent('@Da/User/resources/views/shared/admin_layout.php') ?>
<?= $this->render(
'_form',
[
'model' => $model,
]
) ?>
<?php $this->endContent() ?>

View File

@ -0,0 +1,76 @@
<?php
use yii\grid\ActionColumn;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\rbac\Rule;
/**
* @var $dataProvider \yii\data\ActiveDataProvider
* @var $searchModel \Da\User\Search\RuleSearch
* @var $this yii\web\View
*/
$this->title = Yii::t('usuario', 'Rules');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginContent('@Da/User/resources/views/shared/admin_layout.php') ?>
<?= GridView::widget(
[
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => "{items}\n{pager}",
'columns' => [
[
'attribute' => 'name',
'label' => Yii::t('usuario', 'Name'),
'options' => [
'style' => 'width: 20%'
],
],
[
'attribute' => 'className',
'label' => Yii::t('usuario', 'Class'),
'value' => function ($row) {
$rule = unserialize($row['data']);
return get_class($rule);
},
'options' => [
'style' => 'width: 20%'
],
],
[
'attribute' => 'created_at',
'label' => Yii::t('usuario', 'Created at'),
'format' => 'datetime',
'options' => [
'style' => 'width: 20%'
],
],
[
'attribute' => 'updated_at',
'label' => Yii::t('usuario', 'Updated at'),
'format' => 'datetime',
'options' => [
'style' => 'width: 20%'
],
],
[
'class' => ActionColumn::className(),
'template' => '{update} {delete}',
'urlCreator' => function ($action, $model) {
return Url::to(['/user/rule/' . $action, 'name' => $model['name']]);
},
'options' => [
'style' => 'width: 5%'
],
]
],
]
) ?>
<?php $this->endContent() ?>

View File

@ -0,0 +1,32 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
/**
* @var \Da\User\Model\Role $model
* @var $this yii\web\View
* @var $unassignedItems string[]
*/
$this->title = Yii::t('usuario', 'Update rule');
$this->params['breadcrumbs'][] = ['label' => Yii::t('usuario', 'Rules'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginContent('@Da/User/resources/views/shared/admin_layout.php') ?>
<?= $this->render(
'_form',
[
'model' => $model,
]
) ?>
<?php $this->endContent() ?>

View File

@ -32,6 +32,10 @@ use yii\bootstrap\Nav;
'label' => Yii::t('usuario', 'Permissions'),
'url' => ['/user/permission/index'],
],
[
'label' => Yii::t('usuario', 'Rules'),
'url' => ['/user/rule/index'],
],
[
'label' => Yii::t('usuario', 'Create'),
'items' => [
@ -47,6 +51,10 @@ use yii\bootstrap\Nav;
'label' => Yii::t('usuario', 'New permission'),
'url' => ['/user/permission/create'],
],
[
'label' => Yii::t('usuario', 'New rule'),
'url' => ['/user/rule/create'],
],
],
],
],