From 94df009a988b26e6cdf424bfd6611af101efc946 Mon Sep 17 00:00:00 2001 From: vladfo Date: Tue, 17 Sep 2024 15:39:34 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?utf8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/actions/task/FourColumnsAction.php | 22 +++- erp24/controllers/TaskController.php | 17 +-- erp24/views/task/four-columns.php | 135 +++++++++++++++++++---- 3 files changed, 138 insertions(+), 36 deletions(-) diff --git a/erp24/actions/task/FourColumnsAction.php b/erp24/actions/task/FourColumnsAction.php index aa529e42..686d10c4 100755 --- a/erp24/actions/task/FourColumnsAction.php +++ b/erp24/actions/task/FourColumnsAction.php @@ -12,6 +12,7 @@ use yii_app\records\Admin; use yii_app\records\CompanyFunctions; use yii_app\records\ExportImportTable; use yii_app\records\Task; +use yii_app\records\TaskEntity; use yii_app\records\TaskStatus; use yii_app\services\TaskService; @@ -35,6 +36,7 @@ class FourColumnsAction extends Action return 'fail'; } + $filterModel = DynamicModel::validateData([ 'taskFilter' => '0', 'searchText' => null, 'updatedBy' => '0', 'createdBy' => '0', 'created_at_from' => date("d.m.Y", strtotime("-365 day", time())), @@ -42,12 +44,14 @@ class FourColumnsAction extends Action 'deadline_from' => date("d.m.Y", strtotime("-365 day", time())), 'deadline_to' => date("d.m.Y", strtotime("+365 day", time())), 'company_function_id' => '0', + 'entity_type' => null, // Добавляем свойство entity_type + 'entity_id' => null // Если используется entity_id, добавляем его тоже ], [ [ [ 'taskFilter', 'searchText', 'updatedBy', 'createdBy', 'created_at_from', 'created_at_to', 'deadline_from', 'deadline_to', - 'company_function_id' + 'company_function_id', 'entity_type', 'entity_id', ], 'safe' ] @@ -66,6 +70,11 @@ class FourColumnsAction extends Action } else { $tasksQuery = Task::find(); } + $entityTypesQuery = clone $tasksQuery; + $entityTypes = $entityTypesQuery->select('entity_type')->distinct()->column(); + + // Из таблицы TaskEntity получаем сущности только тех типов, которые есть в задачах. + $taskEntities = TaskEntity::find()->where(['id' => $entityTypes])->all(); if ((int)$filterModel->updatedBy > 0) { $tasksQuery = $tasksQuery->andWhere(['like', 'updated_by', $filterModel->updatedBy]); @@ -75,12 +84,13 @@ class FourColumnsAction extends Action $tasksQuery = $tasksQuery->andWhere(['like', 'created_by', $filterModel->createdBy]); } - if ((int)$filterModel->entity_type > 0) { - $tasksQuery = $tasksQuery->andWhere(['entity_type_id' => $filterModel->entity_type]); + if (!empty($filterModel->entity_type)) { + $entityId = TaskEntity::find()->where(['alias' => $filterModel->entity_type])->one(); + $tasksQuery->andWhere(['entity_type' => $entityId['id']]); } - if ((int)$filterModel->entity_id > 0) { - $tasksQuery = $tasksQuery->andWhere(['entity_id' => $filterModel->entity_id]); + if (!empty($filterModel->entity_id)) { + $tasksQuery->andWhere(['entity_id' => $filterModel->entity_id]); } $tasksQuery = $tasksQuery @@ -139,6 +149,6 @@ class FourColumnsAction extends Action } return $this->controller->render('/task/four-columns', - compact('tasks', 'taskStatuses', 'admins', 'filterModel', 'adminsWithGroup', 'companyFunctions')); + compact('tasks', 'taskStatuses', 'admins', 'filterModel', 'adminsWithGroup', 'companyFunctions', 'taskEntities')); } } \ No newline at end of file diff --git a/erp24/controllers/TaskController.php b/erp24/controllers/TaskController.php index 04f6bb43..b286c4f8 100755 --- a/erp24/controllers/TaskController.php +++ b/erp24/controllers/TaskController.php @@ -4,6 +4,7 @@ declare(strict_types = 1); namespace app\controllers; +use Yii; use yii\helpers\Json; use yii_app\actions\task\CreateRequestAction; use yii_app\actions\task\CreateSupportAction; @@ -12,6 +13,7 @@ use yii_app\actions\task\IndexAction; use yii_app\actions\task\ProofsAction; use yii_app\actions\task\SupportAction; use yii_app\records\TaskSearch; +use yii_app\services\TaskService; class TaskController extends \yii\web\Controller { @@ -29,15 +31,16 @@ class TaskController extends \yii\web\Controller ]; } - public function actionGetEntities() + public function actionFetchEntities() { - if (Yii::$app->request->isAjax) { - $entityTypeId = Yii::$app->request->post('entity_type'); - $entities = Entity::find()->where(['entity_type_id' => $entityTypeId])->all(); + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $alias = Yii::$app->request->post('alias'); - // Вернем JSON ответ с сущностями - Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - return ArrayHelper::map($entities, 'id', 'name'); + if ($alias) { + $entities = TaskService::getEntitiesByAlias($alias); + return $entities; } + + return []; } } \ No newline at end of file diff --git a/erp24/views/task/four-columns.php b/erp24/views/task/four-columns.php index 749100e2..ccea47c5 100755 --- a/erp24/views/task/four-columns.php +++ b/erp24/views/task/four-columns.php @@ -14,6 +14,7 @@ use \yii_app\helpers\PrintBlockHelper; /** @var \yii\base\DynamicModel $filterModel */ /** @var array $adminsWithGroup */ /** @var array $companyFunctions */ +/** @var array $taskEntities */ $this->registerCssFile('/azea/assets/plugins/dragula/dragula.css'); $this->registerJsFile('/azea/assets/plugins/dragula/dragula.js', ['position' => \yii\web\View::POS_END]); @@ -21,12 +22,75 @@ $this->registerJsFile('/js/task/four-columns.js', ['position' => \yii\web\View:: ?> +
+
+

Доска задач

+
+
+ +

Всего задач:

+
+
+ + 'btn btn-success', 'target' => '_blank', 'data-pjax' => '0']) ?> +
+
+ + +
+
+
+ + +
+
+
+ 'filter-form']); ?> -field($filterModel, 'taskFilter')->radioList( +field($filterModel, 'taskFilter')->radioList( + ['0' => 'Мои', '1' => 'На контроле', '2' => 'Участвую', '3' => 'Просматриваю', '4' => 'Неразобранные'], + ['class' => 'form-control', 'onchange' => '$("#filter-form").get(0).submit();'])->label(false)); */?> + + + field($filterModel, 'taskFilter')->radioList( ['0' => 'Мои', '1' => 'На контроле', '2' => 'Участвую', '3' => 'Просматриваю', '4' => 'Неразобранные'], - ['class' => 'form-control', 'onchange' => '$("#filter-form").get(0).submit();'])->label(false)); ?> + ['item' => function($index, $label, $name, $checked, $value) { + // Уникальный ID для каждой кнопки + $id = $name . '_' . $index; + + // Определяем, выбрана ли кнопка + $checkedAttr = $checked ? 'checked' : ''; + + // Возвращаем HTML для одной радио-кнопки с классом btn-check и оберткой + return + Html::radio($name, $checked, [ + 'value' => $value, + 'id' => $id, + 'class' => 'btn-check', + 'autocomplete' => 'off' + ]) . + Html::label($label, $id, ['class' => 'btn btn-secondary']); + }, + + 'class' => 'd-flex btn-group justify-content-center', + 'onchange' => '$("#filter-form").get(0).submit();'])->label(false); ?> + + + + + + +
+
+ +
+
+ + + +