Tasks Module Stage 3: Checklists
- Add migration for task_checklists table - Create TaskChecklistModel with CRUD methods - Add TaskService methods for checklist operations - Add API routes for checklist endpoints - Add controller methods for checklist CRUD - Add UI section in task view with AJAX handlers
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Modules\Tasks\Models\TaskModel;
|
||||
use App\Modules\Tasks\Models\TaskAssigneeModel;
|
||||
use App\Modules\Tasks\Models\TaskColumnModel;
|
||||
use App\Modules\Tasks\Models\TaskSubtaskModel;
|
||||
use App\Modules\Tasks\Models\TaskChecklistModel;
|
||||
use CodeIgniter\Events\Events;
|
||||
|
||||
class TaskService
|
||||
@@ -14,6 +15,7 @@ class TaskService
|
||||
protected TaskAssigneeModel $assigneeModel;
|
||||
protected TaskColumnModel $columnModel;
|
||||
protected TaskSubtaskModel $subtaskModel;
|
||||
protected TaskChecklistModel $checklistModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -21,6 +23,7 @@ class TaskService
|
||||
$this->assigneeModel = new TaskAssigneeModel();
|
||||
$this->columnModel = new TaskColumnModel();
|
||||
$this->subtaskModel = new TaskSubtaskModel();
|
||||
$this->checklistModel = new TaskChecklistModel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,6 +183,9 @@ class TaskService
|
||||
$task['subtasks'] = $this->subtaskModel->getByTask($taskId);
|
||||
$task['subtasks_count'] = count($task['subtasks']);
|
||||
$task['subtasks_completed'] = count(array_filter($task['subtasks'], fn($s) => $s['is_completed']));
|
||||
$task['checklists'] = $this->checklistModel->getByTask($taskId);
|
||||
$task['checklists_count'] = count($task['checklists']);
|
||||
$task['checklists_completed'] = count(array_filter($task['checklists'], fn($c) => $c['is_completed']));
|
||||
|
||||
return $task;
|
||||
}
|
||||
@@ -349,4 +355,83 @@ class TaskService
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ========== Чек-листы (Checklists) ==========
|
||||
|
||||
/**
|
||||
* Добавить элемент чек-листа
|
||||
*/
|
||||
public function addChecklistItem(int $taskId, string $title, int $userId): int
|
||||
{
|
||||
$orderIndex = $this->checklistModel->getNextOrder($taskId);
|
||||
|
||||
$checklistId = $this->checklistModel->insert([
|
||||
'task_id' => $taskId,
|
||||
'title' => trim($title),
|
||||
'order_index' => $orderIndex,
|
||||
]);
|
||||
|
||||
if ($checklistId) {
|
||||
Events::trigger('task.checklist_item_created', $taskId, $checklistId, $userId);
|
||||
}
|
||||
|
||||
return $checklistId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Переключить статус элемента чек-листа
|
||||
*/
|
||||
public function toggleChecklistItem(int $taskId, int $checklistId, int $userId): bool
|
||||
{
|
||||
$checklist = $this->checklistModel->find($checklistId);
|
||||
if (!$checklist || $checklist['task_id'] != $taskId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->checklistModel->toggle($checklistId);
|
||||
|
||||
if ($result) {
|
||||
Events::trigger('task.checklist_item_toggled', $taskId, $checklistId, !$checklist['is_completed'], $userId);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Удалить элемент чек-листа
|
||||
*/
|
||||
public function deleteChecklistItem(int $taskId, int $checklistId, int $userId): bool
|
||||
{
|
||||
$checklist = $this->checklistModel->find($checklistId);
|
||||
if (!$checklist || $checklist['task_id'] != $taskId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->checklistModel->delete($checklistId);
|
||||
|
||||
if ($result) {
|
||||
Events::trigger('task.checklist_item_deleted', $taskId, $checklistId, $userId);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновить элемент чек-листа
|
||||
*/
|
||||
public function updateChecklistItem(int $taskId, int $checklistId, array $data, int $userId): bool
|
||||
{
|
||||
$checklist = $this->checklistModel->find($checklistId);
|
||||
if (!$checklist || $checklist['task_id'] != $taskId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->checklistModel->update($checklistId, $data);
|
||||
|
||||
if ($result) {
|
||||
Events::trigger('task.checklist_item_updated', $taskId, $checklistId, $data, $userId);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user