changed the creator for tasks from project_user to user, fixed api, documentation, filters, some other fixes

This commit is contained in:
iIronside
2021-12-06 15:13:31 +03:00
parent daae8b16b6
commit e78ff7d779
23 changed files with 6024 additions and 117 deletions

View File

@ -137,25 +137,4 @@ class TaskController extends Controller
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionCreator()
{
Yii::$app->response->format = Response::FORMAT_JSON;
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$project_id = $parents[0];
$users = ProjectUser::usersByProjectArr($project_id);
$formattedUsersArr = array();
foreach ($users as $key => $value){
$formattedUsersArr[] = array('id' => $key, 'name' => $value);
}
return ['output'=>$formattedUsersArr, 'selected'=>''];
}
}
return ['output'=>'', 'selected'=>''];
}
}

View File

@ -64,16 +64,42 @@ class TaskUserController extends Controller
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
public function actionCreate($task_id = null)
{
$model = new TaskUser();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($task_id !== null)
{
return $this->redirect(['task/view', 'id' => $task_id]);
}
return $this->redirect(['view', 'id' => $model->id]);
}
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', [
'model' => $model,
'task_id' => $task_id,
]);
}
@ -84,16 +110,23 @@ class TaskUserController extends Controller
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
public function actionUpdate($id, $task_id = null)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($task_id !== null)
{
return $this->redirect(['task/view', 'id' => $task_id]);
}
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'task_id' => $task_id === null ? $model->task_id: $task_id,
]);
}
@ -104,10 +137,15 @@ class TaskUserController extends Controller
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
public function actionDelete($id, $task_id = null)
{
$this->findModel($id)->delete();
if ($task_id !== null)
{
return $this->redirect(['task/view', 'id' => $task_id]);
}
return $this->redirect(['index']);
}

View File

@ -2,6 +2,7 @@
namespace backend\modules\task\models;
use backend\modules\project\models\ProjectUser;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\task\models\Task;
@ -17,7 +18,7 @@ class TaskSearch extends Task
public function rules()
{
return [
[['id', 'project_id', 'status', 'project_user_id', 'user_id'], 'integer'],
[['id', 'project_id', 'status', 'user_id_creator', 'user_id'], 'integer'],
[['title', 'created_at', 'updated_at', 'description'], 'safe'],
];
}
@ -40,7 +41,10 @@ class TaskSearch extends Task
*/
public function search($params)
{
$query = Task::find()->joinWith(['user', 'project', 'projectUser.user']);
$query = Task::find()->joinWith(['user', 'project']);
// => function($query){
// $query->from(ProjectUser::tableName() . ' pt');
// }]); //,
// add conditions that should always apply here
@ -59,16 +63,16 @@ class TaskSearch extends Task
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'project_id' => $this->project_id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'project_user_id' => $this->project_user_id,
'user_id' => $this->user_id,
'task.project_id' => $this->project_id,
'task.status' => $this->status,
'task.created_at' => $this->created_at,
'task.updated_at' => $this->updated_at,
'user_id_creator' => $this->user_id_creator,
'task.user_id' => $this->user_id,
]);
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'description', $this->description]);
->andFilterWhere(['like', 'task.description', $this->description]);
return $dataProvider;
}

View File

@ -11,6 +11,7 @@ use backend\modules\task\models\TaskUser;
*/
class TaskUserSearch extends TaskUser
{
public $projectId;
/**
* {@inheritdoc}
*/
@ -18,6 +19,7 @@ class TaskUserSearch extends TaskUser
{
return [
[['id', 'task_id', 'project_user_id'], 'integer'],
[['projectId'], 'safe']
];
}
@ -39,7 +41,7 @@ class TaskUserSearch extends TaskUser
*/
public function search($params)
{
$query = TaskUser::find()->joinWith(['task', 'projectUser']);
$query = TaskUser::find()->joinWith(['task', 'projectUser', 'projectUser.project']);
// add conditions that should always apply here
@ -59,9 +61,11 @@ class TaskUserSearch extends TaskUser
$query->andFilterWhere([
'id' => $this->id,
'task_id' => $this->task_id,
'project_user_id' => $this->project_user_id,
'task_user.project_user_id' => $this->project_user_id,
]);
$query->andFilterWhere(['like', 'project.id', $this->projectId]);
return $dataProvider;
}
}

View File

@ -2,6 +2,7 @@
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;
@ -9,19 +10,20 @@ 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')->dropDownList(Task::find()
->select(['title', 'id'])->indexBy('id')->column(),
[
'id' => 'task-id',
'prompt' => 'Выберите'
]
);
<?= $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' => true,
],
]);
?>
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
@ -30,13 +32,14 @@ use yii\widgets\ActiveForm;
'pluginOptions' => [
'depends' => ['task-id'],
'placeholder' => 'Выберите',
'initialize' => true,
'url' => Url::to(['/task/task-user/executor'])
]
]
); ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
<?= Html::submitButton('Назначить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>

View File

@ -0,0 +1,35 @@
<?php
use backend\modules\project\models\Project;
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUserSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="question-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'projectId')->widget(Select2::className(),[
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => 'Выберите проект'],
'pluginOptions' => [
'allowClear' => true
],
])->label('Проект') ?>
<div class="form-group">
<?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -3,6 +3,7 @@
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $task_id */
$this->title = 'Назначить сотрудника';
$this->params['breadcrumbs'][] = ['label' => 'Task Users', 'url' => ['index']];
@ -12,6 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $this->render('_form', [
'model' => $model,
'task_id' => $task_id,
]) ?>
</div>

View File

@ -2,7 +2,6 @@
use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\grid\GridView;
@ -19,6 +18,10 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a('Назначить сотрудника', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= $this->render('_search_by_project', [
'model' => $searchModel,
]) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,

View File

@ -1,9 +1,9 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\task\models\TaskUser */
/* @var $task_id */
$this->title = 'Изменить назначение';
$this->params['breadcrumbs'][] = ['label' => 'Task Users', 'url' => ['index']];
@ -14,6 +14,7 @@ $this->params['breadcrumbs'][] = 'Update';
<?= $this->render('_form', [
'model' => $model,
'task_id' => $task_id,
]) ?>
</div>

View File

@ -3,6 +3,7 @@
use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use common\helpers\StatusHelper;
use common\models\User;
use kartik\depdrop\DepDrop;
use kartik\select2\Select2;
use yii\helpers\Html;
@ -21,20 +22,19 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'project_id')->dropDownList(Project::find()
->select(['name', 'id'])->indexBy('id')->column(),
[
'id' => 'project-id',
'prompt' => 'Выберите'
]
);
?>
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
<?= $form->field($model, 'user_id_creator')->widget(Select2::class,
[
'options' => ['id' => 'project-user-id'],
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'depends' => ['project-id'],
'placeholder' => 'Выберите',
'url' => Url::to(['/task/task/creator'])
]
'allowClear' => true,
'prompt' => 'Выберите'
],
]
); ?>
@ -47,12 +47,21 @@ use yii\widgets\ActiveForm;
]
) ?>
<?= $form->field($model, 'user_id')->textInput() ?>
<?= $form->field($model, 'user_id')->widget(Select2::class,
[
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true,
'prompt' => 'Выберите'
],
]
); ?>
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'description')->textarea(['rows' => '6']) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>

View File

@ -29,14 +29,14 @@ $this->params['breadcrumbs'][] = $this->title;
[
'attribute' => 'project_id',
'filter' => ArrayHelper::map(Project::find()->all(), 'id', 'name'),
'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
'value' => 'project.name'
],
'title',
[
'attribute' => 'project_user_id',
'filter' => ProjectUser::find()->select(['username', 'project_user.id'])->joinWith('user')->indexBy('id')->column(),
'value' => 'projectUser.user.username'
'attribute' => 'user_id_creator',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'value' => 'userIdCreator.username'
],
[
'attribute' => 'user_id',
@ -48,12 +48,19 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'status',
'format' => 'raw',
'filter' => StatusHelper::statusList(),
'value' => function ($model) {
'value' => function($model){
return StatusHelper::statusLabel($model->status);
},
}
],
[
'attribute' => 'created_at',
'format' => ['datetime', 'php:d.m.Y H:i']
],
[
'attribute' => 'updated_at',
'filter' => User::find()->select(['updated_at', 'updated_at'])->indexBy('updated_at')->column(),
'format' => ['datetime', 'php:d.m.Y H:i']
],
'created_at',
'updated_at',
['class' => 'yii\grid\ActionColumn'],
],

View File

@ -69,17 +69,43 @@ YiiAsset::register($this);
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'task_id', // ArrayHelper::map(Task::find()->all(), 'id', 'title'),
'value' => 'task.title'
],
[
'attribute' => 'project_user_id',
'value' => 'projectUser.user.username'
],
['class' => 'yii\grid\ActionColumn'],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} {delete}',
'controller' => 'task-user',
'buttons' => [
'update' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-pencil"></span>',
['task-user/update', 'id' => $model['id'], 'task_id' => $model['task_id']]);
},
'delete' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
[
'task-user/delete', 'id' => $model['id'], 'task_id' => $model['task_id']
],
[
'data' => ['confirm' => 'Вы уверены, что хотите удалить этого сотрудника?', 'method' => 'post']
]
);
},
],
],
],
]); ?>
<p>
<?= Html::a(
'Назначить исполнителя',
['task-user/create', 'task_id' => $model->id],
['class' => 'btn btn-primary']
) ?>
</p>
</div>