add filters, some improvements

This commit is contained in:
iIronside
2021-12-17 15:16:45 +03:00
parent 994353d557
commit ef0889aac6
13 changed files with 2990 additions and 33 deletions

View File

@ -75,7 +75,7 @@ return [
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'baseUrl' => '', // TODO /secure
'baseUrl' => '/secure',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
'text/xml' => 'yii/web/XmlParser',

View File

@ -109,8 +109,12 @@ class ProjectUserController extends Controller
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
if ($model->load(Yii::$app->request->post()) ) {
$model->card_id = UserCard::getIdByUserId($model->user_id);
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('update', [

View File

@ -39,7 +39,7 @@ class ProjectUserSearch extends ProjectUser
*/
public function search($params)
{
$query = ProjectUser::find()->joinWith(['project', 'user']);
$query = ProjectUser::find()->joinWith(['project', 'user', 'card']);
// add conditions that should always apply here

View File

@ -0,0 +1,45 @@
<?php
use backend\modules\project\models\Project;
use common\models\User;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\project\models\ProjectUser */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="project-user-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'project_id')->widget(Select2::className(),
[
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
) ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(),
[
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true,
'multiple' => false,
],
]
) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -3,6 +3,7 @@
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project;
use common\models\User;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\grid\GridView;
@ -29,18 +30,54 @@ $this->params['breadcrumbs'][] = $this->title;
[
'attribute' => 'project_id',
'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'value' => 'project.name'
'value' => 'project.name',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'project_id',
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '250px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
[
'attribute' => 'user_id',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'value' => 'user.username'
'value' => 'user.username',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'user_id',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '250px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
[
'attribute' => 'card_id',
'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'value' => 'card.fio'
'value' => 'card.fio',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'card_id',
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '250px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
['class' => 'yii\grid\ActionColumn'],

View File

@ -12,7 +12,7 @@ $this->params['breadcrumbs'][] = 'Update';
?>
<div class="project-user-update">
<?= $this->render('_form', [
<?= $this->render('_form_update', [
'model' => $model,
]) ?>

View File

@ -41,7 +41,7 @@ class TaskUserSearch extends TaskUser
*/
public function search($params)
{
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project']);
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project', 'projectUser.user']);
// add conditions that should always apply here

View File

@ -2,6 +2,7 @@
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\grid\GridView;
@ -30,14 +31,38 @@ $this->params['breadcrumbs'][] = $this->title;
[
'attribute' => 'task_id',
'filter' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'value' => 'task.title'
'value' => 'task.title',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'task_id',
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '250px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
[
'attribute' => 'project_user_id',
'filter' => ProjectUser::find()->select(['user.username', 'project_user.id'])
->joinWith('user')->indexBy('project_user.id')->column(),
'value' => 'projectUser.user.username'
'value' => 'projectUser.user.username',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'project_user_id',
'data' => ProjectUser::find()->select(['user.username', 'project_user.id'])
->joinWith('user')->indexBy('project_user.id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '250px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
['class' => 'yii\grid\ActionColumn'],

View File

@ -2,6 +2,7 @@
use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task;
use common\helpers\StatusHelper;
use common\models\User;
use kartik\select2\Select2;
@ -35,7 +36,10 @@ $this->params['breadcrumbs'][] = $this->title;
'model' => $searchModel,
'attribute' => 'project_id',
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'value' => 'project.name',
'pluginOptions' => [
'allowClear' => true,
'width' => '150px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
@ -45,24 +49,37 @@ $this->params['breadcrumbs'][] = $this->title;
'title',
[
'attribute' => 'user_id_creator',
'value' => 'userIdCreator.username',
'value' => 'userIdCreator.username',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'user_id_creator',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'value' => 'userIdCreator.username',
'pluginOptions' => [
'allowClear' => true,
'width' => '150px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
// 'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
],
[
'attribute' => 'user_id',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'value' => 'user.username'
'value' => 'user.username',
'filter' => Select2::widget([
'model' => $searchModel,
'attribute' => 'user_id',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'pluginOptions' => [
'allowClear' => true,
'width' => '150px',
],
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
'description',
[
@ -79,7 +96,6 @@ $this->params['breadcrumbs'][] = $this->title;
],
[
'attribute' => 'updated_at',
'filter' => User::find()->select(['updated_at', 'updated_at'])->indexBy('updated_at')->column(),
'format' => ['datetime', 'php:d.m.Y H:i']
],

View File

@ -27,7 +27,7 @@
['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position'],
['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill'],
],
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
[
'label' => 'Профили', 'icon' => 'address-book-o', 'url' => '#', 'active' => \Yii::$app->controller->id == 'user-card',
@ -39,12 +39,12 @@
['label' => 'Менеджеры', 'icon' => 'user-circle-o', 'url' => ['/employee/manager'], 'active' => \Yii::$app->controller->id == 'manager'],
['label' => 'Работники', 'icon' => 'user', 'url' => ['/employee/manager-employee'], 'active' => \Yii::$app->controller->id == 'manager-employee'],
],
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
[
'label' => 'Проекты', 'icon' => 'cubes', 'url' => ['#'], //'active' => \Yii::$app->controller->id == 'project',
'items' => $projectItems,
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
[
'label' => 'Задачи', 'icon' => 'tasks', 'url' => '#',
@ -53,7 +53,7 @@
['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'],
],
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', 'visible' => Yii::$app->user->can('confidential_information')],
[
@ -62,7 +62,7 @@
['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'],
['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'],
],
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')],
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')],
@ -91,7 +91,7 @@
['label' => 'Анкеты пользователей', 'icon' => 'drivers-license', 'url' => ['/questionnaire/user-questionnaire'], 'active' => \Yii::$app->controller->id == 'user-questionnaire'],
['label' => 'Ответы пользователей', 'icon' => 'comments', 'url' => ['/questionnaire/user-response'], 'active' => \Yii::$app->controller->id == 'user-response'],
],
// TODO 'visible' => Yii::$app->user->can('confidential_information')
'visible' => Yii::$app->user->can('confidential_information')
],
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],