add multi-assignment to tasks and projects

This commit is contained in:
iIronside
2021-12-16 17:14:33 +03:00
parent 27c0951202
commit 994353d557
17 changed files with 10342 additions and 54 deletions

View File

@ -3,6 +3,8 @@
namespace backend\modules\task\controllers;
use backend\modules\project\models\ProjectUser;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\web\Response;
use Yii;
use backend\modules\task\models\TaskUser;
@ -63,41 +65,39 @@ class TaskUserController extends Controller
* Creates a new TaskUser model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
* @throws \Exception
*/
public function actionCreate($task_id = null)
{
$model = new TaskUser();
$post = \Yii::$app->request->post('TaskUser');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (!empty($post)) {
$project_user_id_arr = ArrayHelper::getValue($post, 'project_user_id');
foreach ($project_user_id_arr as $project_user_id) {
$emtModel = new TaskUser();
$emtModel->task_id = $post['task_id'];
$emtModel->project_user_id = $project_user_id;
if (!$emtModel->save()) {
return $this->render('create', [
'model' => $emtModel,
'task_id' => $task_id,
]);
}
}
if ($task_id !== null)
{
return $this->redirect(['task/view', 'id' => $task_id]);
}
return $this->redirect(['view', 'id' => $model->id]);
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
'task_id' => $task_id,
]);
}
/**
* Creates a new TaskUser model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreateForCurrentTask($task_id = null)
{
$model = new TaskUser();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['task/view', 'id' => $task_id]);
}
return $this->render('create_for_current_task', [
return $this->render('create', [
'model' => $model,
'task_id' => $task_id,
]);
@ -185,4 +185,9 @@ class TaskUserController extends Controller
}
return ['output'=>'', 'selected'=>''];
}
public function actionDynamicProjectUser()
{
var_dump('hhh'); die;
}
}

View File

@ -21,19 +21,27 @@ use yii\widgets\ActiveForm;
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
'pluginOptions' => [
'allowClear' => true,
'allowClear' => false,
],
]);
?>
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
[
'options' => ['id' => 'project-user-id'],
'type' => DepDrop::TYPE_SELECT2,
'options' => ['id' => 'project-user-id', 'allowClear' => true, 'multiple' => true], // , 'multiple' => true
'select2Options' => [
'pluginOptions' => [
'allowClear' => true,
'closeOnSelect' => false,
],
'showToggleAll' => false,
],
'pluginOptions' => [
'depends' => ['task-id'],
'placeholder' => 'Выберите',
'initialize' => true,
'url' => Url::to(['/task/task-user/executor'])
'url' => Url::to(['/task/task-user/executor']),
]
]
); ?>

View File

@ -0,0 +1,47 @@
<?php
use backend\modules\task\models\Task;
use kartik\depdrop\DepDrop;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $form yii\widgets\ActiveForm */
/* @var $task_id */
?>
<div class="task-user-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'task_id')->widget(Select2::className(),[
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => 'Выберите проект', 'value' => $task_id, 'id' => 'task-id',],
'pluginOptions' => [
'allowClear' => false,
],
]);
?>
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
[
'options' => ['id' => 'project-user-id', 'allowClear' => true],
'pluginOptions' => [
'depends' => ['task-id'],
'placeholder' => 'Выберите',
'initialize' => true,
'url' => Url::to(['/task/task-user/executor']),
]
]
); ?>
<div class="form-group">
<?= Html::submitButton('Назначить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

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

View File

@ -30,7 +30,7 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'user_id_creator')->widget(Select2::class,
[
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
'pluginOptions' => [
'allowClear' => true,
'prompt' => 'Выберите'

View File

@ -4,6 +4,7 @@ use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use common\helpers\StatusHelper;
use common\models\User;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\grid\GridView;
@ -29,14 +30,34 @@ $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(),
'value' => 'project.name',
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
],
'title',
[
'attribute' => 'user_id_creator',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'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',
'options' => [
'class' => 'form-control',
'placeholder' => 'Выберите значение'
],
])
// 'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
],
[
'attribute' => 'user_id',