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

@ -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']
],