From 7eab647ff7fd66bf2444b323dbea7924de16f887 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Fri, 12 May 2023 02:12:43 +0300 Subject: [PATCH] task priority, comments --- backend/config/main.php | 3 + backend/modules/comment/Comment.php | 24 ++++ .../comment/controllers/CommentController.php | 127 ++++++++++++++++ .../comment/controllers/DefaultController.php | 20 +++ backend/modules/comment/models/Comment.php | 8 ++ .../modules/comment/models/CommentSearch.php | 75 ++++++++++ .../modules/comment/views/comment/_form.php | 43 ++++++ .../modules/comment/views/comment/_search.php | 43 ++++++ .../modules/comment/views/comment/create.php | 18 +++ .../modules/comment/views/comment/index.php | 37 +++++ .../modules/comment/views/comment/update.php | 21 +++ .../modules/comment/views/comment/view.php | 44 ++++++ .../modules/comment/views/default/index.php | 12 ++ .../task/controllers/TaskController.php | 3 +- backend/modules/task/views/task/_form.php | 2 + backend/modules/task/views/task/view.php | 9 +- common/models/Comment.php | 104 ++++++++++++++ common/models/ProjectTask.php | 5 +- ...133147_create_user_questionnaire_table.php | 2 +- ..._priority_column_at_project_task_table.php | 40 ++++++ .../m230511_205501_create_comment_table.php | 35 +++++ .../api/controllers/CommentController.php | 136 ++++++++++++++++++ .../api/controllers/TaskController.php | 12 +- frontend/modules/api/models/Comment.php | 63 ++++++++ frontend/modules/api/models/ProjectTask.php | 8 +- 25 files changed, 887 insertions(+), 7 deletions(-) create mode 100644 backend/modules/comment/Comment.php create mode 100644 backend/modules/comment/controllers/CommentController.php create mode 100644 backend/modules/comment/controllers/DefaultController.php create mode 100644 backend/modules/comment/models/Comment.php create mode 100644 backend/modules/comment/models/CommentSearch.php create mode 100644 backend/modules/comment/views/comment/_form.php create mode 100644 backend/modules/comment/views/comment/_search.php create mode 100644 backend/modules/comment/views/comment/create.php create mode 100644 backend/modules/comment/views/comment/index.php create mode 100644 backend/modules/comment/views/comment/update.php create mode 100644 backend/modules/comment/views/comment/view.php create mode 100644 backend/modules/comment/views/default/index.php create mode 100644 common/models/Comment.php create mode 100644 console/migrations/m230511_201352_add_priority_column_at_project_task_table.php create mode 100644 console/migrations/m230511_205501_create_comment_table.php create mode 100644 frontend/modules/api/controllers/CommentController.php create mode 100644 frontend/modules/api/models/Comment.php diff --git a/backend/config/main.php b/backend/config/main.php index 373caac..fbf2de7 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -86,6 +86,9 @@ return [ 'knowledgelevel' => [ 'class' => 'backend\modules\knowledgelevel\KnowledgeLevel', ], + 'comment' => [ + 'class' => 'backend\modules\comment\Comment', + ], ], 'components' => [ 'request' => [ diff --git a/backend/modules/comment/Comment.php b/backend/modules/comment/Comment.php new file mode 100644 index 0000000..c27a49a --- /dev/null +++ b/backend/modules/comment/Comment.php @@ -0,0 +1,24 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Comment models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CommentSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Comment model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Comment model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Comment(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Comment model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Comment model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Comment model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Comment the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Comment::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/comment/controllers/DefaultController.php b/backend/modules/comment/controllers/DefaultController.php new file mode 100644 index 0000000..54a65ce --- /dev/null +++ b/backend/modules/comment/controllers/DefaultController.php @@ -0,0 +1,20 @@ +render('index'); + } +} diff --git a/backend/modules/comment/models/Comment.php b/backend/modules/comment/models/Comment.php new file mode 100644 index 0000000..9de91ac --- /dev/null +++ b/backend/modules/comment/models/Comment.php @@ -0,0 +1,8 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + 'user_id' => $this->user_id, + 'parent_id' => $this->parent_id, + 'entity_type' => $this->entity_type, + 'entity_id' => $this->entity_id, + 'status' => $this->status, + ]); + + $query->andFilterWhere(['like', 'text', $this->text]); + + return $dataProvider; + } +} diff --git a/backend/modules/comment/views/comment/_form.php b/backend/modules/comment/views/comment/_form.php new file mode 100644 index 0000000..b064f0a --- /dev/null +++ b/backend/modules/comment/views/comment/_form.php @@ -0,0 +1,43 @@ + + +
+ + + + field($model, 'user_id')->widget( + Select2::class, + [ + 'data' => \common\models\UserCard::getListUserWithUserId(), + 'options' => ['placeholder' => '...', 'class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ] + ); ?> + + field($model, 'parent_id')->textInput() ?> + + field($model, 'entity_type')->dropDownList(\common\models\Comment::getEntityTypeList()) ?> + + field($model, 'entity_id')->textInput() ?> + + field($model, 'status')->dropDownList(\common\models\Comment::getStatusList()) ?> + + field($model, 'text')->textarea(['rows' => 6]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/comment/views/comment/_search.php b/backend/modules/comment/views/comment/_search.php new file mode 100644 index 0000000..d0b98cc --- /dev/null +++ b/backend/modules/comment/views/comment/_search.php @@ -0,0 +1,43 @@ + + + diff --git a/backend/modules/comment/views/comment/create.php b/backend/modules/comment/views/comment/create.php new file mode 100644 index 0000000..b989a3a --- /dev/null +++ b/backend/modules/comment/views/comment/create.php @@ -0,0 +1,18 @@ +title = 'Добавление'; +$this->params['breadcrumbs'][] = ['label' => 'Комментарии', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/comment/views/comment/index.php b/backend/modules/comment/views/comment/index.php new file mode 100644 index 0000000..533a866 --- /dev/null +++ b/backend/modules/comment/views/comment/index.php @@ -0,0 +1,37 @@ +title = 'Комментарии'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'created_at', + 'user_id', + 'entity_type', + //'status', + 'text:ntext', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/comment/views/comment/update.php b/backend/modules/comment/views/comment/update.php new file mode 100644 index 0000000..e2d414b --- /dev/null +++ b/backend/modules/comment/views/comment/update.php @@ -0,0 +1,21 @@ +title = 'Update Comment: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/comment/views/comment/view.php b/backend/modules/comment/views/comment/view.php new file mode 100644 index 0000000..dbbfcf9 --- /dev/null +++ b/backend/modules/comment/views/comment/view.php @@ -0,0 +1,44 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'created_at', + 'updated_at', + 'user_id', + 'parent_id', + 'entity_type', + 'entity_id', + 'status', + 'text:ntext', + ], + ]) ?> + +
diff --git a/backend/modules/comment/views/default/index.php b/backend/modules/comment/views/default/index.php new file mode 100644 index 0000000..75164a6 --- /dev/null +++ b/backend/modules/comment/views/default/index.php @@ -0,0 +1,12 @@ +
+

context->action->uniqueId ?>

+

+ This is the view content for action "context->action->id ?>". + The action belongs to the controller "context) ?>" + in the "context->module->id ?>" module. +

+

+ You may customize this page by editing the following file:
+ +

+
diff --git a/backend/modules/task/controllers/TaskController.php b/backend/modules/task/controllers/TaskController.php index 52e48e2..0d718d2 100644 --- a/backend/modules/task/controllers/TaskController.php +++ b/backend/modules/task/controllers/TaskController.php @@ -4,6 +4,7 @@ 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; @@ -61,7 +62,7 @@ class TaskController extends Controller { $model = $this->findModel($id); $taskDataProvider = new ActiveDataProvider([ - 'query' => $model->getTaskUsers()->with(['task', 'projectUser']), + 'query' => \common\models\ProjectTaskUser::find()->where(['task_id' => $id])->with(['user']), 'pagination' => [ 'pageSize' => 20, ], diff --git a/backend/modules/task/views/task/_form.php b/backend/modules/task/views/task/_form.php index a71fc3c..ac6327b 100644 --- a/backend/modules/task/views/task/_form.php +++ b/backend/modules/task/views/task/_form.php @@ -57,6 +57,8 @@ use yii\widgets\ActiveForm; field($model, 'description')->textarea(['rows' => '6']) ?> + field($model, 'priority')->input('number') ?> +
'btn btn-success']) ?>
diff --git a/backend/modules/task/views/task/view.php b/backend/modules/task/views/task/view.php index 71b8268..c5a1ed6 100644 --- a/backend/modules/task/views/task/view.php +++ b/backend/modules/task/views/task/view.php @@ -54,13 +54,18 @@ YiiAsset::register($this); 'attribute' => 'user_id', 'value' => ArrayHelper::getValue($model, 'user.userCard.fio'), ], + [ + 'attribute' => 'executor_id', + 'value' => ArrayHelper::getValue($model, 'executor.userCard.fio'), + ], 'description', + 'priority', ], ]) ?>

- +

@@ -71,7 +76,7 @@ YiiAsset::register($this); [ 'attribute' => 'project_user_id', - 'value' => 'projectUser.card.fio' + 'value' => 'user.email' ], [ diff --git a/common/models/Comment.php b/common/models/Comment.php new file mode 100644 index 0000000..602b5f2 --- /dev/null +++ b/common/models/Comment.php @@ -0,0 +1,104 @@ + TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'comment'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['created_at', 'updated_at'], 'safe'], + [['user_id', 'parent_id', 'entity_type', 'entity_id', 'status'], 'integer'], + [['text'], 'string'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'created_at' => 'Дата создания', + 'updated_at' => 'Дата редактирования', + 'user_id' => 'Автор', + 'parent_id' => 'Родительский', + 'entity_type' => 'Сущность', + 'entity_id' => 'Идентификатор сущности', + 'status' => 'Статус', + 'text' => 'Текст', + ]; + } + + /** + * @return string[] + */ + public static function getEntityTypeList(): array + { + return [ + self::ENTITY_TYPE_PROJECT => "Проект", + self::ENTITY_TYPE_TASK => "Задача", + ]; + } + + /** + * @return string[] + */ + public static function getStatusList(): array + { + return [ + self::STATUS_ACTIVE => "Активен", + self::STATUS_DISABLE => "Не активен", + ]; + } +} diff --git a/common/models/ProjectTask.php b/common/models/ProjectTask.php index 475cabf..9ce8abe 100644 --- a/common/models/ProjectTask.php +++ b/common/models/ProjectTask.php @@ -20,6 +20,7 @@ use yii\helpers\ArrayHelper; * @property int $column_id * @property int $user_id * @property int $executor_id + * @property int $priority * @property string $description * * @property Project $project @@ -59,7 +60,7 @@ class ProjectTask extends ActiveRecord { return [ [['project_id', 'status', 'title', 'description',], 'required'], - [['project_id', 'status', 'column_id', 'user_id', 'executor_id'], 'integer'], + [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'], [['created_at', 'updated_at'], 'safe'], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], [['title'], 'string', 'max' => 255], @@ -87,6 +88,7 @@ class ProjectTask extends ActiveRecord 'user_id' => 'Создатель задачи', 'column_id' => 'Колонка', 'executor_id' => 'Исполнитель', + 'priority' => 'Приоритет', ]; } @@ -112,6 +114,7 @@ class ProjectTask extends ActiveRecord ]; }, 'executor_id', + 'priority', 'executor' => function () { if ($this->executor){ return [ diff --git a/console/migrations/m211020_133147_create_user_questionnaire_table.php b/console/migrations/m211020_133147_create_user_questionnaire_table.php index d1d0479..092b50d 100644 --- a/console/migrations/m211020_133147_create_user_questionnaire_table.php +++ b/console/migrations/m211020_133147_create_user_questionnaire_table.php @@ -20,7 +20,7 @@ class m211020_133147_create_user_questionnaire_table extends Migration 'created_at' => $this->dateTime(), 'updated_at' => $this->dateTime(), 'score' => $this->integer(), - 'status' => $this->integer(), + 'status' => $this->integer()->defaultValue(1), ]); diff --git a/console/migrations/m230511_201352_add_priority_column_at_project_task_table.php b/console/migrations/m230511_201352_add_priority_column_at_project_task_table.php new file mode 100644 index 0000000..55dd441 --- /dev/null +++ b/console/migrations/m230511_201352_add_priority_column_at_project_task_table.php @@ -0,0 +1,40 @@ +addColumn('project_task', 'priority', $this->integer(2)->defaultValue(1)); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('project_task', 'priority'); + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m230511_201352_add_priority_column_at_project_task_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m230511_205501_create_comment_table.php b/console/migrations/m230511_205501_create_comment_table.php new file mode 100644 index 0000000..7ca937e --- /dev/null +++ b/console/migrations/m230511_205501_create_comment_table.php @@ -0,0 +1,35 @@ +createTable('{{%comment}}', [ + 'id' => $this->primaryKey(), + 'created_at' => $this->dateTime(), + 'updated_at' => $this->dateTime(), + 'user_id' => $this->integer(11), + 'parent_id' => $this->integer(11), + 'entity_type' => $this->integer(2), + 'entity_id' => $this->integer(11), + 'status' => $this->integer(1), + 'text' => $this->text() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%comment}}'); + } +} diff --git a/frontend/modules/api/controllers/CommentController.php b/frontend/modules/api/controllers/CommentController.php new file mode 100644 index 0000000..bee22e3 --- /dev/null +++ b/frontend/modules/api/controllers/CommentController.php @@ -0,0 +1,136 @@ + ['get'], + 'create' => ['post'], + ]; + } + + /** + * + * @OA\Get(path="/comment/get-entity-type-list", + * summary="Список типов сущностей", + * description="Получить список всех возможных типов сущностей", + * tags={"Comment"}, + * security={ + * {"bearerAuth": {}} + * }, + * @OA\Response( + * response=200, + * description="Возвращает массив", + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * type="array", + * @OA\Items( + * @OA\Property( + * property="id", + * type="integer", + * example="1", + * ), + * @OA\Property( + * property="name", + * type="string", + * example="Проект", + * ), + * ) + * ), + * ), + * + * ), + * ) + * + * @return array + */ + public function actionGetEntityTypeList(): array + { + $arr = []; + foreach (Comment::getEntityTypeList() as $key => $value) { + $arr[] = ["id" => $key, "name" => $value]; + } + + return $arr; + } + + /** + * + * @OA\Post(path="/comment/create", + * summary="Добавить комментарий", + * description="Метод для создания комментария", + * security={ + * {"bearerAuth": {}} + * }, + * tags={"Comment"}, + * + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="multipart/form-data", + * @OA\Schema( + * required={"text"}, + * @OA\Property( + * property="text", + * type="string", + * description="Текст комментария", + * ), + * @OA\Property( + * property="entity_type", + * type="integer", + * description="Тип сущности", + * ), + * @OA\Property( + * property="entity_id", + * type="integer", + * description="Идентификатор сущности", + * ), + * @OA\Property( + * property="status", + * type="integer", + * description="Статус комментария", + * ), + * ), + * ), + * ), + * @OA\Response( + * response=200, + * description="Возвращает объект комментария", + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema(ref="#/components/schemas/Comment"), + * ), + * ), + * ) + * + * @return array|Comment + * @throws BadRequestHttpException + */ + public function actionCreate() + { + $model = new Comment(); + $request = \Yii::$app->request->post(); + + $user_id = \Yii::$app->user->id; + if (!$user_id) { + throw new BadRequestHttpException(json_encode(['User not found'])); + } + + $request['user_id'] = $user_id; + + $model->load($request, ''); + + if (!$model->save()){ + return $model->errors; + } + + return $model; + } + +} \ No newline at end of file diff --git a/frontend/modules/api/controllers/TaskController.php b/frontend/modules/api/controllers/TaskController.php index 2d80c55..7de4774 100644 --- a/frontend/modules/api/controllers/TaskController.php +++ b/frontend/modules/api/controllers/TaskController.php @@ -59,6 +59,11 @@ class TaskController extends ApiController * description="статус", * ), * @OA\Property( + * property="priority", + * type="integer", + * description="Приоритет задачи", + * ), + * @OA\Property( * property="column_id", * type="integer", * description="Колонка к которой относится задача", @@ -275,9 +280,14 @@ class TaskController extends ApiController * description="Идентификатор колонки", * ), * @OA\Property( + * property="priority", + * type="integer", + * description="Приоритет задачи", + * ), + * @OA\Property( * property="status", * type="integer", - * description="Статус запроса", + * description="Статус задачи", * ), * @OA\Property( * property="description", diff --git a/frontend/modules/api/models/Comment.php b/frontend/modules/api/models/Comment.php new file mode 100644 index 0000000..0d9e2d5 --- /dev/null +++ b/frontend/modules/api/models/Comment.php @@ -0,0 +1,63 @@ +