( context: TaskCardRelationshipExpansionContext, card: HTMLElement, task: TaskInfo, expanded: boolean )
| 139 | } |
| 140 | |
| 141 | export async function toggleSubtasksExpansion( |
| 142 | context: TaskCardRelationshipExpansionContext, |
| 143 | card: HTMLElement, |
| 144 | task: TaskInfo, |
| 145 | expanded: boolean |
| 146 | ): Promise<void> { |
| 147 | const { plugin } = context; |
| 148 | const logger = getTaskCardExpansionLogger(plugin); |
| 149 | |
| 150 | try { |
| 151 | if (!expanded) { |
| 152 | removeRelationshipContainer(card, ".task-card__subtasks"); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | const container = ensureRelationshipContainer( |
| 157 | card, |
| 158 | ".task-card__subtasks", |
| 159 | "task-card__subtasks" |
| 160 | ); |
| 161 | clearContainer(container); |
| 162 | |
| 163 | const loadingEl = container.createEl("div", { |
| 164 | cls: "task-card__subtasks-loading", |
| 165 | text: plugin.i18n.translate("contextMenus.task.subtasks.loading"), |
| 166 | }); |
| 167 | |
| 168 | try { |
| 169 | const file = plugin.app.vault.getAbstractFileByPath(task.path); |
| 170 | if (!(file instanceof TFile)) { |
| 171 | throw new Error("Task file not found"); |
| 172 | } |
| 173 | |
| 174 | if (!plugin.projectSubtasksService) { |
| 175 | throw new Error("projectSubtasksService not initialized"); |
| 176 | } |
| 177 | |
| 178 | const relationshipOptions = getRelationshipOptions(context, card); |
| 179 | const subtasks = filterExpandedRelationshipTasks( |
| 180 | await plugin.projectSubtasksService.getTasksLinkedToProject(file), |
| 181 | relationshipOptions |
| 182 | ); |
| 183 | |
| 184 | loadingEl.remove(); |
| 185 | |
| 186 | if (subtasks.length === 0) { |
| 187 | container.createEl("div", { |
| 188 | cls: "task-card__subtasks-loading", |
| 189 | text: plugin.i18n.translate("contextMenus.task.subtasks.noSubtasks"), |
| 190 | }); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | const sortedSubtasks = sortExpandedRelationshipTasks( |
| 195 | subtasks, |
| 196 | relationshipOptions, |
| 197 | (tasks) => plugin.projectSubtasksService.sortTasks(tasks) |
| 198 | ); |
no test coverage detected