Add the ability to select a priority when creating a task (low, medium, high)
This commit is contained in:
parent
1c3eeb4cf3
commit
5ce77f2ef0
@ -2,14 +2,10 @@
|
||||
|
||||
namespace backend\modules\task\controllers;
|
||||
|
||||
use backend\modules\project\models\ProjectUser;
|
||||
use backend\modules\task\models\ProjectTaskUser;
|
||||
use common\classes\Debug;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Response;
|
||||
use Yii;
|
||||
use backend\modules\task\models\ProjectTask;
|
||||
use backend\modules\task\models\TaskSearch;
|
||||
use backend\modules\task\models\ProjectTaskSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -43,7 +39,7 @@ class TaskController extends Controller
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new TaskSearch();
|
||||
$searchModel = new ProjectTaskSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
|
@ -10,7 +10,7 @@ use backend\modules\task\models\ProjectTask;
|
||||
/**
|
||||
* TaskSearch represents the model behind the search form of `backend\modules\task\models\Task`.
|
||||
*/
|
||||
class TaskSearch extends ProjectTask
|
||||
class ProjectTaskSearch extends ProjectTask
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -18,7 +18,7 @@ class TaskSearch extends ProjectTask
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id', 'status'], 'integer'], // 'card_id_creator', 'card_id'
|
||||
[['id', 'project_id', 'status', 'priority'], 'integer'], // 'card_id_creator', 'card_id'
|
||||
[['title', 'created_at', 'updated_at', 'description'], 'safe'],
|
||||
];
|
||||
}
|
||||
@ -60,14 +60,15 @@ class TaskSearch extends ProjectTask
|
||||
// grid filtering conditions
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'task.project_id' => $this->project_id,
|
||||
'task.status' => $this->status,
|
||||
'task.created_at' => $this->created_at,
|
||||
'task.updated_at' => $this->updated_at,
|
||||
'project_task.project_id' => $this->project_id,
|
||||
'project_task.status' => $this->status,
|
||||
'project_task.priority' => $this->priority,
|
||||
'project_task.created_at' => $this->created_at,
|
||||
'project_task.updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title])
|
||||
->andFilterWhere(['like', 'task.description', $this->description]);
|
||||
->andFilterWhere(['like', 'project_task.description', $this->description]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\task\models\ProjectTask;
|
||||
use common\helpers\StatusHelper;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
@ -57,7 +58,12 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'description')->textarea(['rows' => '6']) ?>
|
||||
|
||||
<?= $form->field($model, 'priority')->input('number') ?>
|
||||
<?= $form->field($model, 'priority')->dropDownList(
|
||||
ProjectTask::priorityList(),
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
|
||||
|
@ -4,7 +4,7 @@ use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\TaskSearch */
|
||||
/* @var $model backend\modules\task\models\ProjectTaskSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
|
@ -12,7 +12,7 @@ use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\task\models\TaskSearch */
|
||||
/* @var $searchModel backend\modules\task\models\ProjectTaskSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Задачи';
|
||||
@ -58,6 +58,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
return StatusHelper::statusLabel($model->status);
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'priority',
|
||||
'format' => 'raw',
|
||||
'filter' => ProjectTask::priorityList(),
|
||||
'value' => function($model){
|
||||
return ProjectTask::getPriority($model->status);
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'created_at',
|
||||
'format' => ['datetime', 'php:d.m.Y H:i']
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\task\models\ProjectTask;
|
||||
use common\helpers\StatusHelper;
|
||||
use kartik\grid\GridView;
|
||||
use yii\helpers\ArrayHelper;
|
||||
@ -59,7 +60,12 @@ YiiAsset::register($this);
|
||||
'value' => ArrayHelper::getValue($model, 'executor.userCard.fio'),
|
||||
],
|
||||
'description',
|
||||
'priority',
|
||||
[
|
||||
'attribute' => 'priority',
|
||||
'value' => function($model){
|
||||
return ProjectTask::getPriority($model->status);
|
||||
}
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
@ -37,6 +37,32 @@ class ProjectTask extends ActiveRecord
|
||||
const STATUS_ACTIVE = 1;
|
||||
const STATUS_DISABLE = 0;
|
||||
|
||||
const PRIORITY_LOW = 0;
|
||||
const PRIORITY_MEDIUM = 1;
|
||||
const PRIORITY_HIGH = 2;
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function priorityList() :array
|
||||
{
|
||||
return [
|
||||
self::PRIORITY_LOW => 'Низкий',
|
||||
self::PRIORITY_MEDIUM => 'Средний',
|
||||
self::PRIORITY_HIGH => 'Высокий',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $priority
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPriority($priority): string
|
||||
{
|
||||
return ArrayHelper::getValue(self::priorityList(), $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -66,6 +92,7 @@ class ProjectTask extends ActiveRecord
|
||||
[['project_id', 'status', 'title', 'description',], 'required'],
|
||||
[['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'],
|
||||
[['created_at', 'updated_at', 'dead_line'], 'safe'],
|
||||
['status', 'in', 'range' => [self::PRIORITY_LOW, self::PRIORITY_MEDIUM, self::PRIORITY_HIGH]],
|
||||
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['description'], 'string', 'max' => 1500],
|
||||
|
@ -72,7 +72,7 @@ class TaskController extends ApiController
|
||||
* @OA\Property(
|
||||
* property="priority",
|
||||
* type="integer",
|
||||
* description="Приоритет задачи",
|
||||
* description="Приоритет задачи. (0 -low, 1 - medium, 2 - high)",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="column_id",
|
||||
|
Loading…
Reference in New Issue
Block a user