ticketsService = $ticketsService; $this->dashboardService = $dashboardService; } /** * Retrieves the todo widget assignments. * * @return void */ public function get() { $params = $this->incomingRequest->query->all(); // Set initial pagination - only load first page of tasks per group if (! isset($params['limit'])) { $params['limit'] = $this->limit; } $tplVars = $this->dashboardService->getToDoWidgetData((int) session('userdata.id'), $params); $this->tpl->assign('limit', $tplVars['limit']); array_map([$this->tpl, 'assign'], array_keys($tplVars), array_values($tplVars)); } /** * Save the user's personal task sorting preferences. * * @param mixed $params The sort items posted by the request. */ public function saveSorting($params) { $post = $this->incomingRequest->request->all(); if (is_array($params)) { unset($params['act']); } $result = $this->dashboardService->saveTodoSorting( (int) session('userdata.id'), $params, $post['groupChanges'] ?? [], $post['groupBy'] ?? '' ); if ($result['successCount'] > 0 && $result['errorCount'] === 0) { $this->tpl->setNotification($this->language->__('short_notifications.group_changes_applied'), 'success'); } elseif ($result['successCount'] > 0 && $result['errorCount'] > 0) { $this->tpl->setNotification($this->language->__('short_notifications.group_changes_partial'), 'warning'); } elseif ($result['errorCount'] > 0) { $this->tpl->setNotification($this->language->__('short_notifications.group_changes_failed'), 'error'); } if (! $result['sorted']) { $this->tpl->setNotification($this->language->__('short_notifications.sorting_error'), 'error'); } } /** * Toggle the collapse state of a task. * * @param array $params Request parameters containing the taskId. * @return string|void The new collapse state when a taskId is provided. */ public function toggleTaskCollapse($params) { if (isset($params['taskId'])) { return $this->dashboardService->toggleTaskCollapse((int) session('userdata.id'), $params['taskId']); } } /** * Update task status via HTMX. */ public function updateStatus() { $params = $this->incomingRequest->request->all(); if (isset($params['id']) && isset($params['status'])) { $result = $this->ticketsService->patch($params['id'], ['status' => $params['status']]); if ($result) { $this->tpl->setNotification($this->language->__('short_notifications.status_updated'), 'success'); } else { $this->tpl->setNotification($this->language->__('short_notifications.status_update_error'), 'error'); } } } /** * Update task milestone via HTMX. */ public function updateMilestone() { $params = $this->incomingRequest->request->all(); if (isset($params['id']) && isset($params['milestoneId'])) { $result = $this->ticketsService->patch($params['id'], ['milestoneid' => $params['milestoneId']]); if ($result) { $this->tpl->setNotification($this->language->__('short_notifications.milestone_updated'), 'success'); } else { $this->tpl->setNotification($this->language->__('short_notifications.milestone_update_error'), 'error'); } } } /** * Update task due date via HTMX. */ public function updateDueDate() { $params = $this->incomingRequest->request->all(); if (isset($params['id']) && isset($params['date'])) { $result = $this->ticketsService->patch($params['id'], ['dateToFinish' => $params['date']]); if ($result) { $this->tpl->setNotification($this->language->__('short_notifications.date_updated'), 'success'); } else { $this->tpl->setNotification($this->language->__('short_notifications.date_update_error'), 'error'); } } } /** * Update task title via HTMX. * * @param array $params Request parameters containing id and headline. * @return mixed The raw rendered headline when an id and headline are provided. */ public function updateTitle($params) { if (isset($params['id']) && isset($params['headline'])) { $headline = $params['headline']; $result = $this->ticketsService->patch($params['id'], ['headline' => $headline]); if ($result) { $this->tpl->setNotification($this->language->__('short_notifications.title_updated'), 'success'); } else { $this->tpl->setNotification($this->language->__('short_notifications.title_update_error'), 'error'); } return $this->tpl->displayRaw("{$headline}"); } } /** * Handle subtask creation. */ public function addSubtask() { $params = $this->incomingRequest->request->all(); $getParams = $this->incomingRequest->query->all(); if ($this->dashboardService->addSubtask($params, (int) $getParams['ticketId'])) { $this->tpl->setNotification($this->language->__('notifications.subtask_saved'), 'success'); } else { $this->tpl->setNotification($this->language->__('notifications.subtask_save_error'), 'error'); } // Refresh the todo widget $tplVars = $this->ticketsService->getToDoWidgetHierarchicalAssignments($params); array_map([$this->tpl, 'assign'], array_keys($tplVars), array_values($tplVars)); } /** * Quick-add a to-do and refresh the widget. */ public function addTodo() { $params = $this->incomingRequest->request->all(); if (AuthService::userHasRole([Roles::$owner, Roles::$manager, Roles::$editor])) { if (isset($params['quickadd']) == true) { $result = $this->dashboardService->addTodo($params); if (isset($result['status'])) { $this->tpl->setNotification($result['message'], $result['status']); } else { $this->tpl->setNotification($this->language->__('notifications.ticket_saved'), 'success'); } $this->tpl->setHTMXEvent('HTMX.ShowNotification'); } } $tplVars = $this->ticketsService->getToDoWidgetHierarchicalAssignments($params); array_map([$this->tpl, 'assign'], array_keys($tplVars), array_values($tplVars)); } /** * Load more todos for infinite scroll. */ public function loadMore() { $params = $this->incomingRequest->query->all(); $tplVars = $this->dashboardService->getToDoWidgetLoadMoreData((int) session('userdata.id'), $params, $this->limit); $this->tpl->assign('limit', $tplVars['limit']); array_map([$this->tpl, 'assign'], array_keys($tplVars), array_values($tplVars)); } }