| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentBoards\App\Http\Controllers; |
| 4 | 4 | |
| 5 | +use FluentBoards\Framework\Database\Orm\ModelNotFoundException; | |
| 5 | 6 | use FluentBoards\App\Models\Meta; |
| 6 | 7 | use FluentBoards\App\Models\Stage; |
| 7 | 8 | use FluentBoards\App\Models\Task; |
| 8 | 9 | use FluentBoards\App\Models\Board; |
| @@ -61,10 +62,12 @@ | ||
| 61 | 62 | 'counts' => $taskCounts, |
| 62 | 63 | ]; |
| 63 | 64 | } |
| 64 | 65 | |
| 66 | + /** Return all board tasks with a cursor captured before reading their state. */ | |
| 65 | 67 | public function getTasksByBoard(Request $request, $board_id) |
| 66 | 68 | { |
| 69 | + $syncStartedAt = current_time('mysql'); | |
| 67 | 70 | $board_id = absint($board_id); |
| 68 | 71 | $board = Board::findOrFail($board_id); |
| 69 | 72 | $includeArchived = $request->getSafe('include_archived', 'boolval', false); |
| 70 | 73 | |
| @@ -92,13 +95,16 @@ | ||
| 92 | 95 | } |
| 93 | 96 | |
| 94 | 97 | return [ |
| 95 | 98 | 'tasks' => $tasks, |
| 99 | + 'synced_at' => $syncStartedAt, | |
| 96 | 100 | ]; |
| 97 | 101 | } |
| 98 | 102 | |
| 103 | + /** Fetch each stage's first page, then batch metadata for the combined card list. */ | |
| 99 | 104 | public function getTasksByBoardStage(Request $request, $board_id) |
| 100 | 105 | { |
| 106 | + $syncStartedAt = current_time('mysql'); | |
| 101 | 107 | $board_id = absint($board_id); |
| 102 | 108 | $board = Board::findOrFail($board_id); |
| 103 | 109 | $includeArchived = $request->getSafe('include_archived', 'boolval', false); |
| 104 | 110 | |
| @@ -116,15 +122,9 @@ | ||
| 116 | 122 | ->orderBy('position', 'ASC') |
| 117 | 123 | ->limit(20) |
| 118 | 124 | ->get(); |
| 119 | 125 | |
| 120 | - // Process each stage's tasks | |
| 121 | - $this->processTasks($stageTasks, $board, [ | |
| 122 | - 'includeContact' => false, | |
| 123 | - 'includeObserverState' => false, | |
| 124 | - 'includeRoadmapPopularity' => false, | |
| 125 | - ]); | |
| 126 | - $tasks = array_merge($tasks, $stageTasks->toArray()); // Merge with the main task list | |
| 126 | + $tasks = array_merge($tasks, $stageTasks->all()); | |
| 127 | 127 | |
| 128 | 128 | $startCursor = $stageTasks->count() ? (float) $stageTasks->first()->position : null; |
| 129 | 129 | $endCursor = $stageTasks->count() ? (float) $stageTasks->last()->position : null; |
| 130 | 130 | $loadedCount = $stageTasks->count(); |
| @@ -143,14 +143,22 @@ | ||
| 143 | 143 | 'end_cursor' => $endCursor, |
| 144 | 144 | ]; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | + $this->processTasks($tasks, $board, [ | |
| 148 | + 'includeContact' => false, | |
| 149 | + 'includeObserverState' => false, | |
| 150 | + 'includeRoadmapPopularity' => false, | |
| 151 | + ]); | |
| 152 | + | |
| 147 | 153 | return [ |
| 148 | - 'tasks' => $tasks, | |
| 154 | + 'tasks' => (new Task())->newCollection($tasks)->toArray(), | |
| 149 | 155 | 'pagination_by_stage' => $paginationByStage, |
| 156 | + 'synced_at' => $syncStartedAt, | |
| 150 | 157 | ]; |
| 151 | 158 | } |
| 152 | 159 | |
| 160 | + /** Return paginated tasks matching the board filters, including recurrence and templates. */ | |
| 153 | 161 | public function getTableTasks(Request $request, $board_id) |
| 154 | 162 | { |
| 155 | 163 | $board_id = absint($board_id); |
| 156 | 164 | $board = Board::findOrFail($board_id); |
| @@ -162,8 +170,10 @@ | ||
| 162 | 170 | 'search' => $request->getSafe('search', 'sanitize_text_field', ''), |
| 163 | 171 | 'include_archived' => $request->getSafe('include_archived', 'boolval', false), |
| 164 | 172 | 'stage' => $request->get('stage', []), |
| 165 | 173 | 'task_status' => $request->get('task_status', []), |
| 174 | + 'recurring' => $request->get('recurring', []), | |
| 175 | + 'template' => $request->get('template', []), | |
| 166 | 176 | 'priority' => $request->get('priority', []), |
| 167 | 177 | 'assignee' => $request->get('assignee', []), |
| 168 | 178 | 'labels' => $request->get('labels', []), |
| 169 | 179 | 'watchers' => $request->get('watchers', []), |
| @@ -190,8 +200,9 @@ | ||
| 190 | 200 | ], |
| 191 | 201 | ], 200); |
| 192 | 202 | } |
| 193 | 203 | |
| 204 | + /** Return board tasks matching the requested filters, including recurrence and templates. */ | |
| 194 | 205 | public function getFilteredBoardTasks(Request $request, $board_id) |
| 195 | 206 | { |
| 196 | 207 | $board_id = absint($board_id); |
| 197 | 208 | $board = Board::findOrFail($board_id); |
| @@ -199,8 +210,10 @@ | ||
| 199 | 210 | 'search' => $request->getSafe('search', 'sanitize_text_field', ''), |
| 200 | 211 | 'include_archived' => $request->getSafe('include_archived', 'boolval', false), |
| 201 | 212 | 'stage' => $request->get('stage', []), |
| 202 | 213 | 'task_status' => $request->get('task_status', []), |
| 214 | + 'recurring' => $request->get('recurring', []), | |
| 215 | + 'template' => $request->get('template', []), | |
| 203 | 216 | 'priority' => $request->get('priority', []), |
| 204 | 217 | 'assignee' => $request->get('assignee', []), |
| 205 | 218 | 'labels' => $request->get('labels', []), |
| 206 | 219 | 'watchers' => $request->get('watchers', []), |
| @@ -408,8 +421,10 @@ | ||
| 408 | 421 | * @param array $options |
| 409 | 422 | */ |
| 410 | 423 | private function processTasks($tasks, $board, $options = []) |
| 411 | 424 | { |
| 425 | + $this->taskService->loadTaskListMetadata($tasks); | |
| 426 | + | |
| 412 | 427 | $includeContact = Arr::get($options, 'includeContact', true); |
| 413 | 428 | $includeObserverState = Arr::get($options, 'includeObserverState', true); |
| 414 | 429 | $includeRoadmapPopularity = Arr::get($options, 'includeRoadmapPopularity', true); |
| 415 | 430 | $taskIds = []; |
| @@ -541,8 +556,10 @@ | ||
| 541 | 556 | return [ |
| 542 | 557 | 'task' => $task |
| 543 | 558 | ]; |
| 544 | 559 | |
| 560 | + } catch (ModelNotFoundException $e) { | |
| 561 | + throw $e; | |
| 545 | 562 | } catch (\Exception $e ) { |
| 546 | 563 | return $this->sendError($e->getMessage(), 400); |
| 547 | 564 | } |
| 548 | 565 | |