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:
2026-02-08 18:40:41 +00:00
parent bf609257c3
commit 4a67f00aa7
6 changed files with 450 additions and 0 deletions
@@ -614,4 +614,108 @@ class TasksController extends BaseController
'success' => $result,
]);
}
// ========== Чек-листы (Checklists) ==========
/**
* API: добавить элемент чек-листа
*/
public function addChecklistItem(int $taskId)
{
if (!$this->access->canEdit('tasks')) {
return $this->response->setJSON([
'success' => false,
'error' => 'Нет прав для изменения задач'
]);
}
$organizationId = $this->requireActiveOrg();
$userId = $this->getCurrentUserId();
$title = trim($this->request->getPost('title'));
if (empty($title)) {
return $this->response->setJSON([
'success' => false,
'error' => 'Название элемента чек-листа обязательно'
]);
}
// Проверяем что задача принадлежит организации
$task = $this->taskService->getTask($taskId, $organizationId);
if (!$task) {
return $this->response->setJSON([
'success' => false,
'error' => 'Задача не найдена'
]);
}
$checklistId = $this->taskService->addChecklistItem($taskId, $title, $userId);
return $this->response->setJSON([
'success' => (bool) $checklistId,
'checklist_id' => $checklistId,
]);
}
/**
* API: переключить статус элемента чек-листа
*/
public function toggleChecklistItem(int $taskId, int $checklistId)
{
if (!$this->access->canEdit('tasks')) {
return $this->response->setJSON([
'success' => false,
'error' => 'Нет прав для изменения задач'
]);
}
$organizationId = $this->requireActiveOrg();
$userId = $this->getCurrentUserId();
// Проверяем что задача принадлежит организации
$task = $this->taskService->getTask($taskId, $organizationId);
if (!$task) {
return $this->response->setJSON([
'success' => false,
'error' => 'Задача не найдена'
]);
}
$result = $this->taskService->toggleChecklistItem($taskId, $checklistId, $userId);
return $this->response->setJSON([
'success' => $result,
]);
}
/**
* API: удалить элемент чек-листа
*/
public function deleteChecklistItem(int $taskId, int $checklistId)
{
if (!$this->access->canEdit('tasks')) {
return $this->response->setJSON([
'success' => false,
'error' => 'Нет прав для изменения задач'
]);
}
$organizationId = $this->requireActiveOrg();
$userId = $this->getCurrentUserId();
// Проверяем что задача принадлежит организации
$task = $this->taskService->getTask($taskId, $organizationId);
if (!$task) {
return $this->response->setJSON([
'success' => false,
'error' => 'Задача не найдена'
]);
}
$result = $this->taskService->deleteChecklistItem($taskId, $checklistId, $userId);
return $this->response->setJSON([
'success' => $result,
]);
}
}